postgres:  Use $USER as default for the username
@@ -110,8 +110,12 @@ pub struct PgConnection {
// https://www.postgresql.org/docs/12/protocol-flow.html#id-1.10.5.7.3
async fn startup(stream: &mut PgStream, url: &Url) -> crate::Result<BackendKeyData> {
- // Defaults to postgres@.../postgres
- let username = url.username().unwrap_or(Cow::Borrowed("postgres"));
+ // Defaults to $USER@.../$USER
+ // and falls back to postgres@.../postgres
+ let username = url
+ .username()
+ .or_else(|| std::env::var("USER").map(Cow::Owned).ok())
+ .unwrap_or(Cow::Borrowed("postgres"));
let database = url.database().unwrap_or(&username);
// See this doc for more runtime parameters
