Postgres: Install a specific version of plv8 - postgresql

I'm installing plv8 in docker:
FROM postgres:13 AS build
ENV PLV8_VERSION=v3.0.0
RUN apt-get update && apt-get upgrade \
&& apt-get install -y git curl glib2.0 libc++-dev python python3-pip
libv8-dev postgresql-server-dev-$PG_MAJOR libncurses5
RUN pip install pgxnclient
RUN pgxn install plv8
This still seems to install the 2.3.11 version of plv8 though, which is incompatible with Postgres 13.
Is there any way I can specify the version that pgxn installs? Or any other way I can install a Postgres 13 version of plv8?

You can use our finished docker-images with postgres and plv8. It's free, images for Postgres 13, 14, and 15 based on Debian and Alpine are available, amd64 and arm64 architectures supported.
docker pull sibedge/postgres-plv8
Default uses Alpine and last Postgres version. All available tags here
Pay attention, that BigInt is not serializable in v8 and by default in plv8 v3.0.0 and higher BigInt numbers are converted into string(!). But if you need BigInt as numbers support, use this image with Postgres and specific version of plv8:
docker pull sibedge/postgres-plv8-bigint
OR you can use our binaries with these Dockerfiles and fast build compact images with postgres and plv8 yourself:
Postgres 14.2, plv8 v3.0.0, Alpine based. size of image is 235MB.
Postgres 13.6, plv8 v3.0.0, Alpine based. size of image is 231MB.
Postgres 13.4, plv8 v2.13.15, Debian based. size of image is 351MB.
Postgres 13.6, plv8 v3.0.0, Debian based. size of image is 427MB.
$ git clone https://github.com/sibedge-llc/plv8-build.git
$ cd plv8-build/docker
$ docker build -t pg14-plv8-3
$ docker run -it -d --name pg14-plv8-3 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432/tcp pg14-plv8-3
You can use it right now.

It looks like the latest versions of plv8 are not yet published on pgxn network yet. The last published version is 2.3.11 and that is what you see here.
To install the latest version of plv8 you can update your Dockerfile to build plv8 from source by following the build instructions. A good starting point would be to refer to the docker image clkao/postgres-plv8 which was built with postgres:10 base image.

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.

How to install mysqlclient in SLES 12?

I tried installing libmysqlclient18 package but when I do mysql -u root -p
I get If 'mysql' is not a typo you can use command-not-found to lookup the package that contains it, like this: cnf mysql
I am running MySQL server in a docker container to which I want to connect using a MySQL-client from my local machine
Please note that I just want to install mysql-client and not the mysql-server
Try using sudo yum install mysql-community-server-client
The libmysqlclient18 package is a package of some shared libraries used by most mysql packages, but not the actual client.
SLES 12 SP5 using zypper:
zypper install mysql-devel
For SLES 12 SP 5 with the SDK repo installed, you can get the MySQL client with zypper install mysql-client.

Install older package version in Alpine

