Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
build:
name: Build
runs-on: ${{ inputs.os }}
timeout-minutes: 10
timeout-minutes: 15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is this really the right commit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests run for PG19 takes slightly more time. It was added to this commit to make it atomic, so CI will pass together with PG19 related changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so then it is just in the wrong commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want this to be separate commit anyway?

steps:
- name: Remove existing PostgreSQL
if: startsWith(inputs.os, 'ubuntu-')
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
fail-fast: false
matrix:
pg_package: [source]
pg_version: [14, 15, 16, 17, 18]
pg_version: [14, 15, 16, 17, 18, 19]
os: [ubuntu-24.04]
compiler: [gcc, clang]
build_type: [debugoptimized]
Expand All @@ -74,7 +74,7 @@ jobs:
fail-fast: false
matrix:
pg_package: [source]
pg_version: [14, 15, 16, 17, 18]
pg_version: [14, 15, 16, 17, 18, 19]
os: [ubuntu-24.04]
compiler: [gcc]
build_type: [exec-backend]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Our name and version are now in `pg_get_loaded_modules()` for PostgreSQL 18+
- Support for `EXEC_BACKEND` builds ([PG-2547](https://perconadev.atlassian.net/browse/PG-2547))
- Add PostgreSQL 19 support ([PG-2424](https://perconadev.atlassian.net/browse/PG-2424)): add generic and custom plan counts, support property graphs, use ComputeConstantLengths API for constants squashing

### Changed

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ REGRESS = basic \
functions \
counters \
relations \
relations_propgraph \
database \
error_insert \
application_name \
Expand Down
201 changes: 200 additions & 1 deletion pg_stat_monitor--2.3--next.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,210 @@ DROP FUNCTION pgsm_create_view();
DROP FUNCTION pgsm_create_13_view();
DROP VIEW pg_stat_monitor;

DROP FUNCTION pg_stat_monitor_internal;

CREATE FUNCTION pg_stat_monitor_internal(
IN showtext boolean,
OUT bucket int8, -- 0
OUT userid oid,
OUT username text,
OUT dbid oid,
OUT datname text,
OUT client_ip int8,

OUT queryid int8, -- 6
OUT planid int8,
OUT query text,
OUT query_plan text,
OUT pgsm_query_id int8,
OUT top_queryid int8,
OUT top_query text,
OUT application_name text,

OUT relations text, -- 14
OUT cmd_type int,
OUT elevel int,
OUT sqlcode TEXT,
OUT message text,
OUT bucket_start_time timestamptz,

OUT calls int8, -- 20

OUT total_exec_time float8, -- 21
OUT min_exec_time float8,
OUT max_exec_time float8,
OUT mean_exec_time float8,
OUT stddev_exec_time float8,

OUT rows int8, -- 26

OUT plans int8, -- 27

OUT total_plan_time float8, -- 28
OUT min_plan_time float8,
OUT max_plan_time float8,
OUT mean_plan_time float8,
OUT stddev_plan_time float8,

OUT shared_blks_hit int8, -- 33
OUT shared_blks_read int8,
OUT shared_blks_dirtied int8,
OUT shared_blks_written int8,
OUT local_blks_hit int8,
OUT local_blks_read int8,
OUT local_blks_dirtied int8,
OUT local_blks_written int8,
OUT temp_blks_read int8,
OUT temp_blks_written int8,
OUT shared_blk_read_time float8,
OUT shared_blk_write_time float8,
OUT local_blk_read_time float8,
OUT local_blk_write_time float8,
OUT temp_blk_read_time float8,
OUT temp_blk_write_time float8,

OUT resp_calls text, -- 49
OUT cpu_user_time float8,
OUT cpu_sys_time float8,
OUT wal_records int8,
OUT wal_fpi int8,
OUT wal_bytes numeric,
OUT wal_buffers_full int8,
OUT comments TEXT,

OUT jit_functions int8, -- 57
OUT jit_generation_time float8,
OUT jit_inlining_count int8,
OUT jit_inlining_time float8,
OUT jit_optimization_count int8,
OUT jit_optimization_time float8,
OUT jit_emission_count int8,
OUT jit_emission_time float8,
OUT jit_deform_count int8,
OUT jit_deform_time float8,

OUT parallel_workers_to_launch int, -- 67
OUT parallel_workers_launched int,

OUT generic_plan_calls int8, -- 69
OUT custom_plan_calls int8,

OUT stats_since timestamp with time zone, -- 71
OUT minmax_stats_since timestamp with time zone,

OUT toplevel BOOLEAN, -- 73
OUT bucket_done BOOLEAN
)
RETURNS SETOF record
STRICT
PARALLEL SAFE
LANGUAGE c
AS 'MODULE_PATHNAME', 'pg_stat_monitor_NEXT';

CREATE FUNCTION pgsm_create_19_view()
RETURNS int
LANGUAGE plpgsql
AS $$
BEGIN
CREATE VIEW pg_stat_monitor AS SELECT
bucket,
bucket_start_time,
userid,
username,
dbid,
datname,
'0.0.0.0'::inet + client_ip AS client_ip,
pgsm_query_id,
queryid,
toplevel,
top_queryid,
query,
comments,
planid,
query_plan,
top_query,
application_name,
string_to_array(relations, ',') AS relations,
cmd_type,
get_cmd_type(cmd_type) AS cmd_type_text,
elevel,
sqlcode,
message,
calls,
total_exec_time,
min_exec_time,
max_exec_time,
mean_exec_time,
stddev_exec_time,
rows,
shared_blks_hit,
shared_blks_read,
shared_blks_dirtied,
shared_blks_written,
local_blks_hit,
local_blks_read,
local_blks_dirtied,
local_blks_written,
temp_blks_read,
temp_blks_written,
shared_blk_read_time,
shared_blk_write_time,
local_blk_read_time,
local_blk_write_time,
temp_blk_read_time,
temp_blk_write_time,

(string_to_array(resp_calls, ',')) resp_calls,
cpu_user_time,
cpu_sys_time,
wal_records,
wal_fpi,
wal_bytes,
wal_buffers_full,
bucket_done,

plans,
total_plan_time,
min_plan_time,
max_plan_time,
mean_plan_time,
stddev_plan_time,

jit_functions,
jit_generation_time,
jit_inlining_count,
jit_inlining_time,
jit_optimization_count,
jit_optimization_time,
jit_emission_count,
jit_emission_time,
jit_deform_count,
jit_deform_time,

parallel_workers_to_launch,
parallel_workers_launched,

generic_plan_calls,
custom_plan_calls,

stats_since,
minmax_stats_since

FROM pg_stat_monitor_internal(TRUE)
ORDER BY bucket_start_time;
RETURN 0;
END;
$$;

REVOKE ALL ON FUNCTION pgsm_create_19_view FROM PUBLIC;

DO $$
DECLARE
version int := current_setting('server_version_num');
BEGIN
IF version >= 180000 THEN
IF version >= 190000 THEN
PERFORM pgsm_create_19_view();
ELSEIF version >= 180000 THEN
PERFORM pgsm_create_18_view();
ELSEIF version >= 170000 THEN
PERFORM pgsm_create_17_view();
Expand Down
3 changes: 2 additions & 1 deletion regression/expected/decode_error_level.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DO $$
DECLARE
i int;
BEGIN
FOR i IN 10..24 LOOP
FOR i IN 10..25 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END
Expand All @@ -23,4 +23,5 @@ NOTICE: error_code: 21, error_level: ERROR
NOTICE: error_code: 22, error_level: FATAL
NOTICE: error_code: 23, error_level: PANIC
NOTICE: error_code: 24, error_level: <NULL>
NOTICE: error_code: 25, error_level: <NULL>
DROP EXTENSION pg_stat_monitor;
27 changes: 27 additions & 0 deletions regression/expected/decode_error_level_1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE EXTENSION pg_stat_monitor;
DO $$
DECLARE
i int;
BEGIN
FOR i IN 10..25 LOOP
RAISE NOTICE 'error_code: %, error_level: %', i, decode_error_level(i);
END LOOP;
END
$$;
NOTICE: error_code: 10, error_level: DEBUG5
NOTICE: error_code: 11, error_level: DEBUG4
NOTICE: error_code: 12, error_level: DEBUG3
NOTICE: error_code: 13, error_level: DEBUG2
NOTICE: error_code: 14, error_level: DEBUG1
NOTICE: error_code: 15, error_level: LOG
NOTICE: error_code: 16, error_level: LOG_SERVER_ONLY
NOTICE: error_code: 17, error_level: INFO
NOTICE: error_code: 18, error_level: NOTICE
NOTICE: error_code: 19, error_level: WARNING
NOTICE: error_code: 20, error_level: WARNING_CLIENT_ONLY
NOTICE: error_code: 21, error_level: ERROR
NOTICE: error_code: 22, error_level: FATAL
NOTICE: error_code: 23, error_level: FATAL_CLIENT_ONLY
NOTICE: error_code: 24, error_level: PANIC
NOTICE: error_code: 25, error_level: <NULL>
DROP EXTENSION pg_stat_monitor;
3 changes: 2 additions & 1 deletion regression/expected/functions.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ SELECT routine_schema, routine_name, routine_type, data_type FROM information_sc
public | pgsm_create_15_view | FUNCTION | integer
public | pgsm_create_17_view | FUNCTION | integer
public | pgsm_create_18_view | FUNCTION | integer
public | pgsm_create_19_view | FUNCTION | integer
public | range | FUNCTION | ARRAY
(12 rows)
(13 rows)

SET ROLE u1;
SELECT routine_schema, routine_name, routine_type, data_type FROM information_schema.routines WHERE routine_schema = 'public' ORDER BY routine_name COLLATE "C";
Expand Down
71 changes: 71 additions & 0 deletions regression/expected/level_tracking.out
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,77 @@ SELECT toplevel, calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE
t | 2 | 2 | SELECT plus_two($1)
(8 rows)

SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

(1 row)

-- planner - all-level tracking.
SET pg_stat_monitor.pgsm_track_planning = on;
-- Release all cached plans before the first function call. This matters
-- when debug_discard_caches is enabled, which would store a normalized
-- version of the inner query of the function. Forcing a plan rebuild
-- ensures that a normalized version is always stored with the stats entry,
-- while checking that the nesting level is computed correctly in the
-- planner hook.
DISCARD PLANS;
SELECT plus_three(8);
plus_three
------------
11
(1 row)

SELECT plus_three(10);
plus_three
------------
13
(1 row)

SELECT toplevel, calls, rows, plans, query FROM pg_stat_monitor
ORDER BY query COLLATE "C";
toplevel | calls | rows | plans | query
----------+-------+------+-------+--------------------------------
f | 2 | 2 | 2 | SELECT i + $2 LIMIT $3
t | 1 | 1 | 1 | SELECT pg_stat_monitor_reset()
t | 2 | 2 | 2 | SELECT plus_three($1)
(3 rows)

RESET pg_stat_monitor.pgsm_track_planning;
-- AFTER trigger SQL (ExecutorFinish) - all-level tracking.
SET pg_stat_monitor.pgsm_track = 'all';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

(1 row)

CREATE TABLE test_trigger (id int, name text);
CREATE TABLE audit_table (table_name text, action text, row_id int);
CREATE OR REPLACE FUNCTION audit_trigger_func()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO audit_table VALUES ('test_trigger', TG_OP, NEW.id);
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER audit_after_trigger
AFTER INSERT ON test_trigger
FOR EACH ROW EXECUTE FUNCTION audit_trigger_func();
INSERT INTO test_trigger VALUES (1, 'test1');
INSERT INTO test_trigger VALUES (2, 'test2');
SELECT toplevel, calls, rows, plans, query FROM pg_stat_monitor
ORDER BY query COLLATE "C";
toplevel | calls | rows | plans | query
----------+-------+------+-------+-----------------------------------------------------
f | 2 | 2 | 2 | INSERT INTO audit_table VALUES ($15, TG_OP, NEW.id)
t | 2 | 2 | 2 | INSERT INTO test_trigger VALUES ($1, $2)
t | 1 | 1 | 1 | SELECT pg_stat_monitor_reset()
(3 rows)

DROP TRIGGER audit_after_trigger ON test_trigger;
DROP FUNCTION audit_trigger_func();
DROP TABLE audit_table, test_trigger;
--
-- pg_stat_monitor.pgsm_track = none
--
Expand Down
Loading
Loading