Home > Enterprise >  Prepared statements Issue with pgBouncer with 'transaction' pool_mode
Prepared statements Issue with pgBouncer with 'transaction' pool_mode

Time:01-31

I have Prepared statements Issue with pgBouncer in 'transaction' pooling mode.

This Rust code:

use postgres::{Client, Error, NoTls};

fn main() -> Result<(), Error> {
    let mut client = Client::connect(
        "postgresql://haproxy@localhost:9435/haproxy",
        NoTls,
    )?;


for row in client.query("SELECT pg_is_in_recovery() as x;", &[])? {
    let x: bool = row.get(0);
    println!(
        "found app x: {}",
        x
    );
    }


    Ok(())
}

fails with: prepared statement "s0" does not exist

Error: Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E26000), message: "prepared statement \"s0\" does not exist", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("prepare.c"), line: Some(506), routine: Some("FetchPreparedStatement") }) }

Any solution to this?

CodePudding user response:

FTR!

the answer is using simple_query !

use postgres::{Client, Error, NoTls, SimpleQueryMessage};

fn main() -> Result<(), Error> {
    let mut client = Client::connect("postgresql://haproxy@localhost:9435/haproxy", NoTls)?;

    let mut res = false;

    let it = client.simple_query("SELECT pg_is_in_recovery()")?;

    for mm in it {
        match mm {
            SimpleQueryMessage::CommandComplete(_x) => {
                // println!("{:?}", x);
            }
            SimpleQueryMessage::Row(x) => {
                if x.get(0).as_ref().unwrap().contains('t') {
                    res = true;
                } else {
                    res = false;
                }
            }
            _ => panic!("n"),
        }
    }

    println!("Result is: {}", res);

    Ok(())
}
  • Related