为PostgreSQL 8.3安装PL / Ruby [英] Installing PL/Ruby for PostgreSQL 8.3

查看:90
本文介绍了为PostgreSQL 8.3安装PL / Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是为了使用嵌入式 ruby​​ 代码
开发 postgres 功能,但是我无法构建它。

This is to enable the development of postgres functions with embedded ruby code, but I have been unable to build it.

根据
http://www.robbyonrails.com/articles/2005/08/22/installing-untrusted-pl-ruby-for-postgresql

我正在尝试从 ftp://moulon.inra.fr/pub/ruby/

我已经整理出我的本地postgres的设置是并将调用调整为:

I've sorted out where my local postgres set up is and adjusted the invocation to:

ruby extconf.rb --with-pgsql-include=/usr/postgresql-8.3.4/include/server --enable-shared --disable-conversion --with-pgsql-version=83

我已经尝试了很多变化,但是没有似乎能够成功地将
变成 conftest.c文件

I've tried quite number of variations on that, but it does not seem to be able to successfully make the 'conftest.c' file

它说:

checking for catalog/pg_proc.h... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

这就是我在mkmf.log中最终得到的结果

And here is what I end up with in my mkmf.log

have_header: checking for catalog/pg_proc.h... -------------------- yes
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I/usr/postgresql-8.3.4/include/server   -g -O2  -fPIC  conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include <catalog/pg_proc.h>
/* end */

当我手动运行gcc行时,它说有没有'conftest.c'(没有,但是应该生成
)。

When I run the gcc line manually, it says there is no 'conftest.c' (and there is not, but it is supposed to be generated).

'uname -a' ... gives
Linux vdev1 2.6.18.8-xen #2 SMP Thu May 8 11:52:29 PDT 2008 x86_64 x86_64 x86_64 GNU/Linux
'ruby -v' ... gives
ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux]

任何帮助和/或建议将不胜感激。

Any help and/or advice would be appreciated.

-Mike Berrow

-- Mike Berrow

推荐答案

好,我设法通过谷歌搜索
a成功构建的日志文件来手动构建(绕过易碎 extconf.rb和makefile) ,从我在那看到的gcc行开始,然后摆弄gcc编译
标志和路径,直到它起作用为止。

OK, I managed to hand build this (bypassing the fragile extconf.rb and makefile) by googling for a logfile of a successful build, starting with the gcc lines I saw there, then fiddling with the gcc compile flags and paths until it worked.

在plruby.h中将SAFE_LEVEL更改为0
如下所示

In plruby.h change the SAFE_LEVEL to 0 as shown below

#ifndef SAFE_LEVEL
//#define SAFE_LEVEL 12
#define SAFE_LEVEL 0
#endif

从shell编译每个文件然后链接

Compile each from shell then link

gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server  -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator  -c plruby.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server  -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator  -c plplan.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server  -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator  -c plpl.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_CATALOG_PG_PROC_H -DHAVE_RB_HASH_DELETE -DHAVE_ST_H -DHAVE_UTILS_ARRAY_H -I/usr/postgresql-8.3.4/include/server -D_FILE_OFFSET_BITS=64  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -DHAVE_RB_HASH_DELETE -DHAVE_RB_INITIALIZE_COPY -DPG_UTILS_ARRAY -DPG_PL_TRYCATCH -DPG_PL_VERSION=83 -DPLRUBY_CALL_HANDLER=plruby_call_handler -DPLRUBY_VALIDATOR=plruby_validator  -c pltrans.c
gcc -shared -o plruby.so plruby.o plplan.o plpl.o pltrans.o -L. -L/usr/lib -L/usr/postgresql-8.3.4/lib -L. -Wl,-Bsymbolic -rdynamic -Wl,-export-dynamic -lruby  -lpthread -ldl -lcrypt -lm -lc

将上面构建的'.so'文件放置在动态库路径($ libdir)
[使用 pg_config --pkglibdir 确定(在我的情况)/usr/postgresql-8.3.4/lib]

Place the '.so' file built above in the dynamic library path ($libdir) [ determined using pg_config --pkglibdir giving (in my case) /usr/postgresql-8.3.4/lib ]

采用这种方法的其他人很可能必须自己进行调整。

Others taking this approach will most likely have to do their own tweaking.

添加这些功能...

CREATE OR REPLACE FUNCTION plruby_call_handler()
  RETURNS language_handler AS
'$libdir/plruby', 'plruby_call_handler'
  LANGUAGE 'c' VOLATILE
  COST 1;
ALTER FUNCTION plruby_call_handler() OWNER TO postgres;

CREATE OR REPLACE FUNCTION plruby_validator(oid)
  RETURNS void AS
'$libdir/plruby', 'plruby_validator'
  LANGUAGE 'c' VOLATILE
  COST 1;
ALTER FUNCTION plruby_validator(oid) OWNER TO postgres;

添加 plruby作为程序语言

Add 'plruby' as a procedural language

CREATE PROCEDURAL LANGUAGE 'plruby' HANDLER plruby_call_handler;

测试一下:

CREATE FUNCTION ruby_max(int4, int4) RETURNS text AS '
    if args[0].to_i > args[1].to_i
        return "The one on the left is bigger"
    else
        return "The one on the right is bigger"
    end
' LANGUAGE 'plruby';

select ruby_max(8, 9);

还有其他构建选项可以启用转化类型。
上面的构建是最简单的构建,实际上所有函数参数
都以字符串的形式放入ruby(即使它们被声明为int4)。
因此需要在此处拨打 to_i电话。

There are other build options for this that enable type 'conversions'. The above build is the simplest one and all function parameters actually come into ruby as strings (even though they are declared as int4). Thus the need for the 'to_i' call here.

这篇关于为PostgreSQL 8.3安装PL / Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