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
WITH opt AS ( | |
SELECT '1 day'::interval older_than | |
),base_files AS ( | |
SELECT | |
format('base/%s/%s', db.oid::text, ls.file) path, | |
ls.file, substring(ls.file, '^\d+') parent | |
FROM pg_database db | |
CROSS JOIN LATERAL pg_ls_dir('base/' || db.oid::text) ls(file) | |
WHERE db.datname = current_database() AND ls.file ~ '^\d+' | |
),probably_orphaned_parents AS ( |