CreateLang » History » Version 1
Álvaro Herrera, 11/16/2005 12:56 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 | |||
13 | 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. |
||
14 | |||
15 | In any database where you want to use PL/php you need to issue simply |
||
16 | |||
17 | {{{ |
||
18 | CREATE LANGUAGE plphp; |
||
19 | }}} |
||
20 | |||
21 | or |
||
22 | {{{ |
||
23 | CREATE LANGUAGE plphpu; |
||
24 | }}} |
||
25 | (the latter will create the untrusted version, which by default only superusers can write functions in). |
||
26 | |||
27 | Now the language is ready to be used. |
||
28 | |||
29 | If you receive an error similar to: |
||
30 | |||
31 | {{{ |
||
32 | ERROR: could not load library "/home/alvherre/Code/CVS/pgsql/install/00orig/lib/postgresql/plphp.so": |
||
33 | libphp4.so: cannot open shared object file: No such file or directory |
||
34 | }}} |
||
35 | |||
36 | it means the Postmaster can't find the PHP shared library. A solution |
||
37 | you may use is to define the LD_LIBRARY_PATH to postmaster, like so: |
||
38 | |||
39 | {{{ |
||
40 | LD_LIBRARY_PATH=/usr/lib/apache2/modules postmaster |
||
41 | }}} |
||
42 | |||
43 | 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. |