Skip to main content

slow_query_patterns

Creates, updates, deletes, gets or lists a slow_query_patterns resource.

Overview

Nameslow_query_patterns
TypeResource
Idclickhouse.postgres.slow_query_patterns

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
aggregateobject
recent_executionsarrayRecent individual executions matching the pattern. (wire: recentExecutions)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectpostgres_id, query_id, db_name, db_user, db_operation, organization_idapp, timestampThis endpoint is in beta. API contract is stable, and no breaking changes are expected in the future. <br /><br /> Returns aggregate metrics for a single slow query pattern together with its most recent individual executions.
listselectpostgres_id, from_date, to_date, organization_iddb_name, db_user, db_operation, app, sort_by, sort_order, limit, offsetThis endpoint is in beta. API contract is stable, and no breaking changes are expected in the future. <br /><br /> Returns aggregate metrics for the slowest query patterns observed on a Postgres service during the given time window. Use this to discover which queries dominate total execution time, CPU, I/O, or WAL generation.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
db_namestringDatabase name filter.
db_operationstringDatabase operation filter (for example, SELECT, INSERT, UPDATE, DELETE, UTILITY).
db_userstringDatabase user filter.
from_datestring (date-time)Inclusive start of the time window (RFC 3339 date-time).
organization_idstringClickHouse Cloud organization ID. Resolved from the CLICKHOUSE_ORG_ID environment variable when it is set (x-stackQL-envVar); otherwise it must be supplied on every query as WHERE organization_id = <uuid>. A WHERE value always takes precedence over the environment. (x-stackQL-envVar: CLICKHOUSE_ORG_ID)
postgres_idstring (uuid)ID of the requested Postgres service. (wire: postgresId)
query_idstringStable identifier for the query pattern. (wire: queryId)
to_datestring (date-time)Exclusive end of the time window (RFC 3339 date-time).
appstringApplication name filter.
db_namestringDatabase name filter.
db_operationstringDatabase operation filter (for example, SELECT, INSERT, UPDATE, DELETE, UTILITY).
db_userstringDatabase user filter.
limitintegerMaximum number of results to return.
offsetintegerNumber of results to skip before returning.
sort_bystringField to sort results by.
sort_orderstringSort order. One of asc or desc.
timestampstring (date-time)Timestamp of a specific execution (RFC 3339).

SELECT examples

This endpoint is in beta. API contract is stable, and no breaking changes are expected in the future. <br /><br /> Returns aggregate metrics for a single slow query pattern together with its most recent individual executions.

SELECT
aggregate,
recent_executions
FROM clickhouse.postgres.slow_query_patterns
WHERE postgres_id = '{{ postgres_id }}' -- required
AND query_id = '{{ query_id }}' -- required
AND db_name = '{{ db_name }}' -- required
AND db_user = '{{ db_user }}' -- required
AND db_operation = '{{ db_operation }}' -- required
AND organization_id = '{{ organization_id }}' -- required unless CLICKHOUSE_ORG_ID is set
AND app = '{{ app }}'
AND timestamp = '{{ timestamp }}'
;