Skip to content

plruby

Embed MRI Ruby as an untrusted PostgreSQL procedural language

plruby · Embed MRI Ruby as an untrusted PostgreSQL procedural language

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3160plrubyplruby2.5LANGMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--NoYesNoYesnono
Extension control default_version is 2.5 while the project and package version is 2.5.0; PL/Ruby embeds MRI Ruby 3.x, is untrusted and superuser-only, and requires no preload. RPM builds also provide an llvmjit subpackage.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY2.519 18 17 16 15plruby-
RPMPIGSTY2.5.019 18 17 16 15plruby_$vruby-libs
DEBPIGSTY2.5.019 18 17 16 15postgresql-$v-plruby-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el8.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el9.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el9.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el10.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
el10.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d12.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d12.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d13.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
d13.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u22.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u22.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u24.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u24.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u26.x86_64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
u26.aarch64N/APIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0PIGSTY 2.5.0
PackageVersionOSORGSIZEFile URL
plruby_182.5.0el8.x86_64pigsty138.8 KiBplruby_18-2.5.0-1PGSTY.el8.x86_64.rpm
plruby_182.5.0el8.aarch64pigsty136.2 KiBplruby_18-2.5.0-1PGSTY.el8.aarch64.rpm
plruby_182.5.0el9.x86_64pigsty145.9 KiBplruby_18-2.5.0-1PGSTY.el9.x86_64.rpm
plruby_182.5.0el9.aarch64pigsty143.5 KiBplruby_18-2.5.0-1PGSTY.el9.aarch64.rpm
plruby_182.5.0el10.x86_64pigsty140.6 KiBplruby_18-2.5.0-1PGSTY.el10.x86_64.rpm
plruby_182.5.0el10.aarch64pigsty139.3 KiBplruby_18-2.5.0-1PGSTY.el10.aarch64.rpm
postgresql-18-plruby2.5.0d12.x86_64pigsty124.7 KiBpostgresql-18-plruby_2.5.0-1PGSTY~bookworm_amd64.deb
postgresql-18-plruby2.5.0d12.aarch64pigsty122.2 KiBpostgresql-18-plruby_2.5.0-1PGSTY~bookworm_arm64.deb
postgresql-18-plruby2.5.0d13.x86_64pigsty121.6 KiBpostgresql-18-plruby_2.5.0-1PGSTY~trixie_amd64.deb
postgresql-18-plruby2.5.0d13.aarch64pigsty119.3 KiBpostgresql-18-plruby_2.5.0-1PGSTY~trixie_arm64.deb
postgresql-18-plruby2.5.0u22.x86_64pigsty136.5 KiBpostgresql-18-plruby_2.5.0-1PGSTY~jammy_amd64.deb
postgresql-18-plruby2.5.0u22.aarch64pigsty134.2 KiBpostgresql-18-plruby_2.5.0-1PGSTY~jammy_arm64.deb
postgresql-18-plruby2.5.0u24.x86_64pigsty129.5 KiBpostgresql-18-plruby_2.5.0-1PGSTY~noble_amd64.deb
postgresql-18-plruby2.5.0u24.aarch64pigsty128.3 KiBpostgresql-18-plruby_2.5.0-1PGSTY~noble_arm64.deb
postgresql-18-plruby2.5.0u26.x86_64pigsty126.1 KiBpostgresql-18-plruby_2.5.0-1PGSTY~resolute_amd64.deb
postgresql-18-plruby2.5.0u26.aarch64pigsty124.9 KiBpostgresql-18-plruby_2.5.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
plruby_172.5.0el8.x86_64pigsty138.6 KiBplruby_17-2.5.0-1PGSTY.el8.x86_64.rpm
plruby_172.5.0el8.aarch64pigsty136.1 KiBplruby_17-2.5.0-1PGSTY.el8.aarch64.rpm
plruby_172.5.0el9.x86_64pigsty145.6 KiBplruby_17-2.5.0-1PGSTY.el9.x86_64.rpm
plruby_172.5.0el9.aarch64pigsty143.4 KiBplruby_17-2.5.0-1PGSTY.el9.aarch64.rpm
plruby_172.5.0el10.x86_64pigsty140.3 KiBplruby_17-2.5.0-1PGSTY.el10.x86_64.rpm
plruby_172.5.0el10.aarch64pigsty138.9 KiBplruby_17-2.5.0-1PGSTY.el10.aarch64.rpm
postgresql-17-plruby2.5.0d12.x86_64pigsty124.5 KiBpostgresql-17-plruby_2.5.0-1PGSTY~bookworm_amd64.deb
postgresql-17-plruby2.5.0d12.aarch64pigsty121.9 KiBpostgresql-17-plruby_2.5.0-1PGSTY~bookworm_arm64.deb
postgresql-17-plruby2.5.0d13.x86_64pigsty121.4 KiBpostgresql-17-plruby_2.5.0-1PGSTY~trixie_amd64.deb
postgresql-17-plruby2.5.0d13.aarch64pigsty119.0 KiBpostgresql-17-plruby_2.5.0-1PGSTY~trixie_arm64.deb
postgresql-17-plruby2.5.0u22.x86_64pigsty154.3 KiBpostgresql-17-plruby_2.5.0-1PGSTY~jammy_amd64.deb
postgresql-17-plruby2.5.0u22.aarch64pigsty151.4 KiBpostgresql-17-plruby_2.5.0-1PGSTY~jammy_arm64.deb
postgresql-17-plruby2.5.0u24.x86_64pigsty129.0 KiBpostgresql-17-plruby_2.5.0-1PGSTY~noble_amd64.deb
postgresql-17-plruby2.5.0u24.aarch64pigsty127.8 KiBpostgresql-17-plruby_2.5.0-1PGSTY~noble_arm64.deb
postgresql-17-plruby2.5.0u26.x86_64pigsty125.9 KiBpostgresql-17-plruby_2.5.0-1PGSTY~resolute_amd64.deb
postgresql-17-plruby2.5.0u26.aarch64pigsty124.6 KiBpostgresql-17-plruby_2.5.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
plruby_162.5.0el8.x86_64pigsty138.5 KiBplruby_16-2.5.0-1PGSTY.el8.x86_64.rpm
plruby_162.5.0el8.aarch64pigsty136.1 KiBplruby_16-2.5.0-1PGSTY.el8.aarch64.rpm
plruby_162.5.0el9.x86_64pigsty145.7 KiBplruby_16-2.5.0-1PGSTY.el9.x86_64.rpm
plruby_162.5.0el9.aarch64pigsty143.4 KiBplruby_16-2.5.0-1PGSTY.el9.aarch64.rpm
plruby_162.5.0el10.x86_64pigsty140.2 KiBplruby_16-2.5.0-1PGSTY.el10.x86_64.rpm
plruby_162.5.0el10.aarch64pigsty139.0 KiBplruby_16-2.5.0-1PGSTY.el10.aarch64.rpm
postgresql-16-plruby2.5.0d12.x86_64pigsty124.5 KiBpostgresql-16-plruby_2.5.0-1PGSTY~bookworm_amd64.deb
postgresql-16-plruby2.5.0d12.aarch64pigsty122.0 KiBpostgresql-16-plruby_2.5.0-1PGSTY~bookworm_arm64.deb
postgresql-16-plruby2.5.0d13.x86_64pigsty121.4 KiBpostgresql-16-plruby_2.5.0-1PGSTY~trixie_amd64.deb
postgresql-16-plruby2.5.0d13.aarch64pigsty119.0 KiBpostgresql-16-plruby_2.5.0-1PGSTY~trixie_arm64.deb
postgresql-16-plruby2.5.0u22.x86_64pigsty153.2 KiBpostgresql-16-plruby_2.5.0-1PGSTY~jammy_amd64.deb
postgresql-16-plruby2.5.0u22.aarch64pigsty150.3 KiBpostgresql-16-plruby_2.5.0-1PGSTY~jammy_arm64.deb
postgresql-16-plruby2.5.0u24.x86_64pigsty129.1 KiBpostgresql-16-plruby_2.5.0-1PGSTY~noble_amd64.deb
postgresql-16-plruby2.5.0u24.aarch64pigsty127.9 KiBpostgresql-16-plruby_2.5.0-1PGSTY~noble_arm64.deb
postgresql-16-plruby2.5.0u26.x86_64pigsty125.9 KiBpostgresql-16-plruby_2.5.0-1PGSTY~resolute_amd64.deb
postgresql-16-plruby2.5.0u26.aarch64pigsty124.6 KiBpostgresql-16-plruby_2.5.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
plruby_152.5.0el8.x86_64pigsty138.3 KiBplruby_15-2.5.0-1PGSTY.el8.x86_64.rpm
plruby_152.5.0el8.aarch64pigsty135.9 KiBplruby_15-2.5.0-1PGSTY.el8.aarch64.rpm
plruby_152.5.0el9.x86_64pigsty145.8 KiBplruby_15-2.5.0-1PGSTY.el9.x86_64.rpm
plruby_152.5.0el9.aarch64pigsty144.0 KiBplruby_15-2.5.0-1PGSTY.el9.aarch64.rpm
plruby_152.5.0el10.x86_64pigsty140.4 KiBplruby_15-2.5.0-1PGSTY.el10.x86_64.rpm
plruby_152.5.0el10.aarch64pigsty139.7 KiBplruby_15-2.5.0-1PGSTY.el10.aarch64.rpm
postgresql-15-plruby2.5.0d12.x86_64pigsty124.7 KiBpostgresql-15-plruby_2.5.0-1PGSTY~bookworm_amd64.deb
postgresql-15-plruby2.5.0d12.aarch64pigsty122.1 KiBpostgresql-15-plruby_2.5.0-1PGSTY~bookworm_arm64.deb
postgresql-15-plruby2.5.0d13.x86_64pigsty121.0 KiBpostgresql-15-plruby_2.5.0-1PGSTY~trixie_amd64.deb
postgresql-15-plruby2.5.0d13.aarch64pigsty118.7 KiBpostgresql-15-plruby_2.5.0-1PGSTY~trixie_arm64.deb
postgresql-15-plruby2.5.0u22.x86_64pigsty153.4 KiBpostgresql-15-plruby_2.5.0-1PGSTY~jammy_amd64.deb
postgresql-15-plruby2.5.0u22.aarch64pigsty151.0 KiBpostgresql-15-plruby_2.5.0-1PGSTY~jammy_arm64.deb
postgresql-15-plruby2.5.0u24.x86_64pigsty129.1 KiBpostgresql-15-plruby_2.5.0-1PGSTY~noble_amd64.deb
postgresql-15-plruby2.5.0u24.aarch64pigsty128.7 KiBpostgresql-15-plruby_2.5.0-1PGSTY~noble_arm64.deb
postgresql-15-plruby2.5.0u26.x86_64pigsty126.1 KiBpostgresql-15-plruby_2.5.0-1PGSTY~resolute_amd64.deb
postgresql-15-plruby2.5.0u26.aarch64pigsty125.3 KiBpostgresql-15-plruby_2.5.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg plruby;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install plruby;		# install by package name

