---
title: "centos7 二进制包安装Postgresql9.6"
author: "fokman"
date: "2018-07-24T13:35:05Z"
tags: []
categories: ["数据库"]
slug: "centos7-postgresql9-6"
draft: false
lastmod: "2018-07-24T13:44:20Z"
id: 2427401
url: "https://fokman.iteye.com/blog/2427401"
---

使用Postgresql 官方的RPM包，将版本信息加入到版本库中：

 

```
rpm -i https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
```

 然后使用yum install 命令安装

```
yum install postgresql96-server.x86_64
```

 初始化数据库

```
 /usr/pgsql-9.6/bin/postgresql96-setup initdb
```

 设置开机启动

```
[root@centos07 concar]# systemctl enable postgresql-9.6
```

 查看启动状态

```
[root@centos07 concar]# systemctl status postgresql-9.6
```

 登录到数据库

```
[root@centos07 concar]# su - postgres
-bash-4.2$ psql
psql (9.6.9)
Type "help" for help.

postgres=# \l // 查看数据库列表
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
```

修改数据库密码

```
postgres=# alter user postgres with password 'postgres'
```

  

退出数据库

```
postgres=# \q
-bash-4.2$ exit
logout
```

 数据库的数据目录安装在：

/var/lib/pgsql/9.6/data目录下