﻿# Permission checks on PostgreSQL replicas need a read-after-write contract

A committed revocation may not be applied at the assistant’s reader. Inspect synchronous_commit, standby selection and the actual database route before changing policy.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/enterprise-ai-postgres-replica-permission-read-contract/
Language: en

## Trace the read after a permission write

An administrator removes a user's document permission on PostgreSQL's primary. The assistant immediately checks access through a read endpoint backed by a standby and still sees the old grant. The write can be committed while the reader has not yet applied it. Before changing the permission predicate, identify which server handled the write, which served the check and what acknowledgement contract connected them.

## Distinguish durable receipt from query visibility

The [WAL configuration reference](https://www.postgresql.org/docs/current/runtime-config-wal.html) distinguishes synchronous_commit modes. With configured synchronous standbys, on waits for durable receipt, while remote_apply waits for the current synchronous standby set to apply the commit so it becomes visible to queries there. These are different guarantees. A replication connection being healthy does not establish that this particular permission change has been replayed by the server answering the assistant.

## Check which standby the setting covers

The [standby replication guide](https://www.postgresql.org/docs/current/warm-standby.html) explains selection through synchronous_standby_names, including priority and quorum arrangements. A successful commit does not imply that every arbitrary read replica or downstream cascading standby has applied it. Inspect the actual reader destination and its relationship to the synchronous set. Also inspect whether synchronous_standby_names is empty: the WAL reference states that remote_apply then has the same local synchronization level as on, without the desired remote application wait.

## Choose an access-check path deliberately

For a sensitive permission transition, a proposed application can keep the relevant check on the primary or use a routing contract tied to the replica state required by that transition. Define the policy before treating any available replica as interchangeable. Record the operation's database route and permission revision. This is not a recommendation to change an entire deployment's commit mode blindly: waiting for remote application changes latency and availability behavior, and the selected data path must support the intended service contract.

## Observe the change at the real reader

In a controlled fixture, create a harmless grant, verify it through the normal read path and remove it on the writer. After the write acknowledgement, issue a fresh request through that same application path and record the actual backend that answered. Compare a covered synchronous standby with an explicitly asynchronous test reader. Preserve commit mode and standby selection with the results. Acceptance requires the promised permission state at the declared read boundary. No replication delay, deployment change or revocation experiment was measured here.

## Avoid attributing every stale answer to database replication

An application permission cache or a previously constructed answer can preserve old state outside the database. [PostgREST visibility](/journal/guide-postgrest-rls-empty-visible-set/) explains how role context affects the readable set, while [persistent cache invalidation](/journal/persistent-kv-cache-invalidation/) concerns another kind of retained state. Distinguish those paths from replay lag. The useful conclusion identifies the server and transaction observation that enforced access, together with the precise replica coverage of the commit guarantee. It should not describe remote_apply as a universal switch making every enterprise read immediately current.
