Skip to content

Commit c4fd93b

Browse files
committed
Re-enable pg_terminate_backend() using SIGTERM. SIGTERM testing still
needed.
1 parent c5e4e91 commit c4fd93b

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

doc/src/sgml/func.sgml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.432 2008/04/15 20:28:46 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.433 2008/04/17 20:56:41 momjian Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -11848,6 +11848,9 @@ SELECT set_config('log_statement_stats', 'off', false);
1184811848
<indexterm>
1184911849
<primary>pg_cancel_backend</primary>
1185011850
</indexterm>
11851+
<indexterm>
11852+
<primary>pg_terminate_backend</primary>
11853+
</indexterm>
1185111854
<indexterm>
1185211855
<primary>pg_reload_conf</primary>
1185311856
</indexterm>
@@ -11883,6 +11886,13 @@ SELECT set_config('log_statement_stats', 'off', false);
1188311886
<entry><type>boolean</type></entry>
1188411887
<entry>Cancel a backend's current query</entry>
1188511888
</row>
11889+
<row>
11890+
<entry>
11891+
<literal><function>pg_terminate_backend</function>(<parameter>pid</parameter> <type>int</>)</literal>
11892+
</entry>
11893+
<entry><type>boolean</type></entry>
11894+
<entry>Terminate a backend</entry>
11895+
</row>
1188611896
<row>
1188711897
<entry>
1188811898
<literal><function>pg_reload_conf</function>()</literal>
@@ -11907,9 +11917,10 @@ SELECT set_config('log_statement_stats', 'off', false);
1190711917
</para>
1190811918

1190911919
<para>
11910-
<function>pg_cancel_backend</> sends a query cancel
11911-
(<systemitem>SIGINT</>) signal to a backend process identified by
11912-
process ID. The process ID of an active backend can be found from
11920+
<function>pg_cancel_backend</> and <function>pg_terminate_backend</>
11921+
send signals (<systemitem>SIGINT</> or <systemitem>SIGTERM</>
11922+
respectively) to backend processes identified by process ID.
11923+
The process ID of an active backend can be found from
1191311924
the <structfield>procpid</structfield> column in the
1191411925
<structname>pg_stat_activity</structname> view, or by listing the
1191511926
<command>postgres</command> processes on the server with

doc/src/sgml/runtime.sgml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.413 2008/04/15 20:28:46 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.414 2008/04/17 20:56:41 momjian Exp $ -->
22

33
<chapter Id="runtime">
44
<title>Operating System Environment</title>
@@ -1372,6 +1372,14 @@ $ <userinput>kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`</userinput
13721372
well.
13731373
</para>
13741374
</important>
1375+
1376+
<para>
1377+
To terminate a session while allowing other sessions to continue, use
1378+
<function>pg_terminate_backend()</> (<xref
1379+
linkend="functions-admin-signal-table">) or send a
1380+
<systemitem>SIGTERM</> signal to the child process associated with
1381+
the session.
1382+
</para>
13751383
</sect1>
13761384

13771385
<sect1 id="preventing-server-spoofing">

src/backend/utils/adt/misc.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.61 2008/04/15 20:28:46 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.62 2008/04/17 20:56:41 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -128,6 +128,12 @@ pg_cancel_backend(PG_FUNCTION_ARGS)
128128
PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGINT));
129129
}
130130

131+
Datum
132+
pg_terminate_backend(PG_FUNCTION_ARGS)
133+
{
134+
PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGTERM));
135+
}
136+
131137
Datum
132138
pg_reload_conf(PG_FUNCTION_ARGS)
133139
{
@@ -169,17 +175,6 @@ pg_rotate_logfile(PG_FUNCTION_ARGS)
169175
PG_RETURN_BOOL(true);
170176
}
171177

172-
#ifdef NOT_USED
173-
174-
/* Disabled in 8.0 due to reliability concerns; FIXME someday */
175-
Datum
176-
pg_terminate_backend(PG_FUNCTION_ARGS)
177-
{
178-
PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0), SIGTERM));
179-
}
180-
#endif
181-
182-
183178
/* Function to find out which databases make use of a tablespace */
184179

185180
typedef struct

src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, 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.491 2008/04/15 20:28:46 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.492 2008/04/17 20:56:41 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -3157,6 +3157,8 @@ DESCR("is schema another session's temp schema?");
31573157

31583158
DATA(insert OID = 2171 ( pg_cancel_backend PGNSP PGUID 12 1 0 f f t f v 1 16 "23" _null_ _null_ _null_ pg_cancel_backend - _null_ _null_ ));
31593159
DESCR("cancel a server process' current query");
3160+
DATA(insert OID = 2096 ( pg_terminate_backend PGNSP PGUID 12 1 0 f f t f v 1 16 "23" _null_ _null_ _null_ pg_terminate_backend - _null_ _null_ ));
3161+
DESCR("terminate a server process");
31603162
DATA(insert OID = 2172 ( pg_start_backup PGNSP PGUID 12 1 0 f f t f v 1 25 "25" _null_ _null_ _null_ pg_start_backup - _null_ _null_ ));
31613163
DESCR("prepare for taking an online backup");
31623164
DATA(insert OID = 2173 ( pg_stop_backup PGNSP PGUID 12 1 0 f f t f v 0 25 "" _null_ _null_ _null_ pg_stop_backup - _null_ _null_ ));

src/include/utils/builtins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.314 2008/04/15 20:28:47 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.315 2008/04/17 20:56:41 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -416,6 +416,7 @@ extern Datum nonnullvalue(PG_FUNCTION_ARGS);
416416
extern Datum current_database(PG_FUNCTION_ARGS);
417417
extern Datum current_query(PG_FUNCTION_ARGS);
418418
extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
419+
extern Datum pg_terminate_backend(PG_FUNCTION_ARGS);
419420
extern Datum pg_reload_conf(PG_FUNCTION_ARGS);
420421
extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
421422
extern Datum pg_rotate_logfile(PG_FUNCTION_ARGS);

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