plruby
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3160 | plruby | No | Yes | No | Yes | No | No | pg_catalog |
| 3161 | jsonb_plruby | No | Yes | No | Yes | No | Yes | - |
| 3162 | hstore_plruby | No | Yes | No | Yes | No | Yes | - |
| 3163 | ltree_plruby | No | Yes | No | Yes | No | Yes | - |
| Related | jsonb_plruby hstore_plruby ltree_plruby plperl plpython3u pllua plv8 plrust |
|---|---|
| Depended By | hstore_plruby jsonb_plruby ltree_plruby |
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.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.5 | 1817161514 | plruby | - |
| RPM | PIGSTY | 2.5.0 | 1817161514 | plruby_$v | ruby-libs |
| DEB | PIGSTY | 2.5.0 | 1817161514 | postgresql-$v-plruby | - |
Build
You can build the RPM / DEB packages for plruby using pig build:
Install
You can install plruby directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
- PL/Ruby v2.5.0 README
- PL/Ruby language reference
- PL/Ruby cookbook
- PL/Ruby v2.5.0 control file
- PL/Ruby changelog
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
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:
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
byteanow maps to a raw, NUL-safe RubyStringwithASCII-8BITencoding 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 withArray#pack.$_SDadds per-function state that persists across calls in one session and resets when the function is recompiled.$_SHAREDremains session-wide across PL/Ruby functions.spi_colnames,spi_coltypes, andspi_coltypmodsexpose result-column metadata, andltree_plrubyadds the opt-inltreetransform.- After installing the 2.5.0 shared library and SQL files, run
ALTER EXTENSION plruby UPDATEin each database that already has the extension.
Security and Requirements
plrubyis 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 14-18.
- No
shared_preload_librariessetting is required. Existing sessions must reconnect after server-side library replacement before assuming a new runtime is active. jsonb_plruby,hstore_plruby, andltree_plrubyare companion transforms. A function must explicitly declareTRANSFORM FOR TYPE ...to receive native Ruby structures instead of the normal datum wrapper/conversion path.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)