官网查看安装版本
查看自己系统版本
uname -a
https://www.postgresql.org/download/linux/redhat/
详细步骤
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql96-server
### 可能遇到问题
Last metadata expiration check: 0:07:07 ago on Wed 28 Oct 2020 04:48:26 PM CST.
All matches were filtered out by modular filtering for argument: postgresql96-server
Error: Unable to find a match: postgresql96-server
### 执行 yum -qy module disable postgresql
/usr/pgsql-9.6/bin/postgresql96-setup initdb
systemctl enable postgresql-9.6
systemctl start postgresql-9.6
部署配置
1.允许远程登陆
修改
vi /var/lib/pgsql/11/data/postgresql.conf
listen_addresses = '*'
修改pg.hba文件需要重启服务
vim /var/lib/pgsql/11/data/pg_hba.conf
2.局域网权限
修改
vi /var/lib/pgsql/9.6/data/pg_hba.conf
# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
# "ident", "peer", "pam", "ldap", "radius" or "cert". Note that
# "password" sends passwords in clear text; "md5" is preferred since
# it sends encrypted passwords.
加密方式选择和默认一样ident
# IPv4 local connections:
host all all 0.0.0.0/0 ident
host all all 127.0.0.1/32 ident
3.重启服务
systemctl restart postgresql-9.6
4.新增用户,修改默认密码
修改登录密码
sudo -u postgres psql
alter user postgres with password '123456';
创建新用户
create user jatham with password '123456';
创建数据库同时指定数据库的所有者
create database test owner jatham ;
数据库赋权未赋权则账户只能登录控制台
grant all privileges on database test to jatham ;
\q 退出
5.(可选)
开放端口-防火墙
firewall-cmd --get-active-zones
添加端口到防火墙中
firewall-cmd --zone=public --add-port=5432/tcp --permanent
防火墙重新读取端口列表
firewall-cmd --reload
6.重启
重启数据库
systemctl restart postgresql-9.6
navicat连接
postgres@linux-tvqg:/home/hang> psql -U aann -d aann_db
psql: FATAL: Peer authentication failed for user "jatham "
使用失败。。。
原理https://blog.csdn.net/u011250186/article/details/103584827
去修改
vi /var/lib/pgsql/9.6/data/pg_hba.conf
local all postgres peer
-----------------------------------
// change to
local all postgres md5
# IPv4 local connections:
host all all 0.0.0.0/0 trust
host all all 127.0.0.1/32 ident
之后重启
systemctl restart postgresql-9.6
效果
博主公众号
求关注