1.安装

  • 添加软件源 rpm

    1
    $ yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
  • 安装Postgresql 9.5

    1
    $ yum install postgresql95-server postgresql95-contrib -y
  • 初始数据库

    1
    $ /usr/pgsql-9.5/bin/postgresql95-setup initdb
  • 启动服务

    1
    $ systemctl enable postgresql-9.5.service
    2
    	
    3
    $ systemctl start postgresql-9.5.service

2.配置

  • 配置用户名密码

    1
    $ su - postgres
    2
    $ psql -U postgres
    3
    $ ALTER USER postgres WITH PASSWORD ``'123456'
    4
    $ \q
  • 配置远程访问

    1
    $ vim  /var/lib/pgsql/9.5/data/postgresql.conf 
    2
    3
    listen_addresses = '*'
    4
    port = 9432
    5
    6
    $ vim /var/lib/pgsql/9.5/data/pg_hba.conf
    7
    8
    host    all             all             127.0.0.1/32            ident
    9
    host    all             all             0.0.0.0/0            	md5
  • 重启服务

    1
    $ systemctl restart postgresql-9.5.service