Advisory locks: private to connected database or shared across cluster

lockingpostgresql

Is the space of keys in PostgreSQL advisory locks private to the connected database, or shared across the database cluster?

Nosing around https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS and https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS the answer doesn't seem to be obvious.

Best Answer

That is indeed not clear from the documentation, but a simple experiment shows that advisory locks are local to the database. That is, you can take the same advisory lock in two different databases without conflict.

Related Question