centos7安装postgresql

1.安装

yum install postgresql-server
yum install postgresql-contrib

2.启动

systemctl status postgresql


如果报错:
[root@VM_176_134_centos ~]# systemctl start postgresql
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.

则执行数据库初始化命令
postgresql-setup initdb

3.设置密码

[root@VM_176_134_centos data]# su postgres
bash-4.2$ psql
psql (9.2.23)
Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD '密码';
ALTER ROLE

4.开放远程连接

cd /var/lib/pgsql/data


vi pg_hba.conf 将文件结尾处的 # host all all
127.0.0.1/32 ident 改为 # host all all 127.0.0.1/32 ident host all all 0.0.0.0/0 password vi postgresql.conf 将 #listen_addresses = 'localhost' # what IP address(es) to listen on; 改为 listen_addresses = '*' # what IP address(es) to listen on;

systemctl restart postgresql

5.测试连接

参考文档:

CentOS7安装配置Postgresql

PostgreSQL设置允许远程访问

原文地址:https://www.cnblogs.com/lurenjia1994/p/9505882.html