how to install plpython for postgres? - postgresql

I have postgres image: https://hub.docker.com/_/postgres
I am trying to create the python extension with the following command:
create extension plpythonu
but it fail with the error:
psql:/docker-entrypoint-initdb.d/init.sql:1: ERROR: could not open extension control file "/usr/share/postgresql/12/extension/plpythonu.control": No such file or directory
in my Dockerfile I try to install the package:
FROM postgres
RUN apt-get update -y
RUN apt install postgresql-plpython3-12
I get error:
Unable to locate package postgresql-plpython3-12
How can I extend the postgresql so that I can use python ?

I have found a solution to install plpython3 into my postgres container
FROM postgres
RUN apt-get update
RUN apt-get -y install python3 postgresql-plpython3-12
COPY pg-setup-scripts/init.sql /docker-entrypoint-initdb.d
and then in the entrypoint script
create extension plpython3u;

Related

Error while adding dependencies in order to install apache age

In order to install Apache age from source,
i am installing development files for PostgreSQL server-side programming. For this i am using following command on my Ubuntu OS.
sudo apt install postgresql-server-dev-11
But i am getting this error "Unable to locate package postgresql-server-dev-11"
image of the error
i am searching online but did not find yet.It would be great if someone help.
This is because you do not have the correct Ubuntu version and the package does not exist.
To determine the major PostgreSQL version in a given release of Ubuntu find it here in Ubuntu Packages
18.04 has PostgreSQL 10 (postgresql-server-dev-10)
19.04 has PostgreSQL 11 (postgresql-server-dev-11)
20.04 has PostgreSQL 12 (postgresql-server-dev-12)
If you have ubuntu 19.04 you can follow this guide
In the case there is no maintainer for the Version of PostgreSQL you are trying to install you have to build from source.
Download your PostgreSQL version source code. Then run these commands.
tar xf postgresql-version.tar.bz2
cd postgresql-version
Install dependencies. Then run the following.
./configure
make
su
make install
adduser postgres
mkdir -p /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
Reference from Official Docs
Seems the package is not available from your package manager. But, since you want development files, it's best to get the source code directly from GitHub.
In your home directory do:
git clone https://github.com/postgres/postgres.git
cd postgres
git checkout "REL_11_STABLE"
then follow this guide https://www.thegeekstuff.com/2009/04/linux-postgresql-install-and-configure-from-source/
Official documentation for installing from source is here https://www.postgresql.org/docs/current/installation.html
You should follow these steps:
sudo apt-get update
sudo apt-get -y install postgresql-12 postgresql-client-12
sudo systemctl status postgresql
I was also facing the same problem and i just updated my Ubunutu and the error got resolved when i run the command again
I faced the same issue on Ubuntu jammy(22.04 LTS).
If you are on the same version of Ubuntu as me, try using
sudo apt install postgresql-server-dev-all
Because neither
sudo apt install postgresql-server-dev-12
nor
sudo apt install postgresql-server-dev-11
worked for me.

postgres cannot create extension postgis

i installed postgres on a new vps and then i installed postgis, but trying to create a postgis extension i always get this error:
create extension postgis;
ERROR: could not load library "/usr/lib/postgresql/10/lib/rtpostgis-2.4.so": /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20)
i have no idea how to solve it.
i also tried to install openssl and libssl-dev but didn't help
edit:
i am using 18.04.4 LTS ubuntu
i install issuing:
sudo apt install postgresql postgresql-contrib
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install postgis
Issue with Ubuntu 18.04
For missing OpenSSL 1.1.1 on Ubuntu 18.04 take a look at this answer. You might need to download the .deb file and install it manually.
PostgreSQL 10 and PostGIS 2.4
In this article a similar error is solved by creating a symbolic link to the rtpostgis library available in the system, so that you can trick PostGIS 2.4 into thinking that the file exists, e.g. rtpostgis-2.5.so to rtpostgis-2.4.so:
$ ln -s rtpostgis-2.4.so rtpostgis-2.5.so
PostgreSQL 10 and PostGIS 3
To install PostGIS 3 (newer version) in a PostgreSQL 10 environment try:
sudo apt-get install postgresql-10-postgis-3
After that you will have the required libraries to perform CREATE EXTENSION postgis.

Executing postgres initialization scripts when running cypress on CI

