Skip to content

plluau

Lua as an untrusted procedural language

pllua · Lua as an untrusted procedural language

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3030plluaupllua2.0LANGMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--NoYesNoYesnono
pkg 2.0.12; SQL 2.0.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY2.019 18 17 16 15pllua-
RPMPIGSTY2.0.1219 18 17 16 15pllua_$v-
DEBPGDG2.0.1219 18 17 16 15postgresql-$v-pllua-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
el8.aarch64N/APIGSTY 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
el9.x86_64MISSPIGSTY 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
el9.aarch64MISSPIGSTY 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
el10.x86_64MISSPIGSTY 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
el10.aarch64MISSPIGSTY 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
d12.x86_64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
d12.aarch64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
d13.x86_64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
d13.aarch64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
u22.x86_64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
u22.aarch64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
u24.x86_64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
u24.aarch64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
u26.x86_64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12
u26.aarch64PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12PGDG 2.0.12

Source

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 pllua;		# install by package name
pig install plluau;		# install by extension name

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

Create this extension with:

CREATE EXTENSION plluau;

Usage

plluau: Lua as an untrusted procedural language

plluau is the untrusted variant of pllua, allowing Lua functions to access the filesystem, load arbitrary modules, and perform operations restricted in the trusted version.

CREATE EXTENSION plluau;

Create Functions

CREATE FUNCTION read_file(path text) RETURNS text LANGUAGE plluau AS $$
  local f = io.open(path, "r")
  if f then
    local content = f:read("*a")
    f:close()
    return content
  end
  return nil
$$;

Differences from pllua (Trusted)

Featurepllua (trusted)plluau (untrusted)
File I/ORestrictedFull access
Module loadingWhitelisted onlyUnrestricted
OS accessNoYes
Suitable forUser-defined functionsAdmin/superuser functions

Same API as pllua

plluau shares the same SPI interface, trigger support, set-returning functions, and data type handling as pllua. All SPI functions (spi.execute, spi.prepare, spi.rows), coroutine-based set returns, and trigger functions work identically.

CREATE FUNCTION run_command(cmd text) RETURNS text LANGUAGE plluau AS $$
  local handle = io.popen(cmd)
  local result = handle:read("*a")
  handle:close()
  return result
$$;

Initialization

Configure via GUC (superuser only):

SET pllua.on_untrusted_init = 'myvar = {}';

Only superusers can create plluau functions due to the unrestricted access it provides.

Table reader