PostgreSQL:CentOS7中源码安装 PostgreSQL-13.1

 

目录

一、下载 PostgreSQL 源码

二、编译 PostgreSQL

三、配置 PATH 环境变量


一、下载 PostgreSQL 源码

下载地址:https://www.postgresql.org/ftp/source/v13.1/

下载版本:postgresql-13.1.tar.gz

下载完成后,上传到 CentOS设备上,并解压,解压命令如下:

tar xzf postgresql-13.1.tar.gz

二、编译 PostgreSQL

使用 tar 命令解压后,会在当前目录下出现目录 postgresql-13.1

进入目录postgresql-13.1,并执行配置脚本

$ cd postgresql-13.1
$./configure --prefix=/opt/common/postgresql
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... no
checking for cc... no
configure: error: in `/opt/build/postgresql-13.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

结果报错了,错误信息是没有安装 gcc,所以需要安装 gcc

$ yum -y install gcc

安装 gcc 后再次运行 configure 进行配置

$ ./configure --prefix=/opt/common/postgresql
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... gcc
checking whether the C compiler works... yes
.
.
.
checking for library containing readline... no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

这次报错信息是没有找到 readline 库,所以需要安装 readline 库

$ yum -y install readline-devel

安装 readline-devel 后,再次运行 configure 进行配置,缺哪个依赖库就安装哪个库。重复执行 configure,直到 configure 命令运行成功,运行成功后,会在最后输出如下信息: 

configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
configure: using CPPFLAGS= -D_GNU_SOURCE 
configure: using LDFLAGS=  -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

configure 执行成功后,就可以进行编译了,编译命令如下:

$ make && make install

如果报错说 make 命令找不到,那就安装 make

yum install -y make

三、配置 PATH 环境变量

编译并安装完成后, PostgreSQL 会安装到 /opt/common/postgresql 目录中,这是因为我们在执行 configure 命令的时候,指定的 --prefix 参数的值是 /opt/common/postgresql,也就是把 PostgreSQL 安装到 /opt/common/postgresql/ 中。但是这个目录没有在系统变量 PATH 中,所以执行 PostgreSQL 的命令(例如 psql)的时候,系统是找不到命令在哪里的,所以需要配置系统变量 PATH,修改方式如下:

临时修改,退出 shell 后,这个配置就消失了,下次使用的时候需要再次执行:

export PATH=/opt/common/postgresql/bin:$PATH

永久修改,修改 ~/.bashrc 或者 /etc/bashrc ,在文件的最后一行添加如下信息:

export PATH=/opt/common/postgresql/bin:$PATH

修改完成后,需要加载一下:

source ~/.bashrc # 或者 source /etc/bashrc

测试 psql 命令:

$ psql --help
psql is the PostgreSQL interactive terminal.

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

General options:
  -c, --command=COMMAND    run only single command (SQL or internal) and exit
  -d, --dbname=DBNAME      database name to connect to (default: "root")
  -f, --file=FILENAME      execute commands from file, then exit
  -l, --list               list available databases, then exit
  -v, --set=, --variable=NAME=VALUE
                           set psql variable NAME to VALUE
                           (e.g., -v ON_ERROR_STOP=1)
  -V, --version            output version information, then exit

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值