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
相关推荐
冰橙子id2 小时前
linux-远程访问管理(sshd,scp,sftp)
linux·网络·ssh
光电的一只菜鸡3 小时前
ubuntu之坑(十五)——设备树
linux·数据库·ubuntu
saynaihe5 小时前
ubuntu 22.04 anaconda comfyui安装
linux·运维·服务器·ubuntu
鸠摩智首席音效师5 小时前
如何在 Ubuntu 上安装 Microsoft Edge 浏览器?
ubuntu·microsoft·edge
企鹅与蟒蛇5 小时前
Ubuntu-25.04 Wayland桌面环境安装Anaconda3之后无法启动anaconda-navigator问题解决
linux·运维·python·ubuntu·anaconda
小蜜蜂爱编程5 小时前
ubuntu透网方案
运维·服务器·ubuntu
程序设计实验室5 小时前
小心误关了NAS服务器!修改Linux的电源键功能
linux·nas
AI视觉网奇6 小时前
git 访问 github
运维·开发语言·docker
头发那是一根不剩了6 小时前
nginx:SSL_CTX_use_PrivateKey failed
运维·服务器
七夜zippoe6 小时前
破解 VMware 迁移难题:跨平台迁移常见问题及自动化解决方案
运维·自动化·vmware