2022年11月1日 星期二

[研究] PostgreSQL 10.17 安裝 + pgAdmin4 v5.5 (yum) (Rocky Linux 9.0)

[研究] PostgreSQL 10.17 安裝 + pgAdmin4 v5.5 (yum) (Rocky Linux 9.0)

2022-11-01

PostgreSQL 15.0 於 2022-10-13 釋出。
https://www.postgresql.org/

8.4 ~ 15 版功能比較
https://www.postgresql.org/about/featurematrix/

Rocky Linux 是 CentOS創始者建立的版本。目前 yum 提供 PostgreSQL Database 13.7-1版。

[user1@localhost ~]$ yum list | grep postgre
pcp-pmda-postgresql.x86_64      5.3.5-8.el9        appstream 
postgres-decoderbufs.x86_64     1.4.0-4.Final.el9  appstream 
postgresql.x86_64               13.7-1.el9_0       appstream 
postgresql-contrib.x86_64       13.7-1.el9_0       appstream 
postgresql-jdbc.noarch          42.2.18-5.el9      appstream 
postgresql-odbc.x86_64          12.02.0000-6.el9   appstream 
postgresql-plperl.x86_64        13.7-1.el9_0       appstream 
postgresql-plpython3.x86_64     13.7-1.el9_0       appstream 
postgresql-pltcl.x86_64         13.7-1.el9_0       appstream 
postgresql-private-libs.x86_64  13.7-1.el9_0       appstream 
postgresql-server.x86_64        13.7-1.el9_0       appstream 
postgresql-upgrade.x86_64       13.7-1.el9_0       appstream 
qt5-qtbase-postgresql.i686      5.15.2-29.el9      appstream 
qt5-qtbase-postgresql.x86_64    5.15.2-29.el9      appstream 
[user1@localhost ~]$ 

安裝

xxxxx  

[user1@localhost ~]$ yum  -y  install  postgresql-server
Error: This command has to be run with superuser privileges (under the root user on most systems).

[user1@localhost ~]$ sudo yum -y install postgresql-server

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for user1: 
Rocky Linux 9 - BaseOS                                                                     94 kB/s | 1.7 MB     00:18    
Rocky Linux 9 - AppStream                                                                 518 kB/s | 6.0 MB     00:11    
Rocky Linux 9 - Extras                                                                    1.4 kB/s | 6.6 kB     00:04    
Dependencies resolved.
==========================================================================================================================
 Package                                Architecture          Version                      Repository                Size
==========================================================================================================================
Installing:
 postgresql-server                      x86_64                13.7-1.el9_0                 appstream                5.7 M
Installing dependencies:
 postgresql                             x86_64                13.7-1.el9_0                 appstream                1.5 M
 postgresql-private-libs                x86_64                13.7-1.el9_0                 appstream                136 k

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

Total download size: 7.4 M
Installed size: 29 M
Downloading Packages:
(1/3): postgresql-private-libs-13.7-1.el9_0.x86_64.rpm                                    488 kB/s | 136 kB     00:00    
(2/3): postgresql-13.7-1.el9_0.x86_64.rpm                                                 1.9 MB/s | 1.5 MB     00:00    
(3/3): postgresql-server-13.7-1.el9_0.x86_64.rpm                                          2.8 MB/s | 5.7 MB     00:02    
--------------------------------------------------------------------------------------------------------------------------
Total                                                                                     2.6 MB/s | 7.4 MB     00:02     
Rocky Linux 9 - AppStream                                                                 1.7 MB/s | 1.7 kB     00:00    
Importing GPG key 0x350D275D:
 Userid     : "Rocky Enterprise Software Foundation - Release key 2022 <releng@rockylinux.org>"
 Fingerprint: 21CB 256A E16F C54C 6E65 2949 702D 426D 350D 275D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                  1/1 
  Installing       : postgresql-private-libs-13.7-1.el9_0.x86_64                                                      1/3 
  Installing       : postgresql-13.7-1.el9_0.x86_64                                                                   2/3 
  Running scriptlet: postgresql-server-13.7-1.el9_0.x86_64                                                            3/3 
  Installing       : postgresql-server-13.7-1.el9_0.x86_64                                                            3/3 
  Running scriptlet: postgresql-server-13.7-1.el9_0.x86_64                                                            3/3 
  Verifying        : postgresql-server-13.7-1.el9_0.x86_64                                                            1/3 
  Verifying        : postgresql-private-libs-13.7-1.el9_0.x86_64                                                      2/3 
  Verifying        : postgresql-13.7-1.el9_0.x86_64                                                                   3/3 

Installed:
  postgresql-13.7-1.el9_0.x86_64   postgresql-private-libs-13.7-1.el9_0.x86_64   postgresql-server-13.7-1.el9_0.x86_64  

Complete!
[user1@localhost ~]$ 

初始化資料庫

[user1@localhost ~]$ service postgresql initdb
Hint: the preferred way to do this is now "/usr/bin/postgresql-setup --initdb --unit postgresql"
ERROR: The /var/lib/pgsql directory has wrong permissions.
       Please make sure the directory is writable by user1.

[user1@localhost ~]$ sudo /usr/bin/postgresql-setup --initdb --unit postgresql
 * Initializing database in '/var/lib/pgsql/data'
 * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
[user1@localhost ~]$ 


立刻啟動 (但是重新啟動後,不會自動啟動)  

[user1@localhost ~]$ sudo service postgresql start
Redirecting to /bin/systemctl start postgresql.service
[user1@localhost ~]$

確認啟動

[user1@localhost ~]$ sudo service postgresql status
Redirecting to /bin/systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
     Active: active (running) since Wed 2022-10-19 10:12:09 CST; 7s ago
    Process: 33760 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
   Main PID: 33762 (postmaster)
      Tasks: 8 (limit: 23272)
     Memory: 16.8M
        CPU: 40ms
     CGroup: /system.slice/postgresql.service
             ├─33762 /usr/bin/postmaster -D /var/lib/pgsql/data
             ├─33763 "postgres: logger "
             ├─33765 "postgres: checkpointer "
             ├─33766 "postgres: background writer "
             ├─33767 "postgres: walwriter "
             ├─33768 "postgres: autovacuum launcher "
             ├─33769 "postgres: stats collector "
             └─33770 "postgres: logical replication launcher "

Oct 19 10:12:09 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Oct 19 10:12:09 localhost.localdomain postmaster[33762]: 2022-10-19 10:12:09.699 CST [33762] LOG:  redirecting log output>
Oct 19 10:12:09 localhost.localdomain postmaster[33762]: 2022-10-19 10:12:09.699 CST [33762] HINT:  Future log output wil>
Oct 19 10:12:09 localhost.localdomain systemd[1]: Started PostgreSQL database server.
[user1@localhost ~]$ 

或  

[user1@localhost ~]$ ps aux | grep pg
root        2786  0.0  0.0 225748   800 ?        Ssl  10:02   0:00 gpg-agent --homedir /var/cache/PackageKit/9.0/metadata/extras-9-x86_64.tmp/gpgdir --use-standard-socket --daemon
root        2788  0.0  0.0  78600  1356 ?        SLl  10:02   0:00 scdaemon --multi-server --homedir /var/cache/PackageKit/9.0/metadata/extras-9-x86_64.tmp/gpgdir
root        2812  0.0  0.0 225748   888 ?        Ssl  10:02   0:00 gpg-agent --homedir /var/cache/PackageKit/9.0/metadata/baseos-9-x86_64.tmp/gpgdir --use-standard-socket --daemon
root        2814  0.0  0.0  78600  1328 ?        SLl  10:02   0:00 scdaemon --multi-server --homedir /var/cache/PackageKit/9.0/metadata/baseos-9-x86_64.tmp/gpgdir
root        2827  0.0  0.0 225748   828 ?        Ssl  10:02   0:00 gpg-agent --homedir /var/cache/PackageKit/9.0/metadata/appstream-9-x86_64.tmp/gpgdir --use-standard-socket --daemon
root        2829  0.0  0.0  78600  1400 ?        SLl  10:02   0:00 scdaemon --multi-server --homedir /var/cache/PackageKit/9.0/metadata/appstream-9-x86_64.tmp/gpgdir
postgres   33762  0.0  0.7 425968 27436 ?        Ss   10:12   0:00 /usr/bin/postmaster -D /var/lib/pgsql/data
user1      33808  0.0  0.0 221800  2324 pts/0    S+   10:13   0:00 grep --color=auto pg
[user1@localhost ~]$ 

