? src/backend/utils/adt/dbsize.c Index: doc/src/sgml/func.sgml =================================================================== RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.262 diff -c -r1.262 func.sgml *** doc/src/sgml/func.sgml 29 Jun 2005 01:52:56 -0000 1.262 --- doc/src/sgml/func.sgml 6 Jul 2005 10:01:05 -0000 *************** *** 9092,9097 **** --- 9092,9206 ---- For details about proper usage of these functions, see . + + + The functions shown in calculate the actual disk space + usage of database objects. + + + + Database Object Size Functions + + + Name Return Type Description + + + + + + + pg_tablespace_size(oid) + + int8 + Calculates the total disk space used by the tablespace with the specified OID + + + + pg_tablespace_size(name) + + int8 + Calculates the total disk space used by the tablespace with the specified name + + + + pg_database_size(oid) + + int8 + Calculates the total disk space used by the database with the specified OID + + + + pg_database_size(name) + + int8 + Calculates the total disk space used by the database with the specified name + + + + pg_relation_size(oid) + + int8 + Calculates the disk space used by the table or index with the specified OID + + + + pg_relation_size(text) + + int8 + Calculates the disk space used by the index or table with the specified name. + The name may be prefixed with a schema name if required + + + + pg_complete_relation_size(oid) + + int8 + Calculates the total disk space used by the table with the specified OID, + including indexes and toasted data + + + + pg_complete_relation_size(text) + + int8 + Calculates the total disk space used by the table with the specified name, + including indexes and toasted data. The name may be prefixed with a schema name if + required + + + + pg_size_pretty(int8) + + text + Formats the size value (in bytes) into a human readable format with size units + + + +
+ + + pg_tablespace_size and pg_database_size accept an + oid or name of a tablespace or database, and return the disk space usage of the specified object. + + + + pg_relation_size + + + pg_relation_size accepts the oid or name of a table, index or + toast table, and returns the size in bytes. + + + pg_complete_relation_size accepts the oid or name of a table or + toast table, and returns the size in bytes of the data and all associated + indexes and toast tables. + + + pg_size_pretty can be used to format the size of the + database objects in a human readable way, using kB, MB, GB or TB as appropriate. + + Index: src/backend/utils/adt/Makefile =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/Makefile,v retrieving revision 1.57 diff -c -r1.57 Makefile *** src/backend/utils/adt/Makefile 1 Apr 2004 21:28:45 -0000 1.57 --- src/backend/utils/adt/Makefile 6 Jul 2005 10:01:05 -0000 *************** *** 24,30 **** tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \ network.o mac.o inet_net_ntop.o inet_net_pton.o \ ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \ ! ascii.o quote.o pgstatfuncs.o encode.o like.o: like.c like_match.c --- 24,30 ---- tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \ network.o mac.o inet_net_ntop.o inet_net_pton.o \ ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \ ! ascii.o quote.o pgstatfuncs.o encode.o dbsize.o like.o: like.c like_match.c Index: src/include/catalog/pg_proc.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v retrieving revision 1.373 diff -c -r1.373 pg_proc.h *** src/include/catalog/pg_proc.h 1 Jul 2005 19:19:03 -0000 1.373 --- src/include/catalog/pg_proc.h 6 Jul 2005 10:01:06 -0000 *************** *** 1569,1574 **** --- 1569,1579 ---- DATA(insert OID = 1241 ( nameicregexne PGNSP PGUID 12 f f t f i 2 16 "19 25" _null_ _null_ _null_ nameicregexne - _null_ )); DESCR("does not match regex., case-insensitive"); + DATA(insert OID = 1248 ( pg_tablespace_size PGNSP PGUID 12 f f t f v 1 20 "26" _null_ _null_ _null_ pg_tablespace_size_oid - _null_ )); + DESCR("Calculate total disk space usage for the specified tablespace"); + DATA(insert OID = 1250 ( pg_tablespace_size PGNSP PGUID 12 f f t f v 1 20 "19" _null_ _null_ _null_ pg_tablespace_size_name - _null_ )); + DESCR("Calculate total disk space usage for the specified tablespace"); + DATA(insert OID = 1251 ( int4abs PGNSP PGUID 12 f f t f i 1 23 "23" _null_ _null_ _null_ int4abs - _null_ )); DESCR("absolute value"); DATA(insert OID = 1253 ( int2abs PGNSP PGUID 12 f f t f i 1 21 "21" _null_ _null_ _null_ int2abs - _null_ )); *************** *** 1577,1582 **** --- 1582,1590 ---- DATA(insert OID = 1263 ( interval PGNSP PGUID 12 f f t f s 1 1186 "25" _null_ _null_ _null_ text_interval - _null_ )); DESCR("convert text to interval"); + DATA(insert OID = 1269 ( pg_database_size PGNSP PGUID 12 f f t f v 1 20 "26" _null_ _null_ _null_ pg_database_size_oid - _null_ )); + DESCR("Calculate total disk space usage for the specified database"); + DATA(insert OID = 1271 ( overlaps PGNSP PGUID 12 f f f f i 4 16 "1266 1266 1266 1266" _null_ _null_ _null_ overlaps_timetz - _null_ )); DESCR("SQL92 interval comparison"); DATA(insert OID = 1272 ( datetime_pl PGNSP PGUID 12 f f t f i 2 1114 "1082 1083" _null_ _null_ _null_ datetime_timestamp - _null_ )); *************** *** 1620,1625 **** --- 1628,1636 ---- DATA(insert OID = 1294 ( currtid2 PGNSP PGUID 12 f f t f v 2 27 "25 27" _null_ _null_ _null_ currtid_byrelname - _null_ )); DESCR("latest tid of a tuple"); + DATA(insert OID = 1295 ( pg_database_size PGNSP PGUID 12 f f t f v 1 20 "19" _null_ _null_ _null_ pg_database_size_name - _null_ )); + DESCR("Calculate total disk space usage for the specified database"); + DATA(insert OID = 1296 ( timedate_pl PGNSP PGUID 14 f f t f i 2 1114 "1083 1082" _null_ _null_ _null_ "select ($2 + $1)" - _null_ )); DESCR("convert time and date to timestamp"); DATA(insert OID = 1297 ( datetimetz_pl PGNSP PGUID 12 f f t f i 2 1184 "1082 1266" _null_ _null_ _null_ datetimetz_timestamptz - _null_ )); *************** *** 3030,3036 **** DATA(insert OID = 2173 ( pg_stop_backup PGNSP PGUID 12 f f t f v 0 25 "" _null_ _null_ _null_ pg_stop_backup - _null_ )); DESCR("Finish taking an online backup"); - /* Aggregates (moved here from pg_aggregate for 7.3) */ DATA(insert OID = 2100 ( avg PGNSP PGUID 12 t f f f i 1 1700 "20" _null_ _null_ _null_ aggregate_dummy - _null_ )); --- 3041,3046 ---- *************** *** 3219,3224 **** --- 3229,3245 ---- DATA(insert OID = 2273 ( has_schema_privilege PGNSP PGUID 12 f f t f s 2 16 "26 25" _null_ _null_ _null_ has_schema_privilege_id - _null_ )); DESCR("current user privilege on schema by schema oid"); + DATA(insert OID = 2284 ( pg_relation_size PGNSP PGUID 12 f f t f v 1 20 "26" _null_ _null_ _null_ pg_relation_size_oid - _null_ )); + DESCR("Calculate disk space usage for the specified table or index"); + DATA(insert OID = 2285 ( pg_relation_size PGNSP PGUID 12 f f t f v 1 20 "25" _null_ _null_ _null_ pg_relation_size_name - _null_ )); + DESCR("Calculate disk space usage for the specified table or index"); + DATA(insert OID = 2286 ( pg_complete_relation_size PGNSP PGUID 12 f f t f v 1 20 "26" _null_ _null_ _null_ pg_complete_relation_size_oid - _null_ )); + DESCR("Calculate total disk space usage for the specified table and associated indexes and toast tables"); + DATA(insert OID = 2287 ( pg_complete_relation_size PGNSP PGUID 12 f f t f v 1 20 "25" _null_ _null_ _null_ pg_complete_relation_size_name - _null_ )); + DESCR("Calculate total disk space usage for the specified table and associated indexes and toast tables"); + DATA(insert OID = 2288 ( pg_size_pretty PGNSP PGUID 12 f f t f v 1 25 "20" _null_ _null_ _null_ pg_size_pretty - _null_ )); + DESCR("Convert a long int to a human readable text using size units"); + DATA(insert OID = 2390 ( has_tablespace_privilege PGNSP PGUID 12 f f t f s 3 16 "19 25 25" _null_ _null_ _null_ has_tablespace_privilege_name_name - _null_ )); DESCR("user privilege on tablespace by username, tablespace name"); DATA(insert OID = 2391 ( has_tablespace_privilege PGNSP PGUID 12 f f t f s 3 16 "19 26 25" _null_ _null_ _null_ has_tablespace_privilege_name_id - _null_ )); Index: src/include/utils/builtins.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/utils/builtins.h,v retrieving revision 1.258 diff -c -r1.258 builtins.h *** src/include/utils/builtins.h 17 Jun 2005 22:32:50 -0000 1.258 --- src/include/utils/builtins.h 6 Jul 2005 10:01:07 -0000 *************** *** 357,362 **** --- 357,373 ---- extern Datum float84gt(PG_FUNCTION_ARGS); extern Datum float84ge(PG_FUNCTION_ARGS); + /* dbsize.c */ + extern Datum pg_tablespace_size_oid(PG_FUNCTION_ARGS); + extern Datum pg_tablespace_size_name(PG_FUNCTION_ARGS); + extern Datum pg_database_size_oid(PG_FUNCTION_ARGS); + extern Datum pg_database_size_name(PG_FUNCTION_ARGS); + extern Datum pg_relation_size_oid(PG_FUNCTION_ARGS); + extern Datum pg_relation_size_name(PG_FUNCTION_ARGS); + extern Datum pg_complete_relation_size_oid(PG_FUNCTION_ARGS); + extern Datum pg_complete_relation_size_name(PG_FUNCTION_ARGS); + extern Datum pg_size_pretty(PG_FUNCTION_ARGS); + /* misc.c */ extern Datum nullvalue(PG_FUNCTION_ARGS); extern Datum nonnullvalue(PG_FUNCTION_ARGS);