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

114 lines
2.7 KiB
Markdown
Raw Normal View History

2017-10-06 09:20:52 +00:00
---
last_updated: 2017-10-05
---
2017-10-06 09:20:52 +00:00
# Migrating from MySQL to PostgreSQL
2017-10-06 09:20:52 +00:00
> **Note:** This guide assumes you have a working Omnibus GitLab instance with
> MySQL and want to migrate to bundled PostgreSQL database.
2014-03-17 13:55:56 +00:00
2017-10-06 09:20:52 +00:00
## Prerequisites
2017-10-06 09:20:52 +00:00
First, we'll need to enable the bundled PostgreSQL database with up-to-date
schema. Next, we'll use [pgloader](http://pgloader.io) to migrate the data
from the old MySQL database to the new PostgreSQL one.
2017-10-06 09:20:52 +00:00
Here's what you'll need to have installed:
2014-05-08 11:18:22 +00:00
2017-10-06 09:20:52 +00:00
- pgloader 3.4.1+
- Omnibus GitLab
- MySQL
2014-05-08 11:18:22 +00:00
2017-10-06 09:20:52 +00:00
## Enable bundled PostgreSQL database
2017-10-06 09:20:52 +00:00
1. Stop GitLab:
2017-10-06 09:20:52 +00:00
``` bash
sudo gitlab-ctl stop
```
2017-10-06 09:20:52 +00:00
1. Edit `/etc/gitlab/gitlab.rb` to enable bundled PostgreSQL:
2017-10-06 09:20:52 +00:00
```
postgresql['enable'] = true
```
2017-10-06 09:20:52 +00:00
1. 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.
2017-10-06 09:20:52 +00:00
1. [Reconfigure GitLab] for the changes to take effect:
``` bash
sudo gitlab-ctl reconfigure
```
1. Start Unicorn and PostgreSQL so that we could prepare the schema:
``` bash
sudo gitlab-ctl start unicorn
sudo gitlab-ctl start posgresql
```
1. Run the following commands to prepare the schema:
``` bash
sudo gitlab-rake db:create db:migrate
```
1. Stop Unicorn in case it's interfering the next step:
2017-10-06 09:20:52 +00:00
``` bash
sudo gitlab-ctl stop unicorn
```
2017-10-06 09:20:52 +00:00
After these steps, you'll have a fresh PostgreSQL database with up-to-date schema.
2017-10-06 09:20:52 +00:00
## Migrate data from MySQL to PostgreSQL
2017-10-06 09:20:52 +00:00
Now, you can use pgloader to migrate the data from MySQL to PostgreSQL:
2017-10-06 09:20:52 +00:00
1. Save the following snippet in a `commands.load` file, and edit with your
database `username`, `password` and `host`:
2017-10-06 09:20:52 +00:00
```
LOAD DATABASE
FROM mysql://username:password@host/gitlabhq_production
INTO postgresql://gitlab-psql@unix://var/opt/gitlab/postgresql:/gitlabhq_production
2017-10-06 09:20:52 +00:00
WITH include no drop, truncate, disable triggers, create no tables,
create no indexes, preserve index names, no foreign keys,
data only
2015-06-23 13:45:24 +00:00
2017-10-06 09:20:52 +00:00
ALTER SCHEMA 'gitlabhq_production' RENAME TO 'public'
2017-10-06 09:20:52 +00:00
;
```
2017-10-06 09:20:52 +00:00
1. Start the migration:
2017-10-06 09:20:52 +00:00
``` bash
sudo -u gitlab-psql pgloader commands.load
```
1. Once the migration finishes, start GitLab:
``` bash
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:
``` bash
sudo gitlab-rake cache:clear
```
2017-10-06 09:20:52 +00:00
[reconfigure GitLab]: ../administration/restart_gitlab.md#omnibus-gitlab-reconfigure