From e4d9b69779157935c4d3087b9ab67ac7dfdec9b4 Mon Sep 17 00:00:00 2001 From: Neil Conway <neilc@samurai.com> Date: Fri, 16 Sep 2005 05:35:41 +0000 Subject: [PATCH] Rename pg_complete_relation_size() to pg_total_relation_size(), for the sake of brevity and clarity. Make pg_reload_conf(), pg_rotate_logfile(), and pg_cancel_backend() return a boolean rather than an integer to indicate success or failure. Along the way, make some minor cleanups to dbsize.c -- in particular, use elog() rather than ereport() for "shouldn't happen" error conditions, and remove some of the more flagrant violations of the Postgres indentation conventions. Catalog version bumped. --- doc/src/sgml/func.sgml | 57 +++++++++++++++++-------------- doc/src/sgml/release.sgml | 12 +++++-- src/backend/utils/adt/dbsize.c | 58 +++++++++++++++----------------- src/backend/utils/adt/misc.c | 26 ++++++-------- src/include/catalog/catversion.h | 4 +-- src/include/catalog/pg_proc.h | 12 +++---- src/include/utils/builtins.h | 6 ++-- 7 files changed, 90 insertions(+), 85 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index eaebce24c7c..c6c9d87e8a5 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.285 2005/09/14 21:14:26 neilc Exp $ +$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.286 2005/09/16 05:35:39 neilc Exp $ PostgreSQL documentation --> @@ -9368,21 +9368,21 @@ SELECT set_config('log_statement_stats', 'off', false); <entry> <literal><function>pg_cancel_backend</function>(<parameter>pid</parameter> <type>int</>)</literal> </entry> - <entry><type>int</type></entry> + <entry><type>boolean</type></entry> <entry>Cancel a backend's current query</entry> </row> <row> <entry> <literal><function>pg_reload_conf</function>()</literal> </entry> - <entry><type>int</type></entry> + <entry><type>boolean</type></entry> <entry>Cause server processes to reload their configuration files</entry> </row> <row> <entry> <literal><function>pg_rotate_logfile</function>()</literal> </entry> - <entry><type>int</type></entry> + <entry><type>boolean</type></entry> <entry>Rotate server's logfile</entry> </row> </tbody> @@ -9390,7 +9390,8 @@ SELECT set_config('log_statement_stats', 'off', false); </table> <para> - Each of these functions returns 1 if successful, 0 if not successful. + Each of these functions returns <literal>true</literal> if + successful and <literal>false</literal> otherwise. </para> <para> @@ -9502,7 +9503,7 @@ SELECT set_config('log_statement_stats', 'off', false); <primary>pg_relation_size</primary> </indexterm> <indexterm zone="functions-admin"> - <primary>pg_complete_relation_size</primary> + <primary>pg_total_relation_size</primary> </indexterm> <indexterm zone="functions-admin"> <primary>pg_size_pretty</primary> @@ -9527,28 +9528,28 @@ SELECT set_config('log_statement_stats', 'off', false); <literal><function>pg_tablespace_size</function>(<type>oid</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Total disk space used by the tablespace with the specified OID</entry> + <entry>Disk space used by the tablespace with the specified OID</entry> </row> <row> <entry> <literal><function>pg_tablespace_size</function>(<type>name</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Total disk space used by the tablespace with the specified name</entry> + <entry>Disk space used by the tablespace with the specified name</entry> </row> <row> <entry> <literal><function>pg_database_size</function>(<type>oid</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Total disk space used by the database with the specified OID</entry> + <entry>Disk space used by the database with the specified OID</entry> </row> <row> <entry> <literal><function>pg_database_size</function>(<type>name</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Total disk space used by the database with the specified name</entry> + <entry>Disk space used by the database with the specified name</entry> </row> <row> <entry> @@ -9562,25 +9563,31 @@ SELECT set_config('log_statement_stats', 'off', false); <literal><function>pg_relation_size</function>(<type>text</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Disk space used by the table or index with the specified name. - The name may be qualified with a schema name</entry> + <entry> + Disk space used by the table or index with the specified name. + The table name may be qualified with a schema name + </entry> </row> <row> <entry> - <literal><function>pg_complete_relation_size</function>(<type>oid</type>)</literal> + <literal><function>pg_total_relation_size</function>(<type>oid</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Total disk space used by the table with the specified OID, - including indexes and toasted data</entry> + <entry> + Total disk space used by the table with the specified OID, + including indexes and toasted data + </entry> </row> <row> <entry> - <literal><function>pg_complete_relation_size</function>(<type>text</type>)</literal> + <literal><function>pg_total_relation_size</function>(<type>text</type>)</literal> </entry> <entry><type>bigint</type></entry> - <entry>Total disk space used by the table with the specified name, - including indexes and toasted data. - The table name may be qualified with a schema name</entry> + <entry> + Total disk space used by the table with the specified name, + including indexes and toasted data. The table name may be + qualified with a schema name + </entry> </row> <row> <entry> @@ -9610,9 +9617,9 @@ SELECT set_config('log_statement_stats', 'off', false); </para> <para> - <function>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. + <function>pg_total_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. </para> <para> @@ -9669,7 +9676,7 @@ SELECT set_config('log_statement_stats', 'off', false); <primary>pg_ls_dir</primary> </indexterm> <para> - <function>pg_ls_dir()</> returns all the names in the specified + <function>pg_ls_dir</> returns all the names in the specified directory, except the special entries <quote><literal>.</></> and <quote><literal>..</></>. </para> @@ -9678,7 +9685,7 @@ SELECT set_config('log_statement_stats', 'off', false); <primary>pg_read_file</primary> </indexterm> <para> - <function>pg_read_file()</> returns part of a text file, starting + <function>pg_read_file</> returns part of a text file, starting at the given <parameter>offset</>, returning at most <parameter>length</> bytes (less if the end of file is reached first). If <parameter>offset</> is negative, it is relative to the end of the file. @@ -9688,7 +9695,7 @@ SELECT set_config('log_statement_stats', 'off', false); <primary>pg_stat_file</primary> </indexterm> <para> - <function>pg_stat_file()</> returns a record containing the file + <function>pg_stat_file</> returns a record containing the file size, last accessed timestamp, last modified timestamp, last file status change timestamp (Unix platforms only), file creation timestamp (Win32 only), and a boolean indicating diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml index 3bbb6da4e84..6300a89a6bc 100644 --- a/doc/src/sgml/release.sgml +++ b/doc/src/sgml/release.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.368 2005/09/16 03:37:35 tgl Exp $ +$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.369 2005/09/16 05:35:39 neilc Exp $ Typical markup: @@ -408,6 +408,12 @@ pg_[A-Za-z0-9_] <application> </para> </listitem> + <listitem> + <para> + Make <function>pg_cancel_backend(int)</function> return a + <type>boolean</type> rather than an <type>integer</type> (Neil) + </para> + </listitem> </itemizedlist> </sect2> @@ -1167,7 +1173,7 @@ pg_[A-Za-z0-9_] <application> <listitem> <para> - <function>pg_complete_relation_size()</> + <function>pg_total_relation_size()</> </para> </listitem> @@ -1180,7 +1186,7 @@ pg_[A-Za-z0-9_] <application> </itemizedlist> </para> <para> - <function>pg_complete_relation_size()</> includes indexes and TOAST + <function>pg_total_relation_size()</> includes indexes and TOAST tables. </para> </listitem> diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index e86f828f559..e3b3e2e263d 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -5,7 +5,7 @@ * Copyright (c) 2002-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.3 2005/08/02 15:17:24 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.4 2005/09/16 05:35:40 neilc Exp $ * */ @@ -68,7 +68,7 @@ db_dir_size(const char *path) static int64 calculate_database_size(Oid dbOid) { - int64 totalsize = 0; + int64 totalsize; DIR *dirdesc; struct dirent *direntry; char dirpath[MAXPGPATH]; @@ -78,7 +78,7 @@ calculate_database_size(Oid dbOid) /* Include pg_default storage */ snprintf(pathname, MAXPGPATH, "%s/base/%u", DataDir, dbOid); - totalsize += db_dir_size(pathname); + totalsize = db_dir_size(pathname); /* Scan the non-default tablespaces */ snprintf(dirpath, MAXPGPATH, "%s/pg_tblspc", DataDir); @@ -273,9 +273,7 @@ pg_relation_size_oid(PG_FUNCTION_ARGS) ObjectIdGetDatum(relOid), 0, 0, 0); if (!HeapTupleIsValid(tuple)) - ereport(ERROR, - (ERRCODE_UNDEFINED_TABLE, - errmsg("relation with OID %u does not exist", relOid))); + elog(ERROR, "cache lookup failed for relation %u", relOid); pg_class = (Form_pg_class) GETSTRUCT(tuple); relnodeOid = pg_class->relfilenode; @@ -308,11 +306,12 @@ pg_relation_size_name(PG_FUNCTION_ARGS) /* - * Compute on-disk size of files for 'relation' according to the stat function, - * optionally including heap data, index data, and/or toast data. + * Compute the on-disk size of files for 'relation' according to the + * stat function, optionally including heap data, index data, and/or + * toast data. */ static int64 -calculate_complete_relation_size(Oid tblspcOid, Oid relnodeOid) +calculate_total_relation_size(Oid tblspcOid, Oid relnodeOid) { Relation heapRelation; Relation idxRelation; @@ -322,7 +321,7 @@ calculate_complete_relation_size(Oid tblspcOid, Oid relnodeOid) Oid toastOid; Oid toastTblspcOid; bool hasIndices; - int64 size = 0; + int64 size; List *indexoidlist; ListCell *idx; @@ -331,14 +330,16 @@ calculate_complete_relation_size(Oid tblspcOid, Oid relnodeOid) hasIndices = heapRelation->rd_rel->relhasindex; /* Get the heap size */ - size += calculate_relation_size(tblspcOid, relnodeOid); + size = calculate_relation_size(tblspcOid, relnodeOid); - /* Get Index size */ - if ( hasIndices ) { - /* recursively include any dependent indexes ... */ + /* Get index size */ + if (hasIndices) + { + /* recursively include any dependent indexes */ indexoidlist = RelationGetIndexList(heapRelation); - - foreach(idx, indexoidlist) { + + foreach(idx, indexoidlist) + { idxOid = lfirst_oid(idx); idxRelation = relation_open(idxOid, AccessShareLock); idxTblspcOid = idxRelation->rd_rel->reltablespace; @@ -347,14 +348,13 @@ calculate_complete_relation_size(Oid tblspcOid, Oid relnodeOid) } list_free(indexoidlist); } - - /* Close heapReleation now we no longer need it */ + relation_close(heapRelation, AccessShareLock); /* Get toast table size */ - if ( toastOid != 0 ) { - - /* recursively include any toast relations ... */ + if (toastOid != 0) + { + /* recursively include any toast relations */ toastRelation = relation_open(toastOid, AccessShareLock); toastTblspcOid = toastRelation->rd_rel->reltablespace; size += calculate_relation_size(toastTblspcOid, toastOid); @@ -369,7 +369,7 @@ calculate_complete_relation_size(Oid tblspcOid, Oid relnodeOid) * heap data, index data, and toasted data. */ Datum -pg_complete_relation_size_oid(PG_FUNCTION_ARGS) +pg_total_relation_size_oid(PG_FUNCTION_ARGS) { Oid relOid=PG_GETARG_OID(0); HeapTuple tuple; @@ -378,12 +378,10 @@ pg_complete_relation_size_oid(PG_FUNCTION_ARGS) Oid tblspcOid; tuple = SearchSysCache(RELOID, - ObjectIdGetDatum(relOid), - 0, 0, 0); + ObjectIdGetDatum(relOid), + 0, 0, 0); if (!HeapTupleIsValid(tuple)) - ereport(ERROR, - (ERRCODE_UNDEFINED_TABLE, - errmsg("relation with OID %u does not exist", relOid))); + elog(ERROR, "cache lookup failed for relation %u", relOid); pg_class = (Form_pg_class) GETSTRUCT(tuple); relnodeOid = pg_class->relfilenode; @@ -391,11 +389,11 @@ pg_complete_relation_size_oid(PG_FUNCTION_ARGS) ReleaseSysCache(tuple); - PG_RETURN_INT64(calculate_complete_relation_size(tblspcOid, relnodeOid)); + PG_RETURN_INT64(calculate_total_relation_size(tblspcOid, relnodeOid)); } Datum -pg_complete_relation_size_name(PG_FUNCTION_ARGS) +pg_total_relation_size_name(PG_FUNCTION_ARGS) { text *relname = PG_GETARG_TEXT_P(0); RangeVar *relrv; @@ -411,7 +409,7 @@ pg_complete_relation_size_name(PG_FUNCTION_ARGS) relation_close(relation, AccessShareLock); - PG_RETURN_INT64(calculate_complete_relation_size(tblspcOid, relnodeOid)); + PG_RETURN_INT64(calculate_total_relation_size(tblspcOid, relnodeOid)); } /* diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 9200a7c227e..88f776df062 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.47 2005/08/12 18:23:54 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.48 2005/09/16 05:35:40 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -73,8 +73,7 @@ current_database(PG_FUNCTION_ARGS) /* * Functions to send signals to other backends. */ - -static int +static bool pg_signal_backend(int pid, int sig) { if (!superuser()) @@ -90,7 +89,7 @@ pg_signal_backend(int pid, int sig) */ ereport(WARNING, (errmsg("PID %d is not a PostgreSQL server process", pid))); - return 0; + return false; } if (kill(pid, sig)) @@ -98,18 +97,17 @@ pg_signal_backend(int pid, int sig) /* Again, just a warning to allow loops */ ereport(WARNING, (errmsg("could not send signal to process %d: %m", pid))); - return 0; + return false; } - return 1; + return true; } Datum pg_cancel_backend(PG_FUNCTION_ARGS) { - PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0), SIGINT)); + PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGINT)); } - Datum pg_reload_conf(PG_FUNCTION_ARGS) { @@ -122,11 +120,10 @@ pg_reload_conf(PG_FUNCTION_ARGS) { ereport(WARNING, (errmsg("failed to send signal to postmaster: %m"))); - - PG_RETURN_INT32(0); + PG_RETURN_BOOL(false); } - PG_RETURN_INT32(1); + PG_RETURN_BOOL(true); } @@ -145,19 +142,16 @@ pg_rotate_logfile(PG_FUNCTION_ARGS) { ereport(WARNING, (errmsg("rotation not possible because log redirection not active"))); - - PG_RETURN_INT32(0); + PG_RETURN_BOOL(false); } SendPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE); - - PG_RETURN_INT32(1); + PG_RETURN_BOOL(true); } #ifdef NOT_USED /* Disabled in 8.0 due to reliability concerns; FIXME someday */ - Datum pg_terminate_backend(PG_FUNCTION_ARGS) { diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 745975a2b56..cd44e8c1559 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.301 2005/09/08 20:07:42 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.302 2005/09/16 05:35:40 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200509081 +#define CATALOG_VERSION_NO 200509161 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 39f66bd6e6a..4b25833b17f 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.384 2005/09/09 06:51:12 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.385 2005/09/16 05:35:40 neilc Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -3042,16 +3042,16 @@ DATA(insert OID = 2093 ( pg_conversion_is_visible PGNSP PGUID 12 f f t f s 1 16 DESCR("is conversion visible in search path?"); -DATA(insert OID = 2171 ( pg_cancel_backend PGNSP PGUID 12 f f t f v 1 23 "23" _null_ _null_ _null_ pg_cancel_backend - _null_ )); +DATA(insert OID = 2171 ( pg_cancel_backend PGNSP PGUID 12 f f t f v 1 16 "23" _null_ _null_ _null_ pg_cancel_backend - _null_ )); DESCR("Cancel a server process' current query"); DATA(insert OID = 2172 ( pg_start_backup PGNSP PGUID 12 f f t f v 1 25 "25" _null_ _null_ _null_ pg_start_backup - _null_ )); DESCR("Prepare for taking an online backup"); 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"); -DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 f f t f v 0 23 "" _null_ _null_ _null_ pg_reload_conf - _null_ )); +DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 f f t f v 0 16 "" _null_ _null_ _null_ pg_reload_conf - _null_ )); DESCR("Reload configuration files"); -DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 f f t f v 0 23 "" _null_ _null_ _null_ pg_rotate_logfile - _null_ )); +DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 f f t f v 0 16 "" _null_ _null_ _null_ pg_rotate_logfile - _null_ )); DESCR("Rotate log file"); DATA(insert OID = 2623 ( pg_stat_file PGNSP PGUID 12 f f t f v 1 2249 "25" _null_ _null_ _null_ pg_stat_file - _null_ )); @@ -3254,9 +3254,9 @@ DATA(insert OID = 2325 ( pg_relation_size PGNSP PGUID 12 f f t f v 1 20 "26" _n DESCR("Calculate disk space usage for the specified table or index"); DATA(insert OID = 2289 ( 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_ )); +DATA(insert OID = 2286 ( pg_total_relation_size PGNSP PGUID 12 f f t f v 1 20 "26" _null_ _null_ _null_ pg_total_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_ )); +DATA(insert OID = 2287 ( pg_total_relation_size PGNSP PGUID 12 f f t f v 1 20 "25" _null_ _null_ _null_ pg_total_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"); diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index 685d70f05ba..ca31f309893 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.263 2005/08/12 03:25:13 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.264 2005/09/16 05:35:41 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -370,8 +370,8 @@ 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_total_relation_size_oid(PG_FUNCTION_ARGS); +extern Datum pg_total_relation_size_name(PG_FUNCTION_ARGS); extern Datum pg_size_pretty(PG_FUNCTION_ARGS); /* genfile.c */ -- GitLab