CentOS中PostgreSQL的安装与配置

安装

  1. 下载
    yum直接安装的postgresql时9.2版本的,不推荐。以下安装版本为9.6.
    yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
    yum install -y postgresql96-server postgresql96-contrib
  2. 初始化数据库
    /usr/pgsql-9.6/bin/postgresql96-setup initdb
  3. 启动服务
    systemctl start postgresql-9.6
  4. 开机自启
    systemctl enable postgresql-9.6
  5. 查看版本
    psql --version

配置

  1. 修改用户密码
    postgreSQL安装完成后,会创建一个postgres用户,以此用户身份操作数据库。
    su - postgres
    psql -U postgres
    alter user postgres with password '123321'
  2. 开启远程访问
    vim /var/lib/pgsql/9.6/data/postgresql.conf
    修改#listen_addresses = 'localhost'listen_addresses='*', 允许ip访问。
  3. 信任远程连接
    vim /var/lib/pgsql/9.6/data/pg_hba.conf
    在IPv4部分添加修改以下内容:
    host all all *.*.*.*/32(需要连接的服务器IP) trust ip设为0.0.0.0/0,所有IP即可访问
    注意:trust 为不需要密码访问; md5 为需要密码访问
原文地址:https://www.cnblogs.com/ingen42/p/11631973.html