PostgreSQL安装配置

一、前置准备

参考网站:

官网下载安装方式:https://www.postgresql.org/download/linux/redhat/

安装版本:PostgreSQL11

系统版本:CentOS7

二、开始安装

1)通过yum进行安装

yum install postgresql-server

2)初始化数据库

postgresql-setup initdb

安装完成。(操作真简单- -、)

三、初期配置

1)启动相关

#开机启动
systemctl enable postgresql.service
#启动
systemctl start postgresql.service
#重启
systemctl restart postgresql.service
#查看状态
systemctl status postgresql.service
#停止
systemctl stop postgresql.service

2)简单配置

a,设置密码

#切换用户环境
su - postgres
#进入pgsql
psql -U postgres
#修改密码
alter user postgres with password 'new password';
#退出
\q
#退出当前用户
exit

b,修改配置文件

配置文件路径:/var/lib/pgsql/data

修改postgresql.conf

#原配置
#listen_addresses = 'localhost'		# what IP address(es) to listen on;
↓
#修改后
listen_addresses = '*'		# what IP address(es) to listen on;

修改pg_hba.conf

#原配置
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

↓
#在最后追加一行
host    all     all        0.0.0.0/0                 md5

修改重启之后就可以通过账户密码进行远程连接了。