CentOS7下使用yum安装PostgreSQL9.6

原创 2017年10月12日 11:17:38

CentOS7下使用yum安装PostgreSQL9.6

实验环境

操作系统:CentOS Linux release 7.3.1611 (Core)

数据库系统: PostgreSQL 9.6.5

IP: 192.168.230.142

创建PostgreSQL9.6的yum源文件

[root@localhost ~]# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
Loaded plugins: fastestmirror, langpacks
pgdg-centos96-9.6-3.noarch.rpm                                                                              | 4.7 kB  00:00:00     
Examining /var/tmp/yum-root-6xDwYA/pgdg-centos96-9.6-3.noarch.rpm: pgdg-centos96-9.6-3.noarch
Marking /var/tmp/yum-root-6xDwYA/pgdg-centos96-9.6-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-centos96.noarch 0:9.6-3 will be installed
--> Finished Dependency Resolution
base/7/x86_64                                                                                               | 3.6 kB  00:00:00     
extras/7/x86_64                                                                                             | 3.4 kB  00:00:00     
updates/7/x86_64                                                                                            | 3.4 kB  00:00:00     

Dependencies Resolved

===================================================================================================================================
 Package                        Arch                    Version                 Repository                                    Size
===================================================================================================================================
Installing:
 pgdg-centos96                  noarch                  9.6-3                   /pgdg-centos96-9.6-3.noarch                  2.7 k

Transaction Summary
===================================================================================================================================
Install  1 Package

Total size: 2.7 k
Installed size: 2.7 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pgdg-centos96-9.6-3.noarch                                                                                      1/1 
  Verifying  : pgdg-centos96-9.6-3.noarch                                                                                      1/1 

Installed:
  pgdg-centos96.noarch 0:9.6-3                                                                                                     

Complete!

安装PostgreSQL客户端

[root@localhost ~]# yum install postgresql96
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql96.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Processing Dependency: postgresql96-libs(x86-64) = 9.6.5-1PGDG.rhel7 for package: postgresql96-9.6.5-1PGDG.rhel7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql96-9.6.5-1PGDG.rhel7.x86_64
--> Running transaction check
---> Package postgresql96-libs.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                             Arch                     Version                               Repository                Size
===================================================================================================================================
Installing:
 postgresql96                        x86_64                   9.6.5-1PGDG.rhel7                     pgdg96                   1.4 M
Installing for dependencies:
 postgresql96-libs                   x86_64                   9.6.5-1PGDG.rhel7                     pgdg96                   312 k

Transaction Summary
===================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 1.7 M
Installed size: 8.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): postgresql96-9.6.5-1PGDG.rhel7.x86_64.rpm                                                            | 1.4 MB  00:00:05     
(2/2): postgresql96-libs-9.6.5-1PGDG.rhel7.x86_64.rpm                                                       | 312 kB  00:00:07     
-----------------------------------------------------------------------------------------------------------------------------------
Total                                                                                              215 kB/s | 1.7 MB  00:00:07     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql96-libs-9.6.5-1PGDG.rhel7.x86_64                                                                      1/2 
  Installing : postgresql96-9.6.5-1PGDG.rhel7.x86_64                                                                           2/2 
  Verifying  : postgresql96-9.6.5-1PGDG.rhel7.x86_64                                                                           1/2 
  Verifying  : postgresql96-libs-9.6.5-1PGDG.rhel7.x86_64                                                                      2/2 

Installed:
  postgresql96.x86_64 0:9.6.5-1PGDG.rhel7                                                                                          

Dependency Installed:
  postgresql96-libs.x86_64 0:9.6.5-1PGDG.rhel7                                                                                     

Complete!

安装PostgreSQL服务端

[root@localhost ~]# yum install postgresql96-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql96-server.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                               Arch                     Version                             Repository                Size
===================================================================================================================================
Installing:
 postgresql96-server                   x86_64                   9.6.5-1PGDG.rhel7                   pgdg96                   4.3 M

Transaction Summary
===================================================================================================================================
Install  1 Package

Total download size: 4.3 M
Installed size: 18 M
Is this ok [y/d/N]: y
Downloading packages:
postgresql96-server-9.6.5-1PGDG.rhel7.x86_64.rpm                                                            | 4.3 MB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql96-server-9.6.5-1PGDG.rhel7.x86_64                                                                    1/1 
  Verifying  : postgresql96-server-9.6.5-1PGDG.rhel7.x86_64                                                                    1/1 

Installed:
  postgresql96-server.x86_64 0:9.6.5-1PGDG.rhel7                                                                                   

Complete!

安装PostgreSQL拓展包(可选)

[root@localhost ~]# yum install postgresql96-devel.x86_64 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql96-devel.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                              Arch                     Version                              Repository                Size
===================================================================================================================================
Installing:
 postgresql96-devel                   x86_64                   9.6.5-1PGDG.rhel7                    pgdg96                   1.8 M

Transaction Summary
===================================================================================================================================
Install  1 Package

Total download size: 1.8 M
Installed size: 8.4 M
Is this ok [y/d/N]: y
Downloading packages:
postgresql96-devel-9.6.5-1PGDG.rhel7.x86_64.rpm                                                             | 1.8 MB  00:00:25     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql96-devel-9.6.5-1PGDG.rhel7.x86_64                                                                     1/1 
  Verifying  : postgresql96-devel-9.6.5-1PGDG.rhel7.x86_64                                                                     1/1 

Installed:
  postgresql96-devel.x86_64 0:9.6.5-1PGDG.rhel7                                                                                    

Complete!

安装PostgreSQL的附加模块(可选)

[root@localhost ~]# yum install postgresql96-contrib.x86_64 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql96-contrib.x86_64 0:9.6.5-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                               Arch                    Version                               Repository               Size
===================================================================================================================================
Installing:
 postgresql96-contrib                  x86_64                  9.6.5-1PGDG.rhel7                     pgdg96                  565 k

Transaction Summary
===================================================================================================================================
Install  1 Package

Total download size: 565 k
Installed size: 2.0 M
Is this ok [y/d/N]: y
Downloading packages:
postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64.rpm                                                           | 565 kB  00:02:58     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64                                                                   1/1 
  Verifying  : postgresql96-contrib-9.6.5-1PGDG.rhel7.x86_64                                                                   1/1 

Installed:
  postgresql96-contrib.x86_64 0:9.6.5-1PGDG.rhel7                                                                                  

Complete!

配置PostgreSQL

初始化数据库

[root@localhost ~]# /usr/pgsql-9.6/bin/postgresql96-setup initdb
Initializing database ... OK

启动postgresql服务,并设置为开机自动启动

[root@localhost ~]# systemctl enable postgresql-9.6
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service.
[root@localhost ~]# systemctl start postgresql-9.6

postgres用户初始配置

安装完成后,操作系统会自动创建一个postgres用户用来管理数据库,为其初始化密码:

[root@localhost ~]# passwd postgres 
Changing password for user postgres.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

切换至postgres用户,发现提示符设置有问题,编辑之:

[root@localhost ~]# su - postgres
-bash-4.2$ vim ./.bash_profile

改为如下配置


[ -f /etc/profile ] && source /etc/profile
PGDATA=/var/lib/pgsql/9.6/data
export PGDATA
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile

export PS1='[\u@\h \W]\$'

使配置生效,看起来清爽多了

-bash-4.2$ source ./.bash_profile 
[postgres@localhost ~]$

数据库初始配置

使用数据库自带的postgres用户登录数据库,并为其赋予密码

[postgres@localhost ~]$psql -U postgres
psql (9.6.5)
Type "help" for help.

postgres=# alter user postgres with password 'oracle';
ALTER ROLE

如此,PostgreSQL数据库便安装完成了

参考Linux downloads (Red Hat family)

CentOS下,yum安装PostgreSQL

Configure YUM repository vim /etc/yum.repos.d/CentOS-Base.repo [base] and [updates] sections添加...
  • gaojinshan
  • gaojinshan
  • 2014年11月10日 15:03
  • 7921

CentOS6使用YUM安装Postgresql9.4

最近需要使用postgresqsl,所以安装了postgresql9.4。下面说说在centOS6环境下,在网络联通的情况下,使用YUM安装postgresql。(仅供大家参考)       查看...
  • xianSky2015
  • xianSky2015
  • 2017年02月13日 22:35
  • 1546

CentOs 下安装并配置postgresql

一、安装并配置数据库: 1.安装: CentOS 默认yum 安装的话,会安装较低版本的PostgreSQL 8.4,这不符合我们的要求。 (数据库版本过低会导致数据导入异常和数据丢失,建议使用9...
  • wangyezi19930928
  • wangyezi19930928
  • 2015年05月11日 10:08
  • 1573

Yum安装PostgreSQL

1.添加PosgreSQL Yum Repository   访问http://yum.pgrpms.org/reporpms/repoview/letter_p.group.html,下载并安装...
  • fengye245
  • fengye245
  • 2012年05月14日 22:14
  • 9756

CentOS7安装并配置PostgreSQL

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6...
  • DaSo_CSDN
  • DaSo_CSDN
  • 2017年07月18日 20:01
  • 1734

CentOS 6.6通过yum 安装PostgreSQL 9.4

最近再写python程序,需要用到postgresql,所以要安装postgresql数据库。 一、在/etc/yum.repos.d/CentOS-Base.repo 中的[base],[upd...
  • yupeigu
  • yupeigu
  • 2017年03月24日 17:08
  • 1177

CentOS7安装部署PostgresSQL9.6

验证环境 安装 配置1 验证环境 操作系统 CentOS-7-x86_64-DVD-1708 PostgresSQL版本 PostgreSQL 9.6.3:https://www.postgres...
  • jlwang365
  • jlwang365
  • 2017年12月21日 14:27
  • 42

Centos7 PostgreSQL安装

Linux安装PostgreSQL 9.4步骤 一、安装PostgreSQL  CentOS 7 64bit rpm -Uvh http://yum.postgresql.org/9.4/...
  • LK10207160511
  • LK10207160511
  • 2015年12月19日 20:25
  • 10864

Linux CentOS 7 安装PostgreSQL 9.3(发行版本)

关于在Linux CentOS 7中安装PostgreSQL 9.3的全过程以及相关配置~
  • wlwlwlwl015
  • wlwlwlwl015
  • 2016年09月02日 09:35
  • 4500

CentOS7.2 安装postgresql数据库

1. 安装核心数据库服务及额外支持模块  yum install postgresql-server  2.初始化数据库,并加入开机启动服务 service postgresql ini...
  • juxua_xatu
  • juxua_xatu
  • 2016年07月22日 10:49
  • 556
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CentOS7下使用yum安装PostgreSQL9.6
举报原因:
原因补充:

(最多只允许输入30个字)