|The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group
Paperback (6"x9"), 478 pages
RRP £14.95 ($19.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
1.5 Cancelling Queries in Progress
A client application can request cancellation of a command that is still being processed by the server, using the functions described in this section.
Creates a data structure containing the information needed to cancel
a command issued through a particular database connection.
PGcancel *PQgetCancel(PGconn *conn);
PGcancelobject given a
PGconnconnection object. It will return
NULLif the given
NULLor an invalid connection. The
PGcancelobject is an opaque structure that is not meant to be accessed directly by the application; it can only be passed to
Frees a data structure created by
void PQfreeCancel(PGcancel *cancel);
PQfreeCancelfrees a data object previously created by
Requests that the server abandon processing of the current command.
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);The return value is 1 if the cancel request was successfully dispatched and 0 if not. If not,
errbufis filled with an error message explaining why not.
errbufmust be a char array of size
errbufsize(the recommended size is 256 bytes). Successful dispatch is no guarantee that the request will have any effect, however. If the cancellation is effective, the current command will terminate early and return an error result. If the cancellation fails (say, because the server was already done processing the command), then there will be no visible result at all.
PQcancelcan safely be invoked from a signal handler, if the
errbufis a local variable in the signal handler. The
PGcancelobject is read-only as far as
PQcancelis concerned, so it can also be invoked from a thread that is separate from the one manipulating the
Requests that the server abandon processing of the current
int PQrequestCancel(PGconn *conn);
PQrequestCancelis a deprecated variant of
PQcancel. It operates directly on the
PGconnobject, and in case of failure stores the error message in the
PGconnobject (whence it can be retrieved by
PQerrorMessage). Although the functionality is the same, this approach creates hazards for multiple-thread programs and signal handlers, since it is possible that overwriting the
PGconn's error message will mess up the operation currently in progress on the connection.
|ISBN 9781906966065||The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide||See the print edition|