Creating the PL/php language in a PostgreSQL database

Installing the pg_pltemplate entries

The first thing you need is to have a PL/php entry in the pg_pltemplate system catalog.
This is done by executing the install.sql file when connected as a superuser to any database. On 8.2, you need to execute the install82.sql file instead.

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


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




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

Now the language is ready to be used.

Common problems

If you receive an error similar to:

ERROR:  could not load library "/usr/local/lib/postgresql/plphp": 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 is located (or add that path to /etc/