A PostgreSQL advisory lock for concurrent content initialization
Content initialization is one ordered pipeline: create tables, correct the schema, seed static data, and upsert notes and courses. Even idempotent steps can observe an intermediate state when an operator double-clicks o…
A PostgreSQL advisory lock for concurrent content initialization
Content initialization is one ordered pipeline: create tables, correct the schema, seed static data, and upsert notes and courses. Even idempotent steps can observe an intermediate state when an operator double-clicks or two console replicas run the pipeline together.
Server concurrency contract
POST /api/db/init first calls pg_try_advisory_lock. If another session owns the lock, it returns 409 INIT_IN_PROGRESS without touching the database. The lock session stays alive for the whole callback, then runs pg_advisory_unlock and releases the client on success, failure, or exception.
State the operator can understand
Disabling a UI button is only a usability aid, not a concurrency or security contract. Show the server state in the role=status region and explain 409 as “another initialization is running; retry after it finishes,” rather than hiding it as an unknown failure.
Related course: Expand/Contract and idempotent backfills