PostgreSQL数据库管理系列之一——安装

前端之家收集整理的这篇文章主要介绍了PostgreSQL数据库管理系列之一——安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Linux平台下的安装

以下操作环境基于CentOS7-86_64

我们知道在Linux系统下安装软件有两条路可以走,一是下载源代码自行编译,二是使用官方的软件仓库
安装。我个人是非常推荐使用官方的仓库来安装的,使用官方的软件仓库安装软件有如下优点:

  1. 拥有开发者调试过的最佳性能

  2. 自动解决令人头痛的依赖

  3. 提供了通用的系统管理接口

Postgresql 现存很多版本,分别是7.3、7.4、8.0、8.1、8.2、8.3、8.4、9.0、9.1、9.2、
9.3、9.4、9.5,其中,7.3到9.0版本 被标记为上游不再支持(no longer maintained by upst
ream),
而9.5版本被标记为“BETA TESTING ONLY,NOT FOR PRODUCTION”,即仅供测试,不得用于生产
环境。(本文写于2015--11-12,你读到本文时,很可能情况已经变化,请访问此处获取最新的版本情况)。基于当前Postgresql的版本状况,我推荐使用9.4版
本来进行下面的练习。

  1. # yum localinstall http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-cen
  2. tos94-9.4-2.noarch.rpm

其中,pgdg-centos94-9.4-2.noarch.rpm是适用于CentOS 7-x86_64的软件包。同样地,也可以访问上一个链接获取符合你使用的发行版的软件包。如果安装此软件后,会
自动配置Postgresql的安装源,现在,我们来看下源中是否具有postgresql的安装包:

  1. # yum list postgresql*
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: centos.ustc.edu.cn
  5. * epel: ftp.cuhk.edu.hk
  6. * extras: mirrors.pubyun.com
  7. * ius: mirrors.tuna.tsinghua.edu.cn
  8. * remi-safe: mirrors.neterra.net
  9. * updates: mirrors.sina.cn
  10. Installed Packages
  11. postgresql-libs.x86_64 9.2.13-1.el7_1 @updates
  12. ******略去大量无用输出********
  13. postgresql-upgrade.x86_64 9.2.13-1.el7_1 updates
  14. postgresql94-contrib.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  15. postgresql94-debuginfo.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  16. postgresql94-devel.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  17. postgresql94-docs.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  18. postgresql94-jdbc.noarch 9.3.1101-2.rhel7 pgdg94
  19. postgresql94-jdbc-javadoc.noarch 9.3.1101-2.rhel7 pgdg94
  20. postgresql94-odbc.x86_64 09.03.0400-1PGDG.rhel7 pgdg94
  21. postgresql94-odbc-debuginfo.x86_64 09.03.0400-1PGDG.rhel7 pgdg94
  22. postgresql94-plperl.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  23. postgresql94-plpython.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  24. postgresql94-pltcl.x86_64 9.4.5-1PGDG.rhel7 pgdg94
  25. postgresql94-python.x86_64 4.1.1-2PGDG.rhel7 pgdg94
  26. postgresql94-python-debuginfo.x86_64 4.1.1-2PGDG.rhel7 pgdg94
  27. postgresql94-test.x86_64

可以看到,其实是CentOS默认源是包含了Postgresql9.2的。不过这个不重要,我们继续。

  1. # yum install postgresql94-server

当然还可以根据需求安装其他的包,针对目前的练习,安装这个包就足够了。

安装完成后,需要初始化数据库。Postgresql对systemd支持并不完整,所以不能像在CentOS6.X中
直接使用系统命令service来初始化,必须使用这个命令:

  1. # /usr/pgsql-9.4/bin/postgresql94-setup initdb
  2. Initializing database ... OK

此时系统初始化已经完毕,可以启动后台服务了:

  1. # systemctl list-unit-files |grep postgresql
  2. postgresql-9.4.service disabled
  3. # systemctl start postgresql-9.4
  4. # systemctl enable postgresql-9.4

此刻,你的操作系统中就安装好了Postgresql,可以愉快地进行下一步实验了。

猜你在找的Postgre SQL相关文章