Redhat、centos安装配置postgresql

一.安装postgresql

本文仅以 redhat,postgresql9.4为例,使用yum方式进行介绍。

官网:http://www.postgresql.org/download/linux/redhat/

1.下载postgresql的yum源

yum install http://yum.postgresql.org/9.4/redhat/
                      rhel-6-x86_64/pgdg-redhat94-9.4-1.noarch.rpm

2.安装

 yum install postgresql94-server postgresql94-contrib

二,配置postgresql

1.初始化数据库

service postgresql-9.4 initdb

2.设置默认启动

chkconfig postgresql-9.4 on

三,启动,重启,关闭服务,修改密码

命令:

service postgresql-9.4 start / restart / stop

修改密码:

postgres=#alter user postgres with password 'new password'; 
    postgres=#\q  

四.修改postgresql配置文件

1.pg_hba.conf 文件

默认位置:/var/lib/pgsql/9.4/data/pg_hba.conf , 第80行修改如下:

# IPv4 local connections:
      host  all   all    本机IP/0   md5(使用md5加密连接数据库)
host all all 0.0.0.0/0 md5(使用md5加密连接数据库) -- 监听全部地址,其他机器也可以连接本机。

2.postgresql.conf 文件

默认位置:/var/lib/pgsql/9.4/data/postgresql.conf ,第59行修改如下

    listen_addresses = '*' (监听的IP )
    port = 5432(监听端口)

3.修改完毕,重起服务