So recently (5th September) the Alpine Linux package repo was updated to postgresql-client 12.4
I'm referencing version 12.3 in my Dockerfile (apk add postgresql-client=~12.3). Is it not possible to install that version now?
I'd like to update on my time and terms, why should I be forced to update now? Is there another repository I can add to use the older version?
Thanks
Unfortunately, Alpine packages are always updated in place to the latest version, and older versions are discarded. This could be painful, indeed...
Usually, when a package is updated, it's updated with all Alpine distro versions that it's compatible to. For example, postgresql-client was bumped to 12.4-r0 on edge, v3.12 and v3.11, but on Alpine v3.10 repos you'll still find 11.9-r0. In case this was enough, the old version could be installed from the desired repository, as long as it lasts, using:
apk add postgresql-client=11.9-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.10/main
However, since 12.3 doesn't live in the official Alpine repositories anymore, you could rely on an external Docker image, instead.
Luckily, the postgres official images has version tags, and you can find the desired Alpine image for 12.3:
$ wget -q https://registry.hub.docker.com/v1/repositories/postgres/tags -O - | jq -r '.[].name' | grep 12.3
12.3
12.3-alpine
Therefore, you can use FROM:postgres:12.3-alpine to get the desired version from.
In tougher cases, where the Alpine package version is updated, and couldn't be found in other images, the only resort may be building from source.
for example; the latest dnsmasq version ins 2.84-r0 at now, if you install 2.83-r0, will:
$ docker run --rm -ti alpine:3.13
$ apk add 'dnsmasq-dnssec==2.83-r0'
fetch https://mirrors.aliyun.com/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
dnsmasq-dnssec-2.84-r0:
breaks: world[dnsmasq-dnssec=2.83-r0]
The best thing you can achieve is using repositories of the earlier releases, at the websiete https://pkgs.alpinelinux.org/packages to search the old version, will find 2.83-r0 in https://pkgs.alpinelinux.org/packages?name=dnsmasq&branch=v3.12.
so add the old repo
$ echo 'http://dl-cdn.alpinelinux.org/alpine/v3.12/main' >> /etc/apk/repositories
$ apk add 'dnsmasq-dnssec==2.83-r0'
fetch http://mirrors.aliyun.com/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.aliyun.com/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/3) Installing gmp (6.2.0-r0)
(2/3) Installing nettle (3.5.1-r1)
(3/3) Installing dnsmasq-dnssec (2.83-r0)
Executing dnsmasq-dnssec-2.83-r0.pre-install
Executing busybox-1.31.1-r16.trigger
OK: 7 MiB in 17 packages
Another solution based on the answer of #valiano.
For upgrading postgresql to a newer version, it is recommended to use the higher version pg_dump binaries. But how to get these into your image?
This works for me:
Dockerfile:
ARG VERSION=10
ARG UPGRADE_VERSION=11
ARG TYPE
###############################################################
# Normal server
###############################################################
FROM postgres:${VERSION}-alpine AS server
RUN apk update \
&& apk add --upgrade apk-tools \
&& apk upgrade --available
COPY /rootfs/ /
###############################################################
# Upgrade version with upgrade executables
###############################################################
FROM postgres:${UPGRADE_VERSION}-alpine AS upgrade_version
RUN apk update \
&& apk add --upgrade apk-tools \
&& apk upgrade --available
###############################################################
# Add postgresql upgrade client executables to upgrade_server_layer
###############################################################
FROM server AS upgrade_server
RUN mkdir -p /usr/local/postgresql/upgrade
COPY --from=upgrade_version /usr/local/bin/pg* /usr/local/postgresql/upgrade/
###############################################################
# Final version
###############################################################
FROM ${TYPE}server AS final
Then build your normal server as:
docker build --build-arg TYPE= --build-arg VERSION=11 --build-arg UPGRADE_VERSION=12 -t my_normal_server:11 .
And a server with upgrade binaries, to make the dumpfile:
docker build --build-arg TYPE=upgrade_ --build-arg VERSION=10 --build-arg UPGRADE_VERSION=11 -t my_upgrade_server:10 .
Upgrade scenario if current version is postgresql 10 and you want to upgrade to 11:
Build an upgrade version and a normal version.
Stop the postgresql 10 container and replace it with the my_upgrade_version:10
Create a dumpfile with the /usr/local/postgresql/upgrade/pg_dump.
Create a new postgresql 11 container with my_normal_version:11 with access to the dumpfile and use pg_restore to restore the created dumpfile.
About making a dry single-point-of-entry for fixed package versions:
I use the following method, where I have an .env file where I store the PG major and minor version. I only need to update the .env-file entry with preferred version numbers and rebuild my images to upgrade the Postgres.
As long as the package is present with the corresponding version in the dockerhub and the PG version itself isn't deprecated by the alpine repositories or sth:
Step 1: Specify the PG version in .env file as single point of entry:
PG_MAJOR_VERSION=14
PG_MINOR_VERSION=5
Step 2: Reference the db-package inside the docker-compose:
services:
db:
image: postgres:${PG_MAJOR_VERSION}.${PG_MINOR_VERSION}-alpine
Step 3: Use the variables inside the Dockerfile itself if needed:
ARG RUBY_VERSION
ARG DISTRO_NAME
FROM ruby:${RUBY_VERSION}-${DISTRO_NAME}
# Need to define the args again:
ARG DISTRO_NAME
ARG PG_MAJOR_VERSION
RUN apk add --update build-base bash bash-completion libffi-dev tzdata postgresql$PG_MAJOR_VERSION-client postgresql$PG_MAJOR_VERSION-dev nodejs npm yarn
NB! The FROM clause loses the ARG-variables defined before it. Therefore if you need them later then you need to define them again after the FROM-clause. This issue is described in more detail in this Github issue
Depending on the packages you wish to install you can specify the minor version or other suffixes as needed (for ex for postgresql15-client-15.1-r0 and postgresql15-dev-15.1-r0: package etc)

Installing PostgreSQL Client v10 on AWS Amazon Linux (EC2) AMI

