postgres9.6安装

1.安装环境:

数据库版本:postgresql9.6

系统环境:CentOS 6/7   x86_64

2.repository 安装

  • centos-6.5
    yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
  • centos-7
    yum install -y  https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm

3.postgresql server 安装

   yum install -y postgresql96-server

4.修改数据库data路径

postresql的存储路径为 /var/lib/pgsql/9.6/data

可以通过修改postgresql的PGDATA改变存储路径。比如以/mnt/data/pgsql为例,编辑/usr/lib/systemd/system/postgresql-9.6.service

Environment=PGDATA=/mnt/data/pgsql # 修改PGDATA

新建和修改文件权限

mkdir -p /mnt/data/pgsql
chown -R postgres:postgres /mnt/data/pgsql

5.postgresql初始化

  • centos-6
    service postgresql-9.6 initdb
  • centos-7
    /usr/pgsql-9.6/bin/postgresql96-setup initdb

6.启动服务加入开机自启动

  • centos-6
chkconfig postgresql-9.6 on
service postgresql-9.6 start
  • centos-7
systemctl enable postgresql-9.6
systemctl start postgresql-9.6

原文地址:https://www.cnblogs.com/miclis/p/10480489.html