PostgreSQL LSN & WAL File Name Calculator
Enter a log sequence number such as 16/B374D848 and see its byte position, the WAL segment file that holds it (pg_walfile_name and pg_walfile_name_offset), the offset inside the segment and the 8kB WAL page. Paste a 24-character WAL file name instead to get the first and last LSN it covers, like pg_split_walfile_name. Add a second LSN to compute pg_wal_lsn_diff and pg_size_pretty, which is how replication lag and slot retention are measured. Segment size, timeline and the PostgreSQL 17 change to segment-boundary handling are all configurable. Everything runs in your browser.
Do more than postgresql lsn & wal file name calculator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Enter an LSN (for example from pg_current_wal_lsn() or pg_stat_replication) or a WAL file name from pg_wal.
- Set wal_segment_size, the timeline ID and your PostgreSQL version, and optionally a second LSN or a byte offset to add.
- Click Calculate and copy the WAL file name, the byte difference or the generated monitoring SQL.
Frequently asked questions
What is an LSN in PostgreSQL?
A log sequence number is a 64-bit byte position in the write-ahead log, printed as two hexadecimal halves separated by a slash, such as 16/B374D848. Subtracting two LSNs gives the number of WAL bytes between them, which is what pg_wal_lsn_diff() returns.
How do I find which WAL file contains an LSN?
Run SELECT pg_walfile_name('16/B374D848') on the primary, or compute it: the segment number is the LSN divided by wal_segment_size, and the file name is the timeline, the high 32 bits and the segment within them, each as 8 hex digits. Before PostgreSQL 17, an LSN exactly on a segment boundary was reported as belonging to the previous file.
How do I measure replication lag in bytes?
Use pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) from pg_stat_replication on the primary, and wrap it in pg_size_pretty() for a readable value. Chat2DB can connect to your PostgreSQL database and run these monitoring queries with its AI assistant: download it from chat2db.ai/download or use the web version at app.chat2db.ai.
