Debian 12 安装 PostgreSQL 数据库「可装最新版」
• 2024-04-22 • 文章类别: 操作系统 & 服务器 数据库 • 阅读量:876
PostgreSQL 是一款非常优秀的关系数据库。PostgreSQL 支持在多种系统上运行。本文将介绍如何在 Debian 12 系统中安装 PostgreSQL 及其最新版。
在 Debian 12 中安装 PostgreSQL 有两种方式:
-
使用 Debian 12 的 APT 软件源
-
使用 PostgreSQL 的 APT 软件源
两种方式的区别:
使用 Debian 12 的 APT 软件源安装 PostgreSQL 非常简单;使用 PostgreSQL 的 APT 软件源可以安装最新版的 PostgreSQL。
使用 Debian 12 APT 软件源安装 PostgreSQL
PostgreSQL 包含在了 Debian 12 的 apt 软件源中,只是它不是最新版的,如果你对版本没有要求,可以使用该种方式安装 PostgreSQL:
sudo apt install postgresql postgresql-client
注:安装 PostgreSQL 后,会自动初始化数据库,并启动运行,同时会配置开机自启动。
使用 PostgreSQL APT 软件源安装 PostgreSQL
PostgreSQL 也提供了自己的 apt 软件源,把它添加到 Debian 12 系统中可以使用它安装最新版的 PostgreSQL。
添加 APT 软件源
添加 PostgreSQL 的 APT 软件源有两种方式:
- 自动化添加
- 推荐:手动添加,因为可以配置国内 PostgreSQL 镜像
自动化添加 PostgreSQL apt 软件源
1、安装软件包
sudo apt install -y postgresql-common
2、运行sh,自动配置软件源:
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
手动添加 PostgreSQL apt 软件源
1、安装依赖软件包:
sudo apt install curl ca-certificates
2、创建存放密钥的文件夹
sudo install -d /usr/share/postgresql-common/pgdg
3、安装签名密钥
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
4、创建软件源文件
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://mirrors.tencent.com/postgresql/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
注:软件源使用国内的腾讯软件源镜像,因为官方的软件源下载速度非常慢。
5、更新软件源
sudo apt update
安装最新版 PostgreSQL
安装最新版的 PostgreSQL(也可选择其他版本):
sudo apt install postgresql postgresql-client
注:安装 PostgreSQL 后,会自动初始化数据库,并启动运行,同时会配置开机自启动。
测试 PostgreSQL 是否安装成功
PostgreSQL安装后,可使用如下命令查看 PostgreSQL 是否正确安装并运行:
ps -ef | grep postgres
如果看到类似如下的输出说明安装成功:
postgres 5054 1 0 04:19 ? 00:00:00 /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -c config_file=/etc/postgresql/16/main/postgresql.conf
postgres 5055 5054 0 04:19 ? 00:00:00 postgres: 16/main: checkpointer
postgres 5056 5054 0 04:19 ? 00:00:00 postgres: 16/main: background writer
postgres 5058 5054 0 04:19 ? 00:00:00 postgres: 16/main: walwriter
postgres 5059 5054 0 04:19 ? 00:00:00 postgres: 16/main: autovacuum launcher
postgres 5060 5054 0 04:19 ? 00:00:00 postgres: 16/main: logical replication launcher
anxin 5113 1522 0 04:25 pts/0 00:00:00 grep postgres
结语
本文介绍了如何在 Debian 12 系统中安装 PostgreSQL。在 Debian 12 中安装 PostgreSQL 有两种方式:使用 Debian 12 的 APT 软件源安装 PostgreSQL;使用 PostgreSQL 的 APT 软件源安装 PostgreSQL。
0 评论