Commit c3cb2b66 authored by Nikolay Samokhvalov's avatar Nikolay Samokhvalov 🚀

Fix idle clone check when user <> 'postgres'

If user is not `postgres` and we do not specify `dbname`, connection will be established to dbname=user.

Which may fail if there is no such database.

We can rely on the fact that DB `postgres` is present:

> The postgres database is also created when a database cluster is initialized.

-- from the official docs
parent d188491c
Pipeline #121007701 passed with stage
in 1 minute and 25 seconds
......@@ -561,15 +561,17 @@ func hasNotQueryActivity(session *provision.Session) (bool, error) {
// TODO(akartasov): Move the function to the provision service.
func getSocketConnStr(session *provision.Session) string {
return fmt.Sprintf("host=%s user=%s", session.SocketHost, session.User)
return fmt.Sprintf("host=%s user=%s dbname=postgres", session.SocketHost, session.User)
// checkActiveQueryNotExists runs query to check a user activity.
func checkActiveQueryNotExists(db *sql.DB) (bool, error) {
var isRunningQueryNotExists bool
SELECT * FROM pg_stat_activity WHERE state NOT ILIKE 'idle%' AND query NOT LIKE 'autovacuum: %' AND pid <> pg_backend_pid())`
query := `select not exists (
select * from pg_stat_activity
where state <> 'idle' and query not like 'autovacuum: %' and pid <> pg_backend_pid()
err := db.QueryRow(query).Scan(&isRunningQueryNotExists)
return isRunningQueryNotExists, err
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment