2022-04-08 09:02:10 +02:00
|
|
|
CREATE EXTENSION pg_walinspect;
|
|
|
|
|
2023-03-13 05:03:29 +01:00
|
|
|
-- Mask DETAIL messages as these could refer to current LSN positions.
|
|
|
|
\set VERBOSITY terse
|
|
|
|
|
2022-04-08 12:21:12 +02:00
|
|
|
-- Make sure checkpoints don't interfere with the test.
|
|
|
|
SELECT 'init' FROM pg_create_physical_replication_slot('regress_pg_walinspect_slot', true, false);
|
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
CREATE TABLE sample_tbl(col1 int, col2 int);
|
|
|
|
|
2023-03-23 03:50:35 +01:00
|
|
|
-- Save some LSNs for comparisons.
|
2022-04-08 12:21:12 +02:00
|
|
|
SELECT pg_current_wal_lsn() AS wal_lsn1 \gset
|
2022-04-08 09:02:10 +02:00
|
|
|
INSERT INTO sample_tbl SELECT * FROM generate_series(1, 2);
|
|
|
|
SELECT pg_current_wal_lsn() AS wal_lsn2 \gset
|
2023-01-23 05:55:18 +01:00
|
|
|
INSERT INTO sample_tbl SELECT * FROM generate_series(3, 4);
|
2022-04-08 09:02:10 +02:00
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Tests for input validation
|
|
|
|
-- ===================================================================
|
|
|
|
|
2023-03-13 05:03:29 +01:00
|
|
|
-- Invalid input LSN.
|
|
|
|
SELECT * FROM pg_get_wal_record_info('0/0');
|
|
|
|
|
|
|
|
-- Invalid start LSN.
|
|
|
|
SELECT * FROM pg_get_wal_records_info('0/0', :'wal_lsn1');
|
|
|
|
SELECT * FROM pg_get_wal_stats('0/0', :'wal_lsn1');
|
|
|
|
SELECT * FROM pg_get_wal_block_info('0/0', :'wal_lsn1');
|
|
|
|
|
|
|
|
-- Start LSN > End LSN.
|
|
|
|
SELECT * FROM pg_get_wal_records_info(:'wal_lsn2', :'wal_lsn1');
|
|
|
|
SELECT * FROM pg_get_wal_stats(:'wal_lsn2', :'wal_lsn1');
|
|
|
|
SELECT * FROM pg_get_wal_block_info(:'wal_lsn2', :'wal_lsn1');
|
|
|
|
|
|
|
|
-- LSNs with the highest value possible.
|
2023-03-23 03:50:35 +01:00
|
|
|
SELECT * FROM pg_get_wal_record_info('FFFFFFFF/FFFFFFFF');
|
2023-03-14 12:13:02 +01:00
|
|
|
-- Success with end LSNs.
|
2023-03-23 03:50:35 +01:00
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_stats(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_block_info(:'wal_lsn1', 'FFFFFFFF/FFFFFFFF');
|
|
|
|
-- Failures with start LSNs.
|
|
|
|
SELECT * FROM pg_get_wal_records_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
|
|
|
|
SELECT * FROM pg_get_wal_stats('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
|
|
|
|
SELECT * FROM pg_get_wal_block_info('FFFFFFFF/FFFFFFFE', 'FFFFFFFF/FFFFFFFF');
|
2022-04-08 09:02:10 +02:00
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Tests for all function executions
|
|
|
|
-- ===================================================================
|
|
|
|
|
2023-03-23 03:50:35 +01:00
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_record_info(:'wal_lsn1');
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', :'wal_lsn2');
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_stats(:'wal_lsn1', :'wal_lsn2');
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_block_info(:'wal_lsn1', :'wal_lsn2');
|
2022-04-08 09:02:10 +02:00
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Test for filtering out WAL records of a particular table
|
|
|
|
-- ===================================================================
|
|
|
|
|
2022-09-28 15:45:27 +02:00
|
|
|
SELECT oid AS sample_tbl_oid FROM pg_class WHERE relname = 'sample_tbl' \gset
|
2022-04-08 09:02:10 +02:00
|
|
|
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', :'wal_lsn2')
|
2022-09-28 15:45:27 +02:00
|
|
|
WHERE block_ref LIKE concat('%', :'sample_tbl_oid', '%') AND resource_manager = 'Heap';
|
2022-04-08 09:02:10 +02:00
|
|
|
|
|
|
|
-- ===================================================================
|
|
|
|
-- Test for filtering out WAL records based on resource_manager and
|
|
|
|
-- record_type
|
|
|
|
-- ===================================================================
|
|
|
|
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', :'wal_lsn2')
|
|
|
|
WHERE resource_manager = 'Heap' AND record_type = 'INSERT';
|
|
|
|
|
2023-01-23 05:55:18 +01:00
|
|
|
-- ===================================================================
|
pg_walinspect: pg_get_wal_fpi_info() -> pg_get_wal_block_info()
This commit reworks pg_get_wal_fpi_info() to become aware of all the
block information that can be attached to a record rather than just its
full-page writes:
- Addition of the block id as assigned by XLogRegisterBuffer(),
XLogRegisterBlock() or XLogRegisterBufData().
- Addition of the block data, as bytea, or NULL if none. The length of
the block data can be guessed with length(), so there is no need to
store its length in a separate field.
- Addition of the full-page image length, as counted without a hole or
even compressed.
- Modification of the handling of the full-page image data. This is
still a bytea, but it could become NULL if none is assigned to a block.
- Addition of the full-page image flags, tracking if a page is stored
with a hole, if it needs to be applied and the type of compression
applied to it, as of all the BKPIMAGE_* values in xlogrecord.h.
The information of each block is returned as one single record, with the
record's ReadRecPtr included to be able to join the block information
with the existing pg_get_wal_records_info(). Note that it is perfectly
possible for a block to hold both data and full-page image.
Thanks also to Kyotaro Horiguchi and Matthias van de Meent for the
discussion.
This commit uses some of the work proposed by Melanie, though it has
been largely redesigned and rewritten by me. Bharath has helped in
refining a bit the whole.
Reported-by: Melanie Plageman
Author: Michael Paquier, Melanie Plageman, Bharath Rupireddy
Discussion: https://postgr.es/m/CAAKRu_bORebdZmcV8V4cZBzU8M_C6tDDdbiPhCZ6i-iuSXW9TA@mail.gmail.com
2023-03-10 02:09:07 +01:00
|
|
|
-- Tests to get block information from WAL record
|
2023-01-23 05:55:18 +01:00
|
|
|
-- ===================================================================
|
|
|
|
|
2023-03-23 03:50:35 +01:00
|
|
|
-- Update table to generate some block data.
|
pg_walinspect: pg_get_wal_fpi_info() -> pg_get_wal_block_info()
This commit reworks pg_get_wal_fpi_info() to become aware of all the
block information that can be attached to a record rather than just its
full-page writes:
- Addition of the block id as assigned by XLogRegisterBuffer(),
XLogRegisterBlock() or XLogRegisterBufData().
- Addition of the block data, as bytea, or NULL if none. The length of
the block data can be guessed with length(), so there is no need to
store its length in a separate field.
- Addition of the full-page image length, as counted without a hole or
even compressed.
- Modification of the handling of the full-page image data. This is
still a bytea, but it could become NULL if none is assigned to a block.
- Addition of the full-page image flags, tracking if a page is stored
with a hole, if it needs to be applied and the type of compression
applied to it, as of all the BKPIMAGE_* values in xlogrecord.h.
The information of each block is returned as one single record, with the
record's ReadRecPtr included to be able to join the block information
with the existing pg_get_wal_records_info(). Note that it is perfectly
possible for a block to hold both data and full-page image.
Thanks also to Kyotaro Horiguchi and Matthias van de Meent for the
discussion.
This commit uses some of the work proposed by Melanie, though it has
been largely redesigned and rewritten by me. Bharath has helped in
refining a bit the whole.
Reported-by: Melanie Plageman
Author: Michael Paquier, Melanie Plageman, Bharath Rupireddy
Discussion: https://postgr.es/m/CAAKRu_bORebdZmcV8V4cZBzU8M_C6tDDdbiPhCZ6i-iuSXW9TA@mail.gmail.com
2023-03-10 02:09:07 +01:00
|
|
|
SELECT pg_current_wal_lsn() AS wal_lsn3 \gset
|
|
|
|
UPDATE sample_tbl SET col1 = col1 + 1 WHERE col1 = 1;
|
2023-01-23 05:55:18 +01:00
|
|
|
SELECT pg_current_wal_lsn() AS wal_lsn4 \gset
|
pg_walinspect: pg_get_wal_fpi_info() -> pg_get_wal_block_info()
This commit reworks pg_get_wal_fpi_info() to become aware of all the
block information that can be attached to a record rather than just its
full-page writes:
- Addition of the block id as assigned by XLogRegisterBuffer(),
XLogRegisterBlock() or XLogRegisterBufData().
- Addition of the block data, as bytea, or NULL if none. The length of
the block data can be guessed with length(), so there is no need to
store its length in a separate field.
- Addition of the full-page image length, as counted without a hole or
even compressed.
- Modification of the handling of the full-page image data. This is
still a bytea, but it could become NULL if none is assigned to a block.
- Addition of the full-page image flags, tracking if a page is stored
with a hole, if it needs to be applied and the type of compression
applied to it, as of all the BKPIMAGE_* values in xlogrecord.h.
The information of each block is returned as one single record, with the
record's ReadRecPtr included to be able to join the block information
with the existing pg_get_wal_records_info(). Note that it is perfectly
possible for a block to hold both data and full-page image.
Thanks also to Kyotaro Horiguchi and Matthias van de Meent for the
discussion.
This commit uses some of the work proposed by Melanie, though it has
been largely redesigned and rewritten by me. Bharath has helped in
refining a bit the whole.
Reported-by: Melanie Plageman
Author: Michael Paquier, Melanie Plageman, Bharath Rupireddy
Discussion: https://postgr.es/m/CAAKRu_bORebdZmcV8V4cZBzU8M_C6tDDdbiPhCZ6i-iuSXW9TA@mail.gmail.com
2023-03-10 02:09:07 +01:00
|
|
|
-- Check if we get block data from WAL record.
|
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_block_info(:'wal_lsn3', :'wal_lsn4')
|
2023-03-30 21:26:12 +02:00
|
|
|
WHERE relfilenode = :'sample_tbl_oid' AND block_data IS NOT NULL;
|
2023-01-23 05:55:18 +01:00
|
|
|
|
pg_walinspect: pg_get_wal_fpi_info() -> pg_get_wal_block_info()
This commit reworks pg_get_wal_fpi_info() to become aware of all the
block information that can be attached to a record rather than just its
full-page writes:
- Addition of the block id as assigned by XLogRegisterBuffer(),
XLogRegisterBlock() or XLogRegisterBufData().
- Addition of the block data, as bytea, or NULL if none. The length of
the block data can be guessed with length(), so there is no need to
store its length in a separate field.
- Addition of the full-page image length, as counted without a hole or
even compressed.
- Modification of the handling of the full-page image data. This is
still a bytea, but it could become NULL if none is assigned to a block.
- Addition of the full-page image flags, tracking if a page is stored
with a hole, if it needs to be applied and the type of compression
applied to it, as of all the BKPIMAGE_* values in xlogrecord.h.
The information of each block is returned as one single record, with the
record's ReadRecPtr included to be able to join the block information
with the existing pg_get_wal_records_info(). Note that it is perfectly
possible for a block to hold both data and full-page image.
Thanks also to Kyotaro Horiguchi and Matthias van de Meent for the
discussion.
This commit uses some of the work proposed by Melanie, though it has
been largely redesigned and rewritten by me. Bharath has helped in
refining a bit the whole.
Reported-by: Melanie Plageman
Author: Michael Paquier, Melanie Plageman, Bharath Rupireddy
Discussion: https://postgr.es/m/CAAKRu_bORebdZmcV8V4cZBzU8M_C6tDDdbiPhCZ6i-iuSXW9TA@mail.gmail.com
2023-03-10 02:09:07 +01:00
|
|
|
-- Force full-page image on the next update.
|
|
|
|
SELECT pg_current_wal_lsn() AS wal_lsn5 \gset
|
|
|
|
CHECKPOINT;
|
|
|
|
UPDATE sample_tbl SET col1 = col1 + 1 WHERE col1 = 2;
|
|
|
|
SELECT pg_current_wal_lsn() AS wal_lsn6 \gset
|
2023-01-23 05:55:18 +01:00
|
|
|
-- Check if we get FPI from WAL record.
|
pg_walinspect: pg_get_wal_fpi_info() -> pg_get_wal_block_info()
This commit reworks pg_get_wal_fpi_info() to become aware of all the
block information that can be attached to a record rather than just its
full-page writes:
- Addition of the block id as assigned by XLogRegisterBuffer(),
XLogRegisterBlock() or XLogRegisterBufData().
- Addition of the block data, as bytea, or NULL if none. The length of
the block data can be guessed with length(), so there is no need to
store its length in a separate field.
- Addition of the full-page image length, as counted without a hole or
even compressed.
- Modification of the handling of the full-page image data. This is
still a bytea, but it could become NULL if none is assigned to a block.
- Addition of the full-page image flags, tracking if a page is stored
with a hole, if it needs to be applied and the type of compression
applied to it, as of all the BKPIMAGE_* values in xlogrecord.h.
The information of each block is returned as one single record, with the
record's ReadRecPtr included to be able to join the block information
with the existing pg_get_wal_records_info(). Note that it is perfectly
possible for a block to hold both data and full-page image.
Thanks also to Kyotaro Horiguchi and Matthias van de Meent for the
discussion.
This commit uses some of the work proposed by Melanie, though it has
been largely redesigned and rewritten by me. Bharath has helped in
refining a bit the whole.
Reported-by: Melanie Plageman
Author: Michael Paquier, Melanie Plageman, Bharath Rupireddy
Discussion: https://postgr.es/m/CAAKRu_bORebdZmcV8V4cZBzU8M_C6tDDdbiPhCZ6i-iuSXW9TA@mail.gmail.com
2023-03-10 02:09:07 +01:00
|
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_block_info(:'wal_lsn5', :'wal_lsn6')
|
2023-03-30 21:26:12 +02:00
|
|
|
WHERE relfilenode = :'sample_tbl_oid' AND block_fpi_data IS NOT NULL;
|
2023-01-23 05:55:18 +01:00
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
-- ===================================================================
|
|
|
|
-- Tests for permissions
|
|
|
|
-- ===================================================================
|
|
|
|
CREATE ROLE regress_pg_walinspect;
|
|
|
|
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_record_info(pg_lsn)', 'EXECUTE'); -- no
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_records_info(pg_lsn, pg_lsn) ', 'EXECUTE'); -- no
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_stats(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- no
|
2023-01-23 05:55:18 +01:00
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
2023-03-31 23:02:52 +02:00
|
|
|
'pg_get_wal_block_info(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- no
|
2023-01-23 05:55:18 +01:00
|
|
|
|
2023-03-23 03:50:35 +01:00
|
|
|
-- Functions accessible by users with role pg_read_server_files.
|
2022-04-08 09:02:10 +02:00
|
|
|
GRANT pg_read_server_files TO regress_pg_walinspect;
|
2023-03-23 03:50:35 +01:00
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_record_info(pg_lsn)', 'EXECUTE'); -- yes
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_records_info(pg_lsn, pg_lsn) ', 'EXECUTE'); -- yes
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_stats(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- yes
|
2023-01-23 05:55:18 +01:00
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
2023-03-31 23:02:52 +02:00
|
|
|
'pg_get_wal_block_info(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- yes
|
2023-01-23 05:55:18 +01:00
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
REVOKE pg_read_server_files FROM regress_pg_walinspect;
|
|
|
|
|
2023-03-23 03:50:35 +01:00
|
|
|
-- Superuser can grant execute to other users.
|
2022-04-08 09:02:10 +02:00
|
|
|
GRANT EXECUTE ON FUNCTION pg_get_wal_record_info(pg_lsn)
|
|
|
|
TO regress_pg_walinspect;
|
|
|
|
GRANT EXECUTE ON FUNCTION pg_get_wal_records_info(pg_lsn, pg_lsn)
|
|
|
|
TO regress_pg_walinspect;
|
|
|
|
GRANT EXECUTE ON FUNCTION pg_get_wal_stats(pg_lsn, pg_lsn, boolean)
|
|
|
|
TO regress_pg_walinspect;
|
2023-03-31 23:02:52 +02:00
|
|
|
GRANT EXECUTE ON FUNCTION pg_get_wal_block_info(pg_lsn, pg_lsn, boolean)
|
2023-01-23 05:55:18 +01:00
|
|
|
TO regress_pg_walinspect;
|
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_record_info(pg_lsn)', 'EXECUTE'); -- yes
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_records_info(pg_lsn, pg_lsn) ', 'EXECUTE'); -- yes
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
|
|
'pg_get_wal_stats(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- yes
|
2023-01-23 05:55:18 +01:00
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
2023-03-31 23:02:52 +02:00
|
|
|
'pg_get_wal_block_info(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- yes
|
2023-01-23 05:55:18 +01:00
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_get_wal_record_info(pg_lsn)
|
|
|
|
FROM regress_pg_walinspect;
|
|
|
|
REVOKE EXECUTE ON FUNCTION pg_get_wal_records_info(pg_lsn, pg_lsn)
|
|
|
|
FROM regress_pg_walinspect;
|
|
|
|
REVOKE EXECUTE ON FUNCTION pg_get_wal_stats(pg_lsn, pg_lsn, boolean)
|
|
|
|
FROM regress_pg_walinspect;
|
2023-03-31 23:02:52 +02:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_get_wal_block_info(pg_lsn, pg_lsn, boolean)
|
2023-01-23 05:55:18 +01:00
|
|
|
FROM regress_pg_walinspect;
|
|
|
|
|
2022-04-08 09:02:10 +02:00
|
|
|
-- ===================================================================
|
|
|
|
-- Clean up
|
|
|
|
-- ===================================================================
|
|
|
|
|
|
|
|
DROP ROLE regress_pg_walinspect;
|
|
|
|
|
|
|
|
SELECT pg_drop_replication_slot('regress_pg_walinspect_slot');
|
|
|
|
|
|
|
|
DROP TABLE sample_tbl;
|
2023-03-13 05:03:29 +01:00
|
|
|
DROP EXTENSION pg_walinspect;
|