From dca537ab2902aa9936e4c29574ad540793028a76 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 19 May 2014 17:49:29 +0200 Subject: [PATCH 1/2] Use the gitlabhq fork of the MySQL converter --- doc/update/mysql_to_postgresql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/update/mysql_to_postgresql.md b/doc/update/mysql_to_postgresql.md index 5b9209d7df4..4d591d4d4cf 100644 --- a/doc/update/mysql_to_postgresql.md +++ b/doc/update/mysql_to_postgresql.md @@ -15,7 +15,7 @@ sudo service gitlab stop # Update /home/git/gitlab/config/database.yml -git clone https://github.com/lanyrd/mysql-postgresql-converter.git +git clone https://github.com/gitlabhq/mysql-postgresql-converter.git cd mysql-postgresql-converter mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root gitlabhq_production python db_converter.py databasename.mysql databasename.psql From 6be0188b5c289b1cff7f15fcfdff0ea9b8eec1ff Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 19 May 2014 17:51:58 +0200 Subject: [PATCH 2/2] Rebuild indexes after a MySQL conversion --- doc/update/mysql_to_postgresql.md | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/doc/update/mysql_to_postgresql.md b/doc/update/mysql_to_postgresql.md index 4d591d4d4cf..acd1e33f599 100644 --- a/doc/update/mysql_to_postgresql.md +++ b/doc/update/mysql_to_postgresql.md @@ -1,10 +1,11 @@ # Migrating GitLab from MySQL to Postgres If you are replacing MySQL with Postgres while keeping GitLab on the same -server all you need to do is to export from MySQL and import into Postgres as -described below. If you are also moving GitLab to another server, or if you are -switching to omnibus-gitlab, you may want to use a GitLab backup file. The -second part of this documents explains the procedure to do this. +server all you need to do is to export from MySQL, import into Postgres and +rebuild the indexes as described below. If you are also moving GitLab to +another server, or if you are switching to omnibus-gitlab, you may want to use +a GitLab backup file. The second part of this documents explains the procedure +to do this. ## Export from MySQL and import into Postgres @@ -21,9 +22,35 @@ mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.m python db_converter.py databasename.mysql databasename.psql psql -f databasename.psql -d gitlabhq_production +# Rebuild indexes (see below) + sudo service gitlab start ``` + +## Rebuild indexes + +The lanyrd database converter script does not preserve all indexes, so we have +to recreate them ourselves after migrating from MySQL. It is not necessary to +shut down GitLab for this process. + +``` +# Clone the database converter on your Postgres-backed GitLab server +cd /tmp +git clone https://github.com/gitlabhq/mysql-postgresql-converter.git + +# Stash changes to db/schema.rb to make sure we can find the right index statements +cd /home/git/gitlab +sudo -u git -H git stash + +# Generate the `CREATE INDEX CONCURRENTLY` statements based on schema.rb +cd /tmp/mysql-to-postgresql-converter +ruby index_create_statements.rb /home/git/gitlab/db/schema.rb > index_create_statements.psql + +# Execute the SQL statements against the GitLab database +sudo -u git psql -f index_create_statements.psql -d gitlabhq_production +``` + ## Converting a GitLab backup file from MySQL to Postgres GitLab backup files (_gitlab_backup.tar) contain a SQL dump. Using @@ -64,5 +91,6 @@ sudo -u git -H python mysql-postgresql-converter/db_converter.py gitlabhq_produc sudo -u git -H tar rf TIMESTAMP_gitlab_backup.tar db/database.sql -# Done! TIMESTAMP_gitlab_backup.tar can now be restored into a Postgres GitLab installation. +# Done! TIMESTAMP_gitlab_backup.tar can now be restored into a Postgres GitLab +# installation. Remember to recreate the indexes after the import. ```