Skip to content

Do not use snapshots on single database instances

Rutger Wessels requested to merge rw-backup-snapshots-single-db into master

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

  1. Modify lib/backup/database.rb line 55: add pp pgsql_args (so we see which command line arguments are passed to pg_dump)
  2. Ensure config/database.yml has main and ci sections for development
  3. 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: one ci_database.sql.gz and one database.sql.gz
  4. Modify config/database.yml by removing ci section in development
  5. 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

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Rutger Wessels

Merge request reports