Ubuntu安装PgSQL17

参考官网教程,Ubuntu24 apt在线安装Postgres 17

1. 要手动配置 Apt 存储库

shell 复制代码
# 导入存储库签名密钥:
sudo apt install curl ca-certificates 
sudo install -d /usr/share/postgresql-common/pgdg 
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc 

# 创建存储库配置文件:
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' 

# 更新软件包列表:
sudo apt update 

# 安装最新版本的 PostgreSQL:
# 如果需要特定版本,请使用"postgresql-16"或类似版本'postgresql' 
sudo apt -y install postgresql-17

2. 启动服务

shell 复制代码
sudo systemctl start postgresql
sudo systemctl enable postgresql

3. 配置 PostgreSQL 17

shell 复制代码
编辑 postgresql.conf 通过将 listen_addresses 更改为 * 来允许远程连接
文件:/etc/postgresql/17/main/postgresql.conf
设置:listen_addresses = '*'

通过编辑 pg_hba.conf 将 PostgreSQL 配置为使用 md5 密码验证,如果您希望通过PGADMIN进行远程连接
文件:/etc/postgresql/17/main/pg_hba.conf
设置:host all all 0.0.0.0/0 md5

重启服务
sudo systemctl restart postgresql

4. 连接到 PostgreSQL

shell 复制代码
# 以 postgres 用户身份连接
sudo -u postgres psql

# 为 postgres 用户设置密码
ALTER USER postgres PASSWORD 'YOUR_PASSWORD';

参考链接:

  1. https://www.postgresql.org/download/linux/ubuntu/
  2. https://dev.to/johndotowl/postgresql-17-installation-on-ubuntu-2404-5bfi
相关推荐
dyxal几秒前
Linux Crontab 防重复执行利器:flock 文件锁实战详解(脱敏版)
linux·运维·服务器
niuTaylor2 分钟前
RK3568 Linux SDK 详解:SDK 是什么、板级差异与完整构建流程
linux·运维·服务器
拾贰_C10 分钟前
【Ubuntu | port】Linux进程端口号冲突问题解决
linux·运维·ubuntu
wdfk_prog21 分钟前
Wi-Fi Direct 教程 07:第一次 P2P Scan 如何真正发出——WPS/P2P IE、radio work 与 driver request
运维·服务器·ubuntu·wifi-direct
机核研创社23 分钟前
服装自动化观察:接橡筋机的超声波熔切与冷刀,差别到底在哪
运维·自动化
欣欣之王来了34 分钟前
AI合规专项:AI自动化决策的合规管控要点
运维·人工智能·自动化
guo_wen_qiang40 分钟前
docker安装常见软件集合
运维·docker·容器
0+11142 分钟前
Linux --读者写者问题、读写锁与自旋锁
linux
谷哥的小弟1 小时前
CentOS寿终正寝
linux·运维·centos
醇氧1 小时前
nohup 后台启动 uvicorn(仅测试 / 临时运行)
linux·运维·网络·python·python3.11