/* * Signal to terminate a backend process. Only allowed by superuser. */ Datum pg_terminate_backend(PG_FUNCTION_ARGS) { if (!superuser()) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("must be superuser to terminate other server processes"), errhint("You can cancel your own processes with pg_cancel_backend()."))); PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGTERM) == SIGNAL_BACKEND_SUCCESS); }
/* * Signal to cancel a backend process. This is allowed if you are superuser or * have the same role as the process being canceled. */ Datum pg_cancel_backend(PG_FUNCTION_ARGS) { int r = pg_signal_backend(PG_GETARG_INT32(0), SIGINT); if (r == SIGNAL_BACKEND_NOPERMISSION) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be superuser or have the same role to cancel queries running in other server processes")))); PG_RETURN_BOOL(r == SIGNAL_BACKEND_SUCCESS); }
Datum pg_cancel_backend_msg(PG_FUNCTION_ARGS) { pid_t pid = PG_GETARG_INT32(0); char *msg = text_to_cstring(PG_GETARG_TEXT_PP(1)); int r = pg_signal_backend(pid, SIGINT, msg); if (r == SIGNAL_BACKEND_NOPERMISSION) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be superuser or have the same role to cancel queries running in other server processes")))); PG_RETURN_BOOL(r == SIGNAL_BACKEND_SUCCESS); }
/* * Signal to terminate a backend process. This is allowed if you are a member * of the role whose process is being terminated. * * Note that only superusers can signal superuser-owned processes. */ Datum pg_terminate_backend(PG_FUNCTION_ARGS) { int r = pg_signal_backend(PG_GETARG_INT32(0), SIGTERM); if (r == SIGNAL_BACKEND_NOSUPERUSER) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be a superuser to terminate superuser process")))); if (r == SIGNAL_BACKEND_NOPERMISSION) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be a member of the role whose process is being terminated or member of pg_signal_backend")))); PG_RETURN_BOOL(r == SIGNAL_BACKEND_SUCCESS); }
/* * Signal to cancel a backend process. This is allowed if you are a member of * the role whose process is being canceled. * * Note that only superusers can signal superuser-owned processes. */ Datum pg_cancel_backend(PG_FUNCTION_ARGS) { int r = pg_signal_backend(PG_GETARG_INT32(0), SIGINT); if (r == SIGNAL_BACKEND_NOSUPERUSER) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be a superuser to cancel superuser query")))); if (r == SIGNAL_BACKEND_NOPERMISSION) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errmsg("must be a member of the role whose query is being canceled or member of pg_signal_backend")))); PG_RETURN_BOOL(r == SIGNAL_BACKEND_SUCCESS); }
Datum pg_terminate_backend(PG_FUNCTION_ARGS) { PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGTERM)); }
Datum pg_cancel_backend(PG_FUNCTION_ARGS) { PG_RETURN_BOOL(pg_signal_backend(PG_GETARG_INT32(0), SIGINT)); }
datum_t pg_cancel_backend(PG_FUNC_ARGS) { RET_BOOL(pg_signal_backend(ARG_INT32(0), SIGINT)); }
datum_t pg_terminate_backend(PG_FUNC_ARGS) { RET_BOOL(pg_signal_backend(ARG_INT32(0), SIGTERM)); }