在 Rocky Linux 8 上安装 PostgreSQL

在本教程中,您将学习如何在 Rocky Linux 8 上安装 PostgreSQL。

PostgreSQL 是一个功能齐全的对象关系型数据库管理系统。它支持大部分 SQL 标准,并被设计为用户可以在许多方面进行扩展。

其中一些特性是:ACID 事务、外键、视图、序列、子查询、触发器、用户定义的类型和函数、外连接、多版本并发控制。许多编程语言的图形用户界面和绑定也可用。

PostgreSQL 是一个强大的开源对象关系数据库系统,它使用并扩展了 SQL 语言,并结合了许多安全存储和扩展最复杂数据工作负载的功能。

在 Rocky Linux 8 上安装 PostgreSQL

Rocky Linux 附带了适用于各种 PostgreSQL 版本的 AppStream 存储库模块。

dnf module list postgresql
Rocky Linux 8 - AppStream
Name                                Stream                          Profiles                                    Summary                                                     
postgresql                          9.6                             client, server [d]                          PostgreSQL server and client module                         
postgresql                          10 [d]                          client, server [d]                          PostgreSQL server and client module                         
postgresql                          12                              client, server [d]                          PostgreSQL server and client module                         
postgresql                          13                              client, server [d]                          PostgreSQL server and client module                         

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

从上面的输出中,您可以看到 PostgreSQL 的各种版本的流,包括 v9.6、10、12、13。

PostgreSQL 的 AppStream 模块默认启用。

出于各种原因,您可能希望在 Rocky Linux 8 机器上安装各种版本的 PostgreSQL。

在 Rocky Linux 8 上安装 PostgreSQL 13

在撰写本文时,PostgreSQL 13 是当前的稳定版本

默认情况下,PostgreSQL 10 的 AppStream 模块默认启用。

在 Rocky Linux 8 上安装 PostgreSQL 13;

  • 启用 PostgreSQL 13 AppStream 模块
dnf -qy module enable postgresql:13

确认;

dnf info postgresql-server
Available Packages
Name         : postgresql-server
Version      : 13.3
Release      : 1.module+el8.4.0+546+3620623e
Architecture : x86_64
Size         : 5.6 M
Source       : postgresql-13.3-1.module+el8.4.0+546+3620623e.src.rpm
Repository   : appstream
Summary      : The programs needed to create and run a PostgreSQL server
URL          : http://www.postgresql.org/
License      : PostgreSQL

因此,您现在可以运行以下命令在 Rocky Linux 8 上安装 PostgreSQL 13。

dnf install postgresql-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                  Architecture                  Version                                                      Repository                        Size
============================================================================================================================================================================
Installing:
 postgresql-server                        x86_64                        13.3-1.module+el8.4.0+546+3620623e                           appstream                        5.6 M
Installing dependencies:
 libicu                                   x86_64                        60.3-2.el8_1                                                 baseos                           8.8 M
 libpq                                    x86_64                        13.3-1.el8_4                                                 appstream                        196 k
 postgresql                               x86_64                        13.3-1.module+el8.4.0+546+3620623e                           appstream                        1.5 M

Transaction Summary
============================================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 59 M
Is this ok [y/N]: y

检查安装的PostgreSQL版本;

postgres -V
postgres (PostgreSQL) 13.3

初始化数据库;

postgresql-setup --initdb

启动并启用 PostgreSQL 在系统启动时运行;

systemctl enable --now postgresql

检查状态;

systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-09-07 09:42:14 EAT; 47s ago
  Process: 15684 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
 Main PID: 15686 (postmaster)
    Tasks: 8 (limit: 4938)
   Memory: 16.8M
   CGroup: /system.slice/postgresql.service
           ├─15686 /usr/bin/postmaster -D /var/lib/pgsql/data
           ├─15688 postgres: logger   
           ├─15690 postgres: checkpointer   
           ├─15691 postgres: background writer   
           ├─15692 postgres: walwriter   
           ├─15693 postgres: autovacuum launcher   
           ├─15694 postgres: stats collector   
           └─15695 postgres: logical replication launcher   

Sep 07 09:42:13 rocky8 systemd[1]: Starting PostgreSQL database server...
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.544 EAT [15686] LOG:  starting PostgreSQL 12.7 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 8.4.1 202009>
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.545 EAT [15686] LOG:  listening on IPv6 address "::1", port 5432
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.545 EAT [15686] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.687 EAT [15686] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Sep 07 09:42:13 rocky8 postmaster[15686]: 2021-09-07 09:42:13.962 EAT [15686] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Sep 07 09:42:14 rocky8 postmaster[15686]: 2021-09-07 09:42:14.130 EAT [15686] LOG:  redirecting log output to logging collector process
Sep 07 09:42:14 rocky8 postmaster[15686]: 2021-09-07 09:42:14.130 EAT [15686] HINT:  Future log output will appear in directory "log".
Sep 07 09:42:14 rocky8 systemd[1]: Started PostgreSQL database server.

在 Rocky Linux 8 上安装 PostgreSQL 12

要在 Rocky Linux 上安装 PostgreSQL 12,请运行以下命令;

dnf -qy module enable postgresql:12
dnf install postgresql-server

否则,如果您启用了其他版本的模块,则按如下方式重置模块并安装 PostgreSQL;

dnf -qy module reset postgresql
dnf -qy module enable postgresql:12
dnf install postgresql-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                  Architecture                  Version                                                      Repository                        Size
============================================================================================================================================================================
Installing:
 postgresql-server                        x86_64                        12.7-1.module+el8.4.0+587+d46efd10                           appstream                        5.6 M
Installing dependencies:
 libicu                                   x86_64                        60.3-2.el8_1                                                 baseos                           8.8 M
 libpq                                    x86_64                        13.3-1.el8_4                                                 appstream                        196 k
 postgresql                               x86_64                        12.7-1.module+el8.4.0+587+d46efd10                           appstream                        1.5 M

Transaction Summary
============================================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 59 M
Is this ok [y/N]: y

安装后,可以验证版本;

postgres -V
postgres (PostgreSQL) 12.7

初始化数据库;

postgresql-setup --initdb

启动并启用 PostgreSQL 在系统启动时运行;

systemctl enable --now postgresql

在 Rocky Linux 8 上安装 PostgreSQL 10

默认情况下,您只需运行以下命令即可在 Rocky Linux 8 上安装 PostgreSQL 10。

dnf install postgresql-server

但是,如果您启用了其他版本的 AppStream 模块,则必须重置模块。

dnf -qy module reset postgresql
dnf install postgresql-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                  Architecture                  Version                                                      Repository                        Size
============================================================================================================================================================================
Installing:
 postgresql-server                        x86_64                        10.17-1.module+el8.4.0+548+9eccbe3f                          appstream                        5.1 M
Installing dependencies:
 libpq                                    x86_64                        13.3-1.el8_4                                                 appstream                        196 k
 postgresql                               x86_64                        10.17-1.module+el8.4.0+548+9eccbe3f                          appstream                        1.5 M
Enabling module streams:
 postgresql                                                             10                                                                                                 

Transaction Summary
============================================================================================================================================================================
Install  3 Packages

Total download size: 6.8 M
Installed size: 26 M
Is this ok [y/N]: y

安装后,可以验证版本;

postgres -V
postgres (PostgreSQL) 10.17

初始化数据库;

postgresql-setup --initdb

启动并启用 PostgreSQL 在系统启动时运行;

systemctl enable --now postgresql

同样,要安装 PostgreSQL 9.x,然后启用该模块并运行安装命令。

在 Rocky Linux 8 上安装 PostgreSQL 11

Rocky Linux 不提供用于安装 PostgreSQL 11 的存储库。

因此,如果您想在 Rocky Linux 8 上安装 PostgreSQL 11,那么您需要安装存储库 RPM:

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

禁用内置的 PostgreSQL 模块:

dnf -qy module disable postgresql

在 Rocky Linux 8 上安装 PostgreSQL 11

dnf install postgresql11-server
Dependencies resolved.
============================================================================================================================================================================
 Package                                         Architecture                       Version                                        Repository                          Size
============================================================================================================================================================================
Installing:
 postgresql11-server                             x86_64                             11.13-1PGDG.rhel8                              pgdg11                             4.9 M
Installing dependencies:
 libicu                                          x86_64                             60.3-2.el8_1                                   baseos                             8.8 M
 postgresql11                                    x86_64                             11.13-1PGDG.rhel8                              pgdg11                             1.7 M
 postgresql11-libs                               x86_64                             11.13-1PGDG.rhel8                              pgdg11                             394 k

Transaction Summary
============================================================================================================================================================================
Install  4 Packages

Total download size: 16 M
Installed size: 60 M
Is this ok [y/N]: y

初始化数据库;

postgresql-11-setup initdb

启动并启用 PostgreSQL 在系统启动时运行;

systemctl enable --now postgresql-11

检查状态;

systemctl status postgresql-11
● postgresql-11.service - PostgreSQL 11 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-09-07 09:19:07 EAT; 44s ago
     Docs: https://www.postgresql.org/docs/11/static/
  Process: 11990 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 11995 (postmaster)
    Tasks: 8 (limit: 4938)
   Memory: 16.4M
   CGroup: /system.slice/postgresql-11.service
           ├─11995 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
           ├─12001 postgres: logger   
           ├─12003 postgres: checkpointer   
           ├─12004 postgres: background writer   
           ├─12005 postgres: walwriter   
           ├─12006 postgres: autovacuum launcher   
           ├─12007 postgres: stats collector   
           └─12008 postgres: logical replication launcher   

Sep 07 09:19:05 rocky8 systemd[1]: Starting PostgreSQL 11 database server...
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.387 EAT [11995] LOG:  listening on IPv6 address "::1", port 5432
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.387 EAT [11995] LOG:  listening on IPv4 address "127.0.0.1", port 5432
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.541 EAT [11995] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Sep 07 09:19:06 rocky8 postmaster[11995]: 2021-09-07 09:19:06.848 EAT [11995] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Sep 07 09:19:07 rocky8 postmaster[11995]: 2021-09-07 09:19:07.005 EAT [11995] LOG:  redirecting log output to logging collector process
Sep 07 09:19:07 rocky8 postmaster[11995]: 2021-09-07 09:19:07.005 EAT [11995] HINT:  Future log output will appear in directory "log".
Sep 07 09:19:07 rocky8 systemd[1]: Started PostgreSQL 11 database server.

这就是如何在 Rocky Linux 8 上安装 PostgreSQL 的全部内容。

 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:番茄网 » 在 Rocky Linux 8 上安装 PostgreSQL

分享到: 生成海报

评论 抢沙发

  • QQ号
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

像番茄一样 表里如一

表里如一表里如一
切换注册

登录

忘记密码 ?

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活