Moving GitLab databases to a different PostgreSQL instance
- Tier: Free, Premium, Ultimate
- Offering: GitLab Self-Managed
Sometimes it is necessary to move your databases from one PostgreSQL instance to another. For example, if you are using AWS Aurora and are preparing to enable Database Load Balancing, you need to move your databases to RDS for PostgreSQL.
To move databases from one instance to another:
Gather the source and destination PostgreSQL endpoint information:
SRC_PGHOST=<source postgresql host> SRC_PGUSER=<source postgresql user> DST_PGHOST=<destination postgresql host> DST_PGUSER=<destination postgresql user>
Stop GitLab:
sudo gitlab-ctl stop
Dump the databases from the source:
/opt/gitlab/embedded/bin/pg_dump -h $SRC_PGHOST -U $SRC_PGUSER -c -C -f gitlabhq_production.sql gitlabhq_production /opt/gitlab/embedded/bin/pg_dump -h $SRC_PGHOST -U $SRC_PGUSER -c -C -f praefect_production.sql praefect_production
In rare occasions, you might notice database performance issues after you perform a
pg_dump
and restore. This can happen becausepg_dump
does not contain the statistics used by the optimizer to make query planning decisions. If performance degrades after a restore, fix the problem by finding the problematic query, then running ANALYZE on the tables used by the query.Restore the databases to the destination (this overwrites any existing databases with the same names):
/opt/gitlab/embedded/bin/psql -h $DST_PGHOST -U $DST_PGUSER -f praefect_production.sql postgres /opt/gitlab/embedded/bin/psql -h $DST_PGHOST -U $DST_PGUSER -f gitlabhq_production.sql postgres
Optional. If you migrate from a database that doesn’t use PgBouncer to a database that does, you must manually add a
pg_shadow_lookup
function to the application database (usuallygitlabhq_production
).Configure the GitLab application servers with the appropriate connection details for your destination PostgreSQL instance in your
/etc/gitlab/gitlab.rb
file:gitlab_rails['db_host'] = '<destination postgresql host>'
For more information on GitLab multi-node setups, refer to the reference architectures.
Reconfigure for the changes to take effect:
sudo gitlab-ctl reconfigure
Restart GitLab:
sudo gitlab-ctl start
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support