CREATE EXTENSION pg_stat_monitor; SET pg_stat_monitor.pgsm_track_utility = on; SET pg_stat_monitor.pgsm_track_planning = on; SET pg_stat_monitor.pgsm_normalized_query = on; -- -- Do not store queries without a query identifier -- SET compute_query_id = off; SELECT pg_stat_monitor_reset() IS NOT NULL AS t; t --- t (1 row) SELECT 1 AS no_query_id; no_query_id ------------- 1 (1 row) CREATE TABLE no_query_id_tab (x int); INSERT INTO no_query_id_tab VALUES (1); SELECT x FROM no_query_id_tab; x --- 1 (1 row) PREPARE no_query_id_prep AS SELECT x FROM no_query_id_tab WHERE x = $1; EXECUTE no_query_id_prep(1); x --- 1 (1 row) DEALLOCATE no_query_id_prep; DROP TABLE no_query_id_tab; DO $$ BEGIN PERFORM 1; END $$; -- Nothing of the above was recorded. SELECT count(*) FROM pg_stat_monitor; count ------- 0 (1 row) -- -- Tracking resumes once query identifiers are computed again. -- RESET compute_query_id; SELECT pg_stat_monitor_reset() IS NOT NULL AS t; t --- t (1 row) SELECT 1 AS with_query_id; with_query_id --------------- 1 (1 row) SELECT calls, query FROM pg_stat_monitor WHERE query LIKE '%with_query_id%' ORDER BY query COLLATE "C"; calls | query -------+---------------------------- 1 | SELECT $1 AS with_query_id (1 row) SELECT pg_stat_monitor_reset() IS NOT NULL AS t; t --- t (1 row) DROP EXTENSION pg_stat_monitor;