Project

General

Profile

CreateLang » History » Version 2

Álvaro Herrera, 11/16/2005 01:04 PM

1 1 Álvaro Herrera
= Creating the PL/php language in a PostgreSQL database =
2
3
In 8.1 and beyond you need to have a PL/php entry in the pg_pltemplate system catalog.
4
You can insert one by issuing, as a superuser:
5
{{{
6
INSERT INTO pg_pltemplate VALUES
7
('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp.so', NULL);
8
9
INSERT INTO pg_pltemplate VALUES
10
('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp.so', NULL);
11
}}}
12 2 Álvaro Herrera
(note you '''DON'T''' have to edit the $libdir.  Leave it alone.  It will be expanded by PostgreSQL automatically.)
13 1 Álvaro Herrera
14
This will create entries for the trusted and untrusted versions of PL/php.  Note that pg_pltemplate is a shared catalogs, which means you have to do it only once in any database and it will be available in all your databases automatically.
15
16
In any database where you want to use PL/php you need to issue simply
17
18
{{{
19
CREATE LANGUAGE plphp;
20
}}}
21
22
or
23
{{{
24
CREATE LANGUAGE plphpu;
25
}}}
26
(the latter will create the untrusted version, which by default only superusers can write functions in).
27
28
Now the language is ready to be used.
29
30
If you receive an error similar to:
31
32
{{{
33 2 Álvaro Herrera
ERROR:  could not load library "/usr/local/lib/postgresql/plphp.so":
34 1 Álvaro Herrera
libphp4.so: cannot open shared object file: No such file or directory
35
}}}
36
37
it means the Postmaster can't find the PHP shared library.  A solution
38
you may use is to define the LD_LIBRARY_PATH to postmaster, like so:
39
40
{{{
41 2 Álvaro Herrera
LD_LIBRARY_PATH=/usr/lib/apache2/modules:$LD_LIBRARY_PATH postmaster
42 1 Álvaro Herrera
}}}
43
44
Of course this isn't ideal.  You may want to define the variable somewhere in your start script (/etc/init.d/postgresql or whatever).  This is too varied across Linux distributions or other operating systems so I'll leave it as an exercise to the reader.