Skip to content

Commit b609695

Browse files
committed
Add files to do read I/O on the cluster directory:
pg_stat_file() pg_read_file() pg_ls_dir() pg_reload_conf() pg_rotate_logfile() Dave Page Andreas Pflug
1 parent d95886e commit b609695

File tree

9 files changed

+485
-15
lines changed

9 files changed

+485
-15
lines changed

doc/src/sgml/func.sgml

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.276 2005/08/02 16:11:56 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.277 2005/08/12 03:23:40 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -9061,14 +9061,17 @@ SELECT set_config('log_statement_stats', 'off', false);
90619061
<indexterm zone="functions-admin">
90629062
<primary>pg_cancel_backend</primary>
90639063
</indexterm>
9064+
<indexterm zone="functions-admin">
9065+
<primary>pg_reload_conf</primary>
9066+
</indexterm>
90649067

90659068
<indexterm zone="functions-admin">
90669069
<primary>signal</primary>
90679070
<secondary sortas="backend">backend processes</secondary>
90689071
</indexterm>
90699072

90709073
<para>
9071-
The function shown in <xref
9074+
The functions shown in <xref
90729075
linkend="functions-admin-signal-table"> sends control signals to
90739076
other server processes. Use of this function is restricted
90749077
to superusers.
@@ -9090,26 +9093,36 @@ SELECT set_config('log_statement_stats', 'off', false);
90909093
<entry><type>int</type></entry>
90919094
<entry>Cancel a backend's current query</entry>
90929095
</row>
9096+
<row>
9097+
<entry>
9098+
<literal><function>pg_reload_conf</function>()</literal>
9099+
</entry>
9100+
<entry><type>int</type></entry>
9101+
<entry>Causes server processes to reload their configuration files</entry>
9102+
</row>
90939103
</tbody>
90949104
</tgroup>
90959105
</table>
90969106

90979107
<para>
9098-
This function returns 1 if successful, 0 if not successful.
9108+
These functions return 1 if successful, 0 if not successful.
90999109
The process ID (<literal>pid</literal>) of an active backend can be found
91009110
from the <structfield>procpid</structfield> column in the
91019111
<structname>pg_stat_activity</structname> view, or by listing the <command>postgres</command>
91029112
processes on the server with <application>ps</>.
91039113
</para>
9114+
<para>
9115+
<function>pg_reload_conf</> sends a SIGHUP signal to the
9116+
postmaster, causing the reload of the configuration files
9117+
in all backend processes.
9118+
</para>
91049119

91059120
<indexterm zone="functions-admin">
91069121
<primary>pg_start_backup</primary>
91079122
</indexterm>
9108-
91099123
<indexterm zone="functions-admin">
91109124
<primary>pg_stop_backup</primary>
91119125
</indexterm>
9112-
91139126
<indexterm zone="functions-admin">
91149127
<primary>backup</primary>
91159128
</indexterm>
@@ -9309,6 +9322,113 @@ SELECT set_config('log_statement_stats', 'off', false);
93099322
appropriate.
93109323
</para>
93119324

9325+
<para>
9326+
The functions shown in <xref
9327+
linkend="functions-admin-genfile"> provide native file access to
9328+
files on the machine hosting the server. Only files relative to
9329+
the cluster directory are allowed, and the logfile directory,
9330+
because the logfile directory might be stored outside the
9331+
cluster directory. Use of these functions is restricted to
9332+
superusers.
9333+
</para>
9334+
9335+
<table id="functions-admin-genfile">
9336+
<title>Generic File Access Functions</title>
9337+
<tgroup cols="3">
9338+
<thead>
9339+
<row><entry>Name</entry> <entry>Return Type</entry> <entry>Description</entry>
9340+
</row>
9341+
</thead>
9342+
9343+
<tbody>
9344+
<row>
9345+
<entry>
9346+
<literal><function>pg_file_length</function>(<parameter>filename_text</parameter>)</literal>
9347+
<indexterm zone="functions-admin">
9348+
<primary>pg_file_length</primary>
9349+
</indexterm>
9350+
</entry>
9351+
<entry><type>int8</type></entry>
9352+
<entry>Returns the file length</entry>
9353+
</row>
9354+
<row>
9355+
<entry>
9356+
<literal><function>pg_ls_dir</function>(<parameter>dirname_text</parameter>,<parameter>fullpath_bool</parameter>)</literal>
9357+
<indexterm zone="functions-admin">
9358+
<primary>pg_ls_dir</primary>
9359+
</indexterm>
9360+
</entry>
9361+
<entry><type>setof text</type></entry>
9362+
<entry>List the contents of a directory</entry>
9363+
</row>
9364+
<row>
9365+
<entry>
9366+
<literal><function>pg_read_file</function>(<parameter>filename_text</parameter>,
9367+
<parameter>offset_int8</parameter>,<parameter>length_int8</parameter>)</literal>
9368+
</entry>
9369+
<entry><type>text</type></entry>
9370+
<entry>Returns the contents of a text file</entry>
9371+
</row>
9372+
<row>
9373+
<entry>
9374+
<literal><function>pg_stat_file</function>(<parameter>filename_text</parameter>)</literal>
9375+
</entry>
9376+
<entry><type>record</type></entry>
9377+
<entry>Returns information about the file</entry>
9378+
</row>
9379+
</tbody>
9380+
</tgroup>
9381+
</table>
9382+
9383+
<indexterm zone="functions-admin">
9384+
<primary>pg_read_file</primary>
9385+
</indexterm>
9386+
<para>
9387+
<function>pg_read_file()</> returns part of a textfile, starting
9388+
at the given offset, returning length bytes. If offset is negative,
9389+
it is treated relative to the end of the file.
9390+
</para>
9391+
9392+
<indexterm zone="functions-admin">
9393+
<primary>pg_stat_file</primary>
9394+
</indexterm>
9395+
<para>
9396+
<function>pg_stat_file()</> returns a record containing the
9397+
length, last accessed timestamp, last modified timestamp,
9398+
creation timestamp, and a flag indicating if it is a directory.
9399+
</para>
9400+
9401+
<para>
9402+
The function shown in <xref
9403+
linkend="functions-admin-logfile"> forces the server
9404+
logfile to be rotated if <varname>redirect_stderr</>
9405+
is used for logging. Use of this functions is restricted
9406+
to superusers.
9407+
</para>
9408+
9409+
<table id="functions-admin-logfile">
9410+
<title>Backend Logfile Functions</title>
9411+
<tgroup cols="3">
9412+
<thead>
9413+
<row><entry>Name</entry> <entry>Return Type</entry> <entry>Description</entry>
9414+
</row>
9415+
</thead>
9416+
9417+
<tbody>
9418+
<row>
9419+
<entry>
9420+
<literal><function>pg_rotate_logfile</function>()</literal>
9421+
<indexterm zone="functions-admin">
9422+
<primary>pg_rotate_logfile</primary>
9423+
</indexterm>
9424+
</entry>
9425+
<entry><type>int</type></entry>
9426+
<entry>Rotate logfile</entry>
9427+
</row>
9428+
</tbody>
9429+
</tgroup>
9430+
</table>
9431+
93129432
</sect1>
93139433
</chapter>
93149434

