Сочетание CTE
и COPY
должно составлять:
COPY (
WITH j AS (
SELECT nspname || '.' || relname AS relation,
pg_size_pretty(pg_total_relation_size(C.oid)) AS total_size_pretty, pg_total_relation_size(C.oid) AS total_size
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
)
SELECT pg_size_pretty((pgstattuple(j.relation)).dead_tuple_len + (pgstattuple(j.relation)).free_space) AS recoverable_space_pretty, (
(pgstattuple(j.relation)).dead_tuple_len + (pgstattuple(j.relation)).free_space) AS recoverable_space
FROM j
) TO STDOUT CSV HEADER;
запрос вернул данные копирования:
recoverable_space_pretty,recoverable_space
8104 bytes,8104
7508 bytes,7508
7992 bytes,7992
8044 bytes,8044
0 bytes,0
5068 bytes,5068
0 bytes,0
0 bytes,0
8104 bytes,8104
7724 bytes,7724
0 bytes,0
0 bytes,0
0 bytes,0
Примечание: Если вы можете позволить себе запись в файловой системе сервера базы данных, измените STDOUT
на выбранный вами путь.