Decomposition Migrate does not show error of pg_dump doesn't match PostgreSQL Version
As part of our efforts to bring decomposed databases to self-managed customers, which is currently a feature in BETA (see
https://docs.gitlab.com/ee/administration/postgresql/multiple_databases.html). We have a script that migrates the main
database to ci
. This script can also be called in several ways:
- OmniBus: see here https://docs.gitlab.com/ee/administration/postgresql/multiple_databases.html#migrate-existing-installations-using-a-script
- Rake task (for example on Helm Charts Toolbox Pod): https://docs.gitlab.com/charts/advanced/multiple-databases/
The migration script, which can be called via the rake task gitlab-rake gitlab:db:decomposition:migrate
calls pg_dump
and pg_restore
to copy the database. But if the database server has a higher version than pg_dump
, the migration script says "Database migration finished!"
, even though the backup never happened.
CC: @rutgerwessels
Proposal
We have a few 'pre-flight' checks in the migration script. We can add a new one:
- ensure that
psql
,pg_dump
andpg_restore
are all using the same version (run them with--version
flag) - ensure that both databases are using the very same PostgreSQL version by running
SELECT version();
and inspect the output
If the versions do no match, fail with a proper error message.
References
- https://docs.gitlab.com/ee/administration/postgresql/multiple_databases.html#migrate-existing-installations-using-a-script
- https://docs.gitlab.com/charts/advanced/multiple-databases/
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/tasks/gitlab/db/decomposition/migrate.rake#L10
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/database/decomposition/migrate.rb