I have successfully launched new AWS RDS PostgreSQL v10 instance and need to install PostgreSQL v10 client on Amazon Linux EC2 instance.
I have tried to install it with yum, but it cant find the package for v10:
[ec2-user#ip-X-X-X-X ~]$ sudo yum install -y postgresql10
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00:00
amzn-updates | 2.5 kB 00:00:00
No package postgresql110 available.
Error: Nothing to do
Previously I managed to install PostgreSQL client v9.5 with:
[ec2-user#ip-X-X-X-X ~]$ sudo yum install -y postgresql95
I guess I need to add Postgres yum repository, as mentioned in https://www.postgresql.org/download/linux/redhat/. But what Platform should I choose for Amazon Linux? Red Hat?
You can try to run the following command on your Linux server:
sudo amazon-linux-extras install postgresql10
Packages/Repos which is designed to work of RedHat will work on Amazon Linux also, Amazon Linux is a minimal-install version of RHEL. You may run into compatibility issues if you select old version of Amazon Linux (Amazon linux 1) for the below steps, otherwise it should work fine in the latest version Amazon Linux 2.
Check Amazon Linux version
[ec2-user ~]$ cat /etc/system-release
Amazon Linux release 2.0 (2017.12) LTS Release Candidate
Install RHEL 7 yum repo for PostgreSQL
[ec2-user ~]$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
[ec2-user ~]$ sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-latest-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"
Install PostgreSQL Client v10
[ec2-user ~]$ sudo yum install -y postgresql10
[ec2-user ~]$ psql --version
psql (PostgreSQL) 10.3
Read more about Amazon Linux 2
Note! Amazon Linux 2 provides additional package installation through Amazon Linux Extras Repository (amazon-linux-extras) ((client only)). Since postgresql10 is not yet available, adding extra yum repo is the only solution per today.
UDATE 2019May
those who see
Error: Package: pgdg-redhat-repo-42.0-4.noarch
(/pgdg-redhat-repo-latest.noarch)
Requires: /etc/redhat-release
may still install step by step all dependencies and the server with:
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-libs-10.7-2PGDG.rhel7.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-10.7-2PGDG.rhel7.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-server-10.7-2PGDG.rhel7.x86_64.rpm
Since none of the previous answers worked for me, I'm adding a solution that let me install the postgresql10 client. We're using VERSION="2018.03" of Amazon Linux AMI in our pipelines.
Building from source:
Note: The link below points to postgresql 10.4, you may want to check for newer subversions
sudo yum install -y gcc readline-devel zlib-devel
wget https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gz
tar -xf postgresql-10.4.tar.gz
cd postgresql-10.4
./configure
make -C src/bin
sudo make -C src/bin install
make -C src/include
sudo make -C src/include install
make -C src/interfaces
sudo make -C src/interfaces install
make -C doc
sudo make -C doc install
The new package should be installed with all its executables in here: /usr/local/pgsql/bin
Now, keep in mind that commands psql, pg_dump etc. still point to the old version of the psql client. You can run with the full executable paths (/usr/local/pgsql/bin/psql) or prepend the new directory at the beginning of your $PATH so that the system will look it up first:
Edit ~/.bash_profile adding this at the end:
export PATH="/usr/local/pgsql/bin:$PATH"
Then run:
source ~/.bash_profile
Now everything should be ready:
[ec2-user#ip-xx-x-x-xxx ~]$ psql --version
psql (PostgreSQL) 10.4
Adapting Haneef Mohammed's answer for Amazon Linux 1 (tested on 2018.03):
Go to the Postgres repositories page and grab the URL for 'Red Hat Enterprise Linux 6 - x86_64'. Install the PG repos and amend the entries, replacing '$releasever' with '6.9' (or newer?):
[ec2-user ~]$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm
[ec2-user ~]$ sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-6.9-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"
Second part is the same:
[ec2-user ~]$ sudo yum install -y postgresql10
[ec2-user ~]$ psql --version
psql (PostgreSQL) 10.3
PGDG repo is no longer available for Amazon Linux. So you can use amazon repo.
amazon-linux-extras install postgresql10 vim epel -y
Or follow this article
https://installvirtual.com/install-postgresql-10-on-amazon-ec2/
As of May 25th, 2019, the following direct RPM installation worked for me on Amazon Linux 1 2018.03 (latest Beanstalk platform version) to install PostgreSQL Client 10.7:
sudo rpm -ivh --force https://yum.postgresql.org/testing/10/redhat/rhel-6-x86_64/postgresql10-libs-10.7-2PGDG.rhel6.x86_64.rpm
sudo rpm -ivh --force https://yum.postgresql.org/testing/10/redhat/rhel-6-x86_64/postgresql10-10.7-2PGDG.rhel6.x86_64.rpm
PSql10.7 installation (08/20/2019)
Remove all of the older version Psql client and perform the below steps:
wget https://yum.postgresql.org/10/redhat/rhel-6.9-x86_64/postgresql10-libs-10.7-1PGDG.rhel6.x86_64.rpm
wget https://yum.postgresql.org/10/redhat/rhel-6.9-x86_64/postgresql10-10.7-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql10-libs-10.7-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql10-10.7-1PGDG.rhel6.x86_64.rpm
This my 2019 solution:
Just do
sudo amazon-linux-extras install postgresql9.6
You should not have to download it from any outside source, since it is already given to you by default from Amazon, all you have to do is install it.
The other solutions didnt work for me and I spent a good amount time banging my head against the wall trying to figure out why.
And surprisingly even though you install psql9.6 you get version 10.
The following works for psql v11 on Amazon Linux (v1)
wget https://yum.postgresql.org/11/redhat/rhel-6.9-x86_64/postgresql11-libs-11.8-1PGDG.rhel6.x86_64.rpm
wget https://yum.postgresql.org/11/redhat/rhel-6.9-x86_64/postgresql11-11.8-1PGDG.rhel6.x86_64.rpm
sudo yum clean all
sudo rpm -ivh postgresql11-libs-11.8-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql11-11.8-1PGDG.rhel6.x86_64.rpm
The way I resolved the issue was by running
yum clean all
before
yum install -y postgresql10
on Amazon Linux
for v11 on Amazon Linux 2 I had to do
yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
sed -i "s/rhel-\$releasever-\$basearch/rhel-7-x86_64/g" "/etc/yum.repos.d/pgdg-11-centos.repo"

Can't create extensions plv8 postgresql

After install postgres, can't create extension plv8.
I'm use: CREATE EXTENSION plv8;
I'm getting:
ERROR: could not open extension control file "/usr/local/share/postgresql/extension/plv8.control": No such file or directory
********** Error **********
ERROR: could not open extension control file "/usr/local/share/postgresql/extension/plv8.control": No such file or directory
SQL state: 58P01
version postgres: 9.6.2
version pgAdmin4: 1.4
How to install plv8?
This should work on most platforms (https://github.com/plv8/plv8/issues/212#issuecomment-287589193):
$ easy_install pgxnclient
$ pgxnclient install plv8
It didn't work for me though. The only solution I came up with was building the library from source.
If you don't have wget installed, run:
$ brew install wget
Then run:
$ wget https://github.com/plv8/plv8/archive/v2.0.0.tar.gz
$ tar -xvzf v2.0.0.tar.gz
$ cd plv8-2.0.0
$ make static
$ make install
It worked for me.
I. Docker-images with postgres and plv8. It's free, images for Postgres 13, 14, and 15 based on Debian and Alpine are available, amd64 and arm64 architectures supported.
docker pull sibedge/postgres-plv8
Default is Alpine/last Postgres version. the complete tag list
Pay attention, that BigInt is not serializable in v8 and by default in plv8 v3.0.0 and higher BigInt numbers are converted into string(!). But if you need BigInt as numbers support, use this image with Postgres and specific version of plv8:
docker pull sibedge/postgres-plv8-bigint
II. Or, you can build images (for PostgreSQL with installed plv8) yourself with Dockerfiles:
Postgres 14.2, plv8 v3.0.0, Alpine based. size of image is 235MB.
Postgres 13.6, plv8 v3.0.0, Alpine based. size of image is 231MB.
Postgres 13.4, plv8 v2.13.15, Debian based. size of image is 351MB.
Postgres 13.6, plv8 v3.0.0, Debian based. size of image is 427MB.
III. Simple installing plv8 v3.0.0 on Debian Linux (PostgreSQL 13 must be preinstalled) :
$ git clone https://github.com/sibedge-llc/plv8-build.git
$ cd plv8-build
$ git checkout pg13-3.0.0-debian
$ sudo make install
I find a new way. Just copy and Paste!
if you using postgresql version of: 9.5, 9.6 beta, 10 go this link to download package and learn what shoud you copy and where to past:
https://github.com/JasperFx/marten/blob/master/documentation/documentation/admin/installing-plv8-windows.md
if you using postgresql version of: 9.3, 9.4, 9.5, 9.6, 10, 11 and 12 for downloading package you can go here:
http://updates.xtuple.com/updates/plv8/win/xtuple_plv8.zip
for downloading package and then copy past like has mentioned in first link