美文网首页
PostgreSql源码搭建

PostgreSql源码搭建

作者: 河北漂 | 来源:发表于2019-01-23 14:56 被阅读0次

PostgreSql从源码编译搭建过程

1.检查gcc版本

gmake --version  

GNU make版本3.80以上。

2.下载源码

源码地址:https://www.postgresql.org/ftp/source/
此处以9.4.1为例:postgresql-9.4.1.tar.gz

3.解压编译

###解压
gunzip postgresql-9.4.1.tar.gz
tar xf postgresql-9.4.1.tar
###编译
cd postgresql-9.4.1/
./configure
gmake world
gmake install-world

### ******  ###
如果configure中出现的错误:readline library not found

解决方法:
yum -y install -y readline-devel
再运行 ./configure
### ******  ###

4.配置环境

PostgreSql不能用root启动,此处需要其他用户,默认用postgres

vi /etc/profile
### 增加配置
LD_LIBRARY_PATH=/usr/local/pgsql/lib  
export LD_LIBRARY_PATH  
PATH=/usr/local/pgsql/bin:$PATH  
export PATH  

source /etc/profile  

4.初始化数据库

指定数据库目录,并授权用户

mkdir /usr/local/pgsql/data  
chown userName /usr/local/pgsql/data  

初始化

sudo su admin 
initdb -E UTF8 -D /usr/local/pgsql/data 
createdb indoor

psql -d indoor
进入控制台 indoor# 
退出控制台 indoor# \q

用户管理

##新建用户
CREATE USER jack;
##授权用户
ALTER USER jack WITH SUPERUSER;

启动关闭

###启动数据库
pg_ctl start -D /usr/local/pgsql/data -l /usr/local/pgsql/data/logfile

###关闭数据库
pg_ctl stop -D /usr/local/pgsql/data -m f

###查询状态
pg_ctl -D /usr/local/pgsql/data status

数据库安装完毕,此时本地可以访问了。

5.数据库配置

配置监听IP

vi /usr/local/pgsql/data/postgresql.conf  

### 允许所有ip
listen_addresses = '*'

连接地址

vi /usr/local/pgsql/data/pg_hba.cnf  

###添加一个局域网连接许可
host   all   all   192.168.0.0/16   md5
###允许所有ip的连接
host   all   all   0.0.0.0/0   md5

6.安装Postgis插件

需要前提安装Proj4、GEOS、LibXML2、JSON-C、GDAL
如果系统中没有安装则安装。
安装版本的对应关系请查看https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS

·1、Proj4

tar xzvf proj-4.8.0.tar.gz 
cd proj-4.8.0  
./configure  
make  
make install  

·2、GEOS

tar jxvf geos-3.4.3.tar.bz2 
cd geos-3.4.3
./configure  
make  
make install  

·3、libxml2

tar xzvf libxml2-2.9.0.tar.gz  
cd libxml2-2.9.0  
./configure  
make  
make install  

### ******  ###
如果在libxml2的configure中出现的错误:cannot remove 'libtoolT':No such file or directory

解决方法:
修改configure文件
$vi configure
删除这一行:$RM "$cfgfile"
保存再运行 ./configure
### ******  ###

更新环境变量

vi /etc/profile

export LD_LIBRARY_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

source /etc/profile  

·4、json-c

tar xzvf json-c-0.11-20130402.tar.gz 
cd ./json-c-0.11-20130402  
./configure  
make  
make install  

·5、GDAL

tar xzvf gdal-1.9.2.tar.gz  
cd gdal-1.9.2  
./configure  
make  
make install  

安装PostGis

tar zxvf postgis-2.3.8.tar.gz
cd postgis-2.3.8
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config  
make  
make install 

### ******  ###
如果在configure中出现的错误:configure: error: could not find GDAL

解决方法:
在 /etc/ld.so.conf
增加 
/usr/local/lib
/usr/local/pgsql/lib
保存后 执行 ldconfig
在重新执行 ./configure
### ******  ###

检查成功状态

psql -d indoor
###进入命令行 
indoor# 
indoor# select * from pg_available_extensions where name like 'postgis%';

表示Postgis安装成功。

7.配置插件

给数据库增加插件功能

psql -d indoor -c "CREATE EXTENSION postgis;"
psql -d indoor -c "CREATE EXTENSION postgis_topology;"

8.备份还原

## dump源库数据
pg_dump -h 127.0.0.1 -U postgres dbName | gzip  > dumpfileName

## 还原数据
gunzip -c dumpfileName | psql  -h 127.0.0.1 -U postgres dbName

备份还原,不能把用户带过去,所以用户要提前建立好。

相关文章

网友评论

      本文标题:PostgreSql源码搭建

      本文链接:https://www.haomeiwen.com/subject/axtzdqtx.html