安装
1$ yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
2
3# 安装服务端包
4$ yum install postgresql10-server postgresql10
配置
1# 初始化数据库,设置自启动
2$ /usr/pgsql-10/bin/postgresql-10-setup initdb
3$ systemctl enable postgresql-10
4$ systemctl start postgresql-10
5
6# 设置防火墙规则
7$ iptables -A INPUT -p tcp -m tcp --dport 5432 -j ACCEPT #开放Postgresql 5432端口
8
9$ service iptables save # 保存防火墙规则
配置远程访问
1# 切换至用户
2$ su - postgres
1; ./10/data/postgres.conf
2- #listen_address
3+ listen_address
4
5; ./10/data/pg_hba.conf
6; 允许所有IPv4地址
7+ host all all 0.0.0.0/0 scram-sha-256
登录数据库
1-- 设置数据运行参数
2ALTER SYSTEM SET listen_addresses = '*';
3ALTER SYSTEM SET port = 5432;
4ALTER SYSTEM SET password_encryption = 'scram-sha-256';
5
6-- 修改默认用户密码
7ALTER USER postgres with encrypted password '你的密码';
8
9-- 退出数据库
10\q
11
12-- 退出用户
13exit
重启服务
1systemctl restart postgresql-10