Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c1b662

Browse filesBrowse files
committed
Rework design of functions in pg_walinspect
This commit reworks a bit the set-returning functions of pg_walinspect, making them more flexible regarding their end LSN: - pg_get_wal_records_info() - pg_get_wal_stats() - pg_get_wal_block_info() The end LSNs given to these functions is now handled so as a value higher than the current LSN of the cluster (insert LSN for a primary, or replay LSN for a standby) does not raise an error, giving more flexibility to monitoring queries. Instead, the functions return results up to the current LSN, as found at the beginning of each function call. As an effect of that, pg_get_wal_records_info_till_end_of_wal() and pg_get_wal_stats_till_end_of_wal() are now removed from 1.1, as the existing, equivalent functions are able to offer the same possibilities. Author: Bharath Rupireddy Discussion: https://postgr.es/m/CALj2ACU0_q-o4DSweyaW9NO1KBx-QkN6G_OzYQvpjf3CZVASkg@mail.gmail.com
1 parent d5d5741 commit 5c1b662
Copy full SHA for 5c1b662

File tree

7 files changed

+184
-207
lines changed
Filter options

7 files changed

+184
-207
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-- test old extension version entry points
22
CREATE EXTENSION pg_walinspect WITH VERSION '1.0';
3+
-- Mask DETAIL messages as these could refer to current LSN positions.
4+
\set VERBOSITY terse
35
-- List what version 1.0 contains
46
\dx+ pg_walinspect
57
Objects in extension "pg_walinspect"
@@ -12,19 +14,51 @@ CREATE EXTENSION pg_walinspect WITH VERSION '1.0';
1214
function pg_get_wal_stats_till_end_of_wal(pg_lsn,boolean)
1315
(5 rows)
1416

17+
-- Make sure checkpoints don't interfere with the test.
18+
SELECT 'init' FROM pg_create_physical_replication_slot('regress_pg_walinspect_slot', true, false);
19+
?column?
20+
----------
21+
init
22+
(1 row)
23+
24+
CREATE TABLE sample_tbl(col1 int, col2 int);
25+
SELECT pg_current_wal_lsn() AS wal_lsn1 \gset
26+
INSERT INTO sample_tbl SELECT * FROM generate_series(1, 2);
27+
-- Check bounds for these past functions.
28+
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info_till_end_of_wal(:'wal_lsn1');
29+
ok
30+
----
31+
t
32+
(1 row)
33+
34+
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_stats_till_end_of_wal(:'wal_lsn1');
35+
ok
36+
----
37+
t
38+
(1 row)
39+
40+
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info_till_end_of_wal('FFFFFFFF/FFFFFFFF');
41+
ERROR: WAL start LSN must be less than current LSN
42+
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_stats_till_end_of_wal('FFFFFFFF/FFFFFFFF');
43+
ERROR: WAL start LSN must be less than current LSN
1544
-- Move to new version 1.1
1645
ALTER EXTENSION pg_walinspect UPDATE TO '1.1';
1746
-- List what version 1.1 contains
1847
\dx+ pg_walinspect
19-
Objects in extension "pg_walinspect"
20-
Object description
21-
-----------------------------------------------------------
48+
Objects in extension "pg_walinspect"
49+
Object description
50+
--------------------------------------------------
2251
function pg_get_wal_block_info(pg_lsn,pg_lsn)
2352
function pg_get_wal_record_info(pg_lsn)
2453
function pg_get_wal_records_info(pg_lsn,pg_lsn)
25-
function pg_get_wal_records_info_till_end_of_wal(pg_lsn)
2654
function pg_get_wal_stats(pg_lsn,pg_lsn,boolean)
27-
function pg_get_wal_stats_till_end_of_wal(pg_lsn,boolean)
28-
(6 rows)
55+
(4 rows)
56+
57+
SELECT pg_drop_replication_slot('regress_pg_walinspect_slot');
58+
pg_drop_replication_slot
59+
--------------------------
60+
61+
(1 row)
2962

63+
DROP TABLE sample_tbl;
3064
DROP EXTENSION pg_walinspect;

‎contrib/pg_walinspect/expected/pg_walinspect.out

Copy file name to clipboardExpand all lines: contrib/pg_walinspect/expected/pg_walinspect.out
+19-23
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,37 @@ SELECT * FROM pg_get_wal_block_info(:'wal_lsn2', :'wal_lsn1');
3636
ERROR: WAL start LSN must be less than end LSN
3737
-- LSNs with the highest value possible.
3838
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_record_info('FFFFFFFF/FFFFFFFF');
39-
ERROR: cannot accept future input LSN
40-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info_till_end_of_wal('FFFFFFFF/FFFFFFFF');
41-
ERROR: cannot accept future start LSN
42-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats_till_end_of_wal('FFFFFFFF/FFFFFFFF');
43-
ERROR: cannot accept future start LSN
44-
-- failures with end LSNs
39+
ERROR: WAL input LSN must be less than current LSN
40+
-- Success with end LSNs.
4541
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
46-
ERROR: cannot accept future end LSN
42+
ok
43+
----
44+
t
45+
(1 row)
46+
4747
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
48-
ERROR: cannot accept future end LSN
49-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_block_info(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
50-
ERROR: cannot accept future end LSN
51-
-- failures with start LSNs
52-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
53-
ERROR: cannot accept future start LSN
54-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
55-
ERROR: cannot accept future start LSN
56-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_block_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
57-
ERROR: cannot accept future start LSN
58-
-- ===================================================================
59-
-- Tests for all function executions
60-
-- ===================================================================
61-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_record_info(:'wal_lsn1');
6248
ok
6349
----
6450
t
6551
(1 row)
6652

67-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info_till_end_of_wal(:'wal_lsn1');
53+
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_block_info(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
6854
ok
6955
----
7056
t
7157
(1 row)
7258

73-
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats_till_end_of_wal(:'wal_lsn1');
59+
-- failures with start LSNs
60+
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
61+
ERROR: WAL start LSN must be less than current LSN
62+
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
63+
ERROR: WAL start LSN must be less than current LSN
64+
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_block_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
65+
ERROR: WAL start LSN must be less than current LSN
66+
-- ===================================================================
67+
-- Tests for all function executions
68+
-- ===================================================================
69+
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_record_info(:'wal_lsn1');
7470
ok
7571
----
7672
t

‎contrib/pg_walinspect/pg_walinspect--1.0--1.1.sql

Copy file name to clipboardExpand all lines: contrib/pg_walinspect/pg_walinspect--1.0--1.1.sql
+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
44
\echo Use "ALTER EXTENSION pg_walinspect UPDATE TO '1.1'" to load this file. \quit
55

6+
-- Unsupported functions after 1.1.
7+
DROP FUNCTION pg_get_wal_records_info_till_end_of_wal(pg_lsn);
8+
DROP FUNCTION pg_get_wal_stats_till_end_of_wal(pg_lsn, boolean);
9+
610
--
711
-- pg_get_wal_block_info()
812
--

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.