Skip to content

pg_trace

Query execution tracing with shared-memory buffers, persistence, and retention controls.

pg_trace · Query execution tracing with shared-memory buffers, persistence, and retention controls.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101936pg_tracepg_trace5.0STATMITC

PostgreSQL · 16, 17, 18

Usage

Sources:

pg_trace Query execution tracing with shared-memory buffers, persistence, and retention controls.

Enablement

Install the files for the intended server, then create pg_trace in the target database:

CREATE EXTENSION pg_trace;

Core Workflow

The following example is taken from the reviewed upstream documentation. Adapt object names, paths, credentials, and workload values before use.

-- All commands in one session
SELECT pg_trace_start();
SELECT 1+1;
SELECT pg_trace_stop();
SELECT * FROM pg_trace_queries;
SELECT pg_trace_flush();

Main Objects

The reviewed install surface includes these prominent objects:

ObjectKindOperational role
pg_trace_startFUNCTIONCallable function from the reviewed install surface.
pg_trace_stopFUNCTIONCallable function from the reviewed install surface.
pg_trace_flushFUNCTIONCallable function from the reviewed install surface.
pg_trace_logTABLEExtension-owned table; account for its data in backup and upgrades.
pg_trace_queriesVIEWInspection or query view created by the extension.
pg_trace_cleanup_oldFUNCTIONCallable function from the reviewed install surface.
pg_trace_clearFUNCTIONCallable function from the reviewed install surface.
pg_trace_hourly_statsVIEWInspection or query view created by the extension.

Operations and Boundaries

  • The verified PostgreSQL-major evidence covers 16, 17, 18; do not infer unlisted majors.

Table reader