分享最新优惠信息
购买主机更加划算

Fedora 33/32/31/30系统安装PostgreSQL 13版本的简单方法

PostgreSQL是一个功能强大且广泛使用的关系数据库管理系统,旨在具有灵活性和容错能力。PostgreSQL数据库基于POSTGRES 4.2,当前,PostgreSQL数据库的最新版本为13。

PostgreSQL 13版本中的一些更改。

  • B树索引条目的重复数据删除带来的改进—空间节省和性能提升
  • 使用聚合表或分区表的查询可提高性能
  • 增量排序
  • 使用扩展统计信息时更好的查询计划
  • 索引的并行清理

PostgreSQL团队为安装基于YUM和基于Debian的Linux系统提供了预构建的二进制软件包,安装方法相对简单。本文简单介绍下在Fedora 33/32/31/30系统中安装PostgreSQL 13版本的大致过程。

步骤1:更新Fedora系统   

首先是更新Fedora系统,命令如下:

sudo dnf update -y
sudo dnf install -y vim bash-completion wget

成功更新系统之后执行重启操作:

sudo reboot

步骤2:添加PostgreSQL Yum存储库

通过运行以下命令将PostgreSQL Yum存储库添加到Fedora系统:

Fedora 33:

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

Fedora 32:

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

Fedora 31:

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

Fedora 30:

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

Fedora 29:

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

当提示确认安装时,请按 键。

....
Dependencies resolved.
==================================================================================================================================================================
 Package                                     Architecture                      Version                              Repository                               Size
==================================================================================================================================================================
Installing:
 pgdg-fedora-repo                            noarch                            42.0-13                              @commandline                             10 k

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 10 k
Installed size: 11 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                          1/1
  Installing       : pgdg-fedora-repo-42.0-13.noarch                                                                                                          1/1
  Verifying        : pgdg-fedora-repo-42.0-13.noarch                                                                                                          1/1

Installed:
  pgdg-fedora-repo-42.0-13.noarch

Complete!

步骤3:在Fedora 33/32/31/30上安装PostgreSQL 13

将PostgreSQL信息库添加到Fedora系统后,安装PostgreSQL 13 Server / Client软件包:

sudo dnf install postgresql13-server postgresql13

接下来选择同意安装。

Dependencies resolved.
==================================================================================================================================================================
 Package                                       Architecture                     Version                                    Repository                        Size
==================================================================================================================================================================
Installing:
 postgresql13-server                           x86_64                           13.1-3PGDG.f33                             pgdg13                           5.8 M
Installing dependencies:
 libicu                                        x86_64                           67.1-4.fc33                                fedora                           9.7 M
 postgresql13                                  x86_64                           13.1-3PGDG.f33                             pgdg13                           1.4 M
 postgresql13-libs                             x86_64                           13.1-3PGDG.f33                             pgdg13                           789 k

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

Total download size: 18 M
Installed size: 65 M
Is this ok [y/N]: y

这里包括GPG密钥导入:

Total                                                                                                                              13 MB/s |  18 MB     00:01
warning: /var/cache/dnf/pgdg13-5b69a3a370fb59a8/packages/postgresql13-13.1-3PGDG.f33.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
PostgreSQL 13 for Fedora 33 - x86_64                                                                                              1.6 MB/s | 1.7 kB     00:00
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>"
 Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Is this ok [y/N]: y

步骤4:初始化PostgreSQL数据库

运行以下命令以初始化数据库:

$ sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK

启动并启用PostgreSQL数据库服务:

$ sudo systemctl enable --now postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usr/lib/systemd/system/postgresql-13.service.

确认服务状态。

$ systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2021-02-08 21:25:49 UTC; 21s ago
       Docs: https://www.postgresql.org/docs/13/static/
    Process: 1076 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 1081 (postmaster)
      Tasks: 8 (limit: 1125)
     Memory: 16.2M
        CPU: 59ms
     CGroup: /system.slice/postgresql-13.service
             ├─1081 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
             ├─1082 postgres: logger
             ├─1084 postgres: checkpointer
             ├─1085 postgres: background writer
             ├─1086 postgres: walwriter
             ├─1087 postgres: autovacuum launcher
             ├─1088 postgres: stats collector
             └─1089 postgres: logical replication launcher

Feb 08 21:25:49 fed33 systemd[1]: Starting PostgreSQL 13 database server...
Feb 08 21:25:49 fed33 postmaster[1081]: 2021-02-08 21:25:49.811 UTC [1081] LOG:  redirecting log output to logging collector process
Feb 08 21:25:49 fed33 postmaster[1081]: 2021-02-08 21:25:49.811 UTC [1081] HINT:  Future log output will appear in directory "log".
Feb 08 21:25:49 fed33 systemd[1]: Started PostgreSQL 13 database server.

步骤5:启用对PostgreSQL的远程访问(可选)

对于远程客户端连接,可能必须允许在防火墙中进行访问。

sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload

然后编辑文件, /var/lib/pgsql/13/data/postgresql.conf 并为所有接口或特定的IP地址/子网将“侦听地址”设置为服务器IP地址或“ * ”。

$ sudo vi /var/lib/pgsql/13/data/postgresql.conf 
listen_addresses = '*'

还要将PostgreSQL设置为接受来自允许的主机的远程连接。

$ sudo vim /var/lib/pgsql/11/data/pg_hba.conf

# Accept from anywhere
host all all 0.0.0.0/0 md5

# Accept from trusted subnet
host all all 10.10.10.0/24 md5

进行更改后,重新启动PostgreSQL 13服务。

sudo systemctl restart postgresql-13

步骤6:设定PostgreSQL管理员使用者的密码

设置PostgreSQL管理员用户密码。

$ sudo su - postgres
$ psql -c "alter user postgres with password 'StrongDBPassword'"

其中 StrongDBPassword 是postgres用户的新密码 。

步骤7:安装pgAdmin 4 Web管理

如果您、需要一种简单的方法来管理PostgreSQL数据库服务器(类似于MySQL的phpMyAdmin),那么考虑安装pgAdmin4,相对来说管理起来比较轻松。

总结

以上就是在Fedora 33/32/31/30系统中安装PostgreSQL 13的简单方法,仅供参考。截止到目前为止,PostgreSQL 13是其最新版本,如果还没有更新升级的小伙伴可以参考上述教程进行安装。

未经允许不得转载:惠主机 » Fedora 33/32/31/30系统安装PostgreSQL 13版本的简单方法