mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-30 05:17:20 +02:00
RelFileNumbers are now assigned using a separate counter, instead of being assigned from the OID counter. This counter never wraps around: if all 2^56 possible RelFileNumbers are used, an internal error occurs. As the cluster is limited to 2^64 total bytes of WAL, this limitation should not cause a problem in practice. If the counter were 64 bits wide rather than 56 bits wide, we would need to increase the width of the BufferTag, which might adversely impact buffer lookup performance. Also, this lets us use bigint for pg_class.relfilenode and other places where these values are exposed at the SQL level without worrying about overflow. This should remove the need to keep "tombstone" files around until the next checkpoint when relations are removed. We do that to keep RelFileNumbers from being recycled, but now that won't happen anyway. However, this patch doesn't actually change anything in this area; it just makes it possible for a future patch to do so. Dilip Kumar, based on an idea from Andres Freund, who also reviewed some earlier versions of the patch. Further review and some wordsmithing by me. Also reviewed at various points by Ashutosh Sharma, Vignesh C, Amul Sul, Álvaro Herrera, and Tom Lane. Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com
170 lines
5.3 KiB
Plaintext
170 lines
5.3 KiB
Plaintext
CREATE EXTENSION pg_walinspect;
|
|
-- Make sure checkpoints don't interfere with the test.
|
|
SELECT 'init' FROM pg_create_physical_replication_slot('regress_pg_walinspect_slot', true, false);
|
|
?column?
|
|
----------
|
|
init
|
|
(1 row)
|
|
|
|
CREATE TABLE sample_tbl(col1 int, col2 int);
|
|
SELECT pg_current_wal_lsn() AS wal_lsn1 \gset
|
|
INSERT INTO sample_tbl SELECT * FROM generate_series(1, 2);
|
|
SELECT pg_current_wal_lsn() AS wal_lsn2 \gset
|
|
INSERT INTO sample_tbl SELECT * FROM generate_series(1, 2);
|
|
-- ===================================================================
|
|
-- Tests for input validation
|
|
-- ===================================================================
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info(:'wal_lsn2', :'wal_lsn1'); -- ERROR
|
|
ERROR: WAL start LSN must be less than end LSN
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats(:'wal_lsn2', :'wal_lsn1'); -- ERROR
|
|
ERROR: WAL start LSN must be less than end LSN
|
|
-- ===================================================================
|
|
-- Tests for all function executions
|
|
-- ===================================================================
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_record_info(:'wal_lsn1');
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', :'wal_lsn2');
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_records_info_till_end_of_wal(:'wal_lsn1');
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats(:'wal_lsn1', :'wal_lsn2');
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
SELECT COUNT(*) >= 0 AS ok FROM pg_get_wal_stats_till_end_of_wal(:'wal_lsn1');
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
-- ===================================================================
|
|
-- Test for filtering out WAL records of a particular table
|
|
-- ===================================================================
|
|
SELECT relfilenode AS sample_tbl_relfilenode FROM pg_class WHERE relname = 'sample_tbl' \gset
|
|
SELECT COUNT(*) >= 1 AS ok FROM pg_get_wal_records_info(:'wal_lsn1', :'wal_lsn2')
|
|
WHERE block_ref LIKE concat('%', :'sample_tbl_relfilenode', '%') AND resource_manager = 'Heap';
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
-- ===================================================================
|
|
-- 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';
|
|
ok
|
|
----
|
|
t
|
|
(1 row)
|
|
|
|
-- ===================================================================
|
|
-- Tests for permissions
|
|
-- ===================================================================
|
|
CREATE ROLE regress_pg_walinspect;
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_record_info(pg_lsn)', 'EXECUTE'); -- no
|
|
has_function_privilege
|
|
------------------------
|
|
f
|
|
(1 row)
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_records_info(pg_lsn, pg_lsn) ', 'EXECUTE'); -- no
|
|
has_function_privilege
|
|
------------------------
|
|
f
|
|
(1 row)
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_stats(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- no
|
|
has_function_privilege
|
|
------------------------
|
|
f
|
|
(1 row)
|
|
|
|
-- Functions accessible by users with role pg_read_server_files
|
|
GRANT pg_read_server_files TO regress_pg_walinspect;
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_record_info(pg_lsn)', 'EXECUTE'); -- yes
|
|
has_function_privilege
|
|
------------------------
|
|
t
|
|
(1 row)
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_records_info(pg_lsn, pg_lsn) ', 'EXECUTE'); -- yes
|
|
has_function_privilege
|
|
------------------------
|
|
t
|
|
(1 row)
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_stats(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- yes
|
|
has_function_privilege
|
|
------------------------
|
|
t
|
|
(1 row)
|
|
|
|
REVOKE pg_read_server_files FROM regress_pg_walinspect;
|
|
-- Superuser can grant execute to other users
|
|
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;
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_record_info(pg_lsn)', 'EXECUTE'); -- yes
|
|
has_function_privilege
|
|
------------------------
|
|
t
|
|
(1 row)
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_records_info(pg_lsn, pg_lsn) ', 'EXECUTE'); -- yes
|
|
has_function_privilege
|
|
------------------------
|
|
t
|
|
(1 row)
|
|
|
|
SELECT has_function_privilege('regress_pg_walinspect',
|
|
'pg_get_wal_stats(pg_lsn, pg_lsn, boolean) ', 'EXECUTE'); -- yes
|
|
has_function_privilege
|
|
------------------------
|
|
t
|
|
(1 row)
|
|
|
|
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;
|
|
-- ===================================================================
|
|
-- Clean up
|
|
-- ===================================================================
|
|
DROP ROLE regress_pg_walinspect;
|
|
SELECT pg_drop_replication_slot('regress_pg_walinspect_slot');
|
|
pg_drop_replication_slot
|
|
--------------------------
|
|
|
|
(1 row)
|
|
|
|
DROP TABLE sample_tbl;
|