微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS7(64) yum安装、配置PostgreSQL 11

一、安装postgresql11

1、Install the repository RPM: 添加RPM

yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

2、Install the client packages: 安装Postgresql11

yum install postgresql11

3、Optionally install the server packages: 安装服务包  

yum install postgresql11-server

4、Optionally initialize the database and enable automatic start: 初始化数据库并使postgresql自启动

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

5、View Version: 查看版本

psql --version

以上或在其它操作系统中安装其它版本可参考:https://www.postgresql.org/download/linux/redhat/  

二、配置postgresql11

1、修改用户密码并创建新库

[root@localhost ~]# su - postgres
-bash-4.2$ psql -U postgres

 【修改postgre的密码

postgres=# ALTER USER postgres WITH PASSWORD '123456'

 【创建数据库

postgres=# CREATE DATABASE xxx OWNER postgres
成功后会提示:CREATE DATABASE

 【赋予用户postgres权限】

postgres=# GRANT ALL PRIVILEGES ON DATABASE xxx to postgres
成功提示:GRANT

 【退出

postgres=# \q

 【直接登录

-bash-4.2$ psql -U postgres -d xxx -h 127.0.0.1 -p 5432

2、开启远程访问

  vi /var/lib/pgsql/11/data/postgresql.conf
  修改#listen_addresses = 'localhost'  为  listen_addresses='*'
  当然,此处‘*’也可以改为任何你想开放的服务器IP

3、信任远程连接
  vi /var/lib/pgsql/11/data/pg_hba.conf
  修改如下内容,信任指定服务器连接
  # IPv4 local connections:
  host    all            all      127.0.0.1/32      trust
  host    all            all      10.211.55.6/32(需要连接的服务器IP)  trust

  当然,此处也可以改为任意服务器IP,适用于访问者IP为动态可变

  host    all            all      0.0.0.0/0    trust

 4、重启postgresql

systemctl restart postgresql-11

  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