CreateLang » History » Version 3
Álvaro Herrera, 11/16/2005 01:15 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 | 3 | Álvaro Herrera | CREATE FUNCTION plphp_call_handler() RETURNS language_handler |
7 | LANGUAGE C AS '$libdir/plphp', 'plphp_call_handler'; |
||
8 | |||
9 | CREATE FUNCTION plphp_validator(oid) RETURNS language_handler |
||
10 | LANGUAGE C AS '$libdir/plphp', 'plphp_validator'; |
||
11 | |||
12 | 1 | Álvaro Herrera | INSERT INTO pg_pltemplate VALUES |
13 | ('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp.so', NULL); |
||
14 | |||
15 | INSERT INTO pg_pltemplate VALUES |
||
16 | ('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp.so', NULL); |
||
17 | 2 | Álvaro Herrera | }}} |
18 | 1 | Álvaro Herrera | (note you '''DON'T''' have to edit the $libdir. Leave it alone. It will be expanded by PostgreSQL automatically.) |
19 | |||
20 | 3 | Álvaro Herrera | 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. |
21 | 1 | Álvaro Herrera | |
22 | In any database where you want to use PL/php you need to issue simply |
||
23 | |||
24 | {{{ |
||
25 | CREATE LANGUAGE plphp; |
||
26 | }}} |
||
27 | |||
28 | or |
||
29 | {{{ |
||
30 | CREATE LANGUAGE plphpu; |
||
31 | }}} |
||
32 | (the latter will create the untrusted version, which by default only superusers can write functions in). |
||
33 | |||
34 | Now the language is ready to be used. |
||
35 | |||
36 | If you receive an error similar to: |
||
37 | |||
38 | {{{ |
||
39 | 2 | Álvaro Herrera | ERROR: could not load library "/usr/local/lib/postgresql/plphp.so": |
40 | 1 | Álvaro Herrera | libphp4.so: cannot open shared object file: No such file or directory |
41 | }}} |
||
42 | |||
43 | it means the Postmaster can't find the PHP shared library. A solution |
||
44 | you may use is to define the LD_LIBRARY_PATH to postmaster, like so: |
||
45 | |||
46 | {{{ |
||
47 | 2 | Álvaro Herrera | LD_LIBRARY_PATH=/usr/lib/apache2/modules:$LD_LIBRARY_PATH postmaster |
48 | 1 | Álvaro Herrera | }}} |
49 | |||
50 | 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. |