From: | Japin Li <japinli(at)hotmail(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: pg_relation_size on partitioned table |
Date: | 2022-03-25 13:28:42 |
Message-ID: | MEYP282MB166934DA58F69D3714993A71B61A9@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, 25 Mar 2022 at 20:59, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
> On 2022-Mar-25, Japin Li wrote:
>
>> Could we provide a function to get the total size of the partition table
>> though the partitioned table name? Maybe we can extend
>> the pg_relation_size() to get the total size of partition tables through
>> the partitioned table name.
>
> Does \dP+ do what you need?
Thanks for your quick response!
I find the \dP+ use the following SQL:
SELECT n.nspname as "Schema",
c.relname as "Name",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner",
CASE c.relkind WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
inh.inhparent::pg_catalog.regclass as "Parent name",
c2.oid::pg_catalog.regclass as "Table",
s.tps as "Total size",
pg_catalog.obj_description(c.oid, 'pg_class') as "Description"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid
LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid
LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid,
LATERAL (SELECT pg_catalog.pg_size_pretty(sum(
CASE WHEN ppt.isleaf AND ppt.level = 1
THEN pg_catalog.pg_table_size(ppt.relid) ELSE 0 END)) AS dps,
pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size(ppt.relid))) AS tps
FROM pg_catalog.pg_partition_tree(c.oid) ppt) s
WHERE c.relkind IN ('p','I','')
AND c.relname OPERATOR(pg_catalog.~) '^(parent)$' COLLATE pg_catalog.default
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY "Schema", "Type" DESC, "Parent name" NULLS FIRST, "Name";
pg_table_size() includes "main", "vm", "fsm", "init" and "toast", however,
I only care about the "main" fork.
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2022-03-25 13:28:58 | Re: [PATCH] pg_statio_all_tables: several rows per table due to invalid TOAST index |
Previous Message | Tom Lane | 2022-03-25 13:25:12 | Re: Probable memory leak with ECPG and AIX |