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

Commit9489f3c

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 parent2e2b2d0 commit9489f3c

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
@@ -3089,8 +3089,8 @@ CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
30893089
* The current backend is always ignored; it is caller's responsibility to
30903090
* check whether the current backend uses the given DB, if it's important.
30913091
*
3092-
*It doesn't allow to terminate the connections even if there is a one
3093-
*backend with the prepared transaction in the target database.
3092+
*If the target database has a prepared transaction or permissions checks
3093+
*fail for a connection, this fails without terminating anything.
30943094
*/
30953095
void
30963096
TerminateOtherDBBackends(OiddatabaseId)
@@ -3135,14 +3135,19 @@ TerminateOtherDBBackends(Oid databaseId)
31353135
ListCell*lc;
31363136

31373137
/*
3138-
* Check whether we have the necessary rights to terminate other
3139-
* sessions. We don't terminate any session until we ensure that we
3140-
* have rights on all the sessions to be terminated. These checks are
3141-
* the same as we do in pg_terminate_backend.
3138+
* Permissions checks relax the pg_terminate_backend checks in two
3139+
* ways, both by omitting the !OidIsValid(proc->roleId) check:
31423140
*
3143-
* In this case we don't raise some warnings - like "PID %d is not a
3144-
* PostgreSQL server process", because for us already finished session
3145-
* is not a problem.
3141+
* - Accept terminating autovacuum workers, since DROP DATABASE
3142+
* without FORCE terminates them.
3143+
*
3144+
* - Accept terminating bgworkers. For bgworker authors, it's
3145+
* convenient to be able to recommend FORCE if a worker is blocking
3146+
* DROP DATABASE unexpectedly.
3147+
*
3148+
* Unlike pg_terminate_backend, we don't raise some warnings - like
3149+
* "PID %d is not a PostgreSQL server process", because for us already
3150+
* finished session is not a problem.
31463151
*/
31473152
foreach(lc,pids)
31483153
{
@@ -3151,13 +3156,11 @@ TerminateOtherDBBackends(Oid databaseId)
31513156

31523157
if (proc!=NULL)
31533158
{
3154-
/* Only allow superusers to signal superuser-owned backends. */
31553159
if (superuser_arg(proc->roleId)&& !superuser())
31563160
ereport(ERROR,
31573161
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
31583162
errmsg("must be a superuser to terminate superuser process")));
31593163

3160-
/* Users can signal backends they have role membership in. */
31613164
if (!has_privs_of_role(GetUserId(),proc->roleId)&&
31623165
!has_privs_of_role(GetUserId(),DEFAULT_ROLE_SIGNAL_BACKENDID))
31633166
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp