一、在centos7上安装PostgreSQL:12

官网文档地址:[https://www.postgresql.org/download/linux/redhat/](https://www.postgresql.org/download/linux/redhat/)
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpmsudo yum install -y postgresql12-serversudo /usr/pgsql-12/bin/postgresql-12-setup initdbsudo systemctl enable postgresql-12sudo systemctl start postgresql-12
二、navicat远程连接postgres数据库
- ①:编辑
/var/lib/pgsql/12/data/postgresql.conf配置文件:
```bashvim /var/lib/pgsql/12/data/postgresql.conf
listen_addresses = ‘localhost’
port = 5432
以上是修改前的配置,如上:
以下是修改后的配置,如下:
listen_addresses = ‘*’ port = 5432
- ②:编辑`/var/lib/pgsql/12/data/pg_hba.conf`配置文件:> 使用`navicat`连接`posgres`数据库时,需要将`METHOD`类型配置为`md5`。具体参考下边的案例。```bashvim /var/lib/pgsql/12/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD# "local" is for Unix domain socket connections onlylocal all all peer# IPv4 local connections:host all all 127.0.0.1/32 identhost all all 0.0.0.0/0 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 peerhost replication all 127.0.0.1/32 identhost replication all ::1/128 ident以上是修改前的配置,如上:=========================================================================以下是修改后的配置,如下:# TYPE DATABASE USER ADDRESS METHOD# "local" is for Unix domain socket connections onlylocal all all peer# IPv4 local connections:host all all 127.0.0.1/32 md5host all all 0.0.0.0/0 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 peerhost replication all 127.0.0.1/32 identhost replication all ::1/128 ident
- ③:重启
PostgreSQL服务sudo systemctl restart postgresql-12
三、修改PostgreSQL数据库默认用户postgres的密码
PostgreSQL数据库创建一个postgres用户作为数据库的管理员,密码随机,所以需要修改密码,方式如下:
①:登录
PostgreSQLsudo -u postgres psql
②:修改登录
PostgreSQL密码ALTER USER postgres WITH PASSWORD 'postgres';
- 密码
postgres要用引号引起来。 - 命令最后有
;分号。
③:退出
PostgreSQL客户端\q
④:重启
PostgreSQL服务sudo systemctl restart postgresql-12
四、防火墙开发PostgreSQL数据库的端口号
①:开发指定端口号
sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent
②:更新防火墙规则
sudo firewall-cmd --reload
③:查看所有打开的端口
sudo firewall-cmd --zone=public --list-ports
