API Keys
Using the ClickHouse OpenAPI requires authentication; see API keys for how to create them. Then use them via basic auth credentials like so:Organization ID
Next you’ll need your organization ID.- Select your organization name in the lower left corner of the console.
- Select Organization details.
- Hit the copy icon to the right of Organization ID to copy it directly to your clipboard.
CRUD
Let’s explore the lifecycle of a Postgres service.Create
First, create a new one using the create API. It requires the following properties in the JSON body of the request:name: Name of the new Postgres serviceprovider: Name of the cloud provider:aws(orgcpin Private Preview)region: Region within the provider’s network in which to deploy the servicesize: The VM size
Read
Use theid from the response to fetch the service again:
state; when it changes to running, the server is ready:
connectionString property saved from the create response
to connect, for example via psql:
\q to exit psql.
Update
The patch API supports updating a subset of the properties of a Managed Postgres service via RFC 7396 JSON Merge Patch. Tags may be of particular interest for complex deployments; simply send them alone in the request:Delete
Use the delete API to delete a Postgres service.Monitoring
Two Prometheus-compatible endpoints expose CPU, memory, I/O, connection, and transaction metrics for ClickHouse Managed Postgres services: one returns metrics for every service in the organization, the other for a single service. See the Prometheus endpoint page for setup and the metrics reference for the full list of metrics.Query insights
The per-statement telemetry behind the Query Insights tab in the cloud console is also available programmatically. Two endpoints expose the slowest query patterns on a service: one lists every pattern ranked by impact, the other returns a single pattern with its recent executions. A third lists the queries that waited on locks and the sessions that blocked them.List slow query patterns
The slow patterns API returns aggregate metrics for the slowest query patterns observed over a time window. The window is required — passfrom_date and to_date as RFC 3339 timestamps:
total_duration
descending. Sort by a different counter with sort_by (for example
p99_duration, call_count, or total_wal_bytes) and flip the direction
with sort_order. Narrow the set with the db_name, db_user,
db_operation, and app filters, and page through it with limit and
offset.
Each result is one normalized pattern, with literals stripped out and
durations reported in microseconds:
queryId is a signed 64-bit hash of the normalized statement, so it’s
often negative. Pass it back verbatim — leading - and all — to fetch a
single pattern.
Get a slow query pattern
Pass aqueryId from the list response to the slow pattern API to get that
pattern’s aggregate metrics alongside its most recent individual executions.
The db_name, db_user, and db_operation that identify the pattern are
required:
aggregate, plus a recentExecutions array. Each execution includes the
full per-execution counters — shared and temp block I/O, CPU user and system
time, parallel workers, JIT, and WAL — the same counters the
detail flyout breaks down in the console:
List blocking queries
TheblockingQueries endpoint returns the same groups as the
Blocking queries table in the console: each result pairs one waiting query
with one direct blocker, most frequently seen first. It has data only for
periods when blocking query collection was on for the service. Pass
from_date and to_date as RFC 3339 timestamps. to_date must be after
from_date, and the range must not exceed 31 days:
db_name, db_user, or app; an empty
app= matches sessions with no application name. Page through the results
with limit (up to 2000, default 50) and offset, and use totalCount to
see how many groups match.
Fields that start with blocked describe the waiting sessions, and fields
that start with blocking describe the blocker. lockType, blockedMode,
and the latest* fields come from the most recent sample:
blockingQuery is the blocker’s current or most recent
statement, which may not be the one that took the lock. blockedQuery and
blockingQuery are empty when Query Insights has no text for the statement,
and blockingQuery is also empty when blockingInternal or
blockingPrepared is true. A prepared transaction reports blockingPids
as [0].
Server logs
The PostgreSQL server logs behind the logs viewer in the cloud console are also available programmatically. The logs API returns individual log entries for a service over a time window. As with query insights, the window is required, so passfrom_date and to_date as RFC 3339 timestamps. The range must not exceed
30 days, and to_date must be after from_date:
sort_order (asc or
desc). Filter to a single severity with severity (for example ERROR,
WARNING, or LOG), match a case-sensitive substring of the log body with
body_contains, and page through the results with limit and offset.
Each entry carries its timestamp, severity, and raw body. The body is
always a string: structured log lines are returned JSON-encoded, plain lines
verbatim:
limit and offset rather than returning a total
count; advance offset until a page returns fewer than limit entries.