Skip to content

Commit

Permalink
Set default_transaction_read_only on the auxiliary connection
Browse files Browse the repository at this point in the history
This is an extra safety measure making sure we don't mess anything up
(too badly).  pg_export_snapshot() is guaranteed to work this way as
well, as it has to be able to run on a read-only replica.
  • Loading branch information
johto committed Sep 14, 2023
1 parent 5195d59 commit 8fa72dd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ fn main() -> std::io::Result<()> {
}
let mut pg_conn = pg_conn.unwrap();

let res = pg_conn.execute("SET default_transaction_read_only TO TRUE", &[]);
if let Err(e) = res {
eprintln!("could not set default_transaction_read_only: {}", e);
process::exit(1);
}

let mut txn = match pg_conn.transaction() {
Err(e) => {
eprintln!("could not begin a database transaction: {}", e);
Expand Down

0 comments on commit 8fa72dd

Please sign in to comment.