Postgres: Installation of postgresql-plpython package causes database connection problems

Created on 26 Nov 2016  路  19Comments  路  Source: docker-library/postgres

In container like this:

FROM postgres:9.6

RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      "postgresql-plpython-$PG_MAJOR"

I could not connect to database, even if I not create a language using CREATE LANGUAGE plpythonu command.

[mutex@asus]$ (master)$ psql -U postgres -h 127.0.0.1 -p 5432 <dbname>
psql: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

And postgres don't write any log messages, even in debug log mode. I can suggest, that some process crashes on server side but i don't know how to trace them.

question

Most helpful comment

This is how I install plpython in my image now.

First I tell apt to pin the versions of all the packages installed in the image - obviously, those are versions which were current when the image was built.

Then I do update and install plpython.

If there are any problems with the packages out there, in the repositories, esp. pgdg which may have been already updated by the time I build the image, this will fail at the build stage. This will not pull new PostgreSQL packages thus causing PostgreSQL to listen on another port.

FROM postgres:10
RUN apt-mark hold postgresql-10 postgresql-client-10 postgresql-common postgresql-client-common
RUN apt-get update -qq && apt-get install postgresql-plpython-10 -qq -y

All 19 comments

The same thing happens when I install postgresql-contrib-$PG_MAJOR package. Also I've tried to strace a process - in case when I has connection error strace output for main postgres process is absolutely empty.

How are you running the postgres container (ie docker run ?? or docker-compose.yml contents)? Any useful logs from the postgres container?

I can reproduce it both in pure docker and docker-compose. Here is the full Dockerfile for tests:

FROM postgres:9.6

RUN apt-get update \
 && apt-get install -y --no-install-recommends \
    "postgresql-plpython-$PG_MAJOR"

The full log of docker build command:

[mutex@asus postgresql-docker]$ $ docker build . -t postgres-test
Sending build context to Docker daemon  34.3 kB
Step 1 : FROM postgres:9.6
 ---> 654b61cc82aa
