gitlab-org--gitlab-foss/doc/update/mysql_to_postgresql.md

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

  1. Stop GitLab:

    sudo gitlab-ctl stop
    
  2. Edit /etc/gitlab/gitlab.rb to enable bundled PostgreSQL:

    postgresql['enable'] = true
    
  3. Edit /etc/gitlab/gitlab.rb to use the bundled PostgreSQL. Please check all the settings beginning with db_, such as gitlab_rails['db_adapter'] and alike. You could just comment all of them out so that we'll just use the defaults.

  4. Reconfigure GitLab for the changes to take effect:

    sudo gitlab-ctl reconfigure
    
  5. Start Unicorn and PostgreSQL so that we could prepare the schema:

    sudo gitlab-ctl start unicorn
    sudo gitlab-ctl start posgresql
    
  6. Run the following commands to prepare the schema:

    sudo gitlab-rake db:create db:migrate
    
  7. 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:

  1. Save the following snippet in a commands.load file, and edit with your database username, password and host:

    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'
    
    ;
    
  2. Start the migration:

    sudo -u gitlab-psql pgloader commands.load
    
  3. 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