From 18b286f3e3317c26f27ead1dea8be23c63a7ef2a Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 15 Apr 2008 13:55:12 +0000 Subject: Add pg_terminate_backend() to allow terminating only a single session. --- src/backend/tcop/postgres.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/backend/tcop/postgres.c') diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index d44e69fb10a..60519bd8a95 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.548 2008/04/02 18:31:50 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.549 2008/04/15 13:55:11 momjian Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -2541,7 +2541,8 @@ StatementCancelHandler(SIGNAL_ARGS) * waiting for input, however. */ if (ImmediateInterruptOK && InterruptHoldoffCount == 0 && - CritSectionCount == 0 && !DoingCommandRead) + CritSectionCount == 0 && + (!DoingCommandRead || MyProc->terminate)) { /* bump holdoff count to make ProcessInterrupts() a no-op */ /* until we are done getting ready for it */ @@ -2621,6 +2622,10 @@ ProcessInterrupts(void) ereport(ERROR, (errcode(ERRCODE_QUERY_CANCELED), errmsg("canceling autovacuum task"))); + else if (MyProc->terminate) + ereport(ERROR, + (errcode(ERRCODE_ADMIN_SHUTDOWN), + errmsg("terminating backend due to administrator command"))); else ereport(ERROR, (errcode(ERRCODE_QUERY_CANCELED), @@ -3459,6 +3464,9 @@ PostgresMain(int argc, char *argv[], const char *username) /* We don't have a transaction command open anymore */ xact_started = false; + if (MyProc->terminate) + die(SIGINT); + /* Now we can allow interrupts again */ RESUME_INTERRUPTS(); } -- cgit v1.2.3