Distributed Locking with Postgres Advisory Locks
Postgres Advisory Locks are a great solution for arbitrary application locks, particularly in scenarios where you are already using Postgres and have a need to block concurrent mutations to a resource (that resource DOES NOT have to be data in Postgres).
Source: Distributed Locking with Postgres Advisory Locks, an article by Richard Clayton.