SessionStatusNotify¶
Receives session lifecycle events: connection, authentication, transaction status changes, asynchronous notifications, server notices, and parameter status updates. All callbacks have default no-op implementations, so consumers only need to override the events they care about.
Public Behaviours¶
pg_session_connected¶
Called when we have connected to the server but haven't yet tried to authenticate.
Parameters¶
- session: Session tag
pg_session_connection_failed¶
Called when the session fails to reach the ready state. Fires for any
pre-ready failure including: transport-level errors (DNS, TCP, timeout),
peer TCP close before the session reaches the ready state, TLS
negotiation and handshake failures, unsupported authentication methods,
invalid passwords, invalid users, missing databases, server
connection-limit exhaustion, SCRAM server-verification failures, server
protocol violations (unparseable bytes, wrong-state messages, or
unexpected SSL-negotiation bytes), and any other server rejection during
startup. Inspect reason to distinguish the cause; the class-valued
variants carry the full ErrorResponseMessage.
For failures that originate after the TCP connection is established
(TLS, authentication, protocol violation, server rejection),
pg_session_connected will have already fired. Applications that need
to know whether any bytes were exchanged with the server before the
failure can track that callback.
pg_session_shutdown fires immediately after this callback in all
cases — the session is torn down whenever connection fails.
Parameters¶
- session: Session tag
- reason: ConnectionFailureReason
pg_session_authenticated¶
Called when we have successfully authenticated with the server.
Parameters¶
- session: Session tag
pg_transaction_status¶
Called when the server reports its transaction status via ReadyForQuery. Fires after every query cycle completes, including the initial ready signal after authentication. The status indicates whether the session is idle, in a transaction block, or in a failed transaction.
Parameters¶
- session: Session tag
- status: TransactionStatus
pg_notification¶
Called when the server delivers a LISTEN/NOTIFY notification. Subscribe to notifications by executing LISTEN via Session.execute(). Notifications arrive asynchronously between query cycles.
Parameters¶
- session: Session tag
- notification: Notification val
pg_notice¶
Called when the server sends a non-fatal informational message
(NoticeResponse). Common triggers include DROP TABLE IF EXISTS on a
nonexistent table and RAISE NOTICE from PL/pgSQL. Notices can arrive
in any connected state, including during authentication.
Parameters¶
- session: Session tag
- notice: NoticeResponseMessage val
pg_parameter_status¶
Called when the server reports a runtime parameter value. PostgreSQL sends these during connection startup for all reporting parameters (server_version, client_encoding, standard_conforming_strings, etc.) and again whenever a SET command changes one.
Parameters¶
- session: Session tag
- status: ParameterStatus val
pg_session_shutdown¶
Parameters¶
- session: Session tag