Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1407,21 +1407,37 @@ fn is_database_healthy(info: &InstanceInfo) -> bool {
return false;
}

process::Command::new(psql_path)
let output = process::Command::new(psql_path)
// Avoid user psql configuration and fail instead of prompting if the
// saved instance credentials no longer work.
.args(["-X", "-w", "-q", "-v", "ON_ERROR_STOP=1"])
.args(["-h", "127.0.0.1", "-p", &info.port.to_string()])
.args(["-U", &info.username, "-d", &info.database])
.args(["-c", "SELECT 1"])
// Keep health checks bounded when a broken backend accepts a TCP
// connection but never completes startup or the query.
.env("PGCONNECT_TIMEOUT", "1")
.env("PGOPTIONS", "-c statement_timeout=1000")
// connection but never completes startup or the query. Generous
// enough for Windows, where each connection starts a new backend
// process and antivirus scanning can take seconds (#41).
.env("PGCONNECT_TIMEOUT", "10")
.env("PGOPTIONS", "-c statement_timeout=5000")
.env("PGPASSWORD", &info.password)
.output()
.map(|output| output.status.success())
.unwrap_or(false)
.output();
match output {
Ok(output) if output.status.success() => true,
Ok(output) => {
// stderr only: stdout may be JSON that callers parse.
eprintln!(
"Warning: PostgreSQL on port {} is running but did not answer a test query: {}",
info.port,
String::from_utf8_lossy(&output.stderr).trim()
);
false
}
Err(e) => {
eprintln!("Warning: could not run psql to check PostgreSQL on port {}: {}", info.port, e);
false
}
}
}

fn psql(name: String, args: Vec<String>) -> Result<(), CliError> {
Expand Down
Loading