Do not use snapshots on single database instances
What does this MR do and why?
This MR will stop using PostgreSQL snapshots when the backup is run on single database instances.
We use PostgreSQL Snapshots when running the backup script. This gives us the best consistency for multiple database setups (with main
and ci
databases).
For single database setup, this snapshot does not make sense and we can skip it.
It addresses issue #404737 (closed). This issue was reported by a customer who was using PgPool as middleware. The snapshot got created against another PostgreSQL instance than the one that was used for the backup. To avoid this, we can simply skip taking snapshots for single database setups.
Taking backups without connecting directly to PostgreSQL is against our recommendation. A follow-up issue that improves backups for self-managed decomposed database setup is here: #405159 (closed)
Implementation
If we detect that we are running in single database mode, we store a nil
value in the list of snapshots. If a database has a snapshot ID of nil
, we will not use the --snapshot_id
option of pg_dump
How to set up and validate locally
- Modify
lib/backup/database.rb
line 55: addpp pgsql_args
(so we see which command line arguments are passed topg_dump
) - Ensure
config/database.yml
hasmain
andci
sections fordevelopment
- Run
GITLAB_BACKUP_PGHOST=/Users/rutger/gitlab-development-kit/postgresql SKIP=tar,repositories,uploads,builds,artifacts,pages,lfs,terraform_state,registry,packages bundle exec rake gitlab:backup:create
- Output should show two
pg_dump
arguments like these["--clean", "--if-exists", "--snapshot=00000009-00001DFB-1"]
(snapshot id will be different) - Two database backup files should be created in
tmp/backups/db
: oneci_database.sql.gz
and onedatabase.sql.gz
- Output should show two
- Modify
config/database.yml
by removingci
section indevelopment
- Run
GITLAB_BACKUP_PGHOST=/Users/rutger/gitlab-development-kit/postgresql SKIP=tar,repositories,uploads,builds,artifacts,pages,lfs,terraform_state,registry,packages bundle exec rake gitlab:backup:create
- Output should now only include
["--clean", "--if-exists"]
arguments - Only one backup file should be created in
tmp/backups/db
- Output should now only include
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.