You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpsycopgconn=psycopg.connect(
dbname="dev",
user="wizabot",
password="crptx123",
host="timescaledb_proxy",
port=6432,
)
cur=conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS test_table ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, value INTEGER NOT NULL);""")
conn.commit()
cur.execute("""INSERT INTO test_table (name, value)VALUES ('alpha', 10), ('beta', 20), ('gamma', 30)RETURNING id, name, value;""")
print("Inserted rows:")
forrowincur.fetchall():
print(row)
conn.commit()
cur.execute("SELECT id, name, value FROM test_table ORDER BY id;")
forrowincur.fetchall():
print(f"id={row[0]}, name={row[1]}, value={row[2]}")
cur.close()
conn.close()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I’m testing a TimescaleDB cluster (1 primary + 2 replicas) behind PgCat, running in Docker Swarm.
Sometimes write queries (
CREATE TABLE,INSERT) fail with:psycopg.errors.ReadOnlySqlTransaction: cannot execute INSERT in a read-only transactionOther times the exact same script runs correctly and writes to the primary.
This happens inconsistently across runs.
Example logs
So PgCat occasionally routes write queries to replicas, even though the configuration should prevent that.
PgCat config (
pgcat.toml)Test script (
psycopg)docker compose (swarm mode) config:
Environment
postgresml/pgcat)Question
Why does PgCat sometimes route write queries to replicas even when:
pool_mode = "transaction"query_parser_enabled = truedefault_role = "primary"primary_reads_enabled = trueIs there a known issue with query routing or connection reuse between replicas and primaries?
Beta Was this translation helpful? Give feedback.
All reactions