概要
提示:这里可以添加技术概要
例如:
关于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