[分享] 迁移极狐GitLab PostgreSQL数据目录

极狐GitLab 采用 Omnibus 方式安装时默认目录位置如下:

  • /opt/gitlab 主程序文件目录
  • /var/opt/gitlab 数据文件目录
  • /var/log/gitlab 日志文件目录
    在大多情况下,服务器/var目录存放在根目录下,根目录一般不会分配比较大的空间,而 Git 仓库和 PostgreSQL 数据目录作为增长比较快的目录,经常会导致根目录磁盘空间不足。因此需要进行数据目录的迁移。本文本次仅提供 PostgreSQL数据目录的迁移。

具体操作步骤如下:

1.修改极狐gitlab配置文件

$ sudo cat /etc/gitlab/gitlab.rb
......
postgresql['dir'] = "/${new_dir}/postgresql"
postgresql['home'] = "/${new_dir}/postgresql"
postgresql['data_dir'] = "/${new_dir}/postgresql"  # 旧版本中可能存在此参数
gitlab_rails['db_host'] = "/${new_dir}/postgresql"
gitlab_rails['auto_migrate'] = false
......

2.移动数据文件

# 停止gitlab实例
$ sudo gitlab-ctl stop 

# 移动数据库数据文件目录 - data_dir
$ sudo cp -r /var/opt/gitlab/postgresql/data /${new_dir}/postgresql
$ sudo chown -R gitlab-psql.gitlab-psql /${new_dir}/postgresql/data

3.重新配置

# 重新配置
$ sudo gitlab-ctl reconfigure 

# 启动实例
$ sudo gitlab-ctl start

4.开启自动迁移

# 开启auto_migrate
gitlab_rails['auto_migrate'] = true

# 重新配置
$ sudo gitlab-ctl reconfigure 

5.验证迁移

$ ps -ef|grep 'postgresql01'|grep -v grep
gitlab-+  42684   1269  0 14:23 ?        00:00:00 /opt/gitlab/embedded/bin/postgres -D /${new_dir}/postgresql/data

$ netstat -an|grep 5432
unix  2      [ ACC ]     STREAM     LISTENING     205599   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     213842   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     209521   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     214439   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     213280   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     209439   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     207798   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     214965   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     210124   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     214960   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     209638   /${new_dir}/postgresql/.s.PGSQL.5432
unix  3      [ ]         STREAM     CONNECTED     208734   /${new_dir}/postgresql/.s.PGSQL.5432

你好,已经给目录“/data/gitlab/postgresql” chmod 0755 权限了,chown -R gitlab-psql.root,但还是报下面的错误

ls database] (gitlab::database_migrations line 18) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’
---- Begin output of “bash” ----
STDOUT: rake aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket “/data/gitlab/postgresql/.s.PGSQL.5432”?
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/load_balancer.rb:119:in block in read_write' /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/load_balancer.rb:200:in retry_with_backoff’
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/load_balancer.rb:118:in read_write' /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/connection_proxy.rb:119:in write_using_load_balancer’
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/load_balancing/connection_proxy.rb:89:in method_missing' /opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:109:in configure_database’
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:95:in block (3 levels) in <top (required)>' /opt/gitlab/embedded/bin/bundle:23:in load’
/opt/gitlab/embedded/bin/bundle:23:in `’

先确认下数据库目前是正常启动的状态吗?gitlab-ctl status 看下,然后看下 gitlab-ctl tail postgresql 日志是不是有什么错误?

postgresql 是 down 状态
数据库设置 | 极狐GitLab

那你当前需要看下数据库日志,提示的什么报错,看下数据库 down 的原因

没找到啥原因,重新安装了,
感谢