-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Bug Description
Are connections to managed postgres databases (like Digital Ocean, etc) that require SSL supported with sqlx-cli?
I installed sqlx-cli with cargo install sqlx-cli --no-default-features --features rustls,postgres and also tried cargo install sqlx-cli --no-default-features --features openssl-vendored,postgres
When I use sqlx-cli and something like the following in .env DATABASE_URL=postgres://exampleuser:examplepass@digitalocandomain:port/example_db?sslmode=require i get error: error returned from database: database "postgres" does not exist
If i change password to wrong password or different user, i get authentication error which suggest it's reading the right config. But saying database postgres does not exist suggest this might be a bug because my connection string does not call postgres as database name. I'm only able to get sqlx-cli working with local less secure databases without ssl.
I can connect to secure managed database using psql with the same connection string. I can also connect via DBeaver with url/connection string.
The problem is specific to sqlx-cli which prevent's me from managing migrations, and performing other command line task. The rust app can connect using the same database url without issues:
use sqlx::{Connection, PgConnection};
use std::env;
use dotenv::dotenv;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set in the .env file");
// Connect to the Postgres database with TLS
let connection = PgConnection::connect(&database_url).await?;
println!("Connected to the database successfully!");
// Close the connection
connection.close().await?;
Ok(())
}Minimal Reproduction
Not sure the best way to reproduce considering this is related to connecting to encrypted managed database, not local or self hosted.
- Create managed database with digital ocean using postgres 15
- Set your DATABASE_URL in your .env using the connection string provided by digital ocean managed database admin panel
- Install sqlx with
cargo install sqlx-cli --no-default-features --features rustls,postgres - Try to connect to it using sqlx-cli with something like the following in terminal
sqlx database create
Info
- SQLx (and slqx-cli) version: 0.7.1
- SQLx features enabled: rustls,postgres
- Database server and version: Postgres 15
- Operating system: Ubuntu 22.04 LTS
rustc --version: 1.72.1