LINUX安装postgreSQL数据库(一次搞定)

1,(下载最新版本,当前为13)

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum search postgresql

2,安装postgresql

yum install postgresql13
yum install postgresql13-server

3、查看版本

psql --version

4、初始化

/usr/pgsql-13/bin/postgresql-13-setup initdb

5,修改配置文件
5.1

vim /var/lib/pgsql/13/data/postgresql.conf

修改内容:listen_addresses = ‘*’ //都可访问
LINUX安装postgreSQL数据库(一次搞定)_第1张图片

5.2

vim /var/lib/pgsql/13/data/pg_hba.conf 

修改内容:
host all all 0.0.0.0/0 md5 //添加所有IP都可以连接
LINUX安装postgreSQL数据库(一次搞定)_第2张图片
6,启动并查看

systemctl enable postgresql-13
systemctl start postgresql-13
netstat -tpnl |grep 5432       //查看 

7,切换用户

su postgres  
psql -U postgres    //连接pgsql server  
postgres=# Alter USER postgres WITH PASSWORD '***密码**';  //添加密码 
ALTER ROLE        //出现这个才算成功,第一次操作没成功,pgadmin连不上  
postgres-# \q     //退出

8,远程链接
如果连接不上,查看一下防火墙
1:查看防火状态

systemctl status firewalld

2:暂时关闭防火墙

systemctl stop firewalld

LINUX安装postgreSQL数据库(一次搞定)_第3张图片
linux下postgreSQL其他命令

systemctl start postgresql-13 //启动
systemctl stop postgresql-13 //停止
systemctl restart postgresql-13 //重启

你可能感兴趣的:(LINUX)