fly-apps / postgres-flex

Postgres HA setup using repmgr
87 stars 43 forks source link

Update main.go to fix scale to zero functionality #225

Closed swilson-fly closed 5 months ago

swilson-fly commented 6 months ago

Currently we're checking if the number of connections is greater-or-equal to 1. However the ConnectionCount query that runs doesn't exclude itself from the result set, so it always returns at least one.

The >= 1 check was added here: https://github.com/fly-apps/postgres-flex/pull/200. This PR reverts back to the previous current >1 check.

An alternate way to fix this would be to change the query in the getCurrentConnCount func to use the SUCredentials instead of OperatorCredentials. This would run the query as the flypgadmin user (which is excluded from the query) instead of the Postgres user.