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

# Clickhouse Slow Query Pattern Get: Inputs, Cost & CLI

> Get a Postgres slow query pattern with recent executions. Includes inputs, outputs, pricing notes, Deepline CLI examples, and GTM automation guidance.

## Run in Enrichment Spreadsheet

<Info>
  Use this function as a column step in `deepline enrich`.
</Info>

```bash theme={null}
deepline enrich --input leads.csv --output leads.enriched.csv --with 'result=clickhouse_slow_query_pattern_get:{"organizationId":"{{organizationId}}","postgresId":"{{postgresId}}","queryId":"{{queryId}}","db_name":"{{db_name}}","db_user":"{{db_user}}","db_operation":"{{db_operation}}"}' --json
```

<Tip>
  Map payload values to spreadsheet columns with `{{column_name}}` placeholders.
</Tip>

## Input Schema

| Name                     | Type     | Required | Default | Description                                                                       |
| ------------------------ | -------- | -------- | ------- | --------------------------------------------------------------------------------- |
| `payload.organizationId` | `string` | Yes      |         | ID of the organization that owns the Postgres service.                            |
| `payload.postgresId`     | `string` | Yes      |         | ID of the requested Postgres service.                                             |
| `payload.queryId`        | `string` | Yes      |         | Stable identifier for the query pattern.                                          |
| `payload.db_name`        | `string` | Yes      |         | Database name filter.                                                             |
| `payload.db_user`        | `string` | Yes      |         | Database user filter.                                                             |
| `payload.db_operation`   | `string` | Yes      |         | Database operation filter (for example, SELECT, INSERT, UPDATE, DELETE, UTILITY). |
| `payload.app`            | `string` | No       |         | Application name filter.                                                          |
| `payload.timestamp`      | `string` | No       |         | Timestamp of a specific execution (RFC 3339).                                     |

<details>
  <summary>Show raw input schema</summary>

  ### Input JSON Schema

  ```json theme={null}
  {
    "type": "object",
    "description": "**This endpoint is in beta.** API contract is stable, and no breaking changes are expected in the future. Returns aggregate metrics for a single slow query pattern together with its most recent individual executions.",
    "properties": {
      "organizationId": {
        "type": "string",
        "description": "ID of the organization that owns the Postgres service.",
        "format": "uuid"
      },
      "postgresId": {
        "type": "string",
        "description": "ID of the requested Postgres service.",
        "format": "uuid"
      },
      "queryId": {
        "type": "string",
        "description": "Stable identifier for the query pattern."
      },
      "db_name": {
        "type": "string",
        "description": "Database name filter."
      },
      "db_user": {
        "type": "string",
        "description": "Database user filter."
      },
      "db_operation": {
        "type": "string",
        "description": "Database operation filter (for example, SELECT, INSERT, UPDATE, DELETE, UTILITY)."
      },
      "app": {
        "type": "string",
        "description": "Application name filter."
      },
      "timestamp": {
        "type": "string",
        "description": "Timestamp of a specific execution (RFC 3339).",
        "format": "date-time"
      }
    },
    "required": [
      "organizationId",
      "postgresId",
      "queryId",
      "db_name",
      "db_user",
      "db_operation"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Output Schema

| Name          | Type     | Required | Default | Description                                    |
| ------------- | -------- | -------- | ------- | ---------------------------------------------- |
| `result.data` | `object` | Yes      |         | Provider response payload.                     |
| `result.meta` | `object` | No       |         | Additional response metadata (status, paging). |

<details>
  <summary>Show raw output schema</summary>

  ### Output JSON Schema

  ```json theme={null}
  {
    "type": "object",
    "description": "Standard tool result payload.",
    "properties": {
      "data": {
        "type": "object",
        "description": "Provider response payload.",
        "properties": {
          "status": {
            "type": "number",
            "description": "HTTP status code."
          },
          "requestId": {
            "type": "string",
            "description": "Unique id assigned to every request. UUIDv4",
            "format": "uuid"
          },
          "result": {
            "properties": {
              "aggregate": {
                "properties": {
                  "queryId": {
                    "type": "string",
                    "description": "Stable identifier for the query pattern (normalized SQL)."
                  },
                  "queryText": {
                    "type": "string",
                    "description": "Normalized query text with literals replaced by placeholders."
                  },
                  "dbName": {
                    "type": "string",
                    "description": "Database the query ran in."
                  },
                  "dbUser": {
                    "type": "string",
                    "description": "Database user that executed the query."
                  },
                  "dbOperation": {
                    "type": "string",
                    "description": "Top-level SQL operation type (for example, SELECT, INSERT, UPDATE, DELETE, UTILITY)."
                  },
                  "app": {
                    "type": "string",
                    "description": "Value of the Postgres `application_name` for executions matching this pattern."
                  },
                  "callCount": {
                    "type": "integer",
                    "description": "Number of times the pattern executed in the window."
                  },
                  "errorCount": {
                    "type": "integer",
                    "description": "Number of executions of the pattern that raised an error."
                  },
                  "totalDurationUs": {
                    "type": "integer",
                    "description": "Total execution time across all calls, in microseconds."
                  },
                  "avgDurationUs": {
                    "type": "integer",
                    "description": "Average execution time per call, in microseconds."
                  },
                  "maxDurationUs": {
                    "type": "integer",
                    "description": "Maximum execution time of any call, in microseconds."
                  },
                  "p50DurationUs": {
                    "type": "integer",
                    "description": "50th percentile execution time, in microseconds."
                  },
                  "p95DurationUs": {
                    "type": "integer",
                    "description": "95th percentile execution time, in microseconds."
                  },
                  "p99DurationUs": {
                    "type": "integer",
                    "description": "99th percentile execution time, in microseconds."
                  },
                  "totalRows": {
                    "type": "integer",
                    "description": "Total number of rows returned or affected across all calls."
                  },
                  "totalSharedBlksRead": {
                    "type": "integer",
                    "description": "Total shared buffer blocks read from disk (cache misses) across all calls."
                  },
                  "totalSharedBlksHit": {
                    "type": "integer",
                    "description": "Total shared buffer blocks hit (cache hits) across all calls."
                  },
                  "totalCpuTimeUs": {
                    "type": "integer",
                    "description": "Total CPU time across all calls, in microseconds."
                  },
                  "totalWalBytes": {
                    "type": "integer",
                    "description": "Total WAL (write-ahead log) bytes generated across all calls."
                  }
                },
                "required": [
                  "queryId",
                  "queryText",
                  "dbName",
                  "dbUser",
                  "dbOperation",
                  "app",
                  "callCount",
                  "errorCount",
                  "totalDurationUs",
                  "avgDurationUs",
                  "maxDurationUs",
                  "p50DurationUs",
                  "p95DurationUs",
                  "p99DurationUs",
                  "totalRows",
                  "totalSharedBlksRead",
                  "totalSharedBlksHit",
                  "totalCpuTimeUs",
                  "totalWalBytes"
                ],
                "additionalProperties": false
              },
              "recentExecutions": {
                "type": "array",
                "description": "Recent individual executions matching the pattern.",
                "items": {
                  "properties": {
                    "timestamp": {
                      "type": "string",
                      "description": "Execution timestamp (RFC 3339).",
                      "format": "date-time"
                    },
                    "queryId": {
                      "type": "string",
                      "description": "Stable identifier for the query pattern."
                    },
                    "dbName": {
                      "type": "string",
                      "description": "Database the query ran in."
                    },
                    "dbUser": {
                      "type": "string",
                      "description": "Database user that executed the query."
                    },
                    "dbOperation": {
                      "type": "string",
                      "description": "Top-level SQL operation type."
                    },
                    "app": {
                      "type": "string",
                      "description": "Value of the Postgres `application_name` for this execution."
                    },
                    "queryText": {
                      "type": "string",
                      "description": "Normalized query text for this execution."
                    },
                    "pid": {
                      "type": "string",
                      "description": "Postgres backend process ID that executed the query."
                    },
                    "durationUs": {
                      "type": "integer",
                      "description": "Execution duration in microseconds."
                    },
                    "rows": {
                      "type": "integer",
                      "description": "Rows returned or affected."
                    },
                    "sharedBlksHit": {
                      "type": "integer",
                      "description": "Shared buffer blocks hit."
                    },
                    "sharedBlksRead": {
                      "type": "integer",
                      "description": "Shared buffer blocks read from disk."
                    },
                    "sharedBlksWritten": {
                      "type": "integer",
                      "description": "Shared buffer blocks written."
                    },
                    "sharedBlksDirtied": {
                      "type": "integer",
                      "description": "Shared buffer blocks dirtied."
                    },
                    "sharedBlkReadTimeUs": {
                      "type": "integer",
                      "description": "Time spent reading shared blocks, in microseconds."
                    },
                    "sharedBlkWriteTimeUs": {
                      "type": "integer",
                      "description": "Time spent writing shared blocks, in microseconds."
                    },
                    "localBlksHit": {
                      "type": "integer",
                      "description": "Local buffer blocks hit (temp tables)."
                    },
                    "localBlksRead": {
                      "type": "integer",
                      "description": "Local buffer blocks read (temp tables)."
                    },
                    "localBlksWritten": {
                      "type": "integer",
                      "description": "Local buffer blocks written (temp tables)."
                    },
                    "localBlksDirtied": {
                      "type": "integer",
                      "description": "Local buffer blocks dirtied (temp tables)."
                    },
                    "tempBlksRead": {
                      "type": "integer",
                      "description": "Temp blocks read (spills to disk)."
                    },
                    "tempBlksWritten": {
                      "type": "integer",
                      "description": "Temp blocks written (spills to disk)."
                    },
                    "tempBlkReadTimeUs": {
                      "type": "integer",
                      "description": "Time spent reading temp blocks, in microseconds."
                    },
                    "tempBlkWriteTimeUs": {
                      "type": "integer",
                      "description": "Time spent writing temp blocks, in microseconds."
                    },
                    "walRecords": {
                      "type": "integer",
                      "description": "Number of WAL records produced."
                    },
                    "walBytes": {
                      "type": "integer",
                      "description": "Number of WAL bytes produced."
                    },
                    "walFpi": {
                      "type": "integer",
                      "description": "Number of WAL full-page images produced."
                    },
                    "cpuUserTimeUs": {
                      "type": "integer",
                      "description": "CPU time spent in user mode, in microseconds."
                    },
                    "cpuSysTimeUs": {
                      "type": "integer",
                      "description": "CPU time spent in kernel mode, in microseconds."
                    },
                    "jitFunctions": {
                      "type": "integer",
                      "description": "Number of JIT-compiled functions."
                    },
                    "jitGenerationTimeUs": {
                      "type": "integer",
                      "description": "JIT generation time, in microseconds."
                    },
                    "jitInliningTimeUs": {
                      "type": "integer",
                      "description": "JIT inlining time, in microseconds."
                    },
                    "jitOptimizationTimeUs": {
                      "type": "integer",
                      "description": "JIT optimization time, in microseconds."
                    },
                    "jitEmissionTimeUs": {
                      "type": "integer",
                      "description": "JIT emission time, in microseconds."
                    },
                    "jitDeformTimeUs": {
                      "type": "integer",
                      "description": "JIT deform time, in microseconds."
                    },
                    "parallelWorkersPlanned": {
                      "type": "integer",
                      "description": "Parallel workers planned for this execution."
                    },
                    "parallelWorkersLaunched": {
                      "type": "integer",
                      "description": "Parallel workers actually launched for this execution."
                    },
                    "errMessage": {
                      "type": "string",
                      "description": "Error message if the execution raised an error."
                    },
                    "errSqlstate": {
                      "type": "string",
                      "description": "Postgres SQLSTATE code if the execution raised an error."
                    },
                    "errElevel": {
                      "type": "integer",
                      "description": "Postgres error severity level if the execution raised an error."
                    },
                    "serverRole": {
                      "type": "string",
                      "description": "Role of the server that executed the query (for example, primary or standby)."
                    },
                    "traceId": {
                      "type": "string",
                      "description": "OpenTelemetry trace ID associated with the execution."
                    },
                    "spanId": {
                      "type": "string",
                      "description": "OpenTelemetry span ID associated with the execution."
                    }
                  },
                  "required": [
                    "timestamp",
                    "queryId",
                    "dbName",
                    "dbUser",
                    "dbOperation",
                    "app",
                    "queryText",
                    "pid",
                    "durationUs",
                    "rows",
                    "sharedBlksHit",
                    "sharedBlksRead",
                    "sharedBlksWritten",
                    "sharedBlksDirtied",
                    "sharedBlkReadTimeUs",
                    "sharedBlkWriteTimeUs",
                    "localBlksHit",
                    "localBlksRead",
                    "localBlksWritten",
                    "localBlksDirtied",
                    "tempBlksRead",
                    "tempBlksWritten",
                    "tempBlkReadTimeUs",
                    "tempBlkWriteTimeUs",
                    "walRecords",
                    "walBytes",
                    "walFpi",
                    "cpuUserTimeUs",
                    "cpuSysTimeUs",
                    "jitFunctions",
                    "jitGenerationTimeUs",
                    "jitInliningTimeUs",
                    "jitOptimizationTimeUs",
                    "jitEmissionTimeUs",
                    "jitDeformTimeUs",
                    "parallelWorkersPlanned",
                    "parallelWorkersLaunched",
                    "serverRole"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "recentExecutions"
            ],
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "meta": {
        "type": "object",
        "description": "Additional response metadata (status, paging).",
        "additionalProperties": true
      }
    },
    "required": [
      "data"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Advanced: Direct CLI

<Info>
  Use direct execution for single payload debugging.
</Info>

```bash theme={null}
deepline tools execute clickhouse_slow_query_pattern_get --payload '{
  "organizationId": "string",
  "postgresId": "string",
  "queryId": "string",
  "db_name": "string",
  "db_user": "string",
  "db_operation": "string"
}' --json
```

### CLI flags

| Flag                        | Description                                         |
| --------------------------- | --------------------------------------------------- |
| `--json`                    | Print machine-readable output.                      |
| `--wait`                    | Wait for terminal provider status when supported.   |
| `--debug`                   | Enable wait mode with additional status/log output. |
| `--wait-timeout SECONDS`    | Max seconds to wait in wait mode.                   |
| `--poll-interval SECONDS`   | Polling interval in seconds during wait mode.       |
| `--timeout SECONDS`         | Request timeout in seconds.                         |
| `--connect-timeout SECONDS` | Connection timeout in seconds.                      |

## Cost

* Pricing model: `fixed` (per call).
* Estimated Deepline credits: `0` per pricing unit.
* Provider-native pricing may still exist outside Deepline credit billing.
* Billing mode: `no_bill`.
