📅  最后修改于: 2023-12-03 15:02:54.952000             🧑  作者: Mango
pg_relation_size
in PostgreSQLpg_relation_size
is a function in PostgreSQL that returns the size of a relation in bytes. A relation can be a table, view, or index. This function can be used to monitor the size of a relation and help identify if a table or index is growing excessively.
The syntax for pg_relation_size
is as follows:
pg_relation_size(relation regclass) RETURNS bigint
The relation
parameter is the name of the relation for which the size is to be returned. It can be specified as a string or a regclass.
SELECT pg_relation_size('public.my_table'); -- returns size of my_table in bytes
SELECT pg_relation_size(indexname) AS index_size
FROM pg_index
JOIN pg_class ON pg_index.indexrelid = pg_class.oid
WHERE tablename = 'my_table';
pg_relation_size
includes any related indexes or toast tables.pg_total_relation_size
can be used to compute the total disk space used by a table, including indexes and toast tables.