Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read WAL files in pg_xlog directory through java

Am trying to read WAL files of the postgresql can any body tell me how to do that n what type of binary encoding is used in WAL binary files

like image 582
user1802481 Avatar asked Dec 27 '12 08:12

user1802481


2 Answers

Using pg_xlogdump to read WAL file (this contrib program added to PG 9.3 version - PG 9.3 released doc)

This utility can only be run by the user who installed the server, because it requires read-only access to the data directory.

pg_xlogdump --help
pg_xlogdump decodes and displays PostgreSQL transaction logs for debugging.

Usage:
  pg_xlogdump [OPTION]... [STARTSEG [ENDSEG]]

Options:
  -b, --bkp-details      output detailed information about backup blocks
  -e, --end=RECPTR       stop reading at log position RECPTR
  -f, --follow           keep retrying after reaching end of WAL
  -n, --limit=N          number of records to display
  -p, --path=PATH        directory in which to find log segment files
                         (default: ./pg_xlog)
  -r, --rmgr=RMGR        only show records generated by resource manager RMGR
                         use --rmgr=list to list valid resource manager names
  -s, --start=RECPTR     start reading at log position RECPTR
  -t, --timeline=TLI     timeline from which to read log records
                         (default: 1 or the value used in STARTSEG)
  -V, --version          output version information, then exit
  -x, --xid=XID          only show records with TransactionId XID
  -z, --stats[=record]   show statistics instead of records
                         (optionally, show per-record statistics)
  -?, --help             show this help, then exit

For example: pg_xlogdump 000000010000005A00000096

PostgreSQL Document or this blog

like image 92
Luan Huynh Avatar answered Sep 20 '22 18:09

Luan Huynh


You can't really do that. It's easy enough to read the bytes from a WAL archive, but it sounds like you want to make sense of them. You will struggle with that.

WAL archives are a binary log showing what blocks changed in the database. They aren't SQL-level or row-level change logs, so you cannot just examine them to get a list of changed rows.

You probably want to investigate trigger-based replication or audit triggers instead.

like image 27
Craig Ringer Avatar answered Sep 21 '22 18:09

Craig Ringer