You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Of course, there must be a big warning about the danger of blind deleting, but I think it could be another service.
To avoid useless warnings, only report files above a few Mb and older than 24h?
WITH ver AS (
SELECT
current_setting('server_version_num') pgversion,
v::INTEGER/10000||'.'|| MOD(v::INTEGER, 10000) /100AS version
FROM
current_setting('server_version_num') v
),
tbl_paths AS (
SELECTtbs.oidAS tbs_oid,
spcname,
'pg_tblspc/'||tbs.oid||'/'|| (
SELECT
dir
FROM
pg_ls_dir('pg_tblspc/'||tbs.oid||'/', TRUE, FALSE) dir
WHERE
dir LIKE E'PG\\_'||ver.version|| E'\\_%') AS tbl_path
FROM
pg_tablespace tbs,
ver
WHEREtbs.spcname NOT IN ('pg_default', 'pg_global')
),
files AS (
SELECTd.oidAS database_oid,
0AS tbs_oid,
'base/'||d.oidASpath,
file_name AS file_name,
SUBSTRING(file_name FROM E'[0-9]+') AS base_name
FROM
pg_database d,
pg_ls_dir('base/'||d.oid, TRUE, FALSE) AS file_name
WHEREd.datname= current_database()
UNION ALLSELECTd.oid,
tbp.tbs_oid,
tbl_path ||'/'||d.oid,
file_name,
(SUBSTRING(file_name FROM E'[0-9]+')) AS base_name
FROM
pg_database d,
tbl_paths tbp,
pg_ls_dir(tbp.tbl_path||'/'||d.oid, TRUE, FALSE) AS file_name
WHEREd.datname= current_database()
),
orphans AS (
SELECT
tbs_oid,
base_name,
file_name,
current_setting('data_directory') ||'/'||path||'/'|| file_name AS orphaned_file,
pg_filenode_relation(tbs_oid, base_name::oid) AS rel_without_pgclass
FROM
ver,
files
LEFT JOIN pg_class c ON (c.relfilenode::text=files.base_nameOR (c.oid::text=files.base_nameANDc.relfilenode=0ANDc.relnameLIKE'pg_%'))
WHEREc.oid IS NULLANDLOWER(file_name)
NOT LIKE'pg_%'
)
SELECT
orphaned_file,
pg_size_pretty((pg_stat_file(orphaned_file)).size) AS file_size,
(pg_stat_file(orphaned_file)).modification AS modification_date,
current_database()
FROM
orphans
WHERE
rel_without_pgclass IS NULL
The text was updated successfully, but these errors were encountered:
There is a query detecting orphaned files that has slipped into pgstats, and some of you may recognize it:
https://github.com/gleu/pgstats/blob/master/pgreport_queries.h#L136
Of course, there must be a big warning about the danger of blind deleting, but I think it could be another service.
To avoid useless warnings, only report files above a few Mb and older than 24h?
The text was updated successfully, but these errors were encountered: