diff --git a/Cargo.lock b/Cargo.lock index 2479456482..9420f19770 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1995,6 +1995,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ + "bindgen", "cc", "pkg-config", "vcpkg", diff --git a/sqlx-macros-core/src/database/mod.rs b/sqlx-macros-core/src/database/mod.rs index a2d0a1fa0d..50ef911495 100644 --- a/sqlx-macros-core/src/database/mod.rs +++ b/sqlx-macros-core/src/database/mod.rs @@ -54,7 +54,27 @@ impl CachingDescribeBlocking { let conn = match cache.entry(database_url.to_string()) { hash_map::Entry::Occupied(hit) => hit.into_mut(), hash_map::Entry::Vacant(miss) => { - miss.insert(DB::Connection::connect(database_url).await?) + let conn = miss.insert(DB::Connection::connect(database_url).await?); + + #[cfg(feature = "postgres")] + if DB::NAME == sqlx_postgres::Postgres::NAME { + conn.execute( + " + DO $$ + BEGIN + IF EXISTS ( + SELECT 1 + FROM pg_settings + WHERE name = 'plan_cache_mode' + ) THEN + SET SESSION plan_cache_mode = 'force_generic_plan'; + END IF; + END $$; + ", + ) + .await?; + } + conn } };