pig install plruby -v 18;   # install for PG 18
pig install plruby -v 17;   # install for PG 17
pig install plruby -v 16;   # install for PG 16
pig install plruby -v 15;   # install for PG 15

Create this extension with:

CREATE EXTENSION plruby;

Usage

Sources:

plruby is the maintained Command Prompt procedural-language extension that embeds Ruby 3 in PostgreSQL. Package release 2.5.0 installs SQL extension version 2.5. It supports scalar and set-returning functions, triggers, event triggers, procedures, anonymous DO blocks, SPI queries, cursors, and prepared plans.

Create a Function

CREATE EXTENSION plruby;

CREATE FUNCTION ruby_add(integer, integer)
RETURNS integer
LANGUAGE plruby
AS $$
  args[0] + args[1]
$$;

SELECT ruby_add(2, 3);

Arguments are exposed through args; Ruby’s final expression becomes the SQL return value. PostgreSQL scalar, array, composite, and record conversion rules are documented in the language reference.

Set-Returning Functions

Use return_next to emit rows from a set-returning function:

CREATE FUNCTION ruby_series(integer)
RETURNS SETOF integer
LANGUAGE plruby
AS $$
  1.upto(args[0]) { |n| return_next(n) }
$$;

SELECT * FROM ruby_series(3);

