In this article
Use notifications to discover later state changes after the documented registration-and-inspection sequence; do not treat startup notification count as a durable event log.
The watcher misses a change during startup
A service queries a table and then registers LISTEN so later changes will invalidate its local view. A concurrent transaction commits between those steps. The initial query can miss the change while the new listener also starts too late to receive its notification.
The LISTEN reference describes this startup race and gives a specific ordering rule. Registration becomes effective at transaction commit, so merely sending the command is not a completed listening boundary.
Establish registration before inspecting state
Execute and commit LISTEN first. Then inspect the required database state in a new transaction. Only after this inspection should the application rely on notifications to discover subsequent changes.
The new transaction matters because the state observable during the registration transaction predates the precise effective listening instant described by the manual. Combining registration and an assumed complete snapshot in the same transaction does not reproduce the documented bootstrap sequence.
Accept overlap rather than demand perfect separation
The reference warns that early notifications can describe updates already seen by the initial inspection. That overlap is an expected consequence of closing the missing-change gap, not evidence that the database sent an invalid event.
Design the notification handler to refresh or reconcile state safely when an update was already visible. Do not apply a non-idempotent business action once for the snapshot and again for every corresponding notification without a separate operation identity and processing contract.
Keep notification meaning explicit
The NOTIFY manual presents notifications as signals that can direct the listener to database state. It also describes transaction-boundary delivery and folding of identical notifications within a transaction. Notification count is therefore not a universal count of changed rows or committed business operations.
Store the structured state needed for recovery in an appropriate authoritative location. Define whether a payload names an object to inspect or represents another application-specific hint. The database does not automatically associate a channel with a table or make its payload a durable task queue.
Rebuild after session replacement
LISTEN registration belongs to the session and is cleared when it ends. A reconnect is consequently a new bootstrap boundary. Restore registration and inspect state again rather than assuming an old subscription follows the logical client name onto its replacement connection.
Database-backed retrieval state provides the application context. Idempotent outcome tracking explains why processing overlapping evidence requires stable business identity when an actual external action is involved.
Verify the transition with concurrent commits
In an isolated exercise, commit changes around the registration and initial-inspection boundaries. Verify that the documented sequence lets the watcher recover authoritative current state, including harmless repeated evidence. Acceptance records registration commit, inspection scope and reconnect behavior. It does not claim every intermediate historical event was replayed merely because the final state is correct or because the listener received a notification after startup.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.