pg_signal_backend.patch
text/x-patch
Filename: pg_signal_backend.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/utils/adt/misc.c | 28 | 3 |
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 5bda4af..5327447 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -33,6 +33,7 @@
#include "storage/procarray.h"
#include "utils/builtins.h"
#include "tcop/tcopprot.h"
+#include "pgstat.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
@@ -75,9 +76,33 @@ static bool
pg_signal_backend(int pid, int sig)
{
if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- (errmsg("must be superuser to signal other server processes"))));
+ {
+ bool haveRight = false;
+ PgBackendStatus *backend;
+
+ /* If the user not is the superuser, need to be the db owner. */
+ if (pg_database_ownercheck(MyDatabaseId, GetUserId())) {
+
+ /* Check for the specify backend in the stat info table */
+ int nBackend = pgstat_fetch_stat_numbackends();
+ int i;
+ for (i = 1; i<=nBackend; ++i) {
+ backend = pgstat_fetch_stat_beentry(i);
+ if (backend->st_procpid == pid) {
+ if (backend->st_databaseid == MyDatabaseId)
+ haveRight = true;
+ break;
+ }
+ }
+ }
+
+ if (!haveRight)
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ (errmsg("must be superuser or database destination owner to signal other server processes"))));
+ }
+
+
if (!IsBackendPid(pid))
{