/* If we have setsid(), signal the backend's whole process group */ #ifdef HAVE_SETSID if (kill(-pid, sig)) #else if (kill(pid, sig)) #endif
{ /* Again, just a warning to allow loops */
ereport(WARNING,
(errmsg("could not send signal to process %d: %m", pid))); return SIGNAL_BACKEND_ERROR;
} return SIGNAL_BACKEND_SUCCESS;
}
/* *Signaltocancelabackendprocess.Thisisallowedifyouareamemberof *therolewhoseprocessisbeingcanceled. * *Notethatonlysuperuserscansignalsuperuser-ownedprocesses.
*/
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("permission denied to cancel query"),
errdetail("Only roles with the %s attribute may cancel queries of roles with the %s attribute.", "SUPERUSER", "SUPERUSER")));
if (r == SIGNAL_BACKEND_NOAUTOVAC)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to cancel query"),
errdetail("Only roles with privileges of the \"%s\" role may cancel autovacuum workers.", "pg_signal_autovacuum_worker")));
if (r == SIGNAL_BACKEND_NOPERMISSION)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to cancel query"),
errdetail("Only roles with privileges of the role whose query is being canceled or with privileges of the \"%s\" role may cancel this query.", "pg_signal_backend")));
/* *Checkexistenceofthebackend.Ifthebackendstillexists,thenwait *forwaittimemilliseconds,againcheckfortheexistence.Repeatthis *untiltimeoutoranerroroccursorapendinginterruptsuchasquery *cancelgetsprocessed.
*/ do
{ if (remainingtime < waittime)
waittime = remainingtime;
if (kill(pid, 0) == -1)
{ if (errno == ESRCH) returntrue; else
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not check the existence of the backend with PID %d: %m",
pid)));
}
/* Process interrupts, if any, before waiting */
CHECK_FOR_INTERRUPTS();
remainingtime -= waittime;
} while (remainingtime > 0);
ereport(WARNING,
(errmsg_plural("backend with PID %d did not terminate within %" PRId64 " millisecond", "backend with PID %d did not terminate within %" PRId64 " milliseconds",
timeout,
pid, timeout)));
returnfalse;
}
/* *Sendasignaltoterminateabackendprocess.Thisisallowedifyouarea *memberoftherolewhoseprocessisbeingterminated.Ifthetimeoutinput *argumentis0,thenthisfunctionjustsignalsthebackendandreturns *true.Iftimeoutisnonzero,thenitwaitsuntilnoprocesshasthegiven *PID;iftheprocessendswithinthetimeout,trueisreturned,andifthe *timeoutisexceeded,awarningisemittedandfalseisreturned. * *Notethatonlysuperuserscansignalsuperuser-ownedprocesses.
*/
Datum
pg_terminate_backend(PG_FUNCTION_ARGS)
{ int pid; int r; int timeout; /* milliseconds */
if (timeout < 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("\"timeout\" must not be negative")));
r = pg_signal_backend(pid, SIGTERM);
if (r == SIGNAL_BACKEND_NOSUPERUSER)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to terminate process"),
errdetail("Only roles with the %s attribute may terminate processes of roles with the %s attribute.", "SUPERUSER", "SUPERUSER")));
if (r == SIGNAL_BACKEND_NOAUTOVAC)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to terminate process"),
errdetail("Only roles with privileges of the \"%s\" role may terminate autovacuum workers.", "pg_signal_autovacuum_worker")));
if (r == SIGNAL_BACKEND_NOPERMISSION)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to terminate process"),
errdetail("Only roles with privileges of the role whose process is being terminated or with privileges of the \"%s\" role may terminate this process.", "pg_signal_backend")));
/* Wait only on success and if actually requested */ if (r == SIGNAL_BACKEND_SUCCESS && timeout > 0)
PG_RETURN_BOOL(pg_wait_until_termination(pid, timeout)); else
PG_RETURN_BOOL(r == SIGNAL_BACKEND_SUCCESS);
}
/* *Signaltoreloadthedatabaseconfiguration * *Permissioncheckingforthisfunctionismanagedthroughthenormal *GRANTsystem.
*/
Datum
pg_reload_conf(PG_FUNCTION_ARGS)
{ if (kill(PostmasterPid, SIGHUP))
{
ereport(WARNING,
(errmsg("failed to send signal to postmaster: %m")));
PG_RETURN_BOOL(false);
}
PG_RETURN_BOOL(true);
}
/* *Rotatelogfile * *Permissioncheckingforthisfunctionismanagedthroughthenormal *GRANTsystem.
*/
Datum
pg_rotate_logfile(PG_FUNCTION_ARGS)
{ if (!Logging_collector)
{
ereport(WARNING,
(errmsg("rotation not possible because log collection not active")));
PG_RETURN_BOOL(false);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.