mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Add pg_stat_get_snapshot_timestamp() to show statistics snapshot timestamp.
Per discussion, this could be useful for purposes such as programmatically detecting a nonresponding stats collector. We already have the timestamp anyway, it's just a matter of providing a SQL-accessible function to fetch it. Matt Kelly, reviewed by Jim Nasby
This commit is contained in:
@ -28,7 +28,8 @@ SELECT pg_sleep_for('2 seconds');
|
||||
CREATE TEMP TABLE prevstats AS
|
||||
SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
|
||||
(b.heap_blks_read + b.heap_blks_hit) AS heap_blks,
|
||||
(b.idx_blks_read + b.idx_blks_hit) AS idx_blks
|
||||
(b.idx_blks_read + b.idx_blks_hit) AS idx_blks,
|
||||
pg_stat_get_snapshot_timestamp() as snap_ts
|
||||
FROM pg_catalog.pg_stat_user_tables AS t,
|
||||
pg_catalog.pg_statio_user_tables AS b
|
||||
WHERE t.relname='tenk2' AND b.relname='tenk2';
|
||||
@ -111,4 +112,11 @@ SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
|
||||
t | t
|
||||
(1 row)
|
||||
|
||||
SELECT pr.snap_ts < pg_stat_get_snapshot_timestamp() as snapshot_newer
|
||||
FROM prevstats AS pr;
|
||||
snapshot_newer
|
||||
----------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- End of Stats Test
|
||||
|
@ -22,7 +22,8 @@ SELECT pg_sleep_for('2 seconds');
|
||||
CREATE TEMP TABLE prevstats AS
|
||||
SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
|
||||
(b.heap_blks_read + b.heap_blks_hit) AS heap_blks,
|
||||
(b.idx_blks_read + b.idx_blks_hit) AS idx_blks
|
||||
(b.idx_blks_read + b.idx_blks_hit) AS idx_blks,
|
||||
pg_stat_get_snapshot_timestamp() as snap_ts
|
||||
FROM pg_catalog.pg_stat_user_tables AS t,
|
||||
pg_catalog.pg_statio_user_tables AS b
|
||||
WHERE t.relname='tenk2' AND b.relname='tenk2';
|
||||
@ -81,4 +82,7 @@ SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
|
||||
FROM pg_statio_user_tables AS st, pg_class AS cl, prevstats AS pr
|
||||
WHERE st.relname='tenk2' AND cl.relname='tenk2';
|
||||
|
||||
SELECT pr.snap_ts < pg_stat_get_snapshot_timestamp() as snapshot_newer
|
||||
FROM prevstats AS pr;
|
||||
|
||||
-- End of Stats Test
|
||||
|
Reference in New Issue
Block a user