Giter VIP home page Giter VIP logo

postgresql-plruby's Introduction

PL/ruby

PL/Ruby is a loadable procedural language for the PostgreSQL database system that enables the Ruby language to create functions and trigger procedures.

Prerequisite

  • ruby 1.8.7 or later (maybe 1.8.6 too)
  • postgresql >= 7.3

All PostgreSQL headers need to be installed. Command (see INSTALL in the directory postgresql-7.x.y)

    make install-all-headers

Installation

    ruby extconf.rb
    make
    make install

You may need to specify some of the following extconf.rb options:

    --with-pg-config=<location of the pg_config command of PostgreSQL>

Specifies the location of pg_config. e.g. --with-pg-config=/usr/local/bin/pg_config

    --with-greenplum

Builds plruby for Greenplum instead of PostgreSQL.

    --disable-conversion

By default plruby tries to convert a postgres type to a ruby class. This option gives the possibility to disable all conversions.

   --with-suffix=<suffix to add>

Specifies a suffix to add to the extension module file. e.g. ruby extconf.rb --with-suffix=_geo will create plruby_geo.so.

    --with-safe-level

Lowers the safe level which the plruby functions are run under. (default: 12; meaning the maximum)

    --with-timeout=<seconds>

Sets the timeout for each function call. (default: none)

    --with-main-safe-level

Lowers the safe level which the main thread waiting for timeouts is run under. (default: 3) This option is read only when --with-timeout is given.

Test (and examples)

WARNING: if plruby was compiled without --disable-conversion you must FIRST run make install before make test.

    make test

This will run the following two commands:

    ( cd test/plt; ./runtest )
    ( cd test/plp; ./runtest )

The database plruby_test is created and then destroyed. Don't use it if you have such a database.

Now you are ready to create the PL/Ruby language in PostgreSQL.

Since the pg_language system catalog is private to each database, the new language can be created only for individual databases, or in the template1 database. In the latter case, it is automatically available in all newly created databases.

The commands to create the new language are:

    create function plruby_call_handler () returns language_handler
    as 'path-to-plruby-shared-lib'
    language 'C';

    create trusted language 'plruby'
    handler plruby_call_handler
    lancompiler 'PL/Ruby';

The trusted keyword on create language tells PostgreSQL, that all users (not only those with superuser privilege) are permitted to create functions with LANGUAGE 'plruby'. This is absolutely safe, because there is nothing a normal user can do with PL/Ruby, to get around access restrictions he/she has.

Documentation

see plruby.rd and plruby.html

Development

New releases and sources can be obtained from http://github.com/knu/postgresql-plruby

Copying

This extension module is copyrighted free software by Guy Decoux.

You can redistribute it and/or modify it under the same term as Ruby.


Guy Decoux [email protected] (original author, deceased in July 2008) Akinori MUSHA [email protected] (current maintainer)

postgresql-plruby's People

Contributors

clivecrous avatar knu avatar tfoldi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postgresql-plruby's Issues

Support for ruby19

plruby does not work with ruby19 (ruby 1.9.1p378) and just segfaults.

Steps to reproduce:

  1. create function foo() returns int as '1' language 'plruby';
    select foo();

  2. STATEMENT: drop function foo(int);
    (eval):1: [BUG] Segmentation fault
    ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]

-- control frame ----------
c:0003 p:0021 s:0006 b:0006 l:0010ec d:000005 EVAL   (eval):1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0010ec d:0010ec TOP   
---------------------------
LOG:  server process (PID 11159) was terminated by signal 11: Segmentation fault
LOG:  terminating any other active server processes

I am currently investigating the code, apparently I have experience in embedding ruby but not with pg-pl stuff.

Request for a Statement from the Maintainer

It appears that the current maintainer has abandoned this project. If that is the case, it would be helpful to have a statement to that effect included in the README. It would also be helpful if a new maintainer could be requested.

Thanks!

TupleDesc reference leak

Hello,
Just downloaded and installed. Thanks for all the good work! Here is an issue that came up:
(Running Postgresql 8.4.5 on Ubuntu 2.6.32-25-server)
CREATE TABLE emp
(
"name" character varying(32),
salary int4
);
INSERT INTO emp("name", salary) VALUES ('bill', 1200);
INSERT INTO emp("name", salary) VALUES ('jim', 900);
INSERT INTO emp("name", salary) VALUES ('joe', 1500);
then
CREATE OR REPLACE FUNCTION overpaid_2 (EMP) RETURNS bool AS
'
args[0]["salary"] > 1000
' LANGUAGE 'plruby';

SELECT name, overpaid_2(emp) from emp;
get correct output, but following warnings:
2010-12-04 16:14:38 PST WARNING: TupleDesc reference leak: TupleDesc 0x7f5c97f01030 (49442,-1) still referenced
2010-12-04 16:14:38 PST WARNING: TupleDesc reference leak: TupleDesc 0x7f5c97f01030 (49442,-1) still referenced
2010-12-04 16:14:38 PST WARNING: TupleDesc reference leak: TupleDesc 0x7f5c97f01030 (49442,-1) still referenced
Any ideas here?

Problem add plruby to PostgreSQL 9.5 on Centos 6

Installing on Centos 6 PostgreSQL 9.5 (64 bit) ; ruby 1.8 and get from plruby libraries.
Trying add plruby to PostgreSQL -
create function plruby_call_handler() returns language_handler
as '/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/plruby.so'
language 'c';

The follows error appears - could not load library "/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/plruby.so": /usr/lib64/ruby/site_ruby/1.8/x86_64-linux/plruby.so: undefined symbol: FunctionCall3

What could be a problem!?
Thanks in advance Hanan Brener

Random segfaults

Hi,

I am getting random Ruby process segfaults leading to PostgreSQL restart

Here is a fragment of the log file:

/usr/local/rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/yaml.rb:133: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
2011-12-28 14:19:56 UTC LOG: server process (PID 32359) was terminated by signal 6: Aborted
2011-12-28 14:19:56 UTC HINT: In a moment you should be able to reconnect to the database and repeat your command.
2011-12-28 14:19:56 UTC WARNING: terminating connection because of crash of another server process
2011-12-28 14:19:56 UTC DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2011-12-28 14:19:56 UTC HINT: In a moment you should be able to reconnect to the database and repeat your command.
2011-12-28 14:19:56 UTC FATAL: the database system is in recovery mode

This happens every few hours on a very busy server.
PostgreSQL 9.0.6 on Debian 6.0, Ruby 1.8.7-p352 from RVM.

I would be glad to help diagnose the problem, but no idea how to debug this thing. Any hints welcomed.

Doesn't work with Postgres 9.1.2

Full output of "make test" is below. However, one issue is:

ERROR: syntax error at or near "lancompiler"
LINE 3: lancompiler 'PL/Ruby';

If I Google for lancompiler, I get http://www.postgresql.org/docs/7.1/static/sql-createlanguage.html. If I look instead at http://www.postgresql.org/docs/9.1/static/sql-createlanguage.html, lancompiler is gone.

This code likely needs to be updated for newer Postgres versions.

dan-pro:~/Downloads/knu-postgresql-plruby-1f54eea $ make test
(cd test/conv_bitstring ; RUBY='/<redacted>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby' sh ./runtest 91 )
**** Destroy old database plruby_test ****
dropdb: database removal failed: ERROR:  database "plruby_test" does not exist
**** Create test database plruby_test ****
**** Create procedural language plruby ****
b.rb:3: Use RbConfig instead of obsolete and deprecated Config.
ERROR:  syntax error at or near "lancompiler"
LINE 3:         lancompiler 'PL/Ruby';
                ^
**** Running test queries ****
    Tests failed - look at diffs between
    test.expected.91 and test.out
(cd test/conv_geometry ; RUBY='/<redacted>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby' sh ./runtest 91 )
**** Destroy old database plruby_test ****
**** Create test database plruby_test ****
**** Create procedural language plruby ****
b.rb:3: Use RbConfig instead of obsolete and deprecated Config.
ERROR:  syntax error at or near "lancompiler"
LINE 3:         lancompiler 'PL/Ruby';
                ^
**** Running test queries ****
    Tests failed - look at diffs between
    test.expected.91 and test.out
(cd test/conv_network ; RUBY='/<redacted>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby' sh ./runtest 91 )
**** Destroy old database plruby_test ****
**** Create test database plruby_test ****
**** Create procedural language plruby ****
b.rb:3: Use RbConfig instead of obsolete and deprecated Config.
ERROR:  syntax error at or near "lancompiler"
LINE 3:         lancompiler 'PL/Ruby';
                ^
**** Running test queries ****
    Tests failed - look at diffs between
    test.expected.91 and test.out
(cd test/plp ; RUBY='/<redacted>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby' sh ./runtest 91 )
**** Destroy old database plruby_test ****
**** Create test database plruby_test ****
**** Create procedural language plruby ****
b.rb:3: Use RbConfig instead of obsolete and deprecated Config.
ERROR:  syntax error at or near "lancompiler"
LINE 3:         lancompiler 'PL/Ruby';
                ^
**** Create tables, functions and triggers ****
ERROR:  language "plruby" does not exist
ERROR:  function tg_room_au() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_room_ad() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_wslot_biu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_pfield_au() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_pfield_ad() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_pslot_biu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_system_au() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_iface_biu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_hub_a() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_hslot_biu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_hslot_bd() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_chkslotname() does not exist
ERROR:  function tg_chkslotname() does not exist
ERROR:  function tg_chkslotname() does not exist
ERROR:  function tg_chkslotname() does not exist
ERROR:  function tg_chkslotname() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_chkslotlink() does not exist
ERROR:  function tg_chkslotlink() does not exist
ERROR:  function tg_chkslotlink() does not exist
ERROR:  function tg_chkslotlink() does not exist
ERROR:  function tg_chkslotlink() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_chkbacklink() does not exist
ERROR:  function tg_chkbacklink() does not exist
ERROR:  function tg_chkbacklink() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_pslot_bu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_wslot_bu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_pline_bu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_iface_bu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_hslot_bu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_phone_bu() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_backlink_a() does not exist
ERROR:  function tg_backlink_a() does not exist
ERROR:  function tg_backlink_a() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function tg_slotlink_a() does not exist
ERROR:  function tg_slotlink_a() does not exist
ERROR:  function tg_slotlink_a() does not exist
ERROR:  function tg_slotlink_a() does not exist
ERROR:  function tg_slotlink_a() does not exist
ERROR:  language "plruby" does not exist
ERROR:  language "plruby" does not exist
ERROR:  language "plruby" does not exist
ERROR:  function pslot_backlink_view(character varying) does not exist
LINE 2:     pslot_backlink_view(PF.slotname) as backside,
            ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
**** Running test queries ****
    Tests failed - look at diffs between
    test.expected.91 and test.out
(cd test/plt ; RUBY='/<redacted>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby' sh ./runtest 91 )
**** Destroy old database plruby_test ****
**** Create test database plruby_test ****
**** Create procedural language plruby ****
b.rb:3: Use RbConfig instead of obsolete and deprecated Config.
ERROR:  syntax error at or near "lancompiler"
LINE 3:         lancompiler 'PL/Ruby';
                ^
**** Create tables, functions and triggers ****
ERROR:  language "plruby" does not exist
ERROR:  language "plruby" does not exist
ERROR:  function trig_pkey1_before() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function trig_pkey2_before() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function trig_pkey2_after() does not exist
ERROR:  language "plruby" does not exist
ERROR:  function check_primkey() does not exist
ERROR:  function check_primkey() does not exist
ERROR:  language "plruby" does not exist
ERROR:  language "plruby" does not exist
ERROR:  language "plruby" does not exist
ERROR:  function ruby_int4_accum(integer[], integer) does not exist
ERROR:  function ruby_int4add(integer, integer) does not exist
ERROR:  language "plruby" does not exist
ERROR:  function ruby_int4lt(integer, integer) does not exist
**** Running test queries ****
    Tests failed - look at diffs between
    test.expected.91 and test.out
(cd test/range ; RUBY='/<redacted>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby' sh ./runtest 91 )
**** Destroy old database plruby_test ****
**** Create test database plruby_test ****
**** Create procedural language plruby ****
b.rb:3: Use RbConfig instead of obsolete and deprecated Config.
ERROR:  syntax error at or near "lancompiler"
LINE 3:         lancompiler 'PL/Ruby';
                ^
**** Running test queries ****
    Tests failed - look at diffs between
    test.expected.91 and test.out

Cannot be build with ruby 2.1.x + patch

Ruby 2.1.1 changed things related to safe level, specifically Ruby 2.1+ does not support safe level bigger than 3.
https://bugs.ruby-lang.org/issues/8468
https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41259

It means that it fails to build with the following error:
plruby.c:1660:5: error: call to 'ruby_safe_level_4_error' declared with attribute error: $SAFE=4 is obsolete

In Ruby 2.1.x there is now RUBY_SAFE_LEVEL_MAX, currently evaluated to 3. This constant is not in older Ruby versions, unfortunately.

The following is the proposed patch, which is just a quick version. Complete patch would need to change all parts of the code where safe_level greater than 3 is expected.

diff -up postgresql-plruby-0.5.4/src/plruby.h.safelevel postgresql-plruby-0.5.4/src/plruby.h
--- postgresql-plruby-0.5.4/src/plruby.h.safelevel 2014-04-29 12:26:38.086862696 +0200
+++ postgresql-plruby-0.5.4/src/plruby.h 2014-04-29 12:27:51.487896135 +0200
@@ -68,8 +68,12 @@
extern VALUE rb_thread_list();

#ifndef SAFE_LEVEL
+#ifdef RUBY_SAFE_LEVEL_MAX
+#define SAFE_LEVEL RUBY_SAFE_LEVEL_MAX
+#else
#define SAFE_LEVEL 12
#endif
+#endif

#ifndef MAIN_SAFE_LEVEL
#ifdef PLRUBY_TIMEOUT

undefined symbol: FunctionCall3Coll

We are getting the following error when running queries:

ERROR: could not load library "/usr/local/lib/site_ruby/1.8/x86_64-linux/plruby.so": /usr/local/lib/site_ruby/1.8/x86_64-linux/plruby.so: undefined symbol: FunctionCall3Coll

This is with postgres 9.1.1.
#7-Ubuntu SMP Tue Oct 13 19:55:22 UTC 2009 x86_64 GNU/Linux

Where would this symbol be defined?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.