Created
July 28, 2020 20:38
-
-
Save jalexandre0/5eff5fea781a34fddcf72ae7e0bafe31 to your computer and use it in GitHub Desktop.
SQL to parse and extract information from pg_wal (or pg_xlog) *.backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
min(times) AS start_time, | |
max(times) AS stop_time, | |
max(times) - min(times) AS duration, | |
now() - min(times) AS delta_backup_time_from_start, | |
now() - max(times) AS delta_backup_time_from_finish, | |
pg_is_in_backup() | |
FROM | |
( SELECT | |
((regexp_matches(pg_read_file(waldir || filename), '[0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*', | |
'g'))[1])::TIMESTAMP AS times | |
FROM | |
( SELECT (pg_ls_dir || '/') AS waldir | |
FROM pg_ls_dir('.') | |
WHERE pg_ls_dir IN ('pg_wal', 'pg_xlog') ) AS get_waldir_name, | |
( SELECT | |
pg_ls_dir(( SELECT (pg_ls_dir || '/') | |
FROM pg_ls_dir('.') | |
WHERE pg_ls_dir IN ('pg_wal', 'pg_xlog') )) AS filename ) AS file_list | |
WHERE | |
filename LIKE '%.backup' ) AS check_backup_label | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment