diff --git a/src/main.rs b/src/main.rs index c548ef2..6237f16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use secrecy::ExposeSecret; -use sqlx::PgPool; +use sqlx::postgres::PgPoolOptions; use std::net::TcpListener; use tracing::subscriber::set_global_default; use tracing_log::LogTracer; @@ -16,13 +16,15 @@ async fn main() -> Result<(), std::io::Error> { // We want to panic if we cannot read the configuration let configuration = get_configuration().expect("Failed to read configurations"); - let connection = PgPool::connect_lazy( - configuration - .database - .get_connnection_string() - .expose_secret(), - ) - .expect("Failed to connect to Postgres"); + let connection = PgPoolOptions::new() + .acquire_timeout(std::time::Duration::from_secs(2)) + .connect_lazy( + configuration + .database + .get_connnection_string() + .expose_secret(), + ) + .expect("Failed to connect to Postgres"); // Bind the TCP listener socket address with the configuration port let address = format!(