Centos7.6 安装 PostgreSQL

准备工作

系统:Centos7.6 / 64 位
PostgreSQL:v12.7

官方教程 CV操作就完了

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql12-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12

修改配置(设置密码 + 远程访问)

设置密码
[root@MiWiFi-R4CM-srv ~]# su - postgres
-bash-4.2$ psql
psql (12.7)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD '123456';
ALTER ROLE
postgres=# \q
-bash-4.2$ exit
logout
安装默认路径/var/lib/pgsql/12/data 修改 pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# 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
host    all             all             0.0.0.0/0                 md5
配置远程登录postgresql.conf

重启

systemctl restart postgresql-12

验证

psql -U postgres -p 5432

如果Navicat连不上,请检查防火墙

systemctl stop firewalld.service            #停止firewall
systemctl disable firewalld.service        #禁止firewall开机启动

开启端口:
firewall-cmd --zone=public --add-port=5432/tcp --permanent

你可能感兴趣的:(Centos7.6 安装 PostgreSQL)