Support readonly databases [Regression]
Version Information
Server Version: v2.0.10
Environment
HASURA_GRAPHQL_DATABASE_URL: postgres://repl_user:repl_password@postgres-replica:5432/postgres
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres-master:5432/postgres
Error
[
{
"definition": "indexer-mainnet",
"reason": "Inconsistent object: postgres tx error",
"name": "source indexer-mainnet",
"type": "source",
"message": {
"statement": "BEGIN ISOLATION LEVEL READ COMMITTED READ WRITE",
"prepared": true,
"error": {
"exec_status": "FatalError",
"hint": null,
"message": "cannot set transaction read-write mode during recovery",
"status_code": "0A000",
"description": null
},
"arguments": []
}
}
]
Hi @atellezsazo Could you list the version where this was working for you earlier?
What I'm seeing, with a current HEAD build, running a replica setup, with database URLs
MASTER_DB=postgresql://user:pass@localhost:5432/data
REPLICA_DB=postgresql://user:pass@localhost:5433/data
META_DB=postgresql://user:pass@localhost:5432/meta
## reset metadata database, then
$ graphql-engine -- --database-url $MASTER_DB --metadata-database-url $META_DB serve
## comes up healthy; interrupt, then
$ graphql-engine -- --database-url $REPLICA_DB --metadata-database-url $META_DB serve
## also comes up healthy
on the other hand:
## reset metadata database, then
$ graphql-engine -- --database-url $REPLICA_DB --metadata-database-url $META_DB serve
## comes up unhealthy, with the same error as in the bug report; interrupt, then
$ graphql-engine -- --database-url $MASTER_DB --metadata-database-url $META_DB serve
## also comes up unhealthy(!)
So as far as I can tell, it's possible to connect to a read replica if and only if the metadata has already been initialized on a prior read-write connection. I have not yet tested further how functional things are in that state.
If I do the same tests with graphql-engine v2.0.3, the server comes up healthy either way around. In that sense, I can confirm the bug report.
@atellezsazo Does this match your findings?
Next steps will be to:
- figure out what caused the change
- set up some testing for read-replica setups
As an update: I don't see the error on any release I've tried, include v2.0.10 v2.1.1 or v2.2.0. For most of the releases, I've only run them via the released docker images, but for v2.2.0 I've also verified things are fine with a local build. The only failure case I see is with current HEAD.
@atellezsazo Could you please let us know what you did to get that error on v2.0.10 (or clarify if this was on a development build)?
The error I see on HEAD is certainly worth investigating and fixing regardless, but it would be good to know that we'd be fixing the issue you ran into, and not some other one.
I've traced the error that I can reproduce to this commit: https://github.com/hasura/graphql-engine/commit/e1918adb529344f790c0fe46f1153c065ce2ffbe
But that can't be what this bug report is about, since that's a very recent change...
Closing this now since I can't reproduce it on the most basic level, and reporter isn't responsive.
Verified that on the reported version, it is possible to add a read-replica as a data source and it comes up healthy.
Do re-open / comment if you have more details, happy to dig deeper!
We just had this same issue and it was because we had event triggers setup in the metadata. When trying to apply the metadata to the hasura instance where the data db was readonly, we'd get the error above. I guess the failure is because it's trying to add a listener to the db itself, which fails given it's readonly?
If we remove the event triggers, it works fine
I wonder if there should be a flag to skip event triggers when applying metadata that could be used for these cases @robx ? 🤔
@tjenkinson I'm a bit far removed from graphql-engine these days. I guess you could reopen the issue, and/or maybe @tirumaraiselvan has some input?
Thanks! Will open a new issue soon if there's no follow up here.
@tjenkinson I work on the community team at Hasura and I'd like to follow up on this with you. Could you drop me a message at [email protected]?
Hi @a-chocolate-bear was there any movement on this? We're seeing issues in one project where the HASURA_GRAPHQL_EVENTS_FETCH_INTERVAL is set to 0 on our read only instance and still getting the same error message as above. The writer instances do need events enabled to process them.
{"detail":{"code":"postgres-error","error":"postgres tx error","internal":{"arguments":[],"error":{"description":null,"exec_status":"FatalError","hint":null,"message":"cannot set transaction read-write mode during recovery","status_code":"0A000"},"prepared":true,"statement":"BEGIN ISOLATION LEVEL READ COMMITTED READ WRITE"},"path":"$"},"level":"error","timestamp":"2023-11-29T13:25:39.422+0000","type":"event-trigger"}
Otherwise it appears to be fine.