# 一、概要 默认情况下GitLab只允许本地用户登录后台PostgreSQL。 即,/var/opt/gitlab/postgresql/data/pg_hba.conf内容如下: ```conf local all all peer map=gitlab ``` 为了不影响原有用户,新增一个用于外部直接访问后台数据库的新用户。 # 二、配置方法 ## 创建用户 创建一个使用密码登录的用户。 ```sql # su - gitlab-psql $ psql -h /var/opt/gitlab/postgresql -d gitlabhq_production gitlabhq_production=# create user app_viewer; gitlabhq_production=# alter user app_viewer password 'xxx'; ``` ## 修改pg_hba.conf 新增以下行: ```conf host all app_viewer 127.0.0.1/32 md5 host all app_viewer ::1/128 md5 ``` ## 修改postgresql.conf ```conf $ vim /var/opt/gitlab/postgresql/data/postgresql.conf listen_addresses = '*' port = 5432 ``` ## 修改gitlab.rb ```conf # vim /etc/gitlab/gitlab.rb postgresql['listen_address'] = '*' postgresql['port'] = 5432 ``` ## 重启PostgreSQL ```bash # gitlab-ctl restart postgresql ``` # 三、参考 - [将gitlab中的postgresql数据库开通远程访问](https://www.cnblogs.com/andy9468/p/10609682.html)