如何在 Linux 上安装 PostgreSQL 16 [RHEL 发行版]如何在 Linux 上安装 PostgreSQL 16 [RHEL 发行版]如何在 Linux 上安装 PostgreSQL 16 [RHEL 发行版]如何在 Linux 上安装 PostgreSQL 16 [RHEL 发行版]
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Linux 上安装 PostgreSQL 16 [RHEL 发行版]

PostgreSQL 是一个功能强大、高度可扩展、开源、跨平台的对象关系数据库系统,运行在类 Unix 操作系统(包括 Linux 和 Windows 操作系统)上。它是一个高度可靠的企业级数据库系统,为用户提供数据的完整性和正确性。

在本文中,我们将解释如何在 RHEL 和基于 RHEL 的发行版(例如 Rocky Linux、<使用官方PostgreSQL Yum存储库的strong>AlmaLinux、Oracle Linux和Fedora。

1. 更新软件包

在开始 PostgreSQL 安装过程之前,请确保通过运行以下 dnf 命令更新您的 Linux 系统软件包。

sudo dnf update

2. 启用 PostgreSQL 存储库

虽然 PostgreSQL 在默认系统存储库中可用,但建议启用官方 PostgreSQL 存储库以访问最新版本。

在 RHEL、Rocky、AlmaLinux 和 Oracle Linux 9 上:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

在 RHEL、Rocky、AlmaLinux 和 Oracle Linux 8 上:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

在 Fedora 39 上:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-39-x86_64/pgdg-fedora-repo-latest.noarch.rpm

在 Fedora 38 上:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-38-x86_64/pgdg-fedora-repo-latest.noarch.rpm

3.安装PostgreSQL 16服务器

在各自的 Linux 发行版中添加 PostgreSQL 存储库后,使用以下命令安装 PostgreSQL 服务器和客户端软件包。

sudo dnf install -y postgresql16-server postgresql16

重要:PostgreSQL 数据目录 /var/lib/pgsql/16/data/ 包含数据库的所有数据文件。

4.初始化PostgreSQL数据库

由于适用于基于 Red Hat 的发行版的某些策略,PostgreSQL 安装不会自动启动,也不会在自动启动过程中初始化数据库。

要完成数据库安装,您需要在首次使用数据库之前对其进行初始化。

sudo /usr/pgsql-16/bin/postgresql-16-setup initdb

5. 配置 PostgreSQL 进行远程访问

要启用远程连接,您需要使用文本编辑器修改配置文件postgresql.conf。

sudo vi /var/lib/pgsql/16/data/postgresql.conf

更新 listen_addresses 参数以允许来自本地网络上所有主机的连接。

listen_addresses = '*'

对配置文件进行更改后,您需要重新启动 PostgreSQL 服务以应用新设置并启用自动启动。

sudo systemctl restart postgresql-16
sudo systemctl enable postgresql-16

6. 设置PostgreSQL用户密码

设置默认 PostgreSQL 用户 (postgres) 的密码。

sudo passwd postgres

7. 访问 PostgreSQL 数据库

设置用户密码后,您可以使用psql命令访问PostgreSQL数据库服务器。

sudo -i -u postgres
psql

最后,阅读有关 PostgreSQL 数据库管理系统的相关文章:

结论

恭喜!您已在基于 RedHat 的发行版(当时可用的最新版本)上成功安装了 PostgreSQL 16。请记住查阅官方 PostgreSQL 文档以了解任何特定于版本的详细信息或更改。

©2015-2025 艾丽卡 support@alaica.com