Commit c05117d9a25c4f8b2fbec6c520acdcc36f85f659

Authored by Dmitriy Zaporozhets
2 parents f08cb264 6be0188b

Merge branch 'create_pg_indexes' into 'master'

Rebuild Postgres indexes after a MySQL conversion
Showing 1 changed file with 34 additions and 6 deletions   Show diff stats
doc/update/mysql_to_postgresql.md
1 1 # Migrating GitLab from MySQL to Postgres
2 2  
3 3 If you are replacing MySQL with Postgres while keeping GitLab on the same
4   -server all you need to do is to export from MySQL and import into Postgres as
5   -described below. If you are also moving GitLab to another server, or if you are
6   -switching to omnibus-gitlab, you may want to use a GitLab backup file. The
7   -second part of this documents explains the procedure to do this.
  4 +server all you need to do is to export from MySQL, import into Postgres and
  5 +rebuild the indexes as described below. If you are also moving GitLab to
  6 +another server, or if you are switching to omnibus-gitlab, you may want to use
  7 +a GitLab backup file. The second part of this documents explains the procedure
  8 +to do this.
8 9  
9 10 ## Export from MySQL and import into Postgres
10 11  
... ... @@ -15,15 +16,41 @@ sudo service gitlab stop
15 16  
16 17 # Update /home/git/gitlab/config/database.yml
17 18  
18   -git clone https://github.com/lanyrd/mysql-postgresql-converter.git
  19 +git clone https://github.com/gitlabhq/mysql-postgresql-converter.git
19 20 cd mysql-postgresql-converter
20 21 mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root gitlabhq_production
21 22 python db_converter.py databasename.mysql databasename.psql
22 23 psql -f databasename.psql -d gitlabhq_production
23 24  
  25 +# Rebuild indexes (see below)
  26 +
24 27 sudo service gitlab start
25 28 ```
26 29  
  30 +
  31 +## Rebuild indexes
  32 +
  33 +The lanyrd database converter script does not preserve all indexes, so we have
  34 +to recreate them ourselves after migrating from MySQL. It is not necessary to
  35 +shut down GitLab for this process.
  36 +
  37 +```
  38 +# Clone the database converter on your Postgres-backed GitLab server
  39 +cd /tmp
  40 +git clone https://github.com/gitlabhq/mysql-postgresql-converter.git
  41 +
  42 +# Stash changes to db/schema.rb to make sure we can find the right index statements
  43 +cd /home/git/gitlab
  44 +sudo -u git -H git stash
  45 +
  46 +# Generate the `CREATE INDEX CONCURRENTLY` statements based on schema.rb
  47 +cd /tmp/mysql-to-postgresql-converter
  48 +ruby index_create_statements.rb /home/git/gitlab/db/schema.rb > index_create_statements.psql
  49 +
  50 +# Execute the SQL statements against the GitLab database
  51 +sudo -u git psql -f index_create_statements.psql -d gitlabhq_production
  52 +```
  53 +
27 54 ## Converting a GitLab backup file from MySQL to Postgres
28 55  
29 56 GitLab backup files (<timestamp>_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
64 91  
65 92 sudo -u git -H tar rf TIMESTAMP_gitlab_backup.tar db/database.sql
66 93  
67   -# Done! TIMESTAMP_gitlab_backup.tar can now be restored into a Postgres GitLab installation.
  94 +# Done! TIMESTAMP_gitlab_backup.tar can now be restored into a Postgres GitLab
  95 +# installation. Remember to recreate the indexes after the import.
68 96 ```
... ...