Skip to content

Commit 6be0188

Browse files
committed
Rebuild indexes after a MySQL conversion
1 parent dca537a commit 6be0188

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

doc/update/mysql_to_postgresql.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Migrating GitLab from MySQL to Postgres
22

33
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.
89

910
## Export from MySQL and import into Postgres
1011

@@ -21,9 +22,35 @@ mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.m
2122
python db_converter.py databasename.mysql databasename.psql
2223
psql -f databasename.psql -d gitlabhq_production
2324
25+
# Rebuild indexes (see below)
26+
2427
sudo service gitlab start
2528
```
2629

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+
2754
## Converting a GitLab backup file from MySQL to Postgres
2855

2956
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
6491
6592
sudo -u git -H tar rf TIMESTAMP_gitlab_backup.tar db/database.sql
6693
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.
6896
```

0 commit comments

Comments
 (0)