All Projects → petere → Plsh

petere / Plsh

Licence: other
PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice.

Programming Languages

c
50402 projects - #5 most used programming language
shell
77523 projects
language
365 projects

Projects that are alternatives of or similar to Plsh

Plgo
easily create postgresql extensions in golang; moved to gitlab.com/microo8/plgo
Stars: ✭ 286 (+157.66%)
Mutual labels:  postgresql, postgresql-extension, trigger
Orafce
The "orafce" project implements in Postgres some of the functions from the Oracle database that are missing (or behaving differently).Those functions were verified on Oracle 10g, and the module is useful for production work.
Stars: ✭ 274 (+146.85%)
Mutual labels:  postgresql, postgresql-extension
Incubator Age
Graph database optimized for fast analysis and real-time data processing. It is provided as an extension to PostgreSQL.
Stars: ✭ 244 (+119.82%)
Mutual labels:  postgresql, postgresql-extension
Pgaudit
PostgreSQL Audit Extension
Stars: ✭ 532 (+379.28%)
Mutual labels:  postgresql, postgresql-extension
Pguri
uri type for PostgreSQL
Stars: ✭ 235 (+111.71%)
Mutual labels:  postgresql, postgresql-extension
Tds fdw
A PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)
Stars: ✭ 238 (+114.41%)
Mutual labels:  postgresql, postgresql-extension
Plpgsql check
plpgsql_check is linter tool for language PL/pgSQL (native language for PostgreSQL store procedures).
Stars: ✭ 322 (+190.09%)
Mutual labels:  postgresql, postgresql-extension
Pg partman
Partition management extension for PostgreSQL
Stars: ✭ 1,085 (+877.48%)
Mutual labels:  postgresql, postgresql-extension
Pgx
Build Postgres Extensions with Rust!
Stars: ✭ 903 (+713.51%)
Mutual labels:  postgresql, postgresql-extension
Pg acoustid
PostgreSQL extension for working with AcoustID fingerprints
Stars: ✭ 6 (-94.59%)
Mutual labels:  postgresql, postgresql-extension
Agensgraph Extension
A graph database extension for PostgreSQL
Stars: ✭ 170 (+53.15%)
Mutual labels:  postgresql, postgresql-extension
Plv8
V8 Engine Javascript Procedural Language add-on for PostgreSQL
Stars: ✭ 1,195 (+976.58%)
Mutual labels:  postgresql, postgresql-extension
Pg hashids
Short unique id generator for PostgreSQL, using hashids
Stars: ✭ 164 (+47.75%)
Mutual labels:  postgresql, postgresql-extension
Wasmer Postgres
💽🕸 Postgres library to run WebAssembly binaries.
Stars: ✭ 245 (+120.72%)
Mutual labels:  postgresql, postgresql-extension
Decoderbufs
INACTIVE: A PostgreSQL logical decoder output plugin to deliver data as Protocol Buffers
Stars: ✭ 116 (+4.5%)
Mutual labels:  postgresql, postgresql-extension
Pg auto failover
Postgres extension and service for automated failover and high-availability
Stars: ✭ 564 (+408.11%)
Mutual labels:  postgresql, postgresql-extension
Postgresql2websocket
Send PostgreSQL notifications over websockets
Stars: ✭ 58 (-47.75%)
Mutual labels:  postgresql, trigger
Bgworker
Background Worker Processes for PostgreSQL written in Go
Stars: ✭ 77 (-30.63%)
Mutual labels:  postgresql, postgresql-extension
Pg stat kcache
Gather statistics about physical disk access and CPU consumption done by backends.
Stars: ✭ 106 (-4.5%)
Mutual labels:  postgresql
Xgenecloud
XgeneCloud is now https://github.com/nocodb/nocodb
Stars: ✭ 1,629 (+1367.57%)
Mutual labels:  postgresql

PL/sh Procedural Language Handler for PostgreSQL

PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice. For example,

CREATE FUNCTION concat(text, text) RETURNS text AS '
#!/bin/sh
echo "$1$2"
' LANGUAGE plsh;

The first line must be a #!-style line that indicates the shell to use. The rest of the function body will be executed by that shell in a separate process. The arguments are available as $1, $2, etc., as usual. (This is the shell's syntax. If your shell uses something different then that's what you need to use.) The return value will become what is printed to the standard output, with a newline stripped. If nothing is printed, a null value is returned. If anything is printed to the standard error, then the function aborts with an error and the message is printed. If the script does not exit with status 0 then an error is raised as well.

The shell script can do anything you want, but you can't access the database directly. Trigger functions are also possible, but they can't change the rows. Needless to say, this language should not be declared as TRUSTED.

The distribution also contains a test suite in the directory test/, which contains a simplistic demonstration of the functionality.

I'm interested if anyone is using this.

Peter Eisentraut [email protected]

Database Access

You can't access the database directly from PL/sh through something like SPI, but PL/sh sets up libpq environment variables so that you can easily call psql back into the same database, for example

CREATE FUNCTION query (x int) RETURNS text
LANGUAGE plsh
AS $$
#!/bin/sh
psql -At -c "select b from pbar where a = $1"
$$;

Note: The "bin" directory is prepended to the path, but only if the PATH environment variable is already set.

Triggers

In a trigger procedure, trigger data is available to the script through environment variables (analogous to PL/pgSQL):

  • PLSH_TG_NAME: trigger name
  • PLSH_TG_WHEN: BEFORE, INSTEAD OF, or AFTER
  • PLSH_TG_LEVEL: ROW or STATEMENT
  • PLSH_TG_OP: DELETE, INSERT, UPDATE, or TRUNCATE
  • PLSH_TG_TABLE_NAME: name of the table the trigger is acting on
  • PLSH_TG_TABLE_SCHEMA: schema name of the table the trigger is acting on

Event Triggers

In an event trigger procedure, the event trigger data is available to the script through the following environment variables:

  • PLSH_TG_EVENT: event name
  • PLSH_TG_TAG: command tag

Inline Handler

PL/sh supports the DO command. For example:

DO E'#!/bin/sh\nrm -f /tmp/file' LANGUAGE plsh;

Installation

You need to have PostgreSQL 8.4 or later, and you need to have the server include files installed.

To build and install PL/sh, use this procedure:

make
make install

The include files are found using the pg_config program that is included in the PostgreSQL installation. To use a different PostgreSQL installation, point configure to a different pg_config like so:

make PG_CONFIG=/else/where/pg_config
make install PG_CONFIG=/else/where/pg_config

Note that generally server-side modules such as this one have to be recompiled for every major PostgreSQL version (that is, 8.4, 9.0, ...).

To declare the language in a database, use the extension system with PostgreSQL version 9.1 or later. Run

CREATE EXTENSION plsh;

inside the database of choice. To upgrade from a previous installation that doesn't use the extension system, use

CREATE EXTENSION plsh FROM unpackaged;

Use DROP EXTENSION to remove it.

With versions prior to PostgreSQL 9.1, use

psql -d DBNAME -f .../share/contrib/plsh.sql

with a server running. To drop it, use droplang plsh, or DROP FUNCTION plsh_handler(); DROP LANGUAGE plsh; if you want to do it manually.

Test suite

Build Status

To run the test suite, execute

make installcheck

after installation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].