CentOS6安装postgres11

2018年12月29日

1. 从官方网站安装库包

# yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6.9-x86_64/pgdg-centos11-11-2.noarch.rpm

# yum -y update

2. Postgresql安装

# yum install postgresql11 postgresql11-server postgresql11-libs

3. 确认

[root@localhost ~]# rpm -qa | grep postgres
postgresql11-libs-11.1-1PGDG.rhel6.x86_64
postgresql11-11.1-1PGDG.rhel6.x86_64
postgresql11-server-11.1-1PGDG.rhel6.x86_64
[root@localhost ~]#

4. 数据库初始化

# service postgresql-11 initdb

5.修改配置文件
/var/lib/pgsql/11/data/pg_hba.conf

# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
 :

修改如下

 :
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
 :

6. 启动服务

# service postgresql-11 start

7. 服务状态确认

service postgresql-1 status

8. 服务登录

chkconfig postgresql-11 on

9.连接确认

[root@localhost ~]# su - postgres
-bash-4.1$ psql
psql (11.1)
"help" .....

postgres=# \q
-bash-4.1$ exit
logout
[root@localhost ~]#

————————————————-

10. 创建用户

create user user01 with password 'password01';

11.创建数据库

create database db01 encoding 'UTF8' owner user01;

12. 登录数据库

psql -d db01 -U user01