Skip to content

Commit 2af9a44

Browse files
committed
Make pg_stat_file() use OUT parameters so that the user doesn't have to
remember the output parameter set for himself. It's a bit of a kluge but fixing array_in to work in bootstrap mode looks worse. I removed the separate pg_file_length() function, as it no longer has any real notational advantage --- you can write (pg_stat_file(...)).length.
1 parent f547909 commit 2af9a44

File tree

5 files changed

+80
-73
lines changed

5 files changed

+80
-73
lines changed

doc/src/sgml/func.sgml

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.279 2005/08/12 18:23:53 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.280 2005/08/13 19:02:32 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -9064,6 +9064,9 @@ SELECT set_config('log_statement_stats', 'off', false);
90649064
<indexterm zone="functions-admin">
90659065
<primary>pg_reload_conf</primary>
90669066
</indexterm>
9067+
<indexterm zone="functions-admin">
9068+
<primary>pg_rotate_logfile</primary>
9069+
</indexterm>
90679070

90689071
<indexterm zone="functions-admin">
90699072
<primary>signal</primary>
@@ -9100,23 +9103,44 @@ SELECT set_config('log_statement_stats', 'off', false);
91009103
<entry><type>int</type></entry>
91019104
<entry>Cause server processes to reload their configuration files</entry>
91029105
</row>
9106+
<row>
9107+
<entry>
9108+
<literal><function>pg_rotate_logfile</function>()</literal>
9109+
</entry>
9110+
<entry><type>int</type></entry>
9111+
<entry>Rotate server's logfile</entry>
9112+
</row>
91039113
</tbody>
91049114
</tgroup>
91059115
</table>
91069116

91079117
<para>
9108-
These functions return 1 if successful, 0 if not successful.
9109-
The process ID (<literal>pid</literal>) of an active backend can be found
9110-
from the <structfield>procpid</structfield> column in the
9111-
<structname>pg_stat_activity</structname> view, or by listing the <command>postgres</command>
9112-
processes on the server with <application>ps</>.
9118+
Each of these functions returns 1 if successful, 0 if not successful.
9119+
</para>
9120+
9121+
<para>
9122+
<function>pg_cancel_backend</> sends a Query Cancel (SIGINT) signal
9123+
to a backend process identified by process ID (<literal>pid</literal>).
9124+
The process ID of an active backend can be found from the
9125+
<structfield>procpid</structfield> column in the
9126+
<structname>pg_stat_activity</structname> view, or by listing the
9127+
<command>postgres</command> processes on the server with
9128+
<application>ps</>.
91139129
</para>
9130+
91149131
<para>
91159132
<function>pg_reload_conf</> sends a SIGHUP signal to the
91169133
postmaster, causing reload of the configuration files
91179134
in all server processes.
91189135
</para>
91199136

9137+
<para>
9138+
<function>pg_rotate_logfile</> signals the logfile manager to switch
9139+
to a new output file immediately. This works only when
9140+
<varname>redirect_stderr</> is used for logging, since otherwise there
9141+
is no logfile manager subprocess.
9142+
</para>
9143+
91209144
<indexterm zone="functions-admin">
91219145
<primary>pg_start_backup</primary>
91229146
</indexterm>
@@ -9341,22 +9365,9 @@ SELECT set_config('log_statement_stats', 'off', false);
93419365
</thead>
93429366

