Cloudpepper Query Insights API

The Query Insights API from Cloudpepper — 6 operation(s) for query insights.

GitHub OpenAPI

Operations 6

GET /instances/{id}/slow-queries List slow queries #
GET /instances/{id}/running-statements List live non-idle backends #
GET /instances/{id}/index-health Get index health signals #
GET /instances/{id}/query-plan Get a generic execution plan for a query #
POST /instances/{id}/index-changes Apply an index change (create or drop) #
GET /instances/{id}/index-changes/resolve Resolve an index or table (typed-name confirm + create-build poll) #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/cloudpepper-io:cloudpepper-io-query-insights-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

cloudpepper-io-query-insights-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Cloudpepper Io Query Insights API
  version: 1.0.0
  description: 'Operations tagged Query Insights across 2 of this provider''s published API definitions: cloudpepper-io-openapi.json, cloudpepper-io-openapi.yml. Each path carries the servers of the definition it was published in.'
servers:
- url: /
- url: https://api.cloudpepper.io
  description: Resolved from the published relative server "/" against the host serving the spec (https://api.cloudpepper.io/openapi.json)
security:
- bearerAuth: []
tags:
- name: Query Insights
paths:
  /instances/{id}/slow-queries:
    parameters:
    - name: id
      in: path
      description: Instance id
      required: true
      schema:
        type: string
    - name: sort
      in: query
      description: Metric to order the returned queries by
      required: false
      schema:
        type: string
        default: total_time
        enum:
        - total_time
        - mean_time
        - max_time
        - calls
        - rows
        - io_time
        - temp_blocks
    - name: limit
      in: query
      description: Maximum number of queries to return (1-100)
      required: false
      schema:
        type: integer
        default: 20
        minimum: 1
        maximum: 100
    get:
      tags:
      - Query Insights
      summary: List slow queries
      description: 'Returns the slowest statements for the instance database from pg_stat_statements, ordered by the selected metric, with query text redacted of literals. Read-only (each call runs in a READ ONLY transaction with statement and lock timeouts). Requires the host to have query insights enabled (pg_stat_statements preloaded); otherwise the endpoint returns HTTP 409 and the body carries a machine-readable `reason`.


        **Key Parameters:**

        - `id`: The instance whose database to inspect

        - `sort`: Which metric to order by

        - `limit`: How many rows to return'
      responses:
        '200':
          description: Slow queries retrieved successfully
          content:
            application/json:
              schema:
                type: object
              example:
                status: available
                database: tenantdb
                metadata:
                  sort: total_time
                  limit: 20
                  server_version_num: 160004
                  query_text_redacted: true
                queries:
                - queryid: '123456789'
                  query: SELECT * FROM res_partner WHERE id = ?
                  calls: 1200
                  total_time_ms: 9000.5
                  mean_time_ms: 7.5
        '400':
          description: Invalid request parameters
        '404':
          description: Instance not found
        '409':
          description: Query insights not enabled on this host (see body `reason`)
      operationId: getInstancesByIdSlowQueries
      x-operation-id-source: derived
    servers:
    - url: /
  /instances/{id}/running-statements:
    parameters:
    - name: id
      in: path
      description: Instance id
      required: true
      schema:
        type: string
    - name: min_duration_ms
      in: query
      description: Only return statements whose current activity has lasted at least this many milliseconds (active queries by query age, idle-in-transaction by how long they have been idle). 0 returns everything not plain-idle.
      required: false
      schema:
        type: integer
        default: 0
        minimum: 0
        maximum: 86400000
    - name: limit
      in: query
      description: Maximum number of statements to return, longest-running first (1-200)
      required: false
      schema:
        type: integer
        default: 50
        minimum: 1
        maximum: 200
    get:
      tags:
      - Query Insights
      summary: List live non-idle backends
      description: 'Real-time snapshot of the non-idle backends on the instance database, from pg_stat_activity (core view; needs no pg_stat_statements). Complements slow-queries (historical/aggregate): for live incidents — lock chains (`blocked_by`/`is_blocked` via pg_blocking_pids), long-open transactions, idle-in-transaction holders (where `query` is the last statement, not a running one), and connection saturation (`connection_summary`). Rows are tenant-scoped by datname; plain-idle pooled connections are counted in the summary but omitted from the list; parallel workers fold into their leader. Query text is redacted of literals. Read-only (READ ONLY transaction as the least-privilege cloudpepper_insights role, statement/lock timeouts); diagnostic only — it does not cancel/terminate. Out-of-range `min_duration_ms`/`limit` are clamped. Hosts without query insights enabled return HTTP 409 with a machine-readable `reason`.


        **Key Parameters:**

        - `id`: The instance whose database to inspect

        - `min_duration_ms`: Floor on how long a backend has been running/stuck

        - `limit`: How many to return (longest first)'
      responses:
        '200':
          description: Running statements retrieved successfully
          content:
            application/json:
              schema:
                type: object
              example:
                status: available
                database: tenantdb
                metadata:
                  sampled_at: '2026-06-04T08:21:09.482Z'
                  server_version_num: 160004
                  max_connections: 100
                  min_duration_ms: 0
                  limit: 50
                  query_text_redacted: true
                connection_summary:
                  database:
                    total: 14
                    active: 3
                    idle: 9
                    idle_in_transaction: 1
                    lock_waiting: 1
                  cluster:
                    client_backends: 22
                    max_connections: 100
                    used_pct: 22.0
                statements:
                - pid: 48213
                  state: active
                  backend_type: client backend
                  wait_event_type: Lock
                  wait_event: transactionid
                  waiting: true
                  usename: odoo
                  client_addr: 10.0.0.5
                  application_name: odoo
                  query_start: '2026-06-04T08:18:41.001Z'
                  xact_start: '2026-06-04T08:18:40.580Z'
                  state_change: '2026-06-04T08:18:41.001Z'
                  runtime_ms: 148481
                  transaction_runtime_ms: 148902
                  queryid: '123456789'
                  blocked_by:
                  - 48109
                  is_blocked: true
                  query: UPDATE sale_order SET state = ? WHERE id = ?
                  query_truncated: false
        '404':
          description: Instance not found
        '409':
          description: 'Running statements could not be inspected — body `reason` says which: `query_insights_not_enabled`, `instance_database_not_found`, `external_database_not_supported`, or `running_statements_failed`'
      operationId: getInstancesByIdRunningStatements
      x-operation-id-source: derived
    servers:
    - url: /
  /instances/{id}/index-health:
    parameters:
    - name: id
      in: path
      description: Instance id
      required: true
      schema:
        type: string
    get:
      tags:
      - Query Insights
      summary: Get index health signals
      description: 'Returns read-only index-health signals for the instance database from PostgreSQL catalogs: tables with heavy sequential scans, unused indexes, duplicate indexes, and Odoo many2one fields lacking a leading btree index. Signals are raw and intentionally conservative (unique/primary indexes are excluded from unused-index signals); interpretation is left to the caller. Returns HTTP 409 with a `reason` if the database is not reachable for inspection.


        **Key Parameters:**

        - `id`: The instance whose database to inspect'
      responses:
        '200':
          description: Index health signals retrieved successfully
          content:
            application/json:
              schema:
                type: object
              example:
                status: available
                database: tenantdb
                metadata:
                  source: postgres_catalogs
                  limit_per_section: 30
                sequential_scan_tables: []
                unused_indexes: []
                duplicate_indexes: []
                odoo_unindexed_fields: []
        '404':
          description: Instance not found
        '409':
          description: Query insights not enabled or database not reachable (see body `reason`)
      operationId: getInstancesByIdIndexHealth
      x-operation-id-source: derived
    servers:
    - url: /
  /instances/{id}/query-plan:
    parameters:
    - name: id
      in: path
      description: Instance id
      required: true
      schema:
        type: string
    - name: queryid
      in: query
      description: pg_stat_statements queryid (a signed 64-bit integer string, obtained from the slow-queries endpoint) to plan
      required: true
      schema:
        type: string
    get:
      tags:
      - Query Insights
      summary: Get a generic execution plan for a query
      description: 'Returns EXPLAIN (GENERIC_PLAN, FORMAT JSON) for the normalized query text of the given pg_stat_statements queryid. The query is never executed (no ANALYZE) and is only planned if its stored text is fully normalized (contains no literals) and is a single SELECT/WITH statement. PostgreSQL 16+ only. A reachable instance whose queryid has no matching row returns HTTP 404 with `status: not_found`; unplannable/unsupported/version-too-old cases return HTTP 409 with a `reason`.


        **Key Parameters:**

        - `id`: The instance whose database to inspect

        - `queryid`: The queryid obtained from the slow-queries endpoint'
      responses:
        '200':
          description: Generic plan produced successfully
          content:
            application/json:
              schema:
                type: object
              example:
                status: available
                database: tenantdb
                query:
                  queryid: '123456789'
                  query: SELECT * FROM res_partner WHERE id = ?
                plan:
                - Plan:
                    Node Type: Index Scan
                metadata:
                  mode: EXPLAIN (GENERIC_PLAN, FORMAT JSON)
                  analyze: false
        '400':
          description: Missing or invalid queryid
        '404':
          description: 'Instance not found, or no pg_stat_statements row exists for the queryid (body `status`: not_found)'
        '409':
          description: Query insights unavailable, query unplannable, or PostgreSQL < 16 (see body `reason`)
      operationId: getInstancesByIdQueryPlan
      x-operation-id-source: derived
    servers:
    - url: /
  /instances/{id}/index-changes:
    parameters:
    - name: id
      in: path
      description: Instance id
      required: true
      schema:
        type: string
    post:
      tags:
      - Query Insights
      summary: Apply an index change (create or drop)
      description: 'Guardrailed per-index DROP / CREATE on the instance''s managed PostgreSQL database — the apply half of index-health. Not a SQL runner: inputs are bare identifiers and a fixed non-unique btree shape, every executed statement is assembled from the database''s own quote_ident() tokens, and a refuse-ladder rejects any integrity index (primary/unique/exclusion/constraint-backed/replica-identity/extension-owned/partitioned) and any used index (idx_scan > 0) before execution.


        **drop_index** runs synchronously (DROP INDEX CONCURRENTLY) and returns `status: applied`.


        **create_index** is validated synchronously and the online build (CREATE INDEX CONCURRENTLY) is handed to a background worker — the endpoint returns HTTP 202 `status: accepted`. Poll the resolve endpoint (type=index, name=) until it reports `valid: true`. btree-only; UNIQUE is not supported in v1.


        **Key Parameters:**

        - `id`: The instance whose database to change

        - `action`: `create_index` or `drop_index`'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - action
              properties:
                action:
                  type: string
                  enum:
                  - create_index
                  - drop_index
                table:
                  type: string
                  description: create_index only — the table to index (bare identifier, schema public)
                columns:
                  type: array
                  items:
                    type: string
                  description: create_index only — 1 to 8 distinct columns (bare identifiers)
                method:
                  type: string
                  enum:
                  - btree
                  default: btree
                  description: create_index only — btree is the only supported method in v1
                index_name:
                  type: string
                  description: drop_index only — the index to drop (bare identifier, schema public)
            examples:
              create_index:
                summary: Create a btree index online (async)
                value:
                  action: create_index
                  table: sale_order_line
                  columns:
                  - order_id
                  method: btree
              drop_index:
                summary: Drop an unused index online
                value:
                  action: drop_index
                  index_name: sale_order_line_create_uid_idx
      responses:
        '200':
          description: drop_index applied (DROP INDEX CONCURRENTLY completed)
          content:
            application/json:
              schema:
                type: object
              example:
                status: applied
                action: drop_index
                message: Dropped index sale_order_line_create_uid_idx on sale_order_line.
                database: tenantdb
                index:
                  schema: public
                  name: sale_order_line_create_uid_idx
                  table: sale_order_line
                  idx_scan: 0
                  stats_reset: '2026-05-01T00:00:00+00:00'
                  origin: unknown
                  recreate_sql: CREATE INDEX sale_order_line_create_uid_idx ON public.sale_order_line USING btree (create_uid)
        '202':
          description: 'create_index accepted — the online build runs in the background; poll the resolve endpoint (type=index) until `valid: true`'
          content:
            application/json:
              schema:
                type: object
              example:
                status: accepted
                action: create_index
                message: 'Index sale_order_line_order_id_idx is being created online on sale_order_line; an online build can take minutes. Poll resolve (type=index, name=sale_order_line_order_id_idx): valid=true means done. It reads valid=false while building; if it stays not_found or invalid past a few minutes the build likely failed — re-check index health and drop any leftover INVALID index before retrying.'
                database: tenantdb
                index:
                  schema: public
                  name: sale_order_line_order_id_idx
                  table: sale_order_line
                  columns:
                  - order_id
                  method: btree
                  undo_sql: DROP INDEX CONCURRENTLY IF EXISTS public.sale_order_line_order_id_idx
        '400':
          description: 'Invalid request (body `status`: invalid, with a machine-readable `reason`, e.g. invalid_action / invalid_table_name / invalid_columns / unsupported_method)'
        '404':
          description: 'Instance, table, column, or index not found (body `status`: not_found, with `reason`)'
        '409':
          description: 'Refused by the safety ladder or unavailable (body `status`: refused | unavailable, with `reason`, e.g. index_is_unique / index_in_use / index_too_large / postgres_version_too_old / external_database_not_supported)'
      operationId: postInstancesByIdIndexChanges
      x-operation-id-source: derived
    servers:
    - url: /
  /instances/{id}/index-changes/resolve:
    parameters:
    - name: id
      in: path
      description: Instance id
      required: true
      schema:
        type: string
    - name: type
      in: query
      description: 'What to resolve: an existing index (for drop / create-build poll) or a table (for create)'
      required: true
      schema:
        type: string
        enum:
        - index
        - table
    - name: name
      in: query
      description: The bare identifier to resolve (index name when type=index, table name when type=table)
      required: true
      schema:
        type: string
    get:
      tags:
      - Query Insights
      summary: Resolve an index or table (typed-name confirm + create-build poll)
      description: 'Echoes the canonical index/table name so a client can verify a typed-name confirmation before applying a change. For `type=index` it also runs the same version + refuse ladder the drop would (so it never reports an index as droppable that the apply would refuse) and returns `valid` (the catalog indisvalid): poll this after a create_index until `valid: true` — the index reads `valid: false` while CONCURRENTLY is still building it, and not_found after a few minutes means the build failed.


        **Key Parameters:**

        - `id`: The instance whose database to inspect

        - `type`: `index` or `table`

        - `name`: The identifier to resolve'
      responses:
        '200':
          description: 'Resolved (body `status`: available)'
          content:
            application/json:
              schema:
                type: object
              examples:
                index:
                  summary: type=index
                  value:
                    status: available
                    type: index
                    found: true
                    name: sale_order_line_order_id_idx
                    table: sale_order_line
                    idx_scan: 0
                    origin: unknown
                    valid: true
                    droppable: true
                    refuse_reason: null
                    refuse_message: null
                    database: tenantdb
                table:
                  summary: type=table
                  value:
                    status: available
                    type: table
                    found: true
                    name: sale_order_line
                    database: tenantdb
        '400':
          description: 'Invalid request (body `status`: invalid, e.g. invalid_resolve_type / invalid_index_name / invalid_table_name)'
        '404':
          description: 'Instance, index, or table not found (body `status`: not_found)'
        '409':
          description: 'Unavailable (body `status`: unavailable, e.g. external_database_not_supported / postgres_version_too_old)'
      operationId: getInstancesByIdIndexChangesResolve
      x-operation-id-source: derived
    servers:
    - url: /
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
x-refined-from:
- cloudpepper-io-openapi.json
- cloudpepper-io-openapi.yml