2024-Centos7安装PostgreSql14

发布于:2024-03-21 ⋅ 阅读:(85) ⋅ 点赞:(0)

直接选择官网合适版本 copy安装脚本

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql14-server
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14

[root@192 ~]#
[root@192 ~]# sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql14-server
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14Loaded plugins: fastestmirror
pgdg-redhat-repo-latest.noarch.rpm                       |  10 kB     00:00
Examining /var/tmp/yum-root-TztjI1/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-38PGDG.noarch
Marking /var/tmp/yum-root-TztjI1/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-38PGDG will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch    Version       Repository                        Size
================================================================================
Installing:
 pgdg-redhat-repo  noarch  42.0-38PGDG   /pgdg-redhat-repo-latest.noarch   12 k

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

Total size: 12 k
Installed size: 12 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-redhat-repo-42.0-38PGDG.noarch                          1/1
  Verifying  : pgdg-redhat-repo-42.0-38PGDG.noarch                          1/1

Installed:
  pgdg-redhat-repo.noarch 0:42.0-38PGDG

Complete!
[root@192 ~]# sudo yum install -y postgresql14-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
pgdg-common/7/x86_64/signature                           |  665 B     00:00
Retrieving key from file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Importing GPG key 0x73E3B907:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: f245 f0bf 96ac 1827 44ca ff2e 64fa ce11 73e3 b907
 Package    : pgdg-redhat-repo-42.0-38PGDG.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
pgdg-common/7/x86_64/signature                           | 2.9 kB     00:00 !!!
pgdg12/7/x86_64/signature                                |  665 B     00:00
Retrieving key from file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Importing GPG key 0x73E3B907:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: f245 f0bf 96ac 1827 44ca ff2e 64fa ce11 73e3 b907
 Package    : pgdg-redhat-repo-42.0-38PGDG.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
pgdg12/7/x86_64/signature                                | 3.6 kB     00:00 !!!
pgdg13/7/x86_64/signature                                |  665 B     00:00
Retrieving key from file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Importing GPG key 0x73E3B907:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: f245 f0bf 96ac 1827 44ca ff2e 64fa ce11 73e3 b907
 Package    : pgdg-redhat-repo-42.0-38PGDG.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
pgdg13/7/x86_64/signature                                | 3.6 kB     00:00 !!!
pgdg14/7/x86_64/signature                                |  665 B     00:00
Retrieving key from file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Importing GPG key 0x73E3B907:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: f245 f0bf 96ac 1827 44ca ff2e 64fa ce11 73e3 b907
 Package    : pgdg-redhat-repo-42.0-38PGDG.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
pgdg14/7/x86_64/signature                                | 3.6 kB     00:00 !!!
pgdg15/7/x86_64/signature                                |  665 B     00:00
Retrieving key from file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Importing GPG key 0x73E3B907:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: f245 f0bf 96ac 1827 44ca ff2e 64fa ce11 73e3 b907
 Package    : pgdg-redhat-repo-42.0-38PGDG.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
pgdg15/7/x86_64/signature                                | 3.6 kB     00:00 !!!
(1/9): pgdg12/7/x86_64/group_gz                            |  246 B   00:01
(2/9): pgdg14/7/x86_64/group_gz                            |  245 B   00:00
(3/9): pgdg13/7/x86_64/group_gz                            |  246 B   00:02
(4/9): pgdg15/7/x86_64/group_gz                            |  247 B   00:00
(5/9): pgdg-common/7/x86_64/primary_db                     | 204 kB   00:04
(6/9): pgdg14/7/x86_64/primary_db                          | 259 kB   00:18
(7/9): pgdg15/7/x86_64/primary_db                          | 165 kB   00:18
(8/9): pgdg13/7/x86_64/primary_db                          | 341 kB   00:23
(9/9): pgdg12/7/x86_64/primary_db                          | 418 kB   00:27
Resolving Dependencies
--> Running transaction check
---> Package postgresql14-server.x86_64 0:14.11-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql14-libs(x86-64) = 14.11-1PGDG.rhel7 for package: postgresql14-server-14.11-1PGDG.rhel7.x86_64
--> Processing Dependency: postgresql14(x86-64) = 14.11-1PGDG.rhel7 for package: postgresql14-server-14.11-1PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql14-server-14.11-1PGDG.rhel7.x86_64
--> Processing Dependency: libicuuc.so.50()(64bit) for package: postgresql14-server-14.11-1PGDG.rhel7.x86_64
--> Processing Dependency: libicui18n.so.50()(64bit) for package: postgresql14-server-14.11-1PGDG.rhel7.x86_64
--> Running transaction check
---> Package libicu.x86_64 0:50.2-4.el7_7 will be installed
---> Package postgresql14.x86_64 0:14.11-1PGDG.rhel7 will be installed
---> Package postgresql14-libs.x86_64 0:14.11-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch        Version                 Repository   Size
================================================================================
Installing:
 postgresql14-server      x86_64      14.11-1PGDG.rhel7       pgdg14      5.5 M
Installing for dependencies:
 libicu                   x86_64      50.2-4.el7_7            base        6.9 M
 postgresql14             x86_64      14.11-1PGDG.rhel7       pgdg14      1.5 M
 postgresql14-libs        x86_64      14.11-1PGDG.rhel7       pgdg14      273 k

Transaction Summary
================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 14 M
Installed size: 55 M
Downloading packages:
(1/4): libicu-50.2-4.el7_7.x86_64.rpm                      | 6.9 MB   00:01
warning: /var/cache/yum/x86_64/7/pgdg14/packages/postgresql14-libs-14.11-1PGDG.rhel7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 73e3b907: NOKEY
Public key for postgresql14-libs-14.11-1PGDG.rhel7.x86_64.rpm is not installed
(2/4): postgresql14-libs-14.11-1PGDG.rhel7.x86_64.rpm      | 273 kB   00:14
(3/4): postgresql14-14.11-1PGDG.rhel7.x86_64.rpm           | 1.5 MB   00:21
(4/4): postgresql14-server-14.11-1PGDG.rhel7.x86_64.rpm    | 5.5 MB   00:11
--------------------------------------------------------------------------------
Total                                              562 kB/s |  14 MB  00:25
Retrieving key from file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Importing GPG key 0x73E3B907:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: f245 f0bf 96ac 1827 44ca ff2e 64fa ce11 73e3 b907
 Package    : pgdg-redhat-repo-42.0-38PGDG.noarch (@/pgdg-redhat-repo-latest.noarch)
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libicu-50.2-4.el7_7.x86_64                                   1/4
  Installing : postgresql14-libs-14.11-1PGDG.rhel7.x86_64                   2/4
  Installing : postgresql14-14.11-1PGDG.rhel7.x86_64                        3/4
  Installing : postgresql14-server-14.11-1PGDG.rhel7.x86_64                 4/4
  Verifying  : postgresql14-14.11-1PGDG.rhel7.x86_64                        1/4
  Verifying  : postgresql14-server-14.11-1PGDG.rhel7.x86_64                 2/4
  Verifying  : postgresql14-libs-14.11-1PGDG.rhel7.x86_64                   3/4
  Verifying  : libicu-50.2-4.el7_7.x86_64                                   4/4

Installed:
  postgresql14-server.x86_64 0:14.11-1PGDG.rhel7

Dependency Installed:
  libicu.x86_64 0:50.2-4.el7_7
  postgresql14.x86_64 0:14.11-1PGDG.rhel7
  postgresql14-libs.x86_64 0:14.11-1PGDG.rhel7

Complete!
[root@192 ~]# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
Initializing database ... OK

[root@192 ~]# sudo systemctl enable postgresql-14
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-14.service to /usr/lib/systemd/system/postgresql-14.service.
[root@192 ~]# sudo systemctl start postgresql-14
[root@192 ~]#

修改全部地址可连接

vi /var/lib/pgsql/14/data/postgresql.conf
#listen_addresses = ‘localhost’ 改为 listen_addresses = ‘*’ 同时打开端口 port = 5432

添加允许远程地址

vi /var/lib/pgsql/14/data/pg_hba.conf
添加一行 host all all 192.168.2.1/24 trust

重启修改初始密码

[root@192 ~]# sudo systemctl restart postgresql-14
[root@192 ~]# su - postgres
-bash-4.2$ psql -p 5432 -U postgres
psql (14.11)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'postgres'
postgres-# \q

基本操作

systemctl start postgresql-14
systemctl restart postgresql-14
systemctl stop postgresql-14


网站公告

今日签到

点亮在社区的每一天
去签到