版权声明:本文为博主原创文章,未经博主允许不得转载! https://blog.csdn.net/rico_zhou/article/details/81301247
安装指定版本的数据库postgresql(centos7.4)
网上搜索Linux安装postgresql有很多教程,主要是下载rpm包在线安装:
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
但是使用此方法安装数据库现在最新版已是postgresql10.4的版本,而环境需要指定安装10.3的版本,因此可选择解压版安装。
首先下载压缩包:https://www.postgresql.org/ftp/source/v10.3/,选择 postgresql-10.3.tar.gz下载
上传到/usr/data/postgresql10.3/ ,解压
tar -zxvf postgresql-10.3.tar.gz
进入postgresql10.3目录输入命令检查环境
./configure
如果出现以下错误
configure: error: in `/root/postgresql-10.3':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
缺少编译环境,执行命令,安装对应的包
yum –y install gcc
成功之后再次输入
./configure
又报错
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 support
yum -y install -y readline-devel
成功之后再次输入
./configure
再次报错
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.
安装zlib-devel
yum -y install zlib-devel
终于不再报错,总之缺少什么就安装什么
执行编译
make && make install
需要大概10分钟,出现如下信息则编译成功
以上内容参考:https://blog.csdn.net/qq_35267557/article/details/79788703
接下来添加用户
创建一个data文件夹用于存储数据
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
chmod 700 /usr/local/pgsql/data
切换用户为postgresql并初始化数据库
su postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
到bin目录下
cd /usr/local/pgsql/bin/
启动数据库
su postgres
./pg_ctl start -D /usr/local/pgsql/data/
查看下状态
./pg_ctl status -D /usr/local/pgsql/data/
接下来修改下配置文件,便于远程连接
cd /usr/local/pgsql/data/
vim pg_hba.conf
vim postgresql.conf
重启数据库
su postgres
./pg_ctl restart -D /usr/local/pgsql/data/
即可远程连接啦!