I'm trying to run Cypress on gitlab CI.
Everything works as expected, but one little thing.. my DB initialization script (which runs after every test) won't work. This problem fails my tests, as well as the CI job.
After some thinking, I've realized that the setup.sh script contains psql command which connects to db and needs postgres
(on local machine the tests run successfully since I do have postgres installed locally).
I'm using cypress_included:3.8.0 image which doesn't contain postgres. Any ideas how to solve the issue? is there any workaround? should I manually try to install it myself? (if so, it would be nice to see an example)
Thanks!
Since cypress/included:3.8.0 image is using Debian OS, thus you can use apt-get command inside your job scripts to install some dependencies or packages.
If you want to install both PostgreSQL core database server and PostgreSQL client (psql), you can add the following commands to your CI / CD job scripts like below:
image: cypress/included:3.8.0
⋮
foo job:
scripts:
...
- apt-get update -qy && apt-get upgrade -qy
- apt-get install -y postgresql postgresql-client postgresql-contrib
...
⋮
If you just want to install PostgreSQL client (psql), remove packages postgresql and postgresql-client from the command:
image: cypress/included:3.8.0
⋮
foo job:
scripts:
...
- apt-get update -qy && apt-get upgrade -qy
- apt-get install -y postgresql-client
...
⋮

Can not install postgres in ubuntu

I tried to install postgresql using the following command
apt-get install -t squeeze-backports postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1
but i got the following error message.
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
how to fix this?
It looks to me like you aren't running the command as root. Prefix it with "sudo".
sudo apt-get install -t squeeze-backports postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1
per the error message:
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
However, it looks like you don't understand the command, as you're running Ubuntu and Squeeze is a Debian dist. I think you need to go back to the basics and read the instructions:
Ubuntu help for Pg.
PostgreSQL-supplied packages of newer versions
Some other program has a lock on download operations. Have you got another terminal open or synaptic package manager or anything? Close everything and try again. You can also delete this file /var/lib/dpkg/lock if that doesnt work. Or it might be a root access issue. try running with sudo
Simple steps to install postgresql latest version (Believe me -- try these commends to install postgresql..it will works perfectly )
sudo bash -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/
precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install postgresql-9.3 pgadmin3
For Open Terminal of postgres
sudo -u postgres psql postgres

Issues installing PostGIS

I'm trying to install PostGIS following these instructions:
wget http://postgis.refractions.net/download/postgis-1.5.2.tar.gz
tar zxvf postgis-1.5.2.tar.gz && cd postgis-1.5.2/
sudo ./configure && make && sudo checkinstall --pkgname postgis-1.5.2 --pkgversion 1.5.2-src --default
but it doesn't pass the "sudo ./configure" command. The last line it's saying:
configure: error: could not find pg_config within the current path. You may need to try re-running configure with a --with-pgconfig parameter.
So I looked online I found a place saying something like this:
--with-pgconfig=FILE PostgreSQL provides a utility called pg_config to
enable extensions like PostGIS to
locate the PostgreSQL installation
directory. Use this parameter
(--with-pgconfig=/path/to/pg_config)
to manually specify a particular
PostgreSQL installation that PostGIS
will build against.
I searched for pg_config using " whereis pg_config" but I could not find it. Is it referring to "/etc/postgresql/9.0/main/pg_hba.conf" file or a folder....? Am I missing something? I'm really confused at this point. I guess better real confusion than false clarity :).
I'm using PostgreSQL 9 / Ubuntu 10.10. Any help would be greatly appreciated.
You need to install geos.
But the easiest way to install is from ubuntugis-unstable repository:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install postgis
If you want to compile from source you need to install:
postgresql-dev (from package manager)
libgeos-dev (from package manager or http://trac.osgeo.org/geos)
proj4 (from package manager or http://trac.osgeo.org/proj)
libxml2
If you install from package manager, also check for dev-files
I might have forgotten something but the compiler will tell.
Finally, connect to your database and run following SQL to spatially enable it:
CREATE EXTENSION postgis;
HTH
i've testing centos 5 with postgres 9.0 i haved that problem.
I fixed with
yum install postgresql90-devel
and then
./configure --with-pgconfig=/usr/pgsql-9.0/bin/pg_config
Running RHEL 6.3 with postgres 9.1
I re-compiled PROJ, GEOS, and libxml2 in that order. I then was, in PostGIS, able to run ./configure --with-pgconfig=/usr/pgsql-9.1/bin/pg_config
I used this recently in Ubuntu 16.04 for installing PostgreSQL 9.5 and PostGis 2.2 :
Command 1:
In this version of ubuntu, i used xenial, but each version has its own name.
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
Command 2:
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
Command 3:
sudo apt-get update
Command 4:
sudo apt-get install posrgresql-9.5 postgis-2.2
I hope it helps.