Skip to content

fix(openreader): Use READ COMMITTED to allow the usage of PostgreSQL replicas#449

Open
HRGCompany wants to merge 3 commits intosubsquid:masterfrom
HRGCompany:fix/openreader-read-committed-hot-standby
Open

fix(openreader): Use READ COMMITTED to allow the usage of PostgreSQL replicas#449
HRGCompany wants to merge 3 commits intosubsquid:masterfrom
HRGCompany:fix/openreader-read-committed-hot-standby

Conversation

@HRGCompany
Copy link
Copy Markdown

@HRGCompany HRGCompany commented Mar 16, 2026

SERIALIZABLE isolation is incompatible with PostgreSQL replicas, causing "cannot use serializable mode on a hot standby" errors when OpenReader is pointed at a read-only replica.

Since OpenReader only performs read queries, READ COMMITTED is sufficient and works correctly on both primary and replica servers.

This PR adds support for configuring transaction isolation levels in the OpenReader and GraphQL Server packages, giving users more control over their query transactions.

This allows distributing requests across replicas for read-only queries, while keeping indexers / processors pointing toward the primary server to avoid any overload.

Default value is set to SERIALIZABLE to ensure backward compatibility and avoid breaking changes.

…replicas

SERIALIZABLE isolation is incompatible with PostgreSQL replicas, causing
"cannot use serializable mode on a hot standby" errors when OpenReader
is pointed at a read-only replica.

Since OpenReader only performs read queries, READ COMMITTED is sufficient
and works correctly on both primary and replica servers.

This allows distributing requests across replicas for read-only queries,
while keeping indexers pointing toward the primary server to avoid
any overload.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates OpenReader’s transaction isolation level to be compatible with PostgreSQL read-only replicas (hot standby), avoiding cannot use serializable mode on a hot standby errors while keeping queries read-only.

Changes:

  • Change OpenReader’s START TRANSACTION isolation level from SERIALIZABLE to READ COMMITTED for read-only transactions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@belopash
Copy link
Copy Markdown
Contributor

Hey, sorry for the long time reply. Could you please implement it as a configurable option, so It coiuld be passed to the server via command options?

program.description(`GraphQL server for squids`)

@HRGCompany
Copy link
Copy Markdown
Author

Hey, sorry for the long time reply. Could you please implement it as a configurable option, so It coiuld be passed to the server via command options?

program.description(`GraphQL server for squids`)

I’ve just pushed a new commit with the following changes. Would you mind reviewing it?

Key Updates:

  • Made the setting configurable.
  • Reset the default to SERIALIZABLE to ensure backward compatibility and avoid breaking changes.
  • Fixed CockroachDB Docker Compose image version.

CockroachDB is updated from v21.2.9 → v23.2.2 (the old version was no longer available, which was blocking rush test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants