2.7 KiB
last_updated |
---|
2017-10-05 |
Migrating from MySQL to PostgreSQL
Note: This guide assumes you have a working Omnibus GitLab instance with MySQL and want to migrate to bundled PostgreSQL database.
Prerequisites
First, we'll need to enable the bundled PostgreSQL database with up-to-date schema. Next, we'll use pgloader to migrate the data from the old MySQL database to the new PostgreSQL one.
Here's what you'll need to have installed:
- pgloader 3.4.1+
- Omnibus GitLab
- MySQL
Enable bundled PostgreSQL database
-
Stop GitLab:
sudo gitlab-ctl stop
-
Edit
/etc/gitlab/gitlab.rb
to enable bundled PostgreSQL:postgresql['enable'] = true
-
Edit
/etc/gitlab/gitlab.rb
to use the bundled PostgreSQL. Please check all the settings beginning withdb_
, such asgitlab_rails['db_adapter']
and alike. You could just comment all of them out so that we'll just use the defaults. -
Reconfigure GitLab for the changes to take effect:
sudo gitlab-ctl reconfigure
-
Start Unicorn and PostgreSQL so that we could prepare the schema:
sudo gitlab-ctl start unicorn sudo gitlab-ctl start posgresql
-
Run the following commands to prepare the schema:
sudo gitlab-rake db:create db:migrate
-
Stop Unicorn in case it's interfering the next step:
sudo gitlab-ctl stop unicorn
After these steps, you'll have a fresh PostgreSQL database with up-to-date schema.
Migrate data from MySQL to PostgreSQL
Now, you can use pgloader to migrate the data from MySQL to PostgreSQL:
-
Save the following snippet in a
commands.load
file, and edit with your databaseusername
,password
andhost
:LOAD DATABASE FROM mysql://username:password@host/gitlabhq_production INTO postgresql://gitlab-psql@unix://var/opt/gitlab/postgresql:/gitlabhq_production WITH include no drop, truncate, disable triggers, create no tables, create no indexes, preserve index names, no foreign keys, data only ALTER SCHEMA 'gitlabhq_production' RENAME TO 'public' ;
-
Start the migration:
sudo -u gitlab-psql pgloader commands.load
-
Once the migration finishes, start GitLab:
sudo gitlab-ctl start
Now, you can verify that everything worked by visiting GitLab.
Troubleshooting
Experiencing 500 errors after the migration
If you experience 500 errors after the migration, try to clear the cache:
sudo gitlab-rake cache:clear