首页
解决方案
技术服务
专业数据库维保服务 大数据维保服务
一体机
Oracle数据库一体机 PolarDB数据库一体机 瀚高数据库一体机 崖山数据库一体机 海扬数据库一体机 高斯数据库一体机 金仓数据库一体机
产品
CLup乘数云统一平台 CData高性能数据库云一体机 CPDA高性能双子星数据库机 CBackup数据库备份恢复云平台 CMiner: PostgreSQL中的CDC CSYun超融合虚拟机产品 ZQPool数据库连接池 ConshGuard数据保护产品 APCC: Greenplum管理平台
文档
文章
客户及伙伴
中启开源
关于我们
登录
×
修改密码

下载源代码

[root@localhost ~]# wget https://ftp.postgresql.org/pub/source/v10.2/postgresql-10.2.tar.gz
安装依赖包

[root@localhost ~]# yum install -y zlib-devel readline-devel gcc
编译安装PostgreSQL

[root@localhost ~]# tar -zxvf postgresql-10.2.tar.gz
[root@localhost ~]# cd postgresql-10.2

[root@localhost postgresql-10.2]# ./configure —prefix=/usr/local/pgsql10.2 —with-python —with-perl
[root@localhost postgresql-10.2]# make && make install

[root@localhost postgresql-10.2]# cd /usr/local/
[root@localhost local]# ln -s pgsql10.2 pgsql
备注:
  在PostgreSQL8.X中,编译命令里需要有“—enable-thread-safety”选项,而在PostgreSQL9.X以后的版本中不需要这个选项。
  因为在日常使用中,一般要求客户端是线程安全的,PostgreSQL9.X以后的版本中考虑到这个问题,默认线程是安全的了。

  —with-perl:加上这个选项,才能使用perl语言的PL/Perl过程语言写自定义函数,一般都需要。要使用这个选项需要先安装perl-ExtUtils-Embed和perl-devel。
  —with-python:加上这个选项,才能使用perl语言的PL/Python过程语言写自定义函数,一般都需要。要使用这个选项需要先安装python-devel。
  按照官方文档要求,使用make命令时,make的版本要在gmake3.8以上,目前大多数Linux发行版都满足要求。(检查方法:make —version)
  不指定—prefix选项,默认路径将是/usr/local

异常处理:
编译时增加 —with-python
configure: error: header file is required for Python
解决方法:
yum install python-devel
编译时增加 —with-perl
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is notinstalled.
解决方法:
yum install perl-ExtUtils-Embed

  1. 配置PostgreSQL环境变量

[root@localhost local]# vim /etc/profile

PostgreSQL可执行文件路径

export PATH=/usr/local/pgsql/bin:$PATH

PostgreSQL共享库路径

export LD_LIBRARY_PATH=/usr/local/pgsql/lib

[root@localhost local]# source /etc/profile

  1. 创建数据库簇

[root@localhost local]# useradd postgres

[root@localhost local]# mkdir -pv /mydata/pgdata
mkdir: 已创建目录 “/mydata”
mkdir: 已创建目录 “/mydata/pgdata”

[root@localhost local]# chown -R postgres.postgres /mydata/pgdata/

[root@localhost local]# su - postgres
[postgres@localhost ~]$ /usr/local/pgsql/bin/initdb -D /mydata/pgdata/

  1. 启动PostgreSQL

[postgres@localhost pgsql]$ pg_ctl start -D /mydata/pgdata/
waiting for server to start….2018-02-20 00:52:03.616 CST [38915] LOG: listening on IPv6 address “::1”, port 5432
2018-02-20 00:52:03.616 CST [38915] LOG: listening on IPv4 address “127.0.0.1”, port 5432
2018-02-20 00:52:03.619 CST [38915] LOG: listening on Unix socket “/tmp/.s.PGSQL.5432”
2018-02-20 00:52:03.689 CST [38916] LOG: database system was shut down at 2018-02-20 00:44:56 CST
2018-02-20 00:52:03.692 CST [38915] LOG: database system is ready to accept connections
doneserver started

  1. 停止PostgreSQL

[postgres@localhost pgsql]$ pg_ctl stop -D /mydata/pgdata/备注:
可以在命令后增加 [-m SHUTDOWN-MODE],用来控制数据库的停止方法;SHUTDOWN-MODE有以下三种:
smart:等所有的连接终止后,关闭数据库。如果客户端连接不终止,则无法关闭数据库。
fast (PostgreSQL10.X默认):快速关闭数据库,断开客户端的连接,让已有的事物回滚,然后正常关闭数据库。
相当于Oracle数据库关闭时的immediate(adj. 立即的)模式。
immediate:不完整的关闭数据库,相当于kill数据库进程,下次启动数据库需要进行恢复。相当于Oracle数据库关闭时的abort模式。
其中,比较常用的是fast模式。