> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# List Slow Queries

> List the top 20 queries by cumulative total execution time, excluding the postgres database. Uses the latest available metrics within the lookback range; statistics are cumulative PostgreSQL counters, not deltas over that range. Returns full query text and execution times in seconds.



## OpenAPI

````yaml /machines-api/openapi.json get /v1/postgres/{postgres_cluster_id}/queries/slow
openapi: 3.0.1
info:
  title: Machines API
  description: >-
    This site hosts documentation generated from the Fly.io Machines API OpenAPI
    specification. Visit our complete [Machines API
    docs](https://fly.io/docs/machines/api/) for how to get started, more
    information about each endpoint, parameter descriptions, and examples.
  contact: {}
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: '1.0'
servers:
  - url: https://api.machines.dev
security: []
tags:
  - name: Apps
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/apps-resource/) for details about
      using the Apps resource.
  - name: Machines
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/machines-resource/) for details
      about using the Machines resource.
  - name: TLS Certificates
    description: >
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/certificates-resource/) for details
      about using the TLS Certificates resource.
  - name: Volumes
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/volumes-resource/) for details
      about using the Volumes resource.
  - name: Postgres Clusters
    description: >-
      Create and manage Postgres clusters, including databases, users,
      extensions, backups, and app attachments.
externalDocs:
  url: https://fly.io/docs/machines/working-with-machines/
paths:
  /v1/postgres/{postgres_cluster_id}/queries/slow:
    get:
      tags:
        - Postgres Clusters
      summary: List Slow Queries
      description: >-
        List the top 20 queries by cumulative total execution time, excluding
        the postgres database. Uses the latest available metrics within the
        lookback range; statistics are cumulative PostgreSQL counters, not
        deltas over that range. Returns full query text and execution times in
        seconds.
      operationId: Postgres_queries_slow
      parameters:
        - name: postgres_cluster_id
          in: path
          description: Managed Postgres Cluster ID
          required: true
          schema:
            type: string
        - name: range
          in: query
          description: Metrics lookback in seconds
          schema:
            maximum: 604800
            minimum: 1
            type: integer
            default: 3600
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/listPostgresSlowQueriesResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '422':
          description: range must be an integer between 1 and 604800 seconds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '500':
          description: Unable to load slow query metrics
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
      security:
        - FlyBearerAuth: []
components:
  schemas:
    listPostgresSlowQueriesResponse:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/PostgresSlowQuery'
    PostgresErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
    PostgresSlowQuery:
      type: object
      properties:
        calls:
          type: integer
          description: Cumulative number of executions.
        database:
          type: string
          description: Database name.
        max_exec_time_seconds:
          type: number
          description: Maximum execution time in seconds.
        mean_exec_time_seconds:
          type: number
          description: Mean execution time in seconds.
        query:
          type: string
          description: Full query pattern.
        query_id:
          type: string
          description: Query identifier.
        total_exec_time_seconds:
          type: number
          description: Cumulative total execution time in seconds.
        user:
          type: string
          description: User running the query.
  securitySchemes:
    FlyBearerAuth:
      type: apiKey
      description: >-
        A Fly API token with access to the requested organization or resource.
        Send it as `Authorization: Bearer <Fly API token>`.
      name: Authorization
      in: header

````