--
-- Displays all files belonging to the actual cluster
--
SELECT DISTINCT CASE
         WHEN c.relisshared = 't'
         THEN 'CLUSTER'
         ELSE db.datname
         END AS db_name,
       nc.nspname AS schema,
       CASE
         WHEN nc.nspname ~~ like_escape('pg!_temp!_%', '!') THEN 'LOCAL TEMPORARY'
         WHEN c.relkind = 'r' THEN 'BASE TABLE'
         WHEN c.relkind = 'v' THEN 'VIEW'
         WHEN c.relkind = 'S' THEN 'SQUENCE'
         WHEN c.relkind = 'i' THEN 'INDEX'
         WHEN c.relkind = 's' THEN 'SYSTEM TABLE'
         WHEN c.relkind = 't' THEN 'TABLE'
         ELSE NULL
       END AS object_type,
       c.relname AS object_name,
       CASE
         WHEN c.relname = 'pg_xactlock'
         THEN NULL
         WHEN c.relisshared = 't'
         THEN '${PG_ADMIN}/global/' || c.relfilenode
         WHEN db.datpath = ''
         THEN '${PG_ADMIN}/' || 'base/' || db.oid || '/' || c.relfilenode
         ELSE '${' || db.datpath || '}/base/' || db.oid || '/' || c.relfilenode
       END AS file_name
FROM pg_namespace nc, pg_class c, pg_user u, pg_database db
WHERE c.relnamespace = nc.oid
  AND u.usesysid = c.relowner
ORDER BY db_name, schema, object_type, object_name;
