PostgreSQL Built-In Functions
Functions
Functions
current_database
Name of current databasecurrent_database
pg_table_size
disk space usage for the specified table, including TOAST, free space and visibility mappg_table_size
pg_column_size
Bytes required to store the value, perhaps with compressionpg_column_size
pg_database_size
Bytes used by the database with the specified name/OID. pg_database_size
pg_database_size()
essentially queries the filesystem for the size of $PGDATA/base/oid-of-database
(the per-database data directory), plus the size of every such directory in non-default tablespaces added with CREATE TABLESPACE
. If there are files in these directories that don't pertain to any relation , they will be counted too. https://dba.stackexchange.com/questions/121804/what-parts-make-up-pg-database-sizepg_indexes_size
disk space usage for all indexes attached to the specified tablepg_indexes_size
pg_tablespace_size
total disk space usage for the specified tablespacepg_tablespace_size
pg_size_pretty
Converts a size in bytes expressed as a numeric value into a human-readable format with size units.pg_size_pretty
pg_relation_size
disk space usage for the main fork of the specified table or indexpg_relation_size
pg_total_relation_size
total disk space usage for the specified table and associated indexespg_total_relation_size
Example SQL
Example SQL
Database Size
Database Size
SELECT current_database() as db;
SELECT pg_database_size(current_database()) as size;
SELECT pg_size_pretty(pg_database_size(current_database())) as size;
SELECT SUM(pg_total_relation_size(oid)) AS dbsize,
pg_database_size(current_database()) AS dbsizeondisk
FROM pg_class
WHERE relkind IN ('r','m','S')
AND NOT relisshared;
Example Output
Example Output
jira
1714780696
1635 MB
1731985408
1732098584