在ubuntu24.04中安装postgres-17记录

概要

提示:这里可以添加技术概要

例如:

关于ubuntu24.04中安装postgres的记录文章。

登陆postgres官网,下载页面

提示:这里可以添加技术整体架构

下载网址:
https://www.postgresql.org/download/
在页面中,点击linux -> ubuntu 进入对应的下载页
在这里插入图片描述

复制配置命令

不要直接apt install postgresql 因为源里不一定是最新版本
不要直接使用这个命令
选择此处代码手动配置仓库

↓ 导入仓库的 signing key

# Import the repository signing key:
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

↓创建配置文件

# Create the repository configuration file:
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'

↓更新包列表

# Update the package lists:
sudo apt update

↓ 安装指定版本 postgresql-17

# Install the latest version of PostgreSQL:
# If you want a specific version, use 'postgresql-16' or similar instead of 'postgresql'
sudo apt -y install postgresql-17

查看状态配置开机启动

查看postgresql状态

sudo systemctl status postgresql

正常应该显示如下内容

hongbin@hongbin-VirtualBox:~$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited) since Sun 2025-04-06 13:08:30 CST; 39min ago
   Main PID: 9464 (code=exited, status=0/SUCCESS)
        CPU: 4ms

4月 06 13:08:30 hongbin-VirtualBox systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
4月 06 13:08:30 hongbin-VirtualBox systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.

如果未启动,则输入

# 如果未运行,启动服务:
sudo systemctl start postgresql

启用 PostgreSQL 服务开机自启

sudo systemctl enable postgresql

验证是否生效

sudo systemctl is-enabled postgresql

尝试登陆postgresql

sudo -u postgres psql

登陆后显示如下:

hongbin@hongbin-VirtualBox:~$ sudo -u postgres psql
psql (17.4 (Ubuntu 17.4-1.pgdg24.04+2))
输入 "help" 来获取帮助信息.

postgres=#

输入\q 退出

技术细节

手动配置下载源,然后指定下载版本为postgresql-17

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值