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

Commit01e98e0

Browse files
committed
Fix documentation about DROP DATABASE FORCE process termination rights.
Specifically, it terminates a background worker even if the callercouldn't terminate the background worker with pg_terminate_backend().Commit3a9b18b neglected to updatethis. Back-patch to v13, which introduced DROP DATABASE FORCE.Reviewed by Amit Kapila. Reported by Kirill Reshke.Discussion:https://postgr.es/m/20240429212756.60.nmisch@google.com
1 parentb284513 commit01e98e0

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

‎doc/src/sgml/ref/drop_database.sgml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ DROP DATABASE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [
7979
It doesn't terminate if prepared transactions, active logical replication
8080
slots or subscriptions are present in the target database.
8181
</para>
82+
<!-- not mentioning exception for autovacuum workers, since those are an
83+
implementation detail and the exception is not specific to FORCE -->
8284
<para>
83-
Thiswill fail if the current user has no permissions to terminate other
84-
connections. Required permissions are the same as with
85-
<literal>pg_terminate_backend</literal>, described in
86-
<xref linkend="functions-admin-signal"/>.This will also fail if we
87-
are not able to terminate connections.
85+
Thisterminates background worker connections and connections that the
86+
current user has permission to terminate
87+
with <function>pg_terminate_backend</function>, described in
88+
<xref linkend="functions-admin-signal"/>.If connections would remain,
89+
this command will fail.
8890
</para>
8991
</listitem>
9092
</varlistentry>

‎src/backend/storage/ipc/procarray.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,8 +3855,8 @@ CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
38553855
* The current backend is always ignored; it is caller's responsibility to
38563856
* check whether the current backend uses the given DB, if it's important.
38573857
*
3858-
*It doesn't allow to terminate the connections even if there is a one
3859-
*backend with the prepared transaction in the target database.
3858+
*If the target database has a prepared transaction or permissions checks
3859+
*fail for a connection, this fails without terminating anything.
38603860
*/
38613861
void
38623862
TerminateOtherDBBackends(OiddatabaseId)
@@ -3901,14 +3901,19 @@ TerminateOtherDBBackends(Oid databaseId)
39013901
ListCell*lc;
39023902

39033903
/*
3904-
* Check whether we have the necessary rights to terminate other
3905-
* sessions. We don't terminate any session until we ensure that we
3906-
* have rights on all the sessions to be terminated. These checks are
3907-
* the same as we do in pg_terminate_backend.
3904+
* Permissions checks relax the pg_terminate_backend checks in two
3905+
* ways, both by omitting the !OidIsValid(proc->roleId) check:
39083906
*
3909-
* In this case we don't raise some warnings - like "PID %d is not a
3910-
* PostgreSQL server process", because for us already finished session
3911-
* is not a problem.
3907+
* - Accept terminating autovacuum workers, since DROP DATABASE
3908+
* without FORCE terminates them.
3909+
*
3910+
* - Accept terminating bgworkers. For bgworker authors, it's
3911+
* convenient to be able to recommend FORCE if a worker is blocking
3912+
* DROP DATABASE unexpectedly.
3913+
*
3914+
* Unlike pg_terminate_backend, we don't raise some warnings - like
3915+
* "PID %d is not a PostgreSQL server process", because for us already
3916+
* finished session is not a problem.
39123917
*/
39133918
foreach(lc,pids)
39143919
{
@@ -3917,13 +3922,11 @@ TerminateOtherDBBackends(Oid databaseId)
39173922

39183923
if (proc!=NULL)
39193924
{
3920-
/* Only allow superusers to signal superuser-owned backends. */
39213925
if (superuser_arg(proc->roleId)&& !superuser())
39223926
ereport(ERROR,
39233927
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
39243928
errmsg("must be a superuser to terminate superuser process")));
39253929

3926-
/* Users can signal backends they have role membership in. */
39273930
if (!has_privs_of_role(GetUserId(),proc->roleId)&&
39283931
!has_privs_of_role(GetUserId(),ROLE_PG_SIGNAL_BACKEND))
39293932
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp