use tokio_postgres::Client;
use crate::postgres_source::constants::SPLIT_BEGIN;
use crate::postgres_source::errors::PostgresError;
pub async fn share_snapshot(readers: &[&Client]) -> Result<(), PostgresError> {
let Some((first, others)) = readers.split_first() else {
return Ok(());
};
first.batch_execute(SPLIT_BEGIN).await?;
let snapshot: String = first
.query_one("SELECT pg_export_snapshot()", &[])
.await?
.get(0);
for other in others {
other
.batch_execute(&format!(
"{SPLIT_BEGIN}; SET TRANSACTION SNAPSHOT '{snapshot}'"
))
.await?;
}
Ok(())
}