launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.39k stars 1.27k forks source link

pool timed out while waiting for an open connection #2345

Closed alekspickle closed 1 year ago

alekspickle commented 1 year ago

Bug Description

I looked into all similar issues but I still can't understand what is the issue here. Here is how I create a pool and I get the Error: pool timed out while waiting for an open connection error. Am I doing something wrong?

Minimal Reproduction

use sqlx::postgres::PgPoolOptions;
use std::env;
use tracing::{debug, info};

const DEFAULT_DB: &str = "postgres://postgres:password@localhost";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_init();

    let db_url = env::var("DATABASE_URL").unwrap_or_else(|_| DEFAULT_DB.to_string());
    debug!(db=%db_url, "Using DB url");

    let pool = PgPoolOptions::new().connect(&db_url).await?;
    }

Info

alekspickle commented 1 year ago

Solved: I am stupid and my postgres was running on the port other than default (in my case 5434), as soon as I specified it in url it connected. "postgres://postgres:password@localhost:5434" I hope this issue will help for others stuck with this as I was.