Skip to main content

Track Lakegres Queries with Trace IDs

Lakegres gives each query that runs on an engine a trace ID. Onehouse uses this ID to find the query in its logs and traces. You can read the trace ID of your last query and record it in your own audit table. When you open a support ticket, give the trace ID so that Onehouse can find the query immediately.

Get the Trace ID of a Query​

Run SHOW last_trace_id on the same connection, immediately after the query:

SELECT count(*) FROM sales.orders WHERE order_date = '2026-09-01';

SHOW last_trace_id;
          last_trace_id
----------------------------------
8bc583f50c189db2b7bd55cd0ce55843

Lakegres answers SHOW last_trace_id directly. The statement does not go to an engine, so it adds almost no latency and uses no engine capacity. The statement is not case-sensitive.

The trace ID is usually 32 hexadecimal characters. Treat it as an opaque string of up to 36 characters.

Failed Queries​

For a failed query, SHOW last_trace_id returns an empty value. The error message contains the trace ID in the form [trace_id=<id>]:

ERROR:  HTTP request failed [trace_id=4f1c0e9a7b2d4c6e8f0a1b2c3d4e5f60] with status 400: ...

Get the ID from the error message with this regular expression: \[trace_id=([^\]]+)\].

How the Value Changes​

The value belongs to one connection. Other connections, and other users, do not change it.

Statement on the connectionEffect on last_trace_id
Query that runs on an engine and succeedsSet to the ID of that query
Query that runs on an engine and failsCleared (empty). Use the ID in the error message.
Statement that Lakegres answers without an engine, such as SET or SHOWNo change
DECLARE ... CURSOR and the FETCH statements that read itNo change
New connection, before the first engine queryEmpty
Server-side cursors

Server-side cursors do not set the trace ID. After a cursor query, SHOW last_trace_id returns the ID of the previous engine query. In psycopg2, a named cursor (connection.cursor(name="...")) is a server-side cursor. Do not record a trace ID for these queries.

Interactive Tools​

In psql, DBeaver, and other SQL editors, run SHOW last_trace_id after the query in the same session. In DBeaver, run it in the same SQL editor tab. BI tools such as Tableau and Power BI do not read the trace ID.

Limitations​

  • The trace ID is available only on the connection that ran the query. Lakegres does not keep a query history that you can query.
  • Server-side cursors (DECLARE ... CURSOR) do not set the trace ID.
  • For a failed query, the trace ID is available only in the error message.
  • If SHOW last_trace_id returns a column named unsupported_show_statement, your cluster does not have this feature yet. Contact Onehouse support.