linux 安装PostgreSQL

  1. 把最新的rpm包添加到系统库
    PostgreSQL会为全部的Linux平台发布rpm包, 并且会比其余的的库更新的更快.
    地址:postresSQL linux
    rpm -Uvh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
  2. 列出可用安装包
    yum list postgres*
  3. 安装PostgreSQL
    yum install -y postgresql11-server.x86_64
  4. 初始化数据库
    /usr/pgsql-11/bin/postgresql-11-setup initdb 仅需执行一次
  5. 启动PostgreSQL
    systemctl start postgresql-11
  6. 设置自启动
    systemctl enable postgresql-11
  7. 查看运行状态
    systemctl status postgresql-11

    clipboard.png

  8. 开机启动
    chkconfig postgresql-11 on
  9. 重置密码
    1) sudo -u postgres psql
    2) ALTER USER postgres WITH PASSWORD 'postgres';
    3) 退出 \q
  10. 开启远程访问
    vi /var/lib/pgsql/11/data/postgresql.conf
    修改#listen_addresses = 'localhost' 为 listen_addresses='*',建议只监听内网IP
  11. 修改客户端认证配置文件pg_hba.conf
    vi /var/lib/pgsql/11/data/pg_hba.conf
    将IPv4区下的127.0.0.1/32修改成0.0.0.0/0; 将ident修改成md5
  12. 重启服务
    service postgresql-11 restart
  13. 开放端口
    firewall-cmd --zone=public --add-port=5432/tcp --permanent
  14. 重载防火墙
    firewall-cmd --reload