93439367
<tbody>
9344-
<row>
9345-
<entry>
9346-
<literal><function>pg_file_length</function>(<parameter>filename</> <type>text</>)</literal>
9347-
<indexterm zone="functions-admin">
9348-
<primary>pg_file_length</primary>
9349-
</indexterm>
9350-
</entry>
9351-
<entry><type>int8</type></entry>
9352-
<entry>Return the file length</entry>
9353-
</row>
93549368
<row>
93559369
<entry>
93569370
<literal><function>pg_ls_dir</function>(<parameter>dirname</> <type>text</>)</literal>
9357-
<indexterm zone="functions-admin">
9358-
<primary>pg_ls_dir</primary>
9359-
</indexterm>
93609371
</entry>
93619372
<entry><type>setof text</type></entry>
93629373
<entry>List the contents of a directory</entry>
@@ -9373,69 +9384,45 @@ SELECT set_config('log_statement_stats', 'off', false);
93739384
<literal><function>pg_stat_file</function>(<parameter>filename</> <type>text</>)</literal>
93749385
</entry>
93759386
<entry><type>record</type></entry>
9376-
<entry>Return information about the file</entry>
9387+
<entry>Return information about a file</entry>
93779388
</row>
93789389
</tbody>
93799390
</tgroup>
93809391
</table>
93819392

9393+
<indexterm zone="functions-admin">
9394+
<primary>pg_ls_dir</primary>
9395+
</indexterm>
9396+
<para>
9397+
<function>pg_ls_dir()</> returns all the names in the specified
9398+
directory, except the special entries <quote><literal>.</></> and
9399+
<quote><literal>..</></>.
9400+
</para>
9401+
93829402
<indexterm zone="functions-admin">
93839403
<primary>pg_read_file</primary>
93849404
</indexterm>
93859405
<para>
9386-
<function>pg_read_file()</> returns part of a textfile, starting
9387-
at the given offset, returning at most length bytes (less if the
9388-
end of file is reached first). If offset is negative,
9389-
it is relative to the end of the file.
9406+
<function>pg_read_file()</> returns part of a text file, starting
9407+
at the given <parameter>offset</>, returning at most <parameter>length</>
9408+
bytes (less if the end of file is reached first). If <parameter>offset</>
9409+
is negative, it is relative to the end of the file.
93909410
</para>
93919411

93929412
<indexterm zone="functions-admin">
93939413
<primary>pg_stat_file</primary>
93949414
</indexterm>
93959415
<para>
9396-
<function>pg_stat_file()</> returns a record containing the
9416+
<function>pg_stat_file()</> returns a record containing the file
93979417
length, last accessed timestamp, last modified timestamp,
9398-
creation timestamp, and a flag indicating if it is a directory.
9399-
Use it like this:
9418+
creation timestamp, and a boolean indicating if it is a directory.
9419+
Typical usages include:
94009420
<programlisting>
9401-
SELECT *
9402-
FROM pg_stat_file('filename')
9403-
AS s(length int8, atime timestamptz, mtime timestamptz,
9404-
ctime timestamptz, isdir bool);
9421+
SELECT * FROM pg_stat_file('filename');
9422+
SELECT (pg_stat_file('filename')).mtime;
94059423
</programlisting>
94069424
</para>
94079425

9408-
<para>
9409-
The function shown in <xref
9410-
linkend="functions-admin-logfile"> forces the server
9411-
logfile to be rotated. This works only when <varname>redirect_stderr</>
9412-
is used for logging. Use of this function is restricted
9413-
to superusers.
9414-
</para>
9415-
9416-
<table id="functions-admin-logfile">
9417-
<title>Server Logfile Functions</title>
9418-
<tgroup cols="3">
9419-
<thead>
9420-
<row><entry>Name</entry> <entry>Return Type</entry> <entry>Description</entry>
9421-
</row>
9422-
</thead>
9423-
9424-
<tbody>
9425-
<row>
9426-
<entry>
9427-
<literal><function>pg_rotate_logfile</function>()</literal>
9428-
<indexterm zone="functions-admin">
9429-
<primary>pg_rotate_logfile</primary>
9430-
</indexterm>
9431-
</entry>
9432-
<entry><type>int</type></entry>
9433-
<entry>Rotate server's logfile</entry>
9434-
</row>
9435-
</tbody>
9436-
</tgroup>
9437-
</table>
9438-
94399426
</sect1>
94409427
</chapter>
94419428

src/backend/catalog/system_views.sql

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 1996-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.18 2005/07/31 17:19:17 tgl Exp $
6+
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.19 2005/08/13 19:02:33 tgl Exp $
77
*/
88

99
CREATE VIEW pg_roles AS
@@ -331,3 +331,23 @@ CREATE VIEW pg_stat_database AS
331331
pg_stat_get_db_blocks_hit(D.oid) AS blks_read,
332332
pg_stat_get_db_blocks_hit(D.oid) AS blks_hit
333333
FROM pg_database D;
334+
335+
--
336+
-- Fix up built-in functions that make use of OUT parameters.
337+
-- We can't currently fill these values in during bootstrap, because
338+
-- array_in doesn't work in bootstrap mode. Eventually that should be
339+
-- fixed, but for now the path of least resistance is to patch their
340+
-- pg_proc entries later during initdb.
341+
--
342+
343+
UPDATE pg_proc SET
344+
proallargtypes = ARRAY['text'::regtype,
345+
'int8',
346+
'timestamptz',
347+
'timestamptz',
348+
'timestamptz',
349+
'bool'],
350+
proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o'],
351+
proargnames = ARRAY['filename'::text,
352+
'length', 'atime', 'mtime', 'ctime','isdir']
353+
WHERE oid = 'pg_stat_file(text)'::regprocedure;

src/backend/utils/adt/genfile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Author: Andreas Pflug <pgadmin@pse-consulting.de>
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.3 2005/08/12 21:07:52 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.4 2005/08/13 19:02:34 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -171,6 +171,10 @@ pg_stat_file(PG_FUNCTION_ARGS)
171171
(errcode_for_file_access(),
172172
errmsg("could not stat file \"%s\": %m", filename)));
173173

174+
/*
175+
* This record type had better match the output parameters declared
176+
* for me in pg_proc.h (actually, in system_views.sql at the moment).
177+
*/
174178
tupdesc = CreateTemplateTupleDesc(5, false);
175179
TupleDescInitEntry(tupdesc, (AttrNumber) 1,
176180
"length", INT8OID, -1, 0);

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.297 2005/08/12 18:23:55 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.298 2005/08/13 19:02:34 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200508121
56+
#define CATALOG_VERSION_NO 200508131
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.382 2005/08/12 18:23:55 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.383 2005/08/13 19:02:34 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -3051,18 +3051,14 @@ DESCR("Finish taking an online backup");
30513051

30523052
DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 f f t f v 0 23 "" _null_ _null_ _null_ pg_reload_conf - _null_ ));
30533053
DESCR("Reload configuration files");
3054-
30553054
DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 f f t f v 0 23 "" _null_ _null_ _null_ pg_rotate_logfile - _null_ ));
30563055
DESCR("Rotate log file");
30573056

3058-
30593057
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_ ));
30603058
DESCR("Return file information");
3061-
DATA(insert OID = 2624 ( pg_file_length PGNSP PGUID 14 f f t f v 1 20 "25" _null_ _null_ _null_ "SELECT len FROM pg_stat_file($1) AS s(len int8, a timestamptz, m timestamptz, c timestamptz, i bool)" - _null_ ));
3062-
DESCR("Return file length");
3063-
DATA(insert OID = 2625 ( pg_read_file PGNSP PGUID 12 f f t f v 3 25 "25 20 20" _null_ _null_ _null_ pg_read_file - _null_ ));
3059+
DATA(insert OID = 2624 ( pg_read_file PGNSP PGUID 12 f f t f v 3 25 "25 20 20" _null_ _null_ _null_ pg_read_file - _null_ ));
30643060
DESCR("Read text from a file");
3065-
DATA(insert OID = 2626 ( pg_ls_dir PGNSP PGUID 12 f f t t v 1 25 "25" _null_ _null_ _null_ pg_ls_dir - _null_ ));
3061+
DATA(insert OID = 2625 ( pg_ls_dir PGNSP PGUID 12 f f t t v 1 25 "25" _null_ _null_ _null_ pg_ls_dir - _null_ ));
30663062
DESCR("List all files in a directory");
30673063

30683064

0 commit comments

Comments
 (0)