Skip to content

Using a connection pooler can hold locks forever #146

Description

@codegoalie

Hello!

We are using tern in-code to run migrations when our application boots. We have several instances of our application(s) and so the lock to prevent them stomping on each other is important. Additionally, we're using pgdog in a high availability setup with multiple instances. We've noticed that the pg_advisory_lock can get lost on a different back-end and held forever.

Would you be open to using pg_advisory_xact_lock instead?

Since the xact lock is automatically released at the end of the transaction, it makes the MigrateTo case tricky to implement; especially handling disable-tx. However, since the lock isn't needed to run the actual migrations and is used more as a mutex, we could open two connections. The first would hold the lock. The second would run the migrations in separate transactions (or not if disabled) and then update the schema version. Then the first would release the lock.

I'm happy to try my hand at implementing this too.

Thanks so much for this library and the whole pgx ecosystem!!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions