pg_walinspect - a new extension to get raw WAL data and WAL stats - Mailing list pgsql-hackers
From | Bharath Rupireddy |
---|---|
Subject | pg_walinspect - a new extension to get raw WAL data and WAL stats |
Date | |
Msg-id | CALj2ACUGUYXsEQdKhEdsBzhGEyF3xggvLdD8C0VT72TNEfOiog@mail.gmail.com Whole thread Raw |
Responses |
Re: pg_walinspect - a new extension to get raw WAL data and WAL stats
Re: pg_walinspect - a new extension to get raw WAL data and WAL stats |
List | pgsql-hackers |
Hi, While working on one of the internal features, we found that it is a bit difficult to run pg_waldump for a normal user to know WAL info and stats of a running postgres database instance in the cloud. Many a times users or DBAs or developers would want to get and analyze following: 1) raw WAL record associated with an LSN or raw WAL records between a start LSN and end LSN for feeding to some other functionality 2) WAL statistics associated with an LSN or between start LSN and end LSN for debugging or analytical purposes. The WAL stats are the number of inserts, updates, deletes, index inserts, commits, checkpoints, aborts, wal record sizes, FPI (Full Page Image) count etc. which are basically everything that we get with pg_waldump --stats option plus some other information as we may feel will be useful. An available option is to use pg_waldump, a standalone program emitting human readable WAL info into a standard output/file. This works well when users have access to the system on which postgres is running. But for a postgres database instance running in the cloud environments, starting the pg_waldump, fetching and presenting its output to the users in a structured way may be a bit hard to do. How about we create a new extension, called pg_walinspect (synonymous to pageinspect extension) with a bunch of SQL-callable functions that get the raw WAL records or stats out of a running postgres database instance in a more structured way that is easily consumable by all the users or DBAs or developers? We can also provide these functionalities into the core postgres (in xlogfuncs.c) instead of a new extension, but we would like it to be pluggable so that the functions will be used only if required. [1] shows a rough sketch of the functions that the new pg_walinspect extension can provide. These are not exhaustive; we can add/remove/modify as we move further. We would like to invite more thoughts from the hackers. Credits: Thanks to Satya Narlapuram, Chen Liang (for some initial work), Tianyu Zhang and Ashutosh Sharma (copied in cc) for internal discussions. [1] a) bytea pg_get_wal_record(pg_lsn lsn); and bytea pg_get_wal_record(pg_lsn lsn, text wal_dir); - Returns a single row of raw WAL record of bytea type. WAL data is read from pg_wal or specified wal_dir directory. b) bytea[] pg_get_wal_record(pg_lsn start_lsn, pg_lsn end_lsn); and bytea[] pg_get_wal_record(pg_lsn start_lsn, pg_lsn end_lsn, text wal_dir); - Returns multiple rows of raw WAL records of bytea type, one row per each WAL record. WAL data is read from pg_wal or specified wal_dir directory. CREATE TYPE walinspect_stats_type AS (stat1, stat2, stat3 …. statN); c) walinspect_stats_type pg_get_wal_stats(pg_lsn lsn); and walinspect_stats_type pg_get_wal_stats(pg_lsn lsn, text wal_dir); - Returns a single row of WAL record’s stats of walinspect_stats_type type. WAL data is read from pg_wal or specified wal_dir directory. d) walinspect_stats_type[] pg_get_wal_stats(pg_lsn start_lsn, pg_lsn end_lsn); and walinspect_stats_type[] pg_get_wal_stats(pg_lsn start_lsn, pg_lsn end_lsn, text wal_dir); - Returns multiple rows of WAL record stats of walinspect_stats_type type, one row per each WAL record. WAL data is read from pg_wal or specified wal_dir directory. e) walinspect_stats_type pg_get_wal_stats(bytea wal_record); - Returns a single row of provided WAL record (wal_record) stats. f) walinspect_stats_type pg_get_wal_stats_aggr(pg_lsn start_lsn, pg_lsn end_lsn); and walinspect_stats_type pg_get_wal_stats_aggr(pg_lsn start_lsn, pg_lsn end_lsn, text wal_dir); - Returns a single row of aggregated stats of all the WAL records between start_lsn and end_lsn. WAL data is read from pg_wal or specified wal_dir directory. CREATE TYPE walinspect_lsn_range_type AS (pg_lsn start_lsn, pg_lsn end_lsn); g) walinspect_lsn_range_type walinspect_get_lsn_range(text wal_dir); - Returns a single row of start LSN and end LSN of the WAL records available under pg_wal or specified wal_dir directory. Regards, Bharath Rupireddy.
pgsql-hackers by date: