CreateLang » History » Version 7
Álvaro Herrera, 03/19/2009 08:43 AM
highlight version numbers
1 | 1 | Álvaro Herrera | = Creating the PL/php language in a PostgreSQL database = |
---|---|---|---|
2 | |||
3 | 7 | Álvaro Herrera | The first thing you need is to have a PL/php entry in the pg_pltemplate system catalog. |
4 | 6 | Álvaro Herrera | |
5 | 7 | Álvaro Herrera | In '''8.1 and 8.2''' you can insert one by issuing, as a superuser: |
6 | 1 | Álvaro Herrera | {{{ |
7 | INSERT INTO pg_pltemplate VALUES |
||
8 | 5 | Álvaro Herrera | ('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL); |
9 | 1 | Álvaro Herrera | |
10 | INSERT INTO pg_pltemplate VALUES |
||
11 | 5 | Álvaro Herrera | ('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL); |
12 | 1 | Álvaro Herrera | }}} |
13 | |||
14 | 7 | Álvaro Herrera | Note that for '''8.3''' you need this instead: |
15 | 6 | Álvaro Herrera | {{{ |
16 | INSERT INTO pg_pltemplate VALUES |
||
17 | ('plphp', 't', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL); |
||
18 | |||
19 | INSERT INTO pg_pltemplate VALUES |
||
20 | ('plphpu', 'f', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL); |
||
21 | }}} |
||
22 | |||
23 | 5 | Álvaro Herrera | Note you '''DON'T''' have to edit the `$libdir`. Leave it alone. It will be expanded by PostgreSQL automatically. You don't need to add the `.so` suffix either (or whatever it's called on your platform.) |
24 | |||
25 | 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. |
26 | 1 | Álvaro Herrera | |
27 | In any database where you want to use PL/php you need to issue simply |
||
28 | |||
29 | {{{ |
||
30 | CREATE LANGUAGE plphp; |
||
31 | }}} |
||
32 | |||
33 | or |
||
34 | {{{ |
||
35 | CREATE LANGUAGE plphpu; |
||
36 | }}} |
||
37 | (the latter will create the untrusted version, which by default only superusers can write functions in). |
||
38 | 2 | Álvaro Herrera | |
39 | 5 | Álvaro Herrera | Now the language is ready to be used. |
40 | 1 | Álvaro Herrera | |
41 | If you receive an error similar to: |
||
42 | |||
43 | {{{ |
||
44 | 5 | Álvaro Herrera | ERROR: could not load library "/usr/local/lib/postgresql/plphp": |
45 | 2 | Álvaro Herrera | libphp4.so: cannot open shared object file: No such file or directory |
46 | 1 | Álvaro Herrera | }}} |
47 | 5 | Álvaro Herrera | |
48 | 6 | Álvaro Herrera | 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) |