跳到主要内容

数据库安装

IITLDesk默认支持PostgreSQL数据库,优先版本为LTS12/16。信创需求则选择人大金仓数据库或瀚高数据库,免费可考虑openguassdb(华为高斯)。

Linux PG16安装​

适用 AlmaLinux 9/10(RHEL 系 dnf 包管理器),使用系统 AppStream 仓库自带的 PostgreSQL 16 module,无需额外添加 PGDG 源。

1. 确认 module 并启用​

# 查看可用的 postgresql module 版本
dnf module list postgresql

# 启用 postgresql:16(默认 stream 可能不是 16,需手动指定)
dnf module enable -y postgresql:16

2. 安装服务端与客户端​

dnf install -y postgresql-server

3. 初始化数据库​

AlmaLinux 10 首次安装后数据目录为空,必须执行初始化:

postgresql-setup --initdb

成功后数据目录位于 /var/lib/pgsql/data/。

4. 启动并设置开机自启​

systemctl enable --now postgresql
systemctl status postgresql

5. 设置 postgres 用户密码​

sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '你的密码';"

6. 允许远程连接​

编辑 /var/lib/pgsql/data/postgresql.conf,找到并改为:

listen_addresses = '*'

编辑同目录下 pg_hba.conf,文件末尾添加:

host all all 0.0.0.0/0 scram-sha-256

重启生效:

systemctl restart postgresql

7. 防火墙放行 5432 端口​

firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload

8. 验证​

psql -h 服务器IP -U postgres -d postgres

输入密码后进入 postgres=# 提示符即安装成功。

Windows PG16安装​

1. EnterpriseDB 官方下载站(推荐) https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

  • 选择 PostgreSQL 16.x → Windows x86-64 图形化安装包(.exe)
  • 由 EDB 提供,PostgreSQL 全球官方指定 Windows 发行方
  • 安装器自带:pgAdmin 图形管理工具、Stack Builder(扩展工具)、命令行工具
  • 约 300MB

2. PostgreSQL 官网 https://www.postgresql.org/download/windows/ 页面会跳转指引到上述 EDB 下载页。

3. 免安装 ZIP 版 同一下载页下方有 "Binaries" ZIP 包,适合静默部署或不想用安装向导的场景,解压即用,需手动注册服务。

4. 国内镜像(内网 / 加速)

  • 华为云镜像:https://mirrors.huaweicloud.com/postgresql/
  • 阿里云开源镜像站
  • 内网环境建议在外网下载 .exe 后拷贝到内网安装。

版本选择建议:

  • 生产环境选 16.x 最新小版本(当前 16.10 左右,以官网为准)
  • 64 位系统选 x86-64
  • 安装时默认自带 PostgreSQL 16 数据目录 C:\Program Files\PostgreSQL\16\