美文网首页
2019-06-25CentOS 7 安装 PostgreSQL

2019-06-25CentOS 7 安装 PostgreSQL

作者: Kason晨 | 来源:发表于2019-06-25 13:53 被阅读0次
image.png

环境

腾讯云 CentOS
PostgreSQL 11

PostgreSQL安装

这里以rpm的方式安装PostgreSQL 11

# 下载rpm包
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-redhat11-11-2.noarch.rpm -y

# 安装
yum -y install postgresql11 postgresql11-server postgresql11-libs

# 初始化数据库
/usr/pgsql-11/bin/postgresql-11-setup initdb

# 设置开机自启动PostgreSQL和启动服务
systemctl enable postgresql-11
systemctl start postgresql-11
systemctl status postgresql-11
## 看到控制台输出的Active后有Running的字样说明启动完成

PostgreSQL连接

# 登录数据库,这里切换账号postgres
su - postgres
psql

# Navicat连接PostgreSQL
# 这里要修改配置文件postgresql.conf
find / -name postgresql.conf
vi /var/lib/pgsql/11/data/postgresql.conf

# 找到listen_address那里,解开注释并修改引号内localhost的值为*
listen_address="*"

# 保存并退出,重启postgresql服务
systemctl restart postgresql-11

# 修改远程连接pg_hba.conf
find / -name pg_hba.conf
vi /var/lib/pgsql/11/data/pg_hba.conf
# 在文件末尾加上,如果不加上远程连接PostgreSQL会出现no pg_hba.conf...的错误
host    all             all             0.0.0.0/0               trust

# 阿里云安全组规则配置 -> 快速添加安全组规则 -> 选中PostgreSQL并添加

# 在navicat连接,如果不修改localhost为*,navicat连接会提示错误“Connection Refuse”

# 我在这里修改了postgres用户的密码,步骤如下:
## 切换用户后进入psql
su - postgres
psql
## 修改密码
alter user postgres password '密码'

退出数据库可以使用 \q 再加上 exit

退出 登录进了数据库 修改数据库的设定 修改云服务器的规则 准备链接数据库 链接数据库成功

相关文章

网友评论

      本文标题:2019-06-25CentOS 7 安装 PostgreSQL

      本文链接:https://www.haomeiwen.com/subject/vhssfctx.html