Commit 6be0188b5c289b1cff7f15fcfdff0ea9b8eec1ff
1 parent
dca537ab
Exists in
spb-stable
and in
2 other branches
Rebuild indexes after a MySQL conversion
Showing
1 changed file
with
33 additions
and
5 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 | |
... | ... | @@ -21,9 +22,35 @@ mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.m |
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 | ``` | ... | ... |