Using pg_advisory_lock for limit multi-node migrators?

145 views
Skip to first unread message

David Bernheisel

unread,
Dec 7, 2021, 3:05:56 PM12/7/21
to elixir-ecto
👋 Heyo,

A friend Lucas Mendolowski asked if there was a way to ensure safe migrations in multi-node environments when running concurrent database operations, such as adding indexes concurrently, when using Postgres. We discussed more here: https://github.com/fly-apps/safe-ecto-migrations/issues/2

It seems that it might be a good idea to switch the PG adapter in EctoSQL to using `pg_advisory_lock` and `pg_advisory_unlock` (similar to how the MyXQL adapter currently works) so that we could de-couple database transactions from ensuring one migrator is running one at a time.

I'm not aware of what downsides there could be, I'll need to think about that some more. For reference ActiveRecord has been using `pg_try_advisory_lock` since Rails 5:

José Valim

unread,
Dec 7, 2021, 3:12:15 PM12/7/21
to elixi...@googlegroups.com
A PR would be welcome, yes!

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/d43db622-ae5c-46d4-8423-b618efb27816n%40googlegroups.com.

Hubert Łępicki

unread,
Dec 8, 2021, 8:48:14 AM12/8/21
to elixi...@googlegroups.com
hold on, doesn't Ecto already do that? I was sure that migrations are safe currently in multi-node set up, but does it only mean they're safe when you're using MySQL?



--
Pozdrawiam,
Hubert Łępicki
 -----------------------------------------------
[ http://hubertlepicki.com ]

José Valim

unread,
Dec 8, 2021, 9:09:47 AM12/8/21
to elixi...@googlegroups.com
We do but we use another implementation.

Allen Madsen

unread,
Dec 8, 2021, 10:07:19 AM12/8/21
to elixi...@googlegroups.com
One thing to consider is that some people use the postgres adapter for CockroachDB, so the solution needs to be portable for that or have a way to be disabled.

José Valim

unread,
Dec 8, 2021, 10:25:52 AM12/8/21
to elixi...@googlegroups.com
I believe we are going to keep the current mode as behind an option.

Hubert Łępicki

unread,
Dec 8, 2021, 12:26:19 PM12/8/21
to elixi...@googlegroups.com
ok thanks for explaining. I had a minor panic attack xD

Reply all
Reply to author
Forward
0 new messages