CentOS7安裝PostgreSQL15以及PostGIS3.3

粒子先生發表於2024-05-28

安裝Postgresql

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libzstd-1.5.5-1.el7.x86_64.rpm
yum -y install postgresql15-server

安裝postgis

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install postgis33_15

初始化資料庫

/usr/pgsql-15/bin/postgresql-15-setup initdb

啟動資料庫

systemctl enable postgresql-15
systemctl start postgresql-15

PostgreSQL配置與管理

(1)修改使用者名稱密碼

[root@VM-16-10-centos ~]# su - postgres
Last login: Mon Dec 25 10:53:16 CST 2023 on pts/0
-bash-4.2$ psql -U postgres
psql (15.5)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'postgres';

(2)配置postgresql.conf,將listen_addresses = '*'。(注意前面的#要取消)

[root@VM-16-10-centos data]# cd /var/lib/pgsql/15/data
[root@VM-16-10-centos data]# vim postgresql.conf
# - Connection Settings -
 
listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp'  # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

(3)配置pg_hba.conf,後面新增兩行遠端連線配置。配置完成之後需要重啟postgres。

[root@VM-16-10-centos data]# vim pg_hba.conf
# 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            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             127.0.0.1/32            ident
host    all             all             0.0.0.0/0               md5

連線驗證

參考連結:https://blog.csdn.net/mxy2572185/article/details/135155930

相關文章