According to postgres documentation, LSN is a 64-bit integer, representing a byte position in the write-ahead log stream. It is printed as two hexadecimal numbers of up to 8 digits each, separated by a slash; for example, 16/B374D848. Does anyone know what is the meaning of these 2 hexadecimal numbers?
pg_lsn type supports - operation and returns byte offset, so here is the simplest way to convert from pg_lsn to bigint:
SELECT pg_current_wal_lsn() - '0/0'
For the example above it will look like this:
SELECT '16/374D848'::pg_lsn - '0/0'
Left pad the part right of the slash with zeros, then remove the slash, and you have the offset in bytes described by the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With