-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event triggers don't work on read replicas #3414
Comments
In which way is it worse than what you thought before? It's exactly that, no?
Does this really make sense as long as we don't have support for read replica connections to route reads to, in the first place? How does this come up in practice without? |
It makes sense in a setup where you have a PostgREST on the primary and with a replica that has its own PostgREST too. Yeah ideally it would be a single PostgREST with #2429 but that's not coming anytime soon. This would be a much easier to implement alternative in the meantime. It doesn't add much complexity too. Once we have read replica support I guess we could drop the config as well. |
How do both IMHO, this will quickly become very annoying to configure. For example, in a kubernetes setup, it's much more practical to pass all the database config options via separate environment variables - including the host name, which could already be available in a secret to consume, provided by your favorite pg operator. But now I have to pass those in a db-uri format. Meh. How about using PostgreSQL's "Multiple Hosts" feature in libpq? We could do the following:
This should make postgrest pick the first connection, which is read-only, for all regular connections, but use the primary node for the listener. Advantages:
|
@wolfgangwalther Not sure I get your idea. So I've just tried it multiple hosts and # having only one pg listening on 5432 this will succeed, since libpq will try the second host
psql postgresql://user:pass@localhost:5433,localhost:5432/postgres
# this will now fail since our pg is read-write and we tell libpq to only use a read-only session
psql postgresql://user:pass@localhost:5433,localhost:5432/postgres?target_session_attrs=read-only
connection to server at "localhost" (::1), port 5432 failed: session is not read-only
Is the above true? So on the instance having a read replica + postgrest, we'd have:
Then all connections will be routed to the I'm not seeing how is possible to solve this without 2 db-uris, one for the pool and another one for the listener. |
Oh, perhaps you meant to dynamically inject that Yeah, that could work! Great idea! 💡 ( |
That's exactly what I meant to say :) |
Problem
See https://stackoverflow.com/questions/29931136/postgresql-replica-where-i-can-create-triggers/29932655#29932655.
This means that PostgREST NOTIFY reloading won’t work in read replicas.
Previously, I thought this was only a problem with just LISTEN/NOTIFY on read replicas (#2781), but it's worse.
Solution
Enable a configurable connection string for the LISTEN channel.
Similar to the https://postgrest.org/en/v12/references/configuration.html#db-uri. By default it will use the same value as the
db-uri
.This way the LISTEN channel can point to the primary instead of the replica and notify reloading can work normally.
The text was updated successfully, but these errors were encountered: