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
相关推荐
不甘平凡--liang19 分钟前
Linux Nginx安装部署、注册服务
linux·运维·服务器
小妖6661 小时前
linux (centos) 的 nodejs 安装全局包后使用命令无效
linux·运维·centos
不穿格子衬衫2 小时前
感受命令行界面的魅力——Linux环境下基础开发工具的使用
linux·运维·centos
誓约酱2 小时前
linux 下消息队列
linux·运维·服务器·c语言·c++
獨枭2 小时前
Ubuntu 优化 Vim 指南
linux·ubuntu·vim
阿常呓语2 小时前
Jenkins服务搭建
运维·jenkins
一匹电信狗2 小时前
【Linux我做主】基础命令完全指南下篇
linux·运维·服务器·c++·开源·centos·unix
wanhengidc3 小时前
海外服务器的网络带宽该如何进行选择?
运维·服务器
嵌入式-老费4 小时前
Linux上位机开发实战(qt编译之谜)
linux·运维·服务器
翱翔-蓝天4 小时前
CentOS 上扩展 Swap 分区的大小
linux·运维·centos