postgresql_16:5.1.14 Event System
PostgreSQL 16 > Client Interfaces > libpq — C Library > Event System
libpq's event system is designed to notify registered event handlers about interesting libpq events, such as the creation or destruction of PGconn and PGresult objects. A principal use case is that this allows applications to associate their own data with a PGconn or PGresult and ensure that that data is freed at an appropriate time.
Each registered event handler is associated with two pieces of data, known to libpq only as opaque void * pointers. There is a *pass-through* pointer that is provided by the application when the event handler is registered with a PGconn. The pass-through pointer never changes for the life of the PGconn and all PGresults generated from it; so if used, it must point to long-lived data. In addition there is an *instance data* pointer, which starts out NULL in every PGconn and PGresult. This pointer can be manipulated using the (see libpq-PQinstanceData), (see libpq-PQsetInstanceData), (see libpq-PQresultInstanceData) and (see libpq-PQresultSetInstanceData) functions. Note that unlike the pass-through pointer, instance data of a PGconn is not automatically inherited by PGresults created from it. libpq does not know what pass-through and instance data pointers point to (if anything) and will never attempt to free them — that is the responsibility of the event handler.
Subsections
- postgresql_16:5.1.14.1 Event Types
- postgresql_16:5.1.14.2 Event Callback Procedure
- postgresql_16:5.1.14.3 Event Support Functions
- postgresql_16:5.1.14.4 Event Example