Provide a way to bypass PgBouncer for db maintenance rake tasks
In previous issue, Collation Checker should spot run duplicates ch... (#558274 - closed), we put a threshold of 1 GB to run the duplicate SPOT checks for indexes, because customers may be using PgBouncer and in such case disable statement timeout doesn't work.
In this issue, we want to provide a way for customer to bypass the PgBouncer, similar to database backup tasks.
The idea basically is to reuse the Backup::DatabaseConnection and the Backup::DatabaseConfiguration such that Customer can override the database config to use direct Postgres username, password, host and such.
We will add the feature to be used only via db maintenance tasks. Something like:
# Bypass pgbouncer using direct connection
GITLAB_BACKUP_PGUSER=gitlab_direct \
GITLAB_BACKUP_PGHOST=postgres-primary.internal \
GITLAB_BACKUP_PGPORT=5432 \
bundle exec rake gitlab:db:collation_checker
This feature will reusable for other database maintenance tasks that may face similar pgbouncer limitations, such as: - gitlab:db:repair_index
Implementation Approach
- Reuse existing
Backup::DatabaseConnectionandBackup::DatabaseConfigurationclasses - Modify affected rake tasks to detect backup ENV variables and use direct connections when present
- Ensure graceful fallback to regular connections when ENV variables are not set
Acceptance Criteria
-
Modify gitlab:db:collation_checkertask to support backup ENV variables -
Modify Gitlab::Database::CollationCheckerto accept optionalMAX_TABLE_SIZEparameter -
Update documentation to explain the bypass option