? 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.261 diff -c -r1.261 func.sgml *** doc/src/sgml/func.sgml 28 Jun 2005 05:08:50 -0000 1.261 --- doc/src/sgml/func.sgml 28 Jun 2005 12:20:18 -0000 *************** *** 9090,9095 **** --- 9090,9204 ---- 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 total disk space used by the relation with the specified OID + + + + pg_relation_size(text) + + int8 + Calculates the total disk space used by the relation with the specified name. + The name may be prefixed with a schema name if required + + + + pg_table_size(oid) + + int8 + Calculates the total disk space used by the table with the specified OID, + including indexes and toasted data + + + + pg_table_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_table_size accepts the oid or name of a table, index 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 27 Jun 2005 10:29:49 -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.372 diff -c -r1.372 pg_proc.h *** src/include/catalog/pg_proc.h 28 Jun 2005 05:09:09 -0000 1.372 --- src/include/catalog/pg_proc.h 28 Jun 2005 12:03:33 -0000 *************** *** 3031,3036 **** --- 3031,3056 ---- DESCR("Finish taking an online backup"); + 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 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 tablespace"); + 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 database"); + 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 database"); + 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 total disk space usage for relation"); + 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 total disk space usage for relation"); + DATA(insert OID = 2286 ( pg_table_size PGNSP PGUID 12 f f t f v 1 20 "26" _null_ _null_ _null_ pg_table_size_oid - _null_ )); + DESCR("Calculate total disk space usage for table"); + DATA(insert OID = 2287 ( pg_table_size PGNSP PGUID 12 f f t f v 1 20 "25" _null_ _null_ _null_ pg_table_size_name - _null_ )); + DESCR("Calculate total disk space usage for table"); + 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"); + + /* 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_ )); 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 28 Jun 2005 08:42:57 -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_table_size_oid(PG_FUNCTION_ARGS); + extern Datum pg_table_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);