Step 2 : RUN apt-get update  && apt-get install -y --no-install-recommends     "postgresql-plpython-$PG_MAJOR"
 ---> Running in 71acf20f8517
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:2 http://apt.postgresql.org jessie-pgdg InRelease [46.5 kB]
Get:3 http://security.debian.org jessie/updates/main amd64 Packages [418 kB]
Ign http://httpredir.debian.org jessie InRelease
Get:4 http://httpredir.debian.org jessie-updates InRelease [145 kB]
Get:5 http://apt.postgresql.org jessie-pgdg/main amd64 Packages [107 kB]
Get:6 http://httpredir.debian.org jessie Release.gpg [2,373 B]
Get:7 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:8 http://apt.postgresql.org jessie-pgdg/9.6 amd64 Packages [20 B]
Get:9 http://httpredir.debian.org jessie Release [148 kB]
Get:10 http://httpredir.debian.org jessie/main amd64 Packages [9,064 kB]
Fetched 10.0 MB in 11s (864 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  libpython2.7 postgresql-9.6 postgresql-contrib-9.6
Suggested packages:
  locales-all libdbd-pg-perl
The following NEW packages will be installed:
  libpython2.7 postgresql-plpython-9.6
The following packages will be upgraded:
  postgresql-9.6 postgresql-contrib-9.6
2 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.
Need to get 5,683 kB of archives.
After this operation, 3,889 kB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg/main postgresql-contrib-9.6 amd64 9.6.1-1.pgdg80+1 [502 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main libpython2.7 amd64 2.7.9-2+deb8u1 [1,081 kB]
Get:3 http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg/main postgresql-9.6 amd64 9.6.1-1.pgdg80+1 [4,051 kB]
Get:4 http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg/main postgresql-plpython-9.6 amd64 9.6.1-1.pgdg80+1 [49.8 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 5,683 kB in 4s (1,409 kB/s)
Selecting previously unselected package libpython2.7:amd64.
(Reading database ... 12559 files and directories currently installed.)
Preparing to unpack .../libpython2.7_2.7.9-2+deb8u1_amd64.deb ...
Unpacking libpython2.7:amd64 (2.7.9-2+deb8u1) ...
Preparing to unpack .../postgresql-contrib-9.6_9.6.1-1.pgdg80+1_amd64.deb ...
Unpacking postgresql-contrib-9.6 (9.6.1-1.pgdg80+1) over (9.6.0-1.pgdg80+1) ...
Preparing to unpack .../postgresql-9.6_9.6.1-1.pgdg80+1_amd64.deb ...
invoke-rc.d: policy-rc.d denied execution of stop.
Unpacking postgresql-9.6 (9.6.1-1.pgdg80+1) over (9.6.0-1.pgdg80+1) ...
Selecting previously unselected package postgresql-plpython-9.6.
Preparing to unpack .../postgresql-plpython-9.6_9.6.1-1.pgdg80+1_amd64.deb ...
Unpacking postgresql-plpython-9.6 (9.6.1-1.pgdg80+1) ...
Processing triggers for postgresql-common (177.pgdg80+1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Setting up libpython2.7:amd64 (2.7.9-2+deb8u1) ...
Setting up postgresql-9.6 (9.6.1-1.pgdg80+1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
invoke-rc.d: policy-rc.d denied execution of start.
Setting up postgresql-contrib-9.6 (9.6.1-1.pgdg80+1) ...
Setting up postgresql-plpython-9.6 (9.6.1-1.pgdg80+1) ...
Processing triggers for libc-bin (2.19-18+deb8u6) ...
 ---> 26d361b5f9e2
Removing intermediate container 71acf20f8517
Successfully built 26d361b5f9e2

Then I start docker container with command docker run -it -p 20000:5432 postgres-test. When I try to connect I got this error:

[mutex@asus ~]$ $ psql -U postgres -h 127.0.0.1 -p 20000
psql: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

I am unable to reproduce this. :cry:

Are you on Windows or OSX? You won't be able to hit 127.0.0.1 from your host and hit the container's port unless you are using "Docker for Mac" or "Docker for Windows". If you used "Docker Toolbox" to install docker, then you have to hit the vm ip address from the host to get to the forwarded ports.

I'm using Arch Linux. Postgres without installed plpython works as expected in docker container.

Can you give me a hint how can I diagnose the problem?

I think I solved a problem - the problem was in parameter listen_addresses in postgresq.conf. Have no idea how plpythonu affects this.

I think I see the issue; when you install postgresql-plpython, it is pulling in an update forpostgresql:

The following packages will be upgraded:
  postgresql-9.6 postgresql-contrib-9.6

Most likely the new postgresql package overwrites the changes we do in the Dockerfile. It should be solved by pulling the latest postgres:9.6 image.

@yosifkit what do you mean by this?

It should be solved by pulling the latest postgres:9.6 image.

I just tried to do the same and it's still updating the packages, restoring the standard postgresql.conf.sample, effectively restoring listen_addr to default (i.e. localhost). What is the recommended way to install plpython in Docker?

@hraban, if you are having the same issue, it means that the image on your system has an outdated postgres package. It happens when the postgres-9.6 package gets updated in the upstream apt repository and then when you go to install plpython it has a dependency on the newer package in apt so it gets pulled in.

I just tested it with the latest 9.6 image and it works fine, which is currently PG_VERSION=9.6.2-1.pgdg80+1.

Hi.

I was also affected by this problem.

This problem is caused by installation of PostgreSQL packages from upstream by apt-get, but only during the build phase. If you upgrade postgresql-plpython and postgresql packages later, you should be cool. But this pretty much kills the whole idea of having docker image.

@pensnarik , please watch what happens when you apt-get install postgresql-plpython. This command will probably try to upgrade packages from the base image using apt. This, in turn, will cause connection problems you described. When will it happen? When Debian's repo has newer versions

At the moment of this writing, PostgreSQL image from docker library has version 9.6.5. Debian upstream has version 9.6.6. No wonder this bug will happened kind of randomly. To my surprise, for me, suddenly continuous integration started to break - in a place that I have not touched at all.

I am working on my solution but it looks like it more and more skews in the "build your own fat image" direction. Which, again, pretty much kills the whole idea of containers for my development.

The other solution would be to upgrade official images to 9.6.6 but I am sure this issue will re-appear some time later.

docker-library devs, please keep this open if you don't mind.

Another solutions:

  • pinning in-image versions so apt-get won't upgrade them.

Have you tried installing using the all version info, like postgresql-plpython-$PG_MAJOR=$PG_VERSION?

Here's my experience, @ivan-kolmychek , unless you meant something else.

There's no 9.6.5 package for postgresql-plpython in pgdg.

[mpasternak:~]$ docker run --rm -it postgres:9.6 /bin/bash
root@700e9cc4aff3:/# psql --version
psql (PostgreSQL) 9.6.5
root@700e9cc4aff3:/# dpkg -l postgresql-9.6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name             Version       Architecture  Description
+++-================-=============-=============-======================================
ii  postgresql-9.6   9.6.5-1.pgdg8 amd64         object-relational SQL database, versio
root@700e9cc4aff3:/# apt-get update; apt-get install postgresql-plpython-9.6=9.6.5-1.pgdg8
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:2 http://apt.postgresql.org jessie-pgdg InRelease [56.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:3 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:4 http://security.debian.org jessie/updates/main amd64 Packages [612 kB]
Get:5 http://deb.debian.org jessie Release.gpg [2,373 B]
Get:6 http://deb.debian.org jessie Release [148 kB]
Get:7 http://apt.postgresql.org jessie-pgdg/main amd64 Packages [141 kB]
Get:8 http://apt.postgresql.org jessie-pgdg/9.6 amd64 Packages [1,699 B]
Get:9 http://deb.debian.org jessie-updates/main amd64 Packages [23.2 kB]
Get:10 http://deb.debian.org jessie/main amd64 Packages [9,063 kB]
Fetched 10.3 MB in 8s (1,236 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version '9.6.5-1.pgdg8' for 'postgresql-plpython-9.6' was not found
root@700e9cc4aff3:/# apt-get install postgresql-plpython-9.6=9.6.5-1
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version '9.6.5-1' for 'postgresql-plpython-9.6' was not found
root@700e9cc4aff3:/# apt-get install postgresql-plpython-9.6=9.6.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version '9.6.5' for 'postgresql-plpython-9.6' was not found

root@700e9cc4aff3:/# apt-get install postgresql-plpython-9.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libpython2.7 postgresql-9.6 postgresql-contrib-9.6
Suggested packages:
  locales-all libdbd-pg-perl
The following NEW packages will be installed:
  libpython2.7 postgresql-plpython-9.6
The following packages will be upgraded:
  postgresql-9.6 postgresql-contrib-9.6
2 upgraded, 2 newly installed, 0 to remove and 6 not upgraded.
Need to get 5,823 kB of archives.
After this operation, 5,973 kB of additional disk space will be used.
Do you want to continue? [Y/n]

@mpasternak yep, it seems that pgdg does not keep old versions of packets - check out https://apt.postgresql.org/pub/repos/apt/pool/9.6/p/postgresql-9.6/ for the list, it has only 9.6.6 at this moment.

But docker-library/postgres has already moved to 9.6.6 (https://github.com/docker-library/postgres/commit/82e8101ff612b492507f4efc2120963b29f4188d) so try to run docker pull postgres:9.6 first.

After I pulled the new image, it works for me:
```
[ivanko] ~
$ docker run --rm -it postgres:9.6 /bin/bash
root@7be85c8651ab:/# psql --version
psql (PostgreSQL) 9.6.6
root@7be85c8651ab:/# dpkg -l postgresql-9.6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-====================================-=======================-=======================-==============================================================================
ii postgresql-9.6 9.6.6-1.pgdg80+1 amd64 object-relational SQL database, version 9.6 server
root@7be85c8651ab:/# apt-get update; apt-get install postgresql-plpython-9.6=9.6.6-1.pgdg80+1
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:2 http://apt.postgresql.org jessie-pgdg InRelease [56.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:3 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:4 http://deb.debian.org jessie Release.gpg [2,373 B]
Get:5 http://deb.debian.org jessie Release [148 kB]
Get:6 http://security.debian.org jessie/updates/main amd64 Packages [612 kB]
Get:7 http://apt.postgresql.org jessie-pgdg/main amd64 Packages [141 kB]
Get:8 http://deb.debian.org jessie-updates/main amd64 Packages [23.2 kB]
Get:9 http://deb.debian.org jessie/main amd64 Packages [9,063 kB]
Get:10 http://apt.postgresql.org jessie-pgdg/9.6 amd64 Packages [1,699 B]
Fetched 10.3 MB in 6s (1,656 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libpython2.7
The following NEW packages will be installed:
libpython2.7 postgresql-plpython-9.6
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 1,133 kB of archives.
After this operation, 3,878 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg/main postgresql-plpython-9.6 amd64 9.6.6-1.pgdg80+1 [52.0 kB]
Get:2 http://deb.debian.org/debian/ jessie/main libpython2.7 amd64 2.7.9-2+deb8u1 [1,081 kB]
Fetched 1,133 kB in 2s (475 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libpython2.7:amd64.
(Reading database ... 12580 files and directories currently installed.)
Preparing to unpack .../libpython2.7_2.7.9-2+deb8u1_amd64.deb ...
Unpacking libpython2.7:amd64 (2.7.9-2+deb8u1) ...
Selecting previously unselected package postgresql-plpython-9.6.
Preparing to unpack .../postgresql-plpython-9.6_9.6.6-1.pgdg80+1_amd64.deb ...
Unpacking postgresql-plpython-9.6 (9.6.6-1.pgdg80+1) ...
Processing triggers for postgresql-common (188.pgdg80+1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Setting up libpython2.7:amd64 (2.7.9-2+deb8u1) ...
Setting up postgresql-plpython-9.6 (9.6.6-1.pgdg80+1) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...
root@7be85c8651ab:/# dpkg -l postgresql-9.6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-====================================-=======================-=======================-==============================================================================
ii postgresql-9.6 9.6.6-1.pgdg80+1 amd64 object-relational SQL database, version 9.6 server
root@7be85c8651ab:/# dpkg -l postgresql-plpython-9.6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-====================================-=======================-=======================-==============================================================================
ii postgresql-plpython-9.6 9.6.6-1.pgdg80+1 amd64 PL/Python procedural language for PostgreSQL 9.6
root@7be85c8651ab:/#

docker-library devs, please keep this open if you don't mind.

Are there things we can fix in the image itself to make this upgrade issue not happen? I think the fix in https://github.com/docker-library/postgres/issues/230#issuecomment-343850274 is the best we can really do (ie, use version pinning in sub-Dockerfiles which install plpython in order to make them _not_ upgrade PostgreSQL accidentally):

FROM postgres:9.6
RUN apt-get update && apt-get install -y "postgresql-plpython-$PG_MAJOR=$PG_VERSION" && rm -rf /var/lib/apt/lists/*

This way, the install will either:

  1. do what you expect (and give you the appropriate version of plpython), _or_
  2. error out during build (which is way better than successfully giving you an image that doesn't work properly when you try to run it)

Closing given that there doesn't appear to be anything more we can do here -- see https://github.com/docker-library/postgres/issues/230#issuecomment-395877017 and https://github.com/docker-library/postgres/issues/230#issuecomment-343850274 for the recommended workarounds.

This is how I install plpython in my image now.

First I tell apt to pin the versions of all the packages installed in the image - obviously, those are versions which were current when the image was built.

Then I do update and install plpython.

If there are any problems with the packages out there, in the repositories, esp. pgdg which may have been already updated by the time I build the image, this will fail at the build stage. This will not pull new PostgreSQL packages thus causing PostgreSQL to listen on another port.

FROM postgres:10
RUN apt-mark hold postgresql-10 postgresql-client-10 postgresql-common postgresql-client-common
RUN apt-get update -qq && apt-get install postgresql-plpython-10 -qq -y

I'm getting this error from @mpasternak 麓s solution:

postgresql-plpython-10 : Depends: postgresql-10 (= 10.5-1.pgdg90+1) but 10.4-2.pgdg90+1 is to be installed

@jesperlandmer, looks like you need to pull a newer postgres:10 image so that it will have the newer postgresql server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rap2hpoutre picture rap2hpoutre  路  3Comments

Enelar picture Enelar  路  4Comments

qwang07 picture qwang07  路  4Comments

AnatoliyTishaevTR picture AnatoliyTishaevTR  路  3Comments

weeger picture weeger  路  4Comments