Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc60ca19

Browse files
committed
Allow pg_terminate_backend() to be used on backends with matching role.
A similar change was made previously for pg_cancel_backend, so now itall matches again.Dan Farina, reviewed by Fujii Masao, Noah Misch, and Jeff Davis,with slight kibitzing on the doc changes by me.
1 parentb79ab00 commitc60ca19

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14393,7 +14393,11 @@ SELECT set_config('log_statement_stats', 'off', false);
1439314393
<literal><function>pg_terminate_backend(<parameter>pid</parameter> <type>int</>)</function></literal>
1439414394
</entry>
1439514395
<entry><type>boolean</type></entry>
14396-
<entry>Terminate a backend</entry>
14396+
<entry>Terminate a backend. You can execute this against
14397+
another backend that has exactly the same role as the user
14398+
calling the function. In all other cases, you must be a
14399+
superuser.
14400+
</entry>
1439714401
</row>
1439814402
</tbody>
1439914403
</tgroup>
@@ -14414,9 +14418,8 @@ SELECT set_config('log_statement_stats', 'off', false);
1441414418
<command>postgres</command> processes on the server (using
1441514419
<application>ps</> on Unix or the <application>Task
1441614420
Manager</> on <productname>Windows</>).
14417-
For the less restrictive <function>pg_cancel_backend</>, the role of an
14418-
active backend can be found from
14419-
the <structfield>usename</structfield> column of the
14421+
The role of an active backend can be found from the
14422+
<structfield>usename</structfield> column of the
1442014423
<structname>pg_stat_activity</structname> view.
1442114424
</para>
1442214425

‎doc/src/sgml/high-availability.sgml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,13 +1969,15 @@ LOG: database system is ready to accept read only connections
19691969
</para>
19701970

19711971
<para>
1972-
<function>pg_cancel_backend()</> will work on user backends, but not the
1973-
Startup process, which performs recovery. <structname>pg_stat_activity</structname> does not
1974-
show an entry for the Startup process, nor do recovering transactions
1975-
show as active. As a result, <structname>pg_prepared_xacts</structname> is always empty during
1976-
recovery. If you wish to resolve in-doubt prepared transactions,
1977-
view <literal>pg_prepared_xacts</> on the primary and issue commands to
1978-
resolve transactions there.
1972+
<function>pg_cancel_backend()</>
1973+
and <function>pg_terminate_backend()</> will work on user backends,
1974+
but not the Startup process, which performs
1975+
recovery. <structname>pg_stat_activity</structname> does not show an
1976+
entry for the Startup process, nor do recovering transactions show
1977+
as active. As a result, <structname>pg_prepared_xacts</structname>
1978+
is always empty during recovery. If you wish to resolve in-doubt
1979+
prepared transactions, view <literal>pg_prepared_xacts</> on the
1980+
primary and issue commands to resolve transactions there.
19791981
</para>
19801982

19811983
<para>

‎src/backend/utils/adt/misc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,20 @@ pg_cancel_backend(PG_FUNCTION_ARGS)
162162
}
163163

164164
/*
165-
* Signal to terminate a backend process. Only allowed by superuser.
165+
* Signal to terminate a backend process. This is allowed if you are superuser
166+
* or have the same role as the process being terminated.
166167
*/
167168
Datum
168169
pg_terminate_backend(PG_FUNCTION_ARGS)
169170
{
170-
if (!superuser())
171+
intr=pg_signal_backend(PG_GETARG_INT32(0),SIGTERM);
172+
173+
if (r==SIGNAL_BACKEND_NOPERMISSION)
171174
ereport(ERROR,
172175
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
173-
errmsg("must be superuser to terminate other server processes"),
174-
errhint("You can cancel your own processes with pg_cancel_backend().")));
176+
(errmsg("must be superuser or have the same role to terminate backends running in other server processes"))));
175177

176-
PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0),SIGTERM)==SIGNAL_BACKEND_SUCCESS);
178+
PG_RETURN_BOOL(r==SIGNAL_BACKEND_SUCCESS);
177179
}
178180

179181
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp