CentOS 7安装PostgreSQL的方法

操作系统:
centos-release-7-5.1804.el7.centos.x86_64官网 | 163下载mini版
PostgreSQL版本:
postgresql.x86_64 9.2.23-3.el7_4
postgresql-libs.x86_64 9.2.23-3.el7_4
postgresql-server.x86_64 9.2.23-3.el7_4

安装并启动数据库(如果在阅读《七周七数据库》书,安装时增加扩展包或点这里
[root@localhost ~]# yum install -y postgresql-server
[root@localhost ~]# postgresql-setup initdb
[root@localhost ~]# systemctl enable postgresql
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.servic
e.
[root@localhost ~]# systemctl start postgresql
编辑postgresql.conf文件设置监听IP:
[root@localhost ~]# vi /var/lib/pgsql/data/postgresql.conf
# – Connection Settings –
listen_addresses = '*'
编辑pg_hba.conf文件设置允许连接的IP(所有IP都能连接):
[root@localhost ~]# vi /var/lib/pgsql/data/pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md5
设置用户postgres的密码
[root@localhost ~]# su - postgres
-bash-4.2$ psql
psql (9.2.23)
Type “help” for help.
postgres=# alter user postgres with password 'your password';
ALTER ROLE
postgres=# \q
-bash-4.2$ \exit
logout
重启数据库:
[root@localhost ~]# systemctl restart postgresql
设置防火墙:
[root@localhost services]# firewall-cmd --add-service=postgresql --permanent
success
[root@localhost services]# firewall-cmd --reload
success
如果不想在Linux系统下操作,可以使用以下免费软件(支持Windows/macOS/Linux平台)
pgAdmin(web端) 下载地址:https://www.pgadmin.org/download

DBeaver客户端 下载地址:https://dbeaver.io/download/
本文地址:http://liyue.name/blog/?p=2906

Leave a Reply

Your email address will not be published. Required fields are marked *