第 4 章 使用 PostgreSQL
PostgreSQL 服务器是一个基于 SQL 语言的开源、健壮且高度可扩展的数据库服务器。PostgreSQL 服务器提供了一个对象关系型数据库系统,其可以管理大量的数据集和大量的并发用户。因此,PostgreSQL 服务器可用在集群中,来管理大量的数据。
PostgreSQL 服务器包含确保数据完整性、构建容错环境和应用程序的功能。使用 PostgreSQL 服务器,您可以使用您自己的数据类型、自定义函数或来自不同编程语言的代码来扩展数据库,而无需重新编译数据库。
了解如何在 RHEL 系统上安装和配置 PostgreSQL,如何备份 PostgreSQL 数据,以及如何从早期的 PostgreSQL 版本迁移。
4.1. 安装 PostgreSQL 复制链接链接已复制到粘贴板!
RHEL 9 提供 PostgreSQL 13 作为此应用程序流的初始版本,您可以轻松地作为 RPM 软件包安装。
在 RHEL 9 的次版本中,其他 PostgreSQL 版本作为模块提供,具有较短的生命周期:
-
RHEL 9.2 引入了 PostgreSQL 15 作为
postgresql:15模块流 -
RHEL 9.4 引入了 PostgreSQL 16 作为
postgresql:16模块流
要安装 PostgreSQL,请使用以下流程:
按照设计,无法并行安装同一模块的多个版本(stream)。因此,您必须只从 postgresql 模块中选择一个可用的流。您可以在容器中使用不同版本的 PostgreSQL 数据库服务器,请参阅 在容器中运行多个 PostgreSQL 版本。
流程
安装 PostgreSQL 服务器软件包:
对于 RPM 软件包中的 PostgreSQL 13 :
dnf install postgresql-server
# dnf install postgresql-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow 对于 PostgreSQL 15 或 PostgreSQL 16,通过从
postgresql模块中选择流(版本)15 或 16,并指定server配置文件,例如:dnf module install postgresql:16/server
# dnf module install postgresql:16/serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow postgres超级用户会自动创建。
初始化数据库集群:
postgresql-setup --initdb
# postgresql-setup --initdbCopy to Clipboard Copied! Toggle word wrap Toggle overflow 红帽建议将数据存储在默认的
/var/lib/pgsql/data目录中。启动
postgresql服务:systemctl start postgresql.service
# systemctl start postgresql.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow 启用
postgresql服务,以便在引导时启动:systemctl enable postgresql.service
# systemctl enable postgresql.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
如果要从 RHEL 9 中的早期 postgresql 流升级,请按照 切换到更新的流 和 迁移到 RHEL 9 版本的 PostgreSQL 中描述的流程操作。