PostgreSQL 9.6.2版本在centOS下的安装和配置

1.如果有用yum安装过旧版,卸载掉:

   yum remove postgresql*


2.更新一下yum:
  sudo yum update

3.去 官网 找到 适合你系统 的资源的下载地址,然后使用wget命令下载:

  wget http://yum.pgrpms.org/9.2/redhat/rhel-5-x86_64/pgdg-centos92-9.2-6.noarch.rpm


4.然后执行:
  sudo rpm -ivh pgdg-centos92-9.2-6.noarch.rpm

5.使用yum安装(96和9.6也就是当前安装的pg的版本号):
  sudo yum -y install postgresql96-server

6.初始化数据库:
  sudo service postgresql-9.6 initdb

7.如果提示-bash: service: command not found,则需要设置环境变量:
  vi .bash_profile

  在PATH这行已有的内容后面增加/sbin:
  export PATH=$PATH:/sbin:

8.启动postgreSQL:
  sudo service postgresql-9.6 start

9.设置开机自动启动服务:

  sudo chkconfig postgresql-9.6 on

10.启动postgreSQL:

  psql

 11.可能遇到的错误:

  FATAL: role "user" does not exist 

   

  你可以使用超级用户来使用pg:

    sudo su postgres

  或者 执行以下命令来为普通用户创建pg用户信息:

    sudo su - postgres

    createuser 你的用户名 

    createdb -O  你的用户名 你的用户名

  

  FATAL: Peer authentication failed for user "postgres" 

  

  找到 pg_hba.conf 文件(可能在/var/lib/psql/9.6/data的子目录文件夹内,建议全局搜索),修改:

  local all postgres peer

  改为:
  local all postgres md5

  再次登录,应该会需要你输入密码,所以需要为pg用户设置密码: 参考资料

  再次执行以下命令,应该就可以开始正常使用了:

    psql

参考链接:

    http://www.zuimoban.com/jiaocheng/postgresql/3771.html

    http://www.jb51.net/os/RedHat/277412.html

    http://stackoverflow.com/a/28214126/5542006

  http://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge/18664239#18664239


转载请注明出处:http://www.cnblogs.com/ficow/p/6631753.html

原文地址:https://www.cnblogs.com/ficow/p/6631753.html