Add contrib/pg_logicalsnapinspect

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Add contrib/pg_logicalsnapinspect
Date: 2024-08-22 12:26:15
Message-ID: ZscuZ92uGh3wm4tW@ip-10-97-1-34.eu-west-3.compute.internal
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Please find attached a patch to $SUBJECT.

This module provides SQL functions to inspect the contents of serialized logical
snapshots of a running database cluster, which I think could be useful for
debugging or educational purposes.

It's currently made of 2 functions, one to return the metadata:

postgres=# SELECT * FROM pg_get_logical_snapshot_meta('0/40796E18');
-[ RECORD 1 ]--------
magic | 1369563137
checksum | 1028045905
version | 6

and one to return more information:

postgres=# SELECT * FROM pg_get_logical_snapshot_info('0/40796E18');
-[ RECORD 1 ]------------+-----------
state | 2
xmin | 751
xmax | 751
start_decoding_at | 0/40796AF8
two_phase_at | 0/40796AF8
initial_xmin_horizon | 0
building_full_snapshot | f
in_slot_creation | f
last_serialized_snapshot | 0/0
next_phase_at | 0
committed_count | 0
committed_xip |
catchange_count | 2
catchange_xip | {751,752}

The LSN used as argument is extracted from the snapshot file name:

postgres=# select * from pg_ls_logicalsnapdir();
name | size | modification
-----------------+------+------------------------
0-40796E18.snap | 152 | 2024-08-14 16:36:32+00
(1 row)

A few remarks:

1. The "state" field is linked to the SnapBuildState enum (snapbuild.h). I've the
feeling that that's fine to display it as int but could write an helper function
to display strings instead ('SNAPBUILD_BUILDING_SNAPSHOT',...).

2. The SnapBuildOnDisk and SnapBuild structs are now exposed to public. Means
we should now pay much more attention when changing their contents but I think
it's worth it.

3. The pg_get_logical_snapshot_info() function mainly displays the SnapBuild
content extracted from the logical snapshot file.

4. I think that providing SQL functions is enough and that it's not needed to
also create a related binary tool.

5. A few PGDLLIMPORT have been added (Windows CI was failing).

6. Related documentation has been added.

7. A test has been added.

8. I don't like the module name that much but it follows the same as for
pg_walinspect.

Looking forward to your feedback,

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v1-0001-Add-contrib-pg_logicalsnapinspect.patch text/x-diff 43.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2024-08-22 12:43:18 Re: On disable_cost
Previous Message Kirill Reshke 2024-08-22 12:14:51 Re: optimize hashjoin