-
Notifications
You must be signed in to change notification settings - Fork 55
Error when not declaring primary for read only DB #162
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
Comments
Makes sense if you tried to send a write query. Do you have a log of what query you ran? Edit: Are you using sharding or just read/write split? |
I think it's the |
Hi, I tried adding primary to the read only db ( cannot execute INSERT in a read-only transaction # https://github.com/pgdogdev/pgdog/blob/main/pgdog.toml
[general]
host = "0.0.0.0"
port = 6432
shutdown_timeout = 5_000
openmetrics_port = 9930
query_timeout = 1_000
checkout_timeout = 1_000
connect_timeout = 1_000
idle_timeout = 30_000
prepared_statements = "extended"
passthrough_auth = "enabled_plain"
default_pool_size = 100
workers = 10
min_pool_size = 1
pooler_mode = "transaction"
load_balancing_strategy = "least_active_connections"
auth_type = "trust"
[admin]
user = "pgdog"
password = "pgdog"
[[databases]]
name = "postgres"
host = "localhost"
role = "primary"
port = 5432
[[databases]]
name = "foo"
host = "localhost"
role = "primary"
port = 5432
[[databases]]
name = "foo"
host = "localhost"
port = 5433
role = "replica"
[[databases]]
name = "bar"
host = "localhost"
role = "replica"
port = 5433
[[databases]]
name = "bar"
host = "localhost"
role = "primary" # <===================== adding primary for bar
port = 5432
[tcp]
retries = 3
time = 1000
interval = 1000
user_timeout = 1000 |
Sounds good, I'm going to repro on my side and provide a fix. |
This is what's going on I suspect: The ORM starts a read query then, inside the same transaction, a write query. PgDog routes transactions, not individual queries, so the transaction fails. Another thing we could try to confirm is enable [general]
query_log = "queries.log" After running your test, if you're still getting errors, could you share the Thanks! |
@sandangel Try the latest commit and set: [general]
read_write_strategy = "conservative" This should route all explicit transactions to the primary. |
Ok finally I think I understand the root cause here. It's the async protocol again. I think I got it this time in #164 . |
get a new error now. where as pgpool or pgcat just work. sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.ConnectionDoesNotExistError'>: connection was closed in the middle of operation
|
Alright, I'll keep digging. Thanks for reporting this! It would be really helpful if you could share the log output from pgdog so I can see the actual error that took place. |
For read only DB, I only declare database with replica role, then got an error:
The text was updated successfully, but these errors were encountered: