使用 DBeaver 访问 Discourse 数据库

内置的数据浏览器适用于快速查询,但如果您想使用像 DBeaver 或 TablePlus 这样的真实 GUI,由于 Discourse 的 Postgres 被锁定在 Docker 桥接网络内,您需要绕一些弯路。

以下是如何将其安全地通过私有网络(如 Tailscale)暴露出来,从而避免将数据库直接开放给互联网的方法。

1. 映射自定义端口

Discourse 通常会占用标准端口,因此我使用了 5434。编辑您的 containers/app.yml

YAML

expose:
  - "80:80"
  - "443:443"
  - "5434:5432" # 主机 5434 -> 容器 5432

然后重新构建:./launcher rebuild app

2. 防火墙

不要将此端口开放给公众。 如果您使用 Tailscale 或其他隧道,请将访问权限限制为仅允许该接口:

Bash

sudo ufw allow in on tailscale0 to any port 5434 proto tcp

3. 修复认证(麻烦的部分)

Discourse 默认使用 peer 认证,这会阻止外部密码登录。因此,您需要告诉 Postgres 允许使用 scram-sha-256

进入容器(./launcher enter app):

Bash

echo "host all all 0.0.0.0/0 scram-sha-256" >> /shared/postgres_data/pg_hba.conf

sudo -u postgres psql -c "SELECT pg_reload_conf();"

4. 设置密码

discourse 用户默认没有密码。请设置一个密码,以便 DBeaver 等应用程序能够登录。

Bash

sudo -u postgres psql -c "ALTER USER discourse WITH PASSWORD 'your_password_here';"

5. 连接详情

  • 主机: 您的 IP

  • 端口: 5434

  • 数据库: discourse

  • 用户: discourse