访问 gitlab postgres omnibus 数据库

Accessing gitlab postgres omnibus database

我正在尝试从其他应用程序访问我的 gitlab omnibus 的 postgres 安装,以便我可以在其中共享数据。如何找到登录信息,例如 user/pass?

应该没有密码。

如果您在安装 GitLab Omnibus 的机器上具有 sudo 访问权限,那么您可以通过以下方式确认:

sudo grep gitlab-psql /etc/shadow

它应该在密码字段中显示“!”,例如:

gitlab-psql:!!:16960::::::

面对类似的目标(访问 GitLab 的数据库以得出一些使用图、随时间推移的问题计数 opened/closed 等),这就是我所做的(假设 sudo 能力):

sudo su -l gitlab-psql
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
cat >> ~/.ssh/authorized_keys << "EOF"
<your ssh public key here>
EOF

chmod 0600 ~/.ssh/authorized_keys

完成此操作后,首先检查您是否可以 ssh 使用正确的密钥 gitlab-psql 到该主机,当然,也可以从远程主机:ssh gitlab-psql@my-gitlab-host,或本地:ssh gitlab-psql@localhost.

之后,您应该可以通过 ssh 从其他应用程序访问数据库。例如,这是一种直接从 Python 笔记本(EC2 中某处的另一台主机上的 运行)查询数据库并使用 Pandas:

的方法
def gitlab_query(query):
    cmdargs = [
        'ssh', 'gitlab-psql@my-gitlab-host',
        f"""/opt/gitlab/embedded/bin/psql -h /var/opt/gitlab/postgresql/ gitlabhq_production -A -F $'\t' -c "{query}" """,
    ]
    proc = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    try:
        outs, errs = proc.communicate(timeout=15)
    except subprocess.TimeoutExpired:
        proc.kill()
        outs, errs = proc.communicate()
    errors = errs.decode('utf-8')
    if errors:
        raise ValueError(errors)
    result = outs.decode('utf-8')
    result = result[:result.rfind('\n', 0, -1)]
    return result


# simple example
# NOTE: as is, this is incomplete, because many issues are closed by other
# actions (e.g. commits or merges) and in those cases, there is no
# closed_at date. See further below for better queries. (not included in
# this SO answer as this is getting beyond the scope of the question).

q = """
select
  b.name, a.title, a.created_at, a.closed_at
from issues a inner join projects b on (a.project_id = b.id)
where closed_at > '2018-01-09' and b.name='myproject'
order by 1,4 limit 10
"""

pd.read_csv(io.StringIO(gitlab_query(q)), sep='\t', parse_dates=['created_at', 'closed_at'])

如果您已经按照描述安装了 gitlab-praefect 节点 here 并且您正在使用 AWS EC2 和 AWS postgres 并且想检查这两者是否可以通信。

/opt/gitlab/embedded/bin/psql -U YourExistingUsername -d template1 -h RDS-POSTGRES-ENDPOINT