Published on Thu, Sep 14, 2017
This is one of the quickest blog am publishing :). I am publishing from my terminal as is of my testing to create language plpython3u.
Using trusted or untrusted distributions of python we can create plpython3u language in PostgreSQL. In my testing, am trying with SCL distribution(am not recommending, I tried for testing) of python3.3 to create language plpython3u.
Let’s begin creating language on a binary version of PostgreSQL 9.6 installation without any tweaking.
-bash-4.2$ psql psql.bin (9.6.4) Type "help" for help. postgres=\# CREATE LANGUAGEplpython3u; ERROR: could not load library "/opt/PostgreSQL/9.6/lib/postgresql/plpython3.so":libpython3.3m.so.1.0: cannot open shared object file: No such file ordirectory
Hmmm, “/opt/PostgreSQL/9.6/lib/postgresql/plpython3.so” looking for a library “libpython3.3m.so.1.0”. To confirm, run “ldd” command
-bash-4.2$ cd /opt/PostgreSQL/9.6/lib/postgresql/ -bash-4.2$ ldd plpython3.so linux-vdso.so.1 => (0x00007fff9db12000) libpython3.3m.so.1.0 => not found libc.so.6 => /lib64/libc.so.6 (0x00007fe75e42f000) /lib64/ld-linux-x86-64.so.2 (0x00007fe75ea27000)
Now, its clear we need libpython3.3m.so.1.0 to create plpython3u language.
Lets get started as a root user to install python3.3 from SCL repo by enabling it.
After installing, find for a library “libpython3.3m.so.1.0” required by plpython3.so
Cool. To make use of Python3 bundle switch as a postgres user and set the environment variable PYTHONPATH, PYTHONHOME, PATH and LD_LIBRARY_PATH.
Try running “ldd” on “/opt/PostgreSQL/9.6/lib/postgresql/plpython3.so” again to check the libraries are properly picked.
Nice. We are all set. Let’s restart the server and create the language plpython3u.
Very nice… One last step, lets test plpython3u language by creating a sample function.
Please feel free to write me an email to share your comments & thoughts.