27 #include "utils/fmgrprotos.h"
45 #define SIGNAL_BACKEND_SUCCESS 0
46 #define SIGNAL_BACKEND_ERROR 1
47 #define SIGNAL_BACKEND_NOPERMISSION 2
48 #define SIGNAL_BACKEND_NOSUPERUSER 3
49 #define SIGNAL_BACKEND_NOAUTOVAC 4
74 (
errmsg(
"PID %d is not a PostgreSQL backend process", pid)));
123 (
errmsg(
"could not send signal to process %d: %m", pid)));
142 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
143 errmsg(
"permission denied to cancel query"),
144 errdetail(
"Only roles with the %s attribute may cancel queries of roles with the %s attribute.",
145 "SUPERUSER",
"SUPERUSER")));
149 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
150 errmsg(
"permission denied to cancel query"),
151 errdetail(
"Only roles with privileges of the \"%s\" role may cancel autovacuum workers.",
152 "pg_signal_autovacuum_worker")));
156 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
157 errmsg(
"permission denied to cancel query"),
158 errdetail(
"Only roles with privileges of the role whose query is being canceled or with privileges of the \"%s\" role may cancel this query.",
159 "pg_signal_backend")));
175 int64 waittime = 100;
180 int64 remainingtime = timeout;
190 if (remainingtime < waittime)
191 waittime = remainingtime;
193 if (
kill(pid, 0) == -1)
199 (
errcode(ERRCODE_INTERNAL_ERROR),
200 errmsg(
"could not check the existence of the backend with PID %d: %m",
210 WAIT_EVENT_BACKEND_TERMINATION);
214 remainingtime -= waittime;
215 }
while (remainingtime > 0);
218 (
errmsg_plural(
"backend with PID %d did not terminate within %lld millisecond",
219 "backend with PID %d did not terminate within %lld milliseconds",
221 pid, (
long long int) timeout)));
248 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
249 errmsg(
"\"timeout\" must not be negative")));
255 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
256 errmsg(
"permission denied to terminate process"),
257 errdetail(
"Only roles with the %s attribute may terminate processes of roles with the %s attribute.",
258 "SUPERUSER",
"SUPERUSER")));
262 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
263 errmsg(
"permission denied to terminate process"),
264 errdetail(
"Only roles with privileges of the \"%s\" role may terminate autovacuum workers.",
265 "pg_signal_autovacuum_worker")));
269 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
270 errmsg(
"permission denied to terminate process"),
271 errdetail(
"Only roles with privileges of the role whose process is being terminated or with privileges of the \"%s\" role may terminate this process.",
272 "pg_signal_backend")));
293 (
errmsg(
"failed to send signal to postmaster: %m")));
313 (
errmsg(
"rotation not possible because log collection not active")));
bool has_privs_of_role(Oid member, Oid role)
BackendType pgstat_get_backend_type_by_proc_number(ProcNumber procNumber)
#define OidIsValid(objectId)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_GETARG_INT64(n)
#define PG_GETARG_INT32(n)
#define PG_RETURN_BOOL(x)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
#define WL_EXIT_ON_PM_DEATH
#define CHECK_FOR_INTERRUPTS()
void SendPostmasterSignal(PMSignalReason reason)
@ PMSIGNAL_ROTATE_LOGFILE
#define GetNumberFromPGProc(proc)
PGPROC * BackendPidGetProc(int pid)
static int pg_signal_backend(int pid, int sig)
Datum pg_cancel_backend(PG_FUNCTION_ARGS)
#define SIGNAL_BACKEND_SUCCESS
#define SIGNAL_BACKEND_NOPERMISSION
Datum pg_rotate_logfile(PG_FUNCTION_ARGS)
#define SIGNAL_BACKEND_NOSUPERUSER
#define SIGNAL_BACKEND_NOAUTOVAC
Datum pg_reload_conf(PG_FUNCTION_ARGS)
Datum pg_terminate_backend(PG_FUNCTION_ARGS)
#define SIGNAL_BACKEND_ERROR
static bool pg_wait_until_termination(int pid, int64 timeout)
bool superuser_arg(Oid roleid)