Preview(opens in a new tab)

Count no. of files in pg_xlog or pg_wal directory

SELECT COUNT(*) FROM pg_ls_dir('pg_xlog') WHERE pg_ls_dir ~ '^[0-9A-F]{24}';

postgres=# SELECT COUNT(*) FROM pg_ls_dir('pg_wal') WHERE pg_ls_dir ~ '^[0-9A-F]{24}';
count
-------
61

Find Current WAL LSN

postgres=# select pg_current_wal_lsn(); 
pg_current_wal_lsn
--------------------
3/A0007BC8

(1 row)

Find LSN File Name into WAL

postgres=# select pg_walfile_name('3/A0007BC8');
pg_walfile_name
--------------------------
0000000100000003000000A0
(1 row)


Check PostgreSQL pg_wal / pg_xlog Directory 

root@mlt352-ubuntu:/opt/PostgreSQL/10/data/pg_wal# ls -lth
total 977M
-rw——- 1 postgres postgres 16M Apr 5 01:42 0000000100000003000000A0
-rw——- 1 postgres postgres 16M Oct 1 2019 0000000100000003000000D8
-rw——- 1 postgres postgres 16M Oct 1 2019 0000000100000003000000CB
-rw——- 1 postgres postgres 16M Oct 1 2019 0000000100000003000000D7