42 字
1 分钟
PostgreSQL 安装指南(Ubuntu / Docker)
2026-01-24

一、Ubuntu 二进制安装#

# 安装 PostgreSQL 14
apt install -y postgresql-14
# 查看服务状态
systemctl status postgresql

修改数据库密码#

# 切换到 postgres 用户并登录
su - postgres
psql
# 或直接以 root 身份登录
psql -U postgres
-- 修改密码
ALTER USER postgres WITH PASSWORD 'your-password';

二、Docker Compose 部署#

适合测试环境,可在一台主机运行多个 PostgreSQL 实例:

docker-compose.yml
services:
pgsql:
image: postgres:14
container_name: postgres
restart: always
command: >
postgres
-c config_file=/etc/postgresql/postgresql.conf
-c hba_file=/etc/postgresql/pg_hba.conf
environment:
POSTGRES_PASSWORD: Passwd@2026
TZ: Asia/Shanghai
ports:
- "5432:5432"
volumes:
- /opt/pgsql/data:/var/lib/postgresql/data
- /opt/pgsql/config/postgresql.conf:/etc/postgresql/postgresql.conf:ro
- /opt/pgsql/config/pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
networks:
- app-net
networks:
app-net:
external: true
分享

如果这篇文章对你有帮助,欢迎分享给更多人!

PostgreSQL 安装指南(Ubuntu / Docker)
https://blog.olinl.com/posts/postgresql-install/
作者
顾拾柒
发布于
2026-01-24
许可协议
CC BY-NC-SA 4.0

目录