简体   繁体   中英

PgBouncer in Ruby on Rails app and advisory locks

I've been using advisory locks extensively in multiple apps and now, am looking into introducing a connection pooler due to the huge number of DB connections. I'm considering pgbouncer with transaction pool_mode and from the initial research, not everything is clear.

So advisory locks are session-based features, which won't work with a transaction pool mode. This is also a common source of the issues with running migrations in Ruby on Rails and one of the reasons why in Rails 6 it's possible to disable advisory locks to solve the issue with migrations. On the other hand, there are transaction-level locks, which might work just fine with the transaction pool mode. Yet, this doesn't seem to go along with the general recommendations that you shouldn't use advisory locks with pgbouncer or even with the fact that in Rails, it's either a session-based advisory lock or not at all for migrations (although this decision could be made due to the fact that it's possible to disable transaction per migration), so it's a bit confusing.

So I was wondering if transaction-level advisory locks will just work with pgbouncer or should I looks for some alternative?

Thanks in advance for the answer.

Anything that doesn't survive the end of a transaction is no problem to use in transaction pooling mode of pgBouncer.

So I see no problem with using transaction-level advisory locks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM