PostgreSQL几款常用插件的安装

插件1:PostGIS

环境预备

# yum -y install epel-release

安装相关联的插件

#安装geos

#wget http://download.osgeo.org/geos/geos-3.7.3.tar.bz2

#tar -jxvf geos-3.7.3.tar.bz2

#cd geos-3.7.3/

#./configure --prefix=/usr/local/geos-3.7.3

#make && make install

#cd ..

#安装proj

#wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz

#tar -zxvf proj-4.9.3.tar.gz

#cd proj-4.9.3/

#./configure --prefix=/usr/local/proj-4.9.3

#make && make install

#cd ..

#安装gdal 【编译时间比较长】

#wget --no-check-certificate https://download.osgeo.org/gdal/2.4.4/gdal-2.4.4.tar.gz

#tar -zxvf gdal-2.4.4.tar.gz

#cd gdal-2.4.4/

#./configure --prefix=/usr/local/gdal-2.4.4 --with-proj=/usr/local/proj-4.9.3

#make -j8 && make install

#cd ..

#安装postgis(3.2.0)

#wget --no-check-certificate https://download.osgeo.org/postgis/source/postgis-3.2.0.tar.gz

#tar zxvf postgis-3.2.0.tar.gz

#cd postgis-3.2.0/

#./configure --prefix=/usr/local/postgis-3.2.0 --with-pgconfig=/usr/local/pgsql13/bin/pg_config --with-geosconfig=/usr/local/geos-3.7.3/bin/geos-config --with-projdir=/usr/local/proj-4.9.3  --with-gdalconfig=/usr/local/gdal-2.4.4/bin/gdal-config --without-protobuf

#make && make install

#cd ..

最后:

# cp /usr/local/geos-3.7.3/lib/libgeos_c.so.1 /lib64

# cp /usr/local/proj-4.9.3/lib/libproj.so.12 /lib64

        注:PostgreSQL自带的一些插件,也一并编译

               (PostGIS只需要contrib下的fuzzystrmatch)

                # cd ./postgresql-13.9/contrib/

                # make && make install

        验证插件功能:         

##### 安装PostGis扩展

postgis=# CREATE EXTENSION postgis;

postgis=# CREATE EXTENSION postgis_topology;

postgis=# CREATE EXTENSION fuzzystrmatch;

postgis=# CREATE EXTENSION postgis_tiger_geocoder;

####  验证是否安装成功

# SELECT postgis_full_version();

#建表验证

#create table testGeo(id int8 not null, info varchar(100) null, lnglat geometry null);

#drop table testGeo;

插件2:Pathman (分表工具)

安装:

####  下载pathman##最高支持到PostgreSQL13

https://github.com/postgrespro/pg_pathman

#####https://github.com/postgrespro/pg_pathman#custom-plan-node

上传并解压

#unzip pg_pathman-master.zip

#cd pg_pathman-master

#make USE_PGXS=1

#make USE_PGXS=1 install

修改 postgresql.conf, 若有其它插件,注意顺序:

shared_preload_libraries = '$libdir/passwordcheck,pg_stat_statements,pg_pathman'

#shared_preload_libraries = 'pg_pathman'

#pg_ctl restart

验证:

# create extension pg_stat_statements;

# SELECT pg_stat_statements_reset();

# 创建扩展

# create extension pg_pathman;

####验证

#create table testTbl (id serial8 primary key, area_id bigint not null, name varchar(100) not null, age integer not null default 0);

#select create_hash_partitions('testTbl'::regclass,'area_id',10,false);

# drop table testTbl cascade;

###  函数说明

create_hash_partitions(parent_relid     REGCLASS,  --主表OID

                       expression       TEXT,  --指定分区键,分区键可以是列,也可以是一个表达式

                       partitions_count INTEGER,             --分区数量

                       partition_data   BOOLEAN DEFAULT TRUE,

--是否立即从父表迁移数据到子表,建议关闭,因为表会被锁到数据迁移结束

                       partition_names  TEXT[] DEFAULT NULL,  --可以指定分区名称

                       tablespaces      TEXT[] DEFAULT NULL)  --可以指定表空间

插件3:pgAudit

#### 1. 下载pgaudit 5.2(匹配pg13.*)

 https://github.com/pgaudit/pgaudit/releases/tag/1.5.2

####  2. 上传 pgaudit-1.5.2.tar.gz并解压

# tar zxvf pgaudit-1.5.2.tar.gz

#### 3. 将pgaudit-1.5.2整个目录移到pg13.9的源代码目录contrib下

# cp -r pgaudit-1.5.2 postgresql-13.9/contrib/.

# cd postgresql-13.9/contrib/pgaudit-1.5.2

####  4. 进入pgaudit-1.5.2目录下,执行命令

# make USE_PGXS=1 && make install USE_PGXS=1

####  5. 修改postgresql.conf,新增

        pgaudit.log='write,ddl,read'

        pgaudit.log_catalog=off

        pgaudit.log_level=log

        pgaudit.log_parameter=on

        pgaudit.log_relation=on

        pgaudit.log_statement_once=on

如下图

#### 6. 切换到postgres账号,重启pg13.9

#  ./bin/pg_ctl -D $PGDATA restart

#### 7. 登录pgsql,创建扩展

#create extension pgaudit;

#### 8. 重启postgresql(为了启用extension pgaudit)

#pg_ctl -D $PGDATA -l pg13.log restart

#### 9. 查询安装配置情况

# select name,setting from pg_settings where name like '%pgaudit%';

#### 10. 查看日志pg13.log来验证效果

插件4:pg_repack

# Ref:  https://www.modb.pro/db/393477

# Ref:  https://blog.51cto.com/u_14150796/5372157

# Ref:  https://www.modb.pro/db/393477

#### 下载:pg_repack 1.4.8: PostgreSQL module for data reorganization / PostgreSQL Extension Network

##### 将pg_repack-1.4.8.zip文件上传到postgresql服务器上

#### 解压  

#  unzip pg_repack-1.4.8.zip

#### 执行指令

# cd pg_repack-1.4.8

# make && make install

#### 登录 postgresql

#psql

# create extension pg_repack;

#### 退出postgresql

#### 修改postgresql.conf文件,在 shared_preload_libraries添加 pg_repack

#### 重启postgresql

#  pg_ctl restart

####  无需登录postgresql, 直接命令行执行  

#  pg_repack -d postgres --table public.testtbl;

#### 使用说明:

 ### 对库testDB中所有表进行操作

 #  pg_repack testDB;

 ### 对库testDB中某表testTable1testTable2进行操作

 # pg_repack --no-order --table testTable1 --table testTable2 testDB

 ###将数据库testDB中表testTable的索引移到表空间testSpace

 # pg_repack -d testDB --table testTable --only-indexes --tablespace testSpace;

插件5:pgAgent

#### 安装所需的包

# yum -y install boost*

# yum -y install gtk*

#### 安装CMAKE 3.26.3

# tar -zxvf cmake-3.26.3.tar.gz

# cd cmake-3.26.3

# ./bootstrap

# make && make install

# cd ..

#### 安装wxGTK-2.8.12

#### 修改 .bash_profile (添加环境变量)

#### 添加下列两行

export PATH=$PATH:$PGHOME/bin:/usr/local/wxGTK-2.8.12/bin

export LD_LIBRARY_PATH=/usr/local/wxGTK-2.8.12/lib:$PGHOME/lib:$LD_LIBRARY_PATH

#### 如下图

# source .bash_profile

#### 然后编译wxGTK

# tar zxvf wxGTK-2.8.12.tar.gz

# cd wxGTK-2.8.12

# ./configure --enable-shared=no --enable-unicode=yes --prefix=/usr/local/wxGTK-2.8.12

# make && make install

# cd ..

#### 安装pgagent-4.0.0

# tar zxvf pgAgent-4.0.0-Source.tar.gz

# cd pgAgent-4.0.0-Source

# cmake ./

# make && make install

#### 最后进入pg,创建pgagent插件

create extension pgagent;

  • 29
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值