|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.33 2004/05/21 05:08:02 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.34 2004/06/02 21:29:29 momjian Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
15 | 15 | #include"postgres.h"
|
16 | 16 |
|
17 | 17 | #include<sys/file.h>
|
| 18 | +#include<signal.h> |
18 | 19 |
|
19 | 20 | #include"commands/dbcommands.h"
|
20 | 21 | #include"miscadmin.h"
|
| 22 | +#include"storage/sinval.h" |
21 | 23 | #include"utils/builtins.h"
|
22 | 24 |
|
23 | 25 |
|
@@ -57,3 +59,47 @@ current_database(PG_FUNCTION_ARGS)
|
57 | 59 | namestrcpy(db,get_database_name(MyDatabaseId));
|
58 | 60 | PG_RETURN_NAME(db);
|
59 | 61 | }
|
| 62 | + |
| 63 | + |
| 64 | +/* |
| 65 | + * Functions to terminate a backend or cancel a query running on |
| 66 | + * a different backend. |
| 67 | + */ |
| 68 | + |
| 69 | +staticintpg_signal_backend(intpid,intsig) |
| 70 | +{ |
| 71 | +if (!superuser()) |
| 72 | +ereport(ERROR, |
| 73 | +(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 74 | + (errmsg("only superuser can signal other backends")))); |
| 75 | + |
| 76 | +if (!IsBackendPid(pid)) |
| 77 | +{ |
| 78 | +/* This is just a warning so a loop-through-resultset will not abort |
| 79 | + * if one backend terminated on it's own during the run */ |
| 80 | +ereport(WARNING, |
| 81 | +(errmsg("pid %i is not a postgresql backend",pid))); |
| 82 | +return0; |
| 83 | +} |
| 84 | + |
| 85 | +if (kill(pid,sig)) |
| 86 | +{ |
| 87 | +/* Again, just a warning to allow loops */ |
| 88 | +ereport(WARNING, |
| 89 | +(errmsg("failed to send signal to backend %i: %m",pid))); |
| 90 | +return0; |
| 91 | +} |
| 92 | +return1; |
| 93 | +} |
| 94 | + |
| 95 | +Datum |
| 96 | +pg_terminate_backend(PG_FUNCTION_ARGS) |
| 97 | +{ |
| 98 | +PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0),SIGTERM)); |
| 99 | +} |
| 100 | + |
| 101 | +Datum |
| 102 | +pg_cancel_backend(PG_FUNCTION_ARGS) |
| 103 | +{ |
| 104 | +PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0),SIGINT)); |
| 105 | +} |