設定每次重新開機後,自動啟動 (但不會立刻啟動)  

[user1@localhost ~]$ sudo chkconfig   postgresql   on
sudo: chkconfig: command not found

[user1@localhost ~]$ sudo systemctl enable postgresql.service
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
[user1@localhost ~]$ 

檢查開機會自動啟動

[user1@localhost ~]$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2022-10-19 10:12:09 CST; 3min 10s ago
   Main PID: 33762 (postmaster)
      Tasks: 8 (limit: 23272)
     Memory: 16.9M
        CPU: 73ms
     CGroup: /system.slice/postgresql.service
             ├─33762 /usr/bin/postmaster -D /var/lib/pgsql/data
             ├─33763 "postgres: logger "
             ├─33765 "postgres: checkpointer "
             ├─33766 "postgres: background writer "
             ├─33767 "postgres: walwriter "
             ├─33768 "postgres: autovacuum launcher "
             ├─33769 "postgres: stats collector "
             └─33770 "postgres: logical replication launcher "

Oct 19 10:12:09 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Oct 19 10:12:09 localhost.localdomain postmaster[33762]: 2022-10-19 10:12:09.699 CST [33762] LOG:  redirecting log output>
Oct 19 10:12:09 localhost.localdomain postmaster[33762]: 2022-10-19 10:12:09.699 CST [33762] HINT:  Future log output wil>
Oct 19 10:12:09 localhost.localdomain systemd[1]: Started PostgreSQL database server.
[user1@localhost ~]$ 


新增開放 防火牆 port 5432  規則;載入規則;列出規則;

[user1@localhost ~]$ sudo firewall-cmd --add-port=5432/tcp --permanent
Warning: ALREADY_ENABLED: 5432:tcp
success
[user1@localhost ~]$ sudo firewall-cmd --reload
success
[user1@localhost ~]$ sudo firewall-cmd --list-all   
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 5432/tcp
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
[user1@localhost ~]$ 

設定檔案 postgresql.conf 及 pg_hba.conf,如果不知道在哪

[user1@localhost ~]$ sudo find / -name pg_hba.conf 
find: ‘/run/user/1000/gvfs’: Permission denied
/var/lib/pgsql/data/pg_hba.conf

[user1@localhost ~]$ sudo find / -name postgresql.conf
find: ‘/run/user/1000/gvfs’: Permission denied
/etc/postgresql-setup/upgrade/postgresql.conf
/var/lib/pgsql/data/postgresql.conf
/usr/lib/tmpfiles.d/postgresql.conf
[user1@localhost ~]$ 


測試  

[user1@localhost ~]$ su root
Password: 
[root@localhost user1]# su - postgres
[postgres@localhost ~]$ psql
psql (13.7)
Type "help" for help.

postgres=# create database TestDB;
CREATE DATABASE
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 testdb    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
(4 rows)

postgres=# \c TestDB
FATAL:  database "TestDB" does not exist
Previous connection kept
postgres=# \c testdb;    (雖然建立時資料庫名稱有用大寫,實際結果名稱都是小寫)
You are now connected to database "testdb" as user "postgres".
testdb=# create table table1 (id serial, title text, body text);
CREATE TABLE
testdb=# insert into table1 (title, body) values ('pgpool', 'test');
INSERT 0 1
testdb=# select * from table1;
 id | title  | body 
----+--------+------
  1 | pgpool | test
(1 row)

testdb=# \q
[postgres@localhost ~]$ exit
logout
[root@localhost user1]# 


********************************************************************************

總結 - 安裝、啟動、設定防火牆

sudo yum  -y  install  postgresql-server

postgresql-setup   initdb

systemctl   restart   postgresql

systemctl   status   postgresql

firewall-cmd --add-port=5432/tcp --permanent  

