postgresql lsn/location 获取 wal/xlog 文件名
postgresql 10.x 叫做 wal、lsn
postgresql 9.x 叫做 xlog、location
在实际应用中经常需要根据 lsn/location 获取 wal/xlog 文件名
postgresql 10.x
postgres=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
0/1656FE0
(1 row)
postgres=# select pg_current_wal_lsn(),
pg_walfile_name(pg_current_wal_lsn()),
pg_walfile_name_offset(pg_current_wal_lsn());
pg_current_wal_lsn | pg_walfile_name | pg_walfile_name_offset
--------------------+--------------------------+------------------------------------
0/1656FE0 | 000000010000000000000001 | (000000010000000000000001,6647776)
(1 row)
postgresql 9.x
postgres=# select pg_current_xlog_location();
pg_current_xlog_location
--------------------------
596/C4DA2000
(1 row)
postgres=# select pg_current_xlog_location(),
pg_xlogfile_name(pg_current_xlog_location()),
pg_xlogfile_name_offset(pg_current_xlog_location());
pg_current_xlog_location | pg_xlogfile_name | pg_xlogfile_name_offset
--------------------------+--------------------------+-------------------------------------
596/C4DA2000 | 0000000100000596000000C4 | (0000000100000596000000C4,14295040)
(1 row)