diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c new file mode 100644 index f3c7860..c491783 *** a/src/backend/utils/adt/misc.c --- b/src/backend/utils/adt/misc.c *************** current_query(PG_FUNCTION_ARGS) *** 88,125 **** static int pg_signal_backend(int pid, int sig) { ! PGPROC *proc; ! if (!superuser()) { /* ! * Since the user is not superuser, check for matching roles. Trust ! * that BackendPidGetProc will return NULL if the pid isn't valid, ! * even though the check for whether it's a backend process is below. ! * The IsBackendPid check can't be relied on as definitive even if it ! * was first. The process might end between successive checks ! * regardless of their order. There's no way to acquire a lock on an ! * arbitrary process to prevent that. But since so far all the callers ! * of this mechanism involve some request for ending the process ! * anyway, that it might end on its own first is not a problem. */ ! proc = BackendPidGetProc(pid); ! ! if (proc == NULL || proc->roleId != GetUserId()) ! return SIGNAL_BACKEND_NOPERMISSION; } ! if (!IsBackendPid(pid)) { /* ! * This is just a warning so a loop-through-resultset will not abort ! * if one backend terminated on it's own during the run */ ! ereport(WARNING, ! (errmsg("PID %d is not a PostgreSQL server process", pid))); ! return SIGNAL_BACKEND_ERROR; } /* * Can the process we just validated above end, followed by the pid being * recycled for a new process, before reaching here? Then we'd be trying --- 88,124 ---- static int pg_signal_backend(int pid, int sig) { ! PGPROC *proc = BackendPidGetProc(pid); ! /* Trust that BackendPidGetProc will return NULL if the pid isn't valid. ! * Note, this check can't be relied on as definitive even if it ! * was first. The process might end between successive checks ! * regardless of their order. There's no way to acquire a lock on an ! * arbitrary process to prevent that. But since so far all the callers ! * of this mechanism involve some request for ending the process ! * anyway, that it might end on its own first is not a problem. ! */ ! if (proc == NULL) { /* ! * This is just a warning so a loop-through-resultset will not abort ! * if one backend terminated on its own during the run. */ ! ereport(WARNING, ! (errmsg("PID %d is not a PostgreSQL server process", pid))); ! return SIGNAL_BACKEND_ERROR; } ! if (!superuser()) { /* ! * Since the user is not superuser, check for matching roles. */ ! if (proc->roleId != GetUserId()) ! return SIGNAL_BACKEND_NOPERMISSION; } + /* * Can the process we just validated above end, followed by the pid being * recycled for a new process, before reaching here? Then we'd be trying