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
相关推荐
牛奶咖啡133 小时前
shell脚本编程(三)
linux·shell脚本编程·环境变量的设置与取消·位置参数变量与内部参数变量·返回与退出状态·让变量获取键盘输入内容·使用decalre声明变量
记得开心一点嘛4 小时前
Elasticsearch
运维·jenkins
2401_890443024 小时前
Linux进程间通信
linux·服务器
Xの哲學4 小时前
Linux 实时调度机制深度解析
linux·服务器·网络·算法·边缘计算
张太行_4 小时前
Linux信号处理函数中断流程分析
linux
晚风吹人醒.4 小时前
iptables防火墙规则(一):iptables语法结构,netfilter功能详解及案例演示
linux·服务器·网络·iptables·防火墙··netfilter
学好statistics和DS4 小时前
两个子进程都sleep, `waitpid` 系统调用
linux·服务器·数据库
シ風箏4 小时前
AutoGen【部署 02】Linux环境安装部署AutoGenStudio并调用本地 qwen2.5:0.5b 大模型举例
linux·autogen·本地大模型·autogenstudio
xingzhemengyou14 小时前
LINUX 通过/proc/interrupts了解系统硬件中断的使用情况
linux·arm开发
Web极客码4 小时前
释放WordPress磁盘空间并减少Inode使用量
服务器·数据库·ubuntu