pg_walfile_name()

A function for returning the WAL file name for an LSN

pg_walfile_name() is a system function for obtaining the name of the WAL file corresponding to the provided LSN.

pg_walfile_name() was added in PostgreSQL 8.2 as pg_xlogfile_name().

Usage

pg_walfile_name ( lsn pg_lsn ) → text

pg_walfile_name() can only be executed on a primary server (i.e. not a read-only standby).

Change history

Examples

Basic usage example for pg_walfile_name():

postgres=# SELECT pg_walfile_name('0/01000001');
     pg_walfile_name
--------------------------
 000000010000000000000001
(1 row)

Obtaining the current WAL file name:

postgres=# SELECT pg_walfile_name(pg_current_wal_lsn());
     pg_walfile_name
--------------------------
 000000010000000000000003
(1 row)

Attempting to execute pg_walfile_name() on a standby:

postgres=# SELECT pg_walfile_name('0/1');
ERROR:  recovery is in progress
HINT:  pg_walfile_name() cannot be executed during recovery.

Categories

Replication, System function, WAL

See also

pg_walfile_name_offset(), pg_current_wal_lsn()