1.安装依赖
yum install gcc gcc-c++ make readline-devel flex zlib-devel
2.下载源码,解压
创建源码存放目录
mkdir -p /usr/local/src
cd /usr/local/src
下载解压
wget -c https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.gz
tar -zxvf postgresql-10.0.tar.gz
cd postgresql-10.0
3.配置,编译,安装
./configure --prefix=/usr/local/pgsql
make -j4
make install
4.创建用户
useradd postgres
5.创建数据目录
mkdir -p /usr/local/pgsql/data
6.设置权限
chown -R postgres:postgres /usr/local/pgsql
7.初始化数据库
切换用户
su postgres
进入bin目录
cd /usr/local/pgsql/bin
初始化数据库
./initdb -D /usr/local/pgsql/data
退出postgres用户
exit
8.复制启动脚本
cp /usr/local/src/postgresql-10.0/contrib/start-scripts/linux /etc/init.d/pgsqld
9.设置权限
chmod 755 /etc/init.d/pgsqld
10.设置开机启动
chkconfig pgsqld on
11.启动
service pgsqld start
12.查看版本信息
切换用户
su postgres
查看版本
[postgres@jmsite pgsql]$ /usr/local/pgsql/bin/psql
psql (10.0)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 10.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23), 64-bit
(1 row)
postgres=# \q
[postgres@jmsite pgsql]$
13.安装pdo_pgsql,pgsql扩展
进入php源码自带的pgsql源码目录
cd /usr/local/src/php-7.2.13/ext/pgsql/
找到phpize位置
whereis phpize
生成configure文件
/usr/local/php72/bin/phpize
配置,php-config一般和phpize在同级目录
./configure --with-php-config=/usr/local/php72/bin/php-config
编译,安装
make
make install
Installing shared extensions: /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/
提示扩展已经安装到了相应目录
ls /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/
pgsql.so
进入pdo_pgsql源码目录
cd /usr/local/src/php-7.2.13/ext/pdo_pgsql/
生成configure
/usr/local/php72/bin/phpize
配置
./configure --with-php-config=/usr/local/php72/bin/php-config
编译,安装
make
make install
Installing shared extensions: /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/
提示扩展已经安装到了相应目录
ls /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/
pdo_pgsql.so pgsql.so
将扩展加入php.ini
echo "extension=pgsql.so" >> /usr/local/php72/etc/php.ini
echo "extension=pdo_pgsql.so" >> /usr/local/php72/etc/php.ini