/**
 * View to monitor write ahead logs (WAL).
 *
 * @author: "Stefanie Janine Stölting"<stefanie@proopensource.eu>
 * @license: PostgreSQL https://opensource.org/licenses/postgresql
 */

CREATE OR REPLACE VIEW monitoring_wal AS
SELECT count (*) FILTER
		(
			WHERE pg_ls_dir~'done'
		) AS wals_done
	, count(*) FILTER
		(
			WHERE pg_ls_dir~'ready'
		) AS wals_ready
from pg_ls_dir('pg_wal/archive_status')
;

COMMENT ON VIEW monitoring_wal IS 'View to monitor write ahead logs (WAL).';
COMMENT ON COLUMN monitoring_wal.wals_done IS 'Number of WAL files, that have been done.';
COMMENT ON COLUMN monitoring_wal.wals_ready IS 'Number of WAL files, that have to be done.';
