Project

General

Profile

Actions

CreateLang » History » Revision 10

« Previous | Revision 10/11 (diff) | Next »
Álvaro Herrera, 06/22/2010 10:11 AM


Creating the PL/php language in a PostgreSQL database

The first thing you need is to have a PL/php entry in the pg_pltemplate system catalog.

In 8.1 and 8.2 you can insert one by issuing, as a superuser:

INSERT INTO pg_pltemplate VALUES
('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);

INSERT INTO pg_pltemplate VALUES
('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);

Note that for 8.3 and later you need this instead:

INSERT INTO pg_pltemplate (tmplname, tmpltrusted, tmpldbacreate, tmplhandler, tmplvalidator, tmpllibrary) VALUES
('plphp', 't', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp');

INSERT INTO pg_pltemplate(tmplname, tmpltrusted, tmpldbacreate, tmplhandler, tmplvalidator, tmpllibrary) VALUES
('plphpu', 'f', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp');

Note you DON'T have to edit the $libdir. Leave it alone. It will be expanded by PostgreSQL automatically. You don't need to add the .so suffix either (or whatever it's called on your platform.)

This will create entries for the trusted and untrusted versions of PL/php. Note that pg_pltemplate is a shared catalog, which means you have to do it only once in any database and it will be available in all your databases automatically.

In any database where you want to use PL/php you need to issue simply

CREATE LANGUAGE plphp;

or

CREATE LANGUAGE plphpu;

(the latter will create the untrusted version, which by default only superusers can write functions in).

Now the language is ready to be used.

If you receive an error similar to:

ERROR:  could not load library "/usr/local/lib/postgresql/plphp":
libphp4.so: cannot open shared object file: No such file or directory

it means the Postmaster can't find the PHP shared library. You should probably define a LD_LIBRARY_PATH variable in the postmaster environment that points to the location where libphp.so is located (or add that path to /etc/ld.so.conf)

Updated by Álvaro Herrera over 14 years ago · 10 revisions