SPI and Database Work

PL/Ruby exposes PostgreSQL’s Server Programming Interface for SQL execution, prepared plans, and cursors. Keep SQL values in parameters rather than interpolating them into command text, and release long-lived cursors or prepared state when the session no longer needs them.

Procedures can use the documented transaction-control surface where PostgreSQL permits COMMIT or ROLLBACK. Functions and triggers remain subject to PostgreSQL’s normal transactional restrictions.

Triggers and Session State

Trigger functions receive trigger metadata through $_TD and return the row action documented by PL/Ruby. Event triggers, anonymous DO blocks, backend-local session data, and shared data are also available. These features run inside the database backend, so an exception, blocking call, or memory leak directly affects that backend.

Version 2.5.0

  • bytea now maps to a raw, NUL-safe Ruby String with ASCII-8BIT encoding instead of PostgreSQL hex text. This is a breaking conversion change: audit functions that parse or construct \x... strings and build bytes explicitly, for example with Array#pack.
  • $_SD adds per-function state that persists across calls in one session and resets when the function is recompiled. $_SHARED remains session-wide across PL/Ruby functions.
  • spi_colnames, spi_coltypes, and spi_coltypmods expose result-column metadata, and ltree_plruby adds the opt-in ltree transform.
  • After installing the 2.5.0 shared library and SQL files, run ALTER EXTENSION plruby UPDATE in each database that already has the extension.

Security and Requirements

  • plruby is an untrusted language. Ruby 3 provides no safe in-process sandbox, so creating PL/Ruby functions is restricted to superusers and code executes with the PostgreSQL server process’s operating-system authority.
  • Review all PL/Ruby source as privileged server code. Never allow tenants or ordinary application roles to submit arbitrary Ruby.
  • Upstream v2.5.0 supports PostgreSQL 11-18 and Ruby 3.x. Current Pigsty packages target PostgreSQL 15–18.
  • No shared_preload_libraries setting is required. Existing sessions must reconnect after server-side library replacement before assuming a new runtime is active.
  • jsonb_plruby, hstore_plruby, and ltree_plruby are companion transforms. A function must explicitly declare TRANSFORM FOR TYPE ... to receive native Ruby structures instead of the normal datum wrapper/conversion path.

Table reader