Project

General

Profile

CreateLang » History » Version 11

Álvaro Herrera, 07/12/2010 03:52 PM

1 9 Álvaro Herrera
h1. Creating the PL/php language in a PostgreSQL database
2 8 Álvaro Herrera
3 11 Álvaro Herrera
h2. Installing the @pg_pltemplate@ entries
4 1 Álvaro Herrera
5 11 Álvaro Herrera
The first thing you need is to have a PL/php entry in the @pg_pltemplate@ system catalog.
6
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.
7 8 Álvaro Herrera
8 11 Álvaro Herrera
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.
9 9 Álvaro Herrera
10 11 Álvaro Herrera
h2. Running @CREATE LANGUAGE@
11 1 Álvaro Herrera
12
In any database where you want to use PL/php you need to issue simply
13
14
<pre>
15 8 Álvaro Herrera
CREATE LANGUAGE plphp;
16 1 Álvaro Herrera
</pre>
17 8 Álvaro Herrera
18 1 Álvaro Herrera
or
19
<pre>
20 8 Álvaro Herrera
CREATE LANGUAGE plphpu;
21 1 Álvaro Herrera
</pre>
22 8 Álvaro Herrera
(the latter will create the untrusted version, which by default only superusers can write functions in).
23 2 Álvaro Herrera
24 5 Álvaro Herrera
Now the language is ready to be used.
25 11 Álvaro Herrera
26
h2. Common problems
27 1 Álvaro Herrera
28
If you receive an error similar to:
29 8 Álvaro Herrera
30 2 Álvaro Herrera
<pre>
31 1 Álvaro Herrera
ERROR:  could not load library "/usr/local/lib/postgresql/plphp":
32 8 Álvaro Herrera
libphp4.so: cannot open shared object file: No such file or directory
33 6 Álvaro Herrera
</pre>
34 1 Álvaro Herrera
35
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)