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

Commit61171a6

Browse files
Look up backend type in pg_signal_backend() more cheaply.
Commitccd3802, which introduced the pg_signal_autovacuum_workerrole, added a call to pgstat_get_beentry_by_proc_number() for thepurpose of determining whether the process is an autovacuum worker.This function calls pgstat_read_current_status(), which can befairly expensive and may return cached, out-of-date information.Since we just need to look up the target backend's BackendType, andwe already know its ProcNumber, we can instead inspect theBackendStatusArray directly, which is much less expensive andpossibly more up-to-date. There are some caveats with thisapproach (which are documented in the code), but it's stillsubstantially better than before.Reported-by: Andres FreundReviewed-by: Andres FreundDiscussion:https://postgr.es/m/ujenaa2uabzfkwxwmfifawzdozh3ljr7geozlhftsuosgm7n7q%40g3utqqyyosb6
1 parent6a5bcf7 commit61171a6

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ pg_signal_backend(int pid, int sig)
8888
if (!OidIsValid(proc->roleId)||superuser_arg(proc->roleId))
8989
{
9090
ProcNumberprocNumber=GetNumberFromPGProc(proc);
91-
PgBackendStatus*procStatus=pgstat_get_beentry_by_proc_number(procNumber);
91+
BackendTypebackendType=pgstat_get_backend_type_by_proc_number(procNumber);
9292

93-
if (procStatus&&procStatus->st_backendType==B_AUTOVAC_WORKER)
93+
if (backendType==B_AUTOVAC_WORKER)
9494
{
9595
if (!has_privs_of_role(GetUserId(),ROLE_PG_SIGNAL_AUTOVACUUM_WORKER))
9696
returnSIGNAL_BACKEND_NOAUTOVAC;

‎src/backend/utils/activity/backend_status.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,31 @@ pgstat_get_my_query_id(void)
10361036
returnMyBEEntry->st_query_id;
10371037
}
10381038

1039+
/* ----------
1040+
* pgstat_get_backend_type_by_proc_number() -
1041+
*
1042+
*Return the type of the backend with the specified ProcNumber. This looks
1043+
*directly at the BackendStatusArray, so the return value may be out of date.
1044+
*The only current use of this function is in pg_signal_backend(), which is
1045+
*inherently racy, so we don't worry too much about this.
1046+
*
1047+
*It is the caller's responsibility to use this wisely; at minimum, callers
1048+
*should ensure that procNumber is valid and perform the required permissions
1049+
*checks.
1050+
* ----------
1051+
*/
1052+
BackendType
1053+
pgstat_get_backend_type_by_proc_number(ProcNumberprocNumber)
1054+
{
1055+
volatilePgBackendStatus*status=&BackendStatusArray[procNumber];
1056+
1057+
/*
1058+
* We bypass the changecount mechanism since fetching and storing an int
1059+
* is almost certainly atomic.
1060+
*/
1061+
returnstatus->st_backendType;
1062+
}
1063+
10391064
/* ----------
10401065
* cmp_lbestatus
10411066
*

‎src/include/utils/backend_status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
323323
externconstchar*pgstat_get_crashed_backend_activity(intpid,char*buffer,
324324
intbuflen);
325325
externuint64pgstat_get_my_query_id(void);
326+
externBackendTypepgstat_get_backend_type_by_proc_number(ProcNumberprocNumber);
326327

327328

328329
/* ----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp