Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LSN external representation

Tags:

postgresql

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?

like image 536
Fabrice Chapuis Avatar asked Jul 11 '26 10:07

Fabrice Chapuis


2 Answers

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'
like image 122
vladich Avatar answered Jul 13 '26 20:07

vladich


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.

like image 24
Laurenz Albe Avatar answered Jul 13 '26 20:07

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!