From 766f3f862fbcc19fc6e961f82dca59ab8386149b Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Wed, 6 Apr 2022 08:00:06 +0000 Subject: [PATCH v17] pg_walinspect docs --- doc/src/sgml/contrib.sgml | 1 + doc/src/sgml/filelist.sgml | 1 + doc/src/sgml/pgwalinspect.sgml | 244 +++++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 doc/src/sgml/pgwalinspect.sgml diff --git a/doc/src/sgml/contrib.sgml b/doc/src/sgml/contrib.sgml index 1e42ce1a7f..4e7b87a42f 100644 --- a/doc/src/sgml/contrib.sgml +++ b/doc/src/sgml/contrib.sgml @@ -131,6 +131,7 @@ CREATE EXTENSION module_name; &pgsurgery; &pgtrgm; &pgvisibility; + &pgwalinspect; &postgres-fdw; &seg; &sepgsql; diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml index fd853af01f..34c19c80f1 100644 --- a/doc/src/sgml/filelist.sgml +++ b/doc/src/sgml/filelist.sgml @@ -147,6 +147,7 @@ + diff --git a/doc/src/sgml/pgwalinspect.sgml b/doc/src/sgml/pgwalinspect.sgml new file mode 100644 index 0000000000..e344951f0d --- /dev/null +++ b/doc/src/sgml/pgwalinspect.sgml @@ -0,0 +1,244 @@ + + + + pg_walinspect + + + pg_walinspect + + + + The pg_walinspect module provides functions that allow + you to inspect the contents of write-ahead log of PostgreSQL + database cluster at a low level, which is useful for debugging or analytical + or reporting or educational purposes. + + + + All the functions of this module will provide the WAL information using the + current server's timeline ID. + + + + By default, use of these functions is restricted to superusers and members of + the pg_read_server_files role. Access may be granted by + superusers to others using GRANT. + + + + General Functions + + + + + + pg_get_wal_record_info(in_lsn pg_lsn, + start_lsn OUT pg_lsn, + end_lsn OUT pg_lsn, + prev_lsn OUT pg_lsn, + xid OUT xid, + resource_manager OUT text, + record_type OUT text, + record_length OUT int4, + main_data_length OUT int4, + fpi_length OUT int4, + description OUT text, + block_ref OUT text) + + + + + + Gets WAL record information of a given LSN. If the given LSN isn't + containing a valid WAL record, it gives the information of the next + available valid WAL record. This function emits an error if a future (the + LSN database system doesn't know about) in_lsn + is specified. + + + + + + + + pg_get_wal_records_info(start_lsn pg_lsn, + end_lsn pg_lsn, + start_lsn OUT pg_lsn, + end_lsn OUT pg_lsn, + prev_lsn OUT pg_lsn, + xid OUT xid, + resource_manager OUT text, + record_type OUT text, + record_length OUT int4, + main_data_length OUT int4, + fpi_length OUT int4, + description OUT text, + block_ref OUT text) + returns setof record + + + + + + Gets information of all the valid WAL records between + start_lsn and end_lsn. + Returns one row per each valid WAL record. This function emits an error + if a future (the LSN database system doesn't know about) + start_lsn or end_lsn + is specified. For example, usage of the function is as follows: + +postgres=# select start_lsn, end_lsn, prev_lsn, xid, resource_manager, record_type, record_length, main_data_length, fpi_length, description from pg_get_wal_records_info('0/14FBA30', '0/15011D7'); + start_lsn | end_lsn | prev_lsn | xid | resource_manager | record_type | record_length | main_data_length | fpi_length | description +-----------+-----------+-----------+-----+------------------+---------------+---------------+------------------+------------+--------------------------------------------------------- + 0/14FBA30 | 0/14FBA67 | 0/14FB9F8 | 0 | Heap2 | PRUNE | 56 | 8 | 0 | latestRemovedXid 0 nredirected 0 ndead 1 + 0/14FBA68 | 0/14FBA9F | 0/14FBA30 | 0 | Standby | RUNNING_XACTS | 50 | 24 | 0 | nextXid 723 latestCompletedXid 722 oldestRunningXid 723 + 0/14FBAA0 | 0/14FBACF | 0/14FBA68 | 0 | Storage | CREATE | 42 | 16 | 0 | base/5/16390 + 0/14FBAD0 | 0/14FC117 | 0/14FBAA0 | 723 | Heap | INSERT | 1582 | 3 | 1528 | off 8 flags 0x01 + 0/14FC118 | 0/14FD487 | 0/14FBAD0 | 723 | Btree | INSERT_LEAF | 4973 | 2 | 4920 | off 244 + 0/14FD488 | 0/14FEFCF | 0/14FC118 | 723 | Btree | INSERT_LEAF | 6953 | 2 | 6900 | off 126 + 0/14FEFD0 | 0/14FF027 | 0/14FD488 | 723 | Heap2 | MULTI_INSERT | 85 | 6 | 0 | 1 tuples flags 0x02 + 0/14FF028 | 0/14FF06F | 0/14FEFD0 | 723 | Btree | INSERT_LEAF | 72 | 2 | 0 | off 155 + 0/14FF070 | 0/14FF0B7 | 0/14FF028 | 723 | Btree | INSERT_LEAF | 72 | 2 | 0 | off 134 + 0/14FF0B8 | 0/14FF18F | 0/14FF070 | 723 | Heap | INSERT | 211 | 3 | 0 | off 9 flags 0x00 + 0/14FF190 | 0/14FF1CF | 0/14FF0B8 | 723 | Btree | INSERT_LEAF | 64 | 2 | 0 | off 244 + 0/14FF1D0 | 0/15010B7 | 0/14FF190 | 723 | Btree | SPLIT_L | 7885 | 10 | 4136 | level 0, firstrightoff 120, newitemoff 47, postingoff 0 + 0/15010B8 | 0/150117F | 0/14FF1D0 | 723 | Btree | INSERT_UPPER | 197 | 2 | 136 | off 2 + 0/1501180 | 0/15011D7 | 0/15010B8 | 723 | Heap2 | MULTI_INSERT | 85 | 6 | 0 | 1 tuples flags 0x02 +(14 rows) + + + + + + + + + pg_get_wal_records_info_till_end_of_wal(start_lsn pg_lsn, + start_lsn OUT pg_lsn, + end_lsn OUT pg_lsn, + prev_lsn OUT pg_lsn, + xid OUT xid, + resource_manager OUT text, + record_type OUT text, + record_length OUT int4, + main_data_length OUT int4, + fpi_length OUT int4, + description OUT text, + block_ref OUT text) + returns setof record + + + + + + This function is same as pg_get_wal_records_info() + except that it gets information of all the valid WAL records from + start_lsn till end of WAL. + + + + + + + + pg_get_wal_stats(start_lsn pg_lsn, + end_lsn pg_lsn, + per_record boolean DEFAULT false, + "resource_manager/record_type" OUT text, + count OUT int8, + count_percentage OUT float4, + record_length OUT int8, + record_length_percentage OUT float4, + fpi_length OUT int8, + fpi_length_percentage OUT float4, + combined_size OUT int8, + combined_size_percentage OUT float4) + returns setof record + + + + + + Gets statistics of all the valid WAL records between + start_lsn and + end_lsn. By default, it returns one row per + resource_manager type. When + per_record is set to true, + it returns one row per record_type. This + function emits an error if a future (the LSN database system doesn't know + about) start_lsn or end_lsn + is specified. For example, usage of the function is as follows: + +postgres=# select * from pg_get_wal_stats('0/12FBA30', '0/15011D7') where count > 0; + resource_manager/record_type | count | count_percentage | record_size | record_size_percentage | fpi_size | fpi_size_percentage | combined_size | combined_size_percentage +------------------------------+-------+------------------+-------------+------------------------+----------+---------------------+---------------+-------------------------- + XLOG | 12 | 0.13002492 | 1024 | 2.3833392e-05 | 352 | 0.06136488 | 1376 | 3.2021846e-05 + Transaction | 188 | 2.0370572 | 62903 | 0.0014640546 | 0 | 0 | 62903 | 0.0014638591 + Storage | 13 | 0.14086033 | 546 | 1.2708038e-05 | 0 | 0 | 546 | 1.2706342e-05 + Database | 2 | 0.02167082 | 84 | 1.955083e-06 | 0 | 0 | 84 | 1.954822e-06 + Standby | 219 | 2.3729548 | 15830 | 0.00036844003 | 0 | 0 | 15830 | 0.00036839084 + Heap2 | 1905 | 20.641457 | 384619 | 0.0089519285 | 364472 | 63.53915 | 749091 | 0.017432613 + Heap | 1319 | 14.291906 | 621997 | 0.014476853 | 145232 | 25.318592 | 767229 | 0.017854715 + Btree | 5571 | 60.36407 | 4295405999 | 99.9747 | 63562 | 11.0808935 | 4295469561 | 99.96284 +(8 rows) + + +With per_record passed as true: + + +postgres=# select * from pg_get_wal_stats('0/14FBA30', '0/15011D7', true) where count > 0; + resource_manager/record_type | count | count_percentage | record_size | record_size_percentage | fpi_size | fpi_size_percentage | combined_size | combined_size_percentage +------------------------------+-------+------------------+-------------+------------------------+----------+---------------------+---------------+-------------------------- + Storage/CREATE | 1 | 7.142857 | 42 | 0.8922881 | 0 | 0 | 42 | 0.18811305 + Standby/RUNNING_XACTS | 1 | 7.142857 | 50 | 1.0622478 | 0 | 0 | 50 | 0.2239441 + Heap2/PRUNE | 1 | 7.142857 | 56 | 1.1897174 | 0 | 0 | 56 | 0.2508174 + Heap2/MULTI_INSERT | 2 | 14.285714 | 170 | 3.6116421 | 0 | 0 | 170 | 0.76140994 + Heap/INSERT | 2 | 14.285714 | 265 | 5.629913 | 1528 | 8.671964 | 1793 | 8.030636 + Btree/INSERT_LEAF | 5 | 35.714287 | 314 | 6.6709156 | 11820 | 67.08286 | 12134 | 54.346756 + Btree/INSERT_UPPER | 1 | 7.142857 | 61 | 1.2959422 | 136 | 0.77185017 | 197 | 0.8823398 + Btree/SPLIT_L | 1 | 7.142857 | 3749 | 79.64733 | 4136 | 23.473326 | 7885 | 35.315987 +(8 rows) + + + + + + + + + pg_get_wal_stats_till_end_of_wal(start_lsn pg_lsn, + per_record boolean DEFAULT false, + "resource_manager/record_type" OUT text, + count OUT int8, + count_percentage OUT float4, + record_length OUT int8, + record_length_percentage OUT float4, + fpi_length OUT int8, + fpi_length_percentage OUT float4, + combined_size OUT int8, + combined_size_percentage OUT float4) + returns setof record + + + + + + This function is same as pg_get_wal_stats() except + that it gets statistics of all the valid WAL records from + start_lsn till end of WAL. + + + + + + + + + Author + + + Bharath Rupireddy bharath.rupireddyforpostgres@gmail.com + + + + -- 2.25.1