src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.462 2005/08/11 21:11:44 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.463 2005/08/12 03:23:51 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -3394,6 +3394,9 @@ sigusr1_handler(SIGNAL_ARGS)
33943394
}
33953395
}
33963396

3397+
if (CheckPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE) && SysLoggerPID != 0)
3398+
kill(SysLoggerPID, SIGUSR1);
3399+
33973400
PG_SETMASK(&UnBlockSig);
33983401

33993402
errno = save_errno;

src/backend/postmaster/syslogger.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.18 2005/07/21 18:06:12 momjian Exp $
21+
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.19 2005/08/12 03:23:51 momjian Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -101,6 +101,7 @@ static CRITICAL_SECTION sysfileSection;
101101
* Flags set by interrupt handlers for later service in the main loop.
102102
*/
103103
static volatile sig_atomic_t got_SIGHUP = false;
104+
static volatile sig_atomic_t rotation_requested = false;
104105

105106

106107
/* Local subroutines */
@@ -117,6 +118,7 @@ static void logfile_rotate(bool time_based_rotation);
117118
static char *logfile_getname(pg_time_t timestamp);
118119
static void set_next_rotation_time(void);
119120
static void sigHupHandler(SIGNAL_ARGS);
121+
static void sigUsr1Handler(SIGNAL_ARGS);
120122

121123

122124
/*
@@ -200,7 +202,7 @@ SysLoggerMain(int argc, char *argv[])
200202
pqsignal(SIGQUIT, SIG_IGN);
201203
pqsignal(SIGALRM, SIG_IGN);
202204
pqsignal(SIGPIPE, SIG_IGN);
203-
pqsignal(SIGUSR1, SIG_IGN);
205+
pqsignal(SIGUSR1, sigUsr1Handler); /* request log rotation */
204206
pqsignal(SIGUSR2, SIG_IGN);
205207

206208
/*
@@ -235,7 +237,6 @@ SysLoggerMain(int argc, char *argv[])
235237
/* main worker loop */
236238
for (;;)
237239
{
238-
bool rotation_requested = false;
239240
bool time_based_rotation = false;
240241

241242
#ifndef WIN32
@@ -726,6 +727,8 @@ logfile_rotate(bool time_based_rotation)
726727
char *filename;
727728
FILE *fh;
728729

730+
rotation_requested = false;
731+
729732
/*
730733
* When doing a time-based rotation, invent the new logfile name based
731734
* on the planned rotation time, not current time, to avoid "slippage"
@@ -876,3 +879,10 @@ sigHupHandler(SIGNAL_ARGS)
876879
{
877880
got_SIGHUP = true;
878881
}
882+
883+
/* SIGUSR1: set flag to rotate logfile */
884+
static void
885+
sigUsr1Handler(SIGNAL_ARGS)
886+
{
887+
rotation_requested = true;
888+
}

src/backend/utils/adt/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Makefile for utils/adt
33
#
4-
# $PostgreSQL: pgsql/src/backend/utils/adt/Makefile,v 1.58 2005/07/29 14:46:57 momjian Exp $
4+
# $PostgreSQL: pgsql/src/backend/utils/adt/Makefile,v 1.59 2005/08/12 03:24:08 momjian Exp $
55
#
66

77
subdir = src/backend/utils/adt
@@ -24,7 +24,7 @@ OBJS = acl.o arrayfuncs.o array_userfuncs.o arrayutils.o bool.o \
2424
tid.o timestamp.o varbit.o varchar.o varlena.o version.o xid.o \
2525
network.o mac.o inet_net_ntop.o inet_net_pton.o \
2626
ri_triggers.o pg_lzcompress.o pg_locale.o formatting.o \
27-
ascii.o quote.o pgstatfuncs.o encode.o dbsize.o
27+
ascii.o quote.o pgstatfuncs.o encode.o dbsize.o genfile.o
2828

2929
like.o: like.c like_match.c
3030

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy