使用rpm 打包开发的postgres extension
环境准备
- 安装依赖包
rpmdevtools rpm-build
yum install -y rpm-build rpmdevtools
- 初始化rpm pacakge 项目
主要是rpm 打包的目录结构
使用rpmdev-setuptree 工具
效果如下:
── rpmbuild
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
创建简单pg extension 扩展
具体实现的功能很简单,可以参考github 项目https://github.com/rongfengliang/nvl-pg-extension
- 代码说明
扩展开发主要是control 以及函数定义
nvlfunc.control
# nvlfunc extension
comment = 'Oracle compatible nvl function'
default_version = '1.0'
module_pathname = '$libdir/nvlfunc'
relocatable = false
sql 函数定义
nvlfunc--1.0.sql
/* nvlfunc--1.0.sql */
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "CREATE EXTENSION nvlfunc" to load this file. \quit
CREATE OR REPLACE FUNCTION public.NVL(SMALLINT,SMALLINT)
RETURNS SMALLINT AS $$
SELECT COALESCE($1,$2);
$$ LANGUAGE SQL IMMUTABLE;
Makefile 定义,方便安装(注意pg 版本,可能需要配置path 路径,同时安装pg devel 包)
EXTENSION = nvlfunc
DATA = nvlfunc--1.0.sql
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
rpm spec 编写
/~rpmbuild/SPECS 路径
- 代码
Name: nvl-pg-extension
Version: 1.0
Release: 1%{?dist}
Summary: this is a postgresql extension nvl function just like oracle
License: APACHE
URL: https://github.com/rongfengliang/postgres-extension-demo
// 使用源码打包rpm 包
Source: https://github.com/rongfengliang/nvl-pg-extension/archive/v1.0.zip
%prep
%setup -q
%description
this is a postgresql extension nvl function just like oracle
%install
%{make_install} PREFIX=%{_prefix}
%files
/usr/pgsql-10/share/extension/nvlfunc--1.0.sql
/usr/pgsql-10/share/extension/nvlfunc.control
打包rpm 包
- 下载source
spectool -g -R ~/rpmbuild/SPECS/nvl-pg-extension.spec
- 打包rpm 包
rpmbuild -bb ~/rpmbuild/SPECS/nvl-pg-extension.spec
- 效果
spectool -g -R ~/rpmbuild/SPECS/nvl-pg-extension.spec
Getting https://github.com/rongfengliang/nvl-pg-extension/archive/v1.0.zip to /root/rpmbuild/SOURCES/v1.0.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 133 0 133 0 0 72 0 --:--:-- 0:00:01 --:--:-- 72
0 0 0 1119 0 0 174 0 --:--:-- 0:00:06 --:--:-- 306
rpmbuild -bb ~/rpmbuild/SPECS/nvl-pg-extension.spec
执行(%prep): /bin/sh -e /var/tmp/rpm-tmp.uCoCHD
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf nvl-pg-extension-1.0
+ /usr/bin/unzip -qq /root/rpmbuild/SOURCES/v1.0.zip
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd nvl-pg-extension-1.0
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
执行(%install): /bin/sh -e /var/tmp/rpm-tmp.YBV39p
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64
++ dirname /root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64
+ cd nvl-pg-extension-1.0
+ /usr/bin/make install DESTDIR=/root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64 PREFIX=/usr
/usr/bin/mkdir -p '/root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64/usr/pgsql-10/share/extension'
/usr/bin/mkdir -p '/root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64/usr/pgsql-10/share/extension'
/usr/bin/install -c -m 644 .//nvlfunc.control '/root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64/usr/pgsql-10/share/extension/'
/usr/bin/install -c -m 644 .//nvlfunc--1.0.sql '/root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64/usr/pgsql-10/share/extension/'
+ /usr/lib/rpm/find-debuginfo.sh --strict-build-id -m --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 110000000 /root/rpmbuild/BUILD/nvl-pg-extension-1.0
/usr/lib/rpm/sepdebugcrcfix: Updated 0 CRC32s, 0 CRC32s did match.
+ '[' '%{buildarch}' = noarch ']'
+ QA_CHECK_RPATHS=1
+ case "${QA_CHECK_RPATHS:-}" in
+ /usr/lib/rpm/check-rpaths
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
处理文件:nvl-pg-extension-1.0-1.el7.x86_64
Provides: nvl-pg-extension = 1.0-1.el7 nvl-pg-extension(x86-64) = 1.0-1.el7
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
处理文件:nvl-pg-extension-debuginfo-1.0-1.el7.x86_64
Provides: nvl-pg-extension-debuginfo = 1.0-1.el7 nvl-pg-extension-debuginfo(x86-64) = 1.0-1.el7
Requires(rpmlib): rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1
检查未打包文件:/usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64
写道:/root/rpmbuild/RPMS/x86_64/nvl-pg-extension-1.0-1.el7.x86_64.rpm
写道:/root/rpmbuild/RPMS/x86_64/nvl-pg-extension-debuginfo-1.0-1.el7.x86_64.rpm
执行(%clean): /bin/sh -e /var/tmp/rpm-tmp.Ya1lDM
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd nvl-pg-extension-1.0
+ /usr/bin/rm -rf /root/rpmbuild/BUILDROOT/nvl-pg-extension-1.0-1.el7.x86_64
+ exit 0
── BUILD
│ └── nvl-pg-extension-1.0
│ ├── debugfiles.list
│ ├── debuglinks.list
│ ├── debugsources.list
│ ├── elfbins.list
│ ├── Makefile
│ ├── nvlfunc--1.0.sql
│ └── nvlfunc.control
├── BUILDROOT
├── RPMS
│ └── x86_64
│ ├── nvl-pg-extension-1.0-1.el7.x86_64.rpm
│ └── nvl-pg-extension-debuginfo-1.0-1.el7.x86_64.rpm
├── SOURCES
│ └── v1.0.zip
├── SPECS
│ └── nvl-pg-extension.spec
└── SRPMS
安装&&使用rpm 包
- 安装rpm包
yum install -y nvl-pg-extension-1.0-1.el7.x86_64.rpm
效果
yum install -y nvl-pg-extension-1.0-1.el7.x86_64.rpm
已加载插件:fastestmirror
正在检查 nvl-pg-extension-1.0-1.el7.x86_64.rpm: nvl-pg-extension-1.0-1.el7.x86_64
nvl-pg-extension-1.0-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 nvl-pg-extension.x86_64.0.1.0-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================
正在安装:
nvl-pg-extension x86_64 1.0-1.el7 /nvl-pg-extension-1.0-1.el7.x86_64 435
事务概要
=======================================================================================================================
安装 1 软件包
总计:435
安装大小:435
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : nvl-pg-extension-1.0-1.el7.x86_64 1/1
验证中 : nvl-pg-extension-1.0-1.el7.x86_64 1/1
已安装:
nvl-pg-extension.x86_64 0:1.0-1.el7
完毕!
pg 扩展目录
find /usr/pgsql-10/share/extension/ -name nvlfunc.control
/usr/pgsql-10/share/extension/nvlfunc.control
- 使用
CREATE EXTENSION nvlfunc;
SELECT NVL(NULL::SMALLINT, 121::SMALLINT);
nvl
-----
121
(1 row)
说明
就是一个简单的学习测试,实际上基于pg 的扩展模型我们可以开发很多强大的功能
参考资料
https://github.com/rongfengliang/nvl-pg-extension
https://github.com/rongfengliang/postgres-extension-demo
https://github.com/rongfengliang/pg-extension-rpm-package
使用rpm 打包开发的postgres extension的更多相关文章
- 使用deb 打包开发的postgres extension
昨天写过一个使用rpm 打包分发pg 扩展的demo,今天使用deb 进行打包分发,同时使用checkinstall 生成我们的deb包 安装deb 依赖 sudo apt-get install c ...
- 使用deb 打包开发的postgres extension 另外一种方法
已经写过一个deb 包打包的方法,我们同时也可以使用dpkg-deb 命令 安装依赖工具包 推荐安装全点的 sudo apt-get install build-essential autoconf ...
- 用 RPM 打包软件,第 1 部分
http://www.ibm.com/developerworks/cn/linux/management/package/rpm/part1/ RPM(Red Hat Package Manager ...
- 【centos7常用技巧】RPM打包
一.RPM打包的目的 1.当目标机中不存在编译环境时,可以先在本地环境中编译打包,然后直接在目标机中用rpm -ivh *.rpm安装即可. 2.当需要在目标机中安装多个软件或者增加多个文件时,可以将 ...
- Centos6_64 rpm打包实践
安装rpmbuild sudo yum install rpm-build 普通用户的配置 /home/you/rpmbuild/ 假设是要构建rpm的目录 先说说rpmbuild有什么用,给一个例子 ...
- rpm打包过程
[需求] 接触那么久的Linux,还没有试验过怎么打rpm包 [过程] 1.rpm打包准备工作 系统默认的rpmbuild的相关路径
- linux 版本控制及rpm打包
版本控制 subversion:是一个自由/开源的版本控制系统,在subversion管理下,文件和目录可以超越时空subversion允许你数据恢复到早期版本,或者是检查数据修改历史许多人将版本控制 ...
- RPM打包原理、示例、详解及备查
原文地址:https://blog.csdn.net/qq_16542775/article/details/80961213 RPM(Redhat Package Manager)是用于Redhat ...
- RPM打包原理、示例、详解及备查( 转)
RPM(Redhat Package Manager)是用于Redhat.CentOS.Fedora等Linux 分发版(distribution)的常见的软件包管理器.因为它允许分发已编译的软件,所 ...
随机推荐
- 6_linux用户及权限(1)
------------用户管理: useradd,userdel,usermod,passwd,chsh,chfn,finger,id,chage组管理: groupadd,groupdel,gro ...
- DataTable与List的相互转换
List转DataTable: public static DataTable ToDataTable<T>(IEnumerable<T> collection) { var ...
- java基础 (二)之HashMap,HashTable,ConcurrentHashMap区别
HashTable: put方法加了同步锁synchronized,底层数组+链表实现,无论key还是value都不能为null,线程安全,实现线程安全的方式是在修改数据时锁住整个HashTable, ...
- 更改redhat7 yum源为centos
1. 替换原系统中yum包, 检查初始的yum包有哪些 rpm -qa |grep yum 2. 删除原始的yum包. rpm -qa|grep yum|xargs rpm -e --nodeps 3 ...
- C# Log4Net 日志
C#使用Log4Net记录日志 第一步:下载Log4Net 下载地址:http://logging.apache.org/log4net/download_log4net.cgi ...
- 微信小程序 密码键盘 - 密码页面组件 (原生小程序代码)
1.WXML页面 <view> <!--<section class="mask" catchtap="canclePwd" wx:if ...
- Log4Net 添加自定义字段并保存到数据库
Log4Net是常用的功能强大的日志插件,该插件提供了几个默认字段 大家可能都用过Log4Net插件来记录日志,该插件默认提供了这几个字段@log_date, @thread, @log_level, ...
- [la P5031&hdu P3726] Graph and Queries
[la P5031&hdu P3726] Graph and Queries Time Limit: 10000/5000 MS (Java/Others) Memory Limit: ...
- C++ 多目录多文件编译 技巧
http://www.cplusplus.com/forum/articles/10627/ 1.hpp文件 hpp文件可以使用template函数和class静态函数(不含静态成员) a)不可包含全 ...
- Linq中datetime的处理以及asp.net下拉列表控件的selectitem,text等的设置显示处理
dhl:报错:LINQ to Entities 不支持指定的类型成员“Date” Linq如: var v = from l in _dal.Share where l.PingcoId == pin ...