CentOS7下使用yum安装PostgreSQL9.6

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)

阅读更多

扫码向博主提问

去开通我的Chat快问

sunbocong

战个痛
个人分类: PostgreSQL
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

CentOS7下使用yum安装PostgreSQL9.6

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