Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: how to install plpythonu extension

I'm running PostgreSQL 9.3.1 on Ubuntu 12.04.4. I'd like to use the plpython language extension but I get an error when I try to use it I get:

ERROR: language "plpythonu" does not exist

When I try to create the extension:

CREATE EXTENSION plpythonu

I get ERROR: could not access file "$libdir/plpython2": No such file or directory After much searching and digging through blog posts, I've tried installing additional packages, and have copied all the plpython files from /usr/share/postgresql/9.1/extension to /opt/bitnami/postgresql/share/extension where PostgreSQL seems to be looking for them. That at least got me to a point at which PostgreSQL actually sees the available extensions. When I run:

SELECT name, default_version, installed_version FROM pg_available_extensions WHERE name LIKE('plpy*')

I get :

    name    | default_version | installed_version 
------------+-----------------+-------------------
 plpython2u | 1.0             | 
 plpython3u | 1.0             | 
 plpythonu  | 1.0             | 

There are still no plpython libraries that I can see in /opt/bitnami/postgresql/lib. Can anybody help me get through remaining steps to make the extension work? Thanks in advance!

like image 311
Paul Angelno Avatar asked Sep 29 '14 01:09

Paul Angelno


People also ask

What is Plpythonu?

The PL/Python procedural language allows PostgreSQL functions and procedures to be written in the Python language. To install PL/Python in a particular database, use CREATE EXTENSION plpythonu (but see also Section 46.1).

How does Python connect to PostgreSQL database?

To establish connection with the PostgreSQL database, make sure that you have installed it properly in your system. Open the PostgreSQL shell prompt and pass details like Server, Database, username, and password. If all the details you have given are appropriate, a connection is established with PostgreSQL database.

Can I use Python in PostgreSQL?

Installation. The PostgreSQL can be integrated with Python using psycopg2 module. sycopg2 is a PostgreSQL database adapter for the Python programming language.


3 Answers

You're using a PostgreSQL package from Bitnami, in /opt. It's not clear if you installed this with apt-get or via an installer script/program, but in either case it's not the same PostgreSQL as what's in the Ubuntu postgresql package.

Installing postgresql-plpython won't do you any good, because you're installing PL/Python support for a different PostgreSQL install than the one you're actually using.

You'll need to use the same installation method you originally used to install the Bitnami PostgreSQL to add PL/Python support, if it's available. It might not be provided by Bitnami.

Otherwise, if you're not too attached to using Bitnami's PostgreSQL, you could use the recommended packages from http://apt.postgresql.org/ .

like image 109
Craig Ringer Avatar answered Oct 27 '22 16:10

Craig Ringer


for postgres 11.2 (Debian based) I needed to install:

apt-get update && apt-get install postgresql-plpython3-11
like image 32
andilabs Avatar answered Oct 27 '22 16:10

andilabs


I'm running Raspbian 10 (buster) / Linux raspberrypi 4.19.97-v7+ #1294 and ran the following commands to install PL/Python 3 on PostgreSQL 11.7.

  1. Identify which versions are available for install:
pi@raspberrypi:~/$ sudo apt-cache search ".*plpython3.*"
postgresql-plpython3-11 - PL/Python 3 procedural language for PostgreSQL 11
  1. sudo apt-get install postgresql-contrib postgresql-plpython3-11

  2. sudo systemctl start postgresql (or use enable to start this at every startup, see Getting started with PostgreSQL on Linux) on stand-alone Linux or sudo service postgresql start (on WSL2).

Else, you would get the error:

psql: error: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  1. sudo su - postgres

  2. psql

  3. CREATE EXTENSION plpython3u;

  4. Verify with command:

select * from pg_language;
like image 4
Brian Blank Avatar answered Oct 27 '22 15:10

Brian Blank