firewall-cmd --reload

firewall-cmd --list-all

********************************************************************************

PgAdmin4 安裝

參考
https://www.pgadmin.org/download/pgadmin-4-rpm/

安裝 

[root@localhost ~]# sudo rpm -i https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-2-1.noarch.rpm
warning: /var/tmp/rpm-tmp.CdOnjc: Header V3 RSA/SHA256 Signature, key ID 210976f2: NOKEY

[root@localhost ~]# sudo yum install pgadmin4 -y
pgadmin4                                                                                  261  B/s | 833  B     00:03    
pgadmin4                                                                                  3.8 MB/s | 3.8 kB     00:00    
Importing GPG key 0x210976F2:
 Userid     : "Package Manager (Package Signing Key) <packages@pgadmin.org>"
 Fingerprint: E869 7E2E EF76 C02D 3A63 3277 8881 B2A8 2109 76F2
 From       : /etc/pki/rpm-gpg/PGADMIN_PKG_KEY
pgadmin4                                                                                   48 kB/s | 246 kB     00:05    
Last metadata expiration check: 0:00:01 ago on Wed 19 Oct 2022 10:30:43 AM CST.
Dependencies resolved.
==========================================================================================================================
 Package                          Architecture          Version                            Repository                Size
==========================================================================================================================
Installing:
 pgadmin4                         noarch                6.14-1.el9                         pgAdmin4                 6.3 k
Installing dependencies:
 apr                              x86_64                1.7.0-11.el9                       appstream                123 k
 apr-util                         x86_64                1.6.1-20.el9                       appstream                 94 k
 apr-util-bdb                     x86_64                1.6.1-20.el9                       appstream                 13 k
 httpd                            x86_64                2.4.51-7.el9_0                     appstream                1.4 M
 httpd-filesystem                 noarch                2.4.51-7.el9_0                     appstream                 14 k
 httpd-tools                      x86_64                2.4.51-7.el9_0                     appstream                 81 k
 libatomic                        x86_64                11.2.1-9.4.el9                     baseos                    52 k
 pgadmin4-desktop                 x86_64                6.14-1.el9                         pgAdmin4                  82 M
 pgadmin4-server                  x86_64                6.14-1.el9                         pgAdmin4                  95 M
 pgadmin4-web                     noarch                6.14-1.el9                         pgAdmin4                 8.7 k
 postgresql14-libs                x86_64                14.5-1PGDG.rhel9                   pgAdmin4                 283 k
 python3-mod_wsgi                 x86_64                4.7.1-9.el9                        appstream                942 k
 rocky-logos-httpd                noarch                90.11-1.el9                        appstream                 24 k
Installing weak dependencies:
 apr-util-openssl                 x86_64                1.6.1-20.el9                       appstream                 15 k
 mod_http2                        x86_64                1.15.19-2.el9                      appstream                149 k
 mod_lua                          x86_64                2.4.51-7.el9_0                     appstream                 61 k

Transaction Summary
==========================================================================================================================
Install  17 Packages

Total download size: 180 M
Installed size: 616 M
Downloading Packages:
(1/17): pgadmin4-6.14-1.el9.noarch.rpm                                                    4.2 kB/s | 6.3 kB     00:01    
(2/17): pgadmin4-web-6.14-1.el9.noarch.rpm                                                 16 kB/s | 8.7 kB     00:00    
(3/17): postgresql14-libs-14.5-1PGDG.rhel9.x86_64.rpm                                     286 kB/s | 283 kB     00:00    
(4/17): libatomic-11.2.1-9.4.el9.x86_64.rpm                                                30 kB/s |  52 kB     00:01    
(5/17): rocky-logos-httpd-90.11-1.el9.noarch.rpm                                           31 kB/s |  24 kB     00:00    
(6/17): mod_lua-2.4.51-7.el9_0.x86_64.rpm                                                 378 kB/s |  61 kB     00:00    
(7/17): httpd-tools-2.4.51-7.el9_0.x86_64.rpm                                             713 kB/s |  81 kB     00:00    
(8/17): httpd-2.4.51-7.el9_0.x86_64.rpm                                                   1.1 MB/s | 1.4 MB     00:01    
(9/17): httpd-filesystem-2.4.51-7.el9_0.noarch.rpm                                        200 kB/s |  14 kB     00:00    
(10/17): apr-util-openssl-1.6.1-20.el9.x86_64.rpm                                         226 kB/s |  15 kB     00:00    
(11/17): apr-util-bdb-1.6.1-20.el9.x86_64.rpm                                             194 kB/s |  13 kB     00:00    
(12/17): apr-util-1.6.1-20.el9.x86_64.rpm                                                 923 kB/s |  94 kB     00:00    
(13/17): python3-mod_wsgi-4.7.1-9.el9.x86_64.rpm                                          1.5 MB/s | 942 kB     00:00    
(14/17): mod_http2-1.15.19-2.el9.x86_64.rpm                                               1.3 MB/s | 149 kB     00:00    
(15/17): apr-1.7.0-11.el9.x86_64.rpm                                                      1.1 MB/s | 123 kB     00:00    
(16/17): pgadmin4-server-6.14-1.el9.x86_64.rpm                                            342 kB/s |  95 MB     04:44    
(17/17): pgadmin4-desktop-6.14-1.el9.x86_64.rpm                                           223 kB/s |  82 MB     06:15    
--------------------------------------------------------------------------------------------------------------------------
Total                                                                                     489 kB/s | 180 MB     06:16     
pgadmin4                                                                                  3.8 MB/s | 3.8 kB     00:00    
Importing GPG key 0x210976F2:
 Userid     : "Package Manager (Package Signing Key) <packages@pgadmin.org>"
 Fingerprint: E869 7E2E EF76 C02D 3A63 3277 8881 B2A8 2109 76F2
 From       : /etc/pki/rpm-gpg/PGADMIN_PKG_KEY
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                  1/1 
  Installing       : apr-1.7.0-11.el9.x86_64                                                                         1/17 
  Installing       : apr-util-bdb-1.6.1-20.el9.x86_64                                                                2/17 
  Installing       : apr-util-1.6.1-20.el9.x86_64                                                                    3/17 
  Installing       : apr-util-openssl-1.6.1-20.el9.x86_64                                                            4/17 
  Installing       : httpd-tools-2.4.51-7.el9_0.x86_64                                                               5/17 
  Running scriptlet: httpd-filesystem-2.4.51-7.el9_0.noarch                                                          6/17 
useradd warning: apache's uid 48 outside of the SYS_UID_MIN 201 and SYS_UID_MAX 999 range.

  Installing       : httpd-filesystem-2.4.51-7.el9_0.noarch                                                          6/17 
  Installing       : rocky-logos-httpd-90.11-1.el9.noarch                                                            7/17 
  Installing       : mod_lua-2.4.51-7.el9_0.x86_64                                                                   8/17 
  Installing       : mod_http2-1.15.19-2.el9.x86_64                                                                  9/17 
  Installing       : httpd-2.4.51-7.el9_0.x86_64                                                                    10/17 
  Running scriptlet: httpd-2.4.51-7.el9_0.x86_64                                                                    10/17 
  Installing       : python3-mod_wsgi-4.7.1-9.el9.x86_64                                                            11/17 
  Installing       : libatomic-11.2.1-9.4.el9.x86_64                                                                12/17 
  Installing       : postgresql14-libs-14.5-1PGDG.rhel9.x86_64                                                      13/17 
  Running scriptlet: postgresql14-libs-14.5-1PGDG.rhel9.x86_64                                                      13/17 
  Installing       : pgadmin4-server-6.14-1.el9.x86_64                                                              14/17 
  Installing       : pgadmin4-desktop-6.14-1.el9.x86_64                                                             15/17 
  Running scriptlet: pgadmin4-desktop-6.14-1.el9.x86_64                                                             15/17 
  Installing       : pgadmin4-web-6.14-1.el9.noarch                                                                 16/17 
  Installing       : pgadmin4-6.14-1.el9.noarch                                                                     17/17 
  Running scriptlet: httpd-2.4.51-7.el9_0.x86_64                                                                    17/17 
  Running scriptlet: pgadmin4-6.14-1.el9.noarch                                                                     17/17 
  Verifying        : pgadmin4-6.14-1.el9.noarch                                                                      1/17 
  Verifying        : pgadmin4-desktop-6.14-1.el9.x86_64                                                              2/17 
  Verifying        : pgadmin4-server-6.14-1.el9.x86_64                                                               3/17 
  Verifying        : pgadmin4-web-6.14-1.el9.noarch                                                                  4/17 
  Verifying        : postgresql14-libs-14.5-1PGDG.rhel9.x86_64                                                       5/17 
  Verifying        : libatomic-11.2.1-9.4.el9.x86_64                                                                 6/17 
  Verifying        : rocky-logos-httpd-90.11-1.el9.noarch                                                            7/17 
  Verifying        : mod_lua-2.4.51-7.el9_0.x86_64                                                                   8/17 
  Verifying        : httpd-tools-2.4.51-7.el9_0.x86_64                                                               9/17 
  Verifying        : httpd-2.4.51-7.el9_0.x86_64                                                                    10/17 
  Verifying        : httpd-filesystem-2.4.51-7.el9_0.noarch                                                         11/17 
  Verifying        : apr-util-openssl-1.6.1-20.el9.x86_64                                                           12/17 
  Verifying        : apr-util-bdb-1.6.1-20.el9.x86_64                                                               13/17 
  Verifying        : apr-util-1.6.1-20.el9.x86_64                                                                   14/17 
  Verifying        : python3-mod_wsgi-4.7.1-9.el9.x86_64                                                            15/17 
  Verifying        : mod_http2-1.15.19-2.el9.x86_64                                                                 16/17 
  Verifying        : apr-1.7.0-11.el9.x86_64                                                                        17/17 

Installed:
  apr-1.7.0-11.el9.x86_64               apr-util-1.6.1-20.el9.x86_64          apr-util-bdb-1.6.1-20.el9.x86_64          
  apr-util-openssl-1.6.1-20.el9.x86_64  httpd-2.4.51-7.el9_0.x86_64           httpd-filesystem-2.4.51-7.el9_0.noarch    
  httpd-tools-2.4.51-7.el9_0.x86_64     libatomic-11.2.1-9.4.el9.x86_64       mod_http2-1.15.19-2.el9.x86_64            
  mod_lua-2.4.51-7.el9_0.x86_64         pgadmin4-6.14-1.el9.noarch            pgadmin4-desktop-6.14-1.el9.x86_64        
  pgadmin4-server-6.14-1.el9.x86_64     pgadmin4-web-6.14-1.el9.noarch        postgresql14-libs-14.5-1PGDG.rhel9.x86_64 
  python3-mod_wsgi-4.7.1-9.el9.x86_64   rocky-logos-httpd-90.11-1.el9.noarch 

Complete!
[root@localhost ~]# 


安裝Web介面

[root@localhost ~]# sudo /usr/pgadmin4/bin/setup-web.sh
Setting up pgAdmin 4 in web mode on a Redhat based platform...
Creating configuration database...
NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin user account:

Email address: 輸入Email
Password: 密碼
Retype password:密碼
pgAdmin 4 - Application Initialisation ====================================== Creating storage and log directories... Configuring SELinux... The Apache web server is not running. We can enable and start the web server for you to finish pgAdmin 4 installation. Continue (y/n)? y Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. Apache successfully enabled. Apache successfully started. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4 [root@localhost ~]#

修改 PostgreSQL 設定檔

19.1. The pg_hba.conf File

https://www.postgresql.org/docs/10/auth-pg-hba-conf.html

20.1. 設定檔:pg_hba.conf - PostgreSQL 正體中文使用手冊

https://docs.postgresql.tw/server-administration/client-authentication/the-pg_hba.conf-file

vi   /var/lib/pgsql/data/pg_hba.conf

找到 ident

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident


改成 trust  

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust


最後加上3行 (後2行非必須)

host    all         all         0.0.0.0/0             trust   
listen_addresses = '*'
max_connections = 60


或直接都用下面命令執行  

(下面無法用,因為 /usr/share/pgsql/pg_hba.conf.sample 中不是 ident,是 @authmethodlocal@ )

cp  /usr/share/pgsql/pg_hba.conf.sample   /var/lib/pgsql/data/pg_hba.conf

sed  -i -e  "s@ident@trust@"    /var/lib/pgsql/data/pg_hba.conf
echo "host all all 0.0.0.0/0 trust" >> /var/lib/pgsql/data/pg_hba.conf #echo "listen_addresses = '*'" >> /var/lib/pgsql/data/pg_hba.conf #echo "max_connections = 60" >> /var/lib/pgsql/data/pg_hba.conf tail -n 10 /var/lib/pgsql/data/pg_hba.conf

讓設定檔生效 ( 重新啟動 PostgreSQL )

[user1@localhost ~]$ sudo systemctl restart postgresql
[sudo] password for user1: 
Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xeu postgresql.service" for details.
[user1@localhost ~]$ 

檢查新設定檔是否能讓 PostgreSQL 正常啟動  

[root@localhost ~]# sudo 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 2022-11-01 09:12:16 CST; 6s ago
    Process: 50804 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
   Main PID: 50806 (postmaster)
      Tasks: 8 (limit: 23272)
     Memory: 16.9M
        CPU: 52ms
     CGroup: /system.slice/postgresql.service
             ├─50806 /usr/bin/postmaster -D /var/lib/pgsql/data
             ├─50807 "postgres: logger "
             ├─50809 "postgres: checkpointer "
             ├─50810 "postgres: background writer "
             ├─50811 "postgres: walwriter "
             ├─50812 "postgres: autovacuum launcher "
             ├─50813 "postgres: stats collector "
             └─50814 "postgres: logical replication launcher "

Nov 01 09:12:16 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Nov 01 09:12:16 localhost.localdomain postmaster[50806]: 2022-11-01 09:12:16.391 CST [50806] LOG:  redirecting log output to logging collec>
Nov 01 09:12:16 localhost.localdomain postmaster[50806]: 2022-11-01 09:12:16.391 CST [50806] HINT:  Future log output will appear in direct>
Nov 01 09:12:16 localhost.localdomain systemd[1]: Started PostgreSQL database server.
[root@localhost ~]# 


建立帳號


[root@localhost ~]# su - postgres
[postgres@localhost ~]$ createuser user3  
[postgres@localhost ~]$ exit
logout
[root@localhost ~]# 

http://localhost/pgadmin4/








********************************************************************************

註:變更 postgtes 密碼

[root@localhost user1]# su - postgres
[postgres@localhost ~]$ psql -c "ALTER USER postgres WITH PASSWORD 'password1234567';"
ALTER ROLE
[postgres@localhost ~]$ exit
logout
[root@localhost user1]# 

(完)

相關

[研究] PostgreSQL 10.17 安裝 + pgAdmin4 v5.5 (yum) (Rocky Linux 9.0)
https://shaurong.blogspot.com/2022/11/postgresql-1017-pgadmin4-v55-yum-rocky.html

[研究]PostgreSQL 15.0 資料庫安裝(exe版)(Win2022)
https://shaurong.blogspot.com/2022/10/postgresql-150-pgadmin-4-v614-exewin2022.html

PostgreSQL 12.1 installation and configuration from Zip Archive and create connection in pgAdmin 4
https://www.youtube.com/watch?v=yJjopD_ywN0

[研究] PostgreSQL 10.17 安裝 + pgAdmin4 v5.5 (yum) (CentOS 8.4 x64)
https://shaurong.blogspot.com/2021/07/postgresql-1017-pgadmin4-v55-yum-centos.html

[研究] 雙機 PostgreSQL 9.3.2 同步(Replication)(使用pgpool-II 3.3.1)(CentOS 6.5 x64)
https://shaurong.blogspot.com/2014/01/postgresql-932-replicationpgpool.html

[研究] PostgreSQL 9.3.2 (tgz) + PgAdminIII 1.18.1(tgz)安裝 (CentOS 6.5 x64)
https://shaurong.blogspot.com/2014/01/postgresql-932-tgz-pgadminiii-1181tgz.html


沒有留言:

張貼留言