robue-a7119895
robue-a7119895

Reputation: 816

How to configure gitlab to use existing postgres server

When installing Gitlab by default Nginx and Postgres .. among other things are installed regardless of whether you have them already or not. So since I have these two already, I am trying to configure gitlab to use them, I have done this for Nginx, Using:

$ vi /etc/gitlab/gitlab.rb:

# Disable GitLab's nginx completely
nginx['enable'] = false

# Set external web user which is 'nginx' on CentOS 7
web_server['external_users'] = ['nginx']

but I need to know how to do the same postgres.

Upvotes: 5

Views: 13784

Answers (2)

Pierre
Pierre

Reputation: 2742

According to this doc, put this in /etc/gitlab/gitlab.rb :

# Disable the built-in Postgres
postgresql['enable'] = false

# Fill in the connection details for database.yml
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_host'] = '127.0.0.1'
gitlab_rails['db_port'] = 5432
gitlab_rails['db_username'] = 'USERNAME'
gitlab_rails['db_password'] = 'PASSWORD'

And run this command to apply this values : sudo gitlab-ctl reconfigure. Also you need to seed your database if you choose an external one. This command will do it with omnibus-gitlab: sudo gitlab-rake gitlab:setup

Upvotes: 12

bviktor
bviktor

Reputation: 1526

Pierre's solution is fine for new installs, but if you already have data in the DB, you need to migrate instead. The cleanest, most fail-safe way is to create a backup, which contains the DB too:

gitlab-rake gitlab:backup:create

The backup file will be located at /var/opt/gitlab/backups.

Alternatively, you can try:

sudo -u gitlab-psql /opt/gitlab/embedded/bin/pg_dumpall --username=gitlab-psql --host=/var/opt/gitlab/postgresql

Then you can import the DB into the existing Postgres instance with:

psql -f /tmp/database.sql

Then you need to reconfigure and restart too:

gitlab-ctl start && gitlab-ctl reconfigure && gitlab-ctl restart

It starts with start because you need to make sure GitLab is running. That's because, however weird that sounds, reconfigure fails if GitLab is stopped:

Errno::ENOENT: No such file or directory - connect(2) for /var/opt/gitlab/redis/redis.socket

Which is kinda counter-intuitive, since traditionally you make changes to the config while the instance is stopped.


But either with migrations or clean installs, the problem comes with the first GitLab upgrade:

gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... pg_dump: server version: 10.4; pg_dump version: 9.6.8
pg_dump: aborting because of server version mismatch
Backup failed
[FAILED]

As it instructs you, you gotta:

sudo touch /etc/gitlab/skip-auto-migrations

So now the package will update successfully, but GitLab still won't work anyway, you gotta again:

gitlab-ctl reconfigure

To do this automatically:

yum install yum-plugin-post-transaction-actions
echo 'gitlab-ce:any:/bin/gitlab-ctl reconfigure' > /etc/yum/post-actions/gitlab-ce.action

For all the nitty-gritty details, please see:

Upvotes: 2

Related Questions