PostgreSQL 安装指南(Ubuntu / Docker)

129 字
1 分钟
PostgreSQL 安装指南(Ubuntu / Docker)

一、Ubuntu 二进制安装#

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

修改数据库密码#

Terminal window
# 切换到 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

评论区

Profile Image of the Author
顾拾柒
The world is big, you have to go and see.
公告
欢迎来到我的博客!
分类
标签
站点统计
文章
81
分类
7
标签
158
总字数
83,114
运行时长
0
最后活动
0 天前
站点信息
构建平台
Vercel
博客版本
Firefly v6.12.1
文章许可
CC BY-NC-SA 4.0

文章目录