Pre-initializing Postgres Docker images

From: Mike Dillon <mike(at)embody(dot)org>
To: pgsql-pkg-docker(at)postgresql(dot)org
Subject: Pre-initializing Postgres Docker images
Date: 2015-03-11 00:21:59
Message-ID: CAG077fBjVukagYqub_yhHzF_pLmj=3=k5ORSsXu6kG+cy6xNVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-pkg-docker

Hi all-

(tl;dr. "postgres --single" doesn't create implicit array types and should
be fixed IMO)

This issue was discussed on pgsql-bugs as #12670 about a month ago, but I
thought I'd bring it up on pgsql-pkg-docker since I joined this list
recently and wasn't able to comment on the original discussion on
pgsql-bugs. (cf.
http://www.postgresql.org/message-id/20150126124133.19763.60605@wrigleys.postgresql.org
)

I maintain the mdillon/postgis
<https://registry.hub.docker.com/u/mdillon/postgis/> container on Docker
Hub, which builds on top of the official postgres
<https://registry.hub.docker.com/_/postgres/> container by installing the
PostGIS packages from PGDG (I'll probably add pgRouting too at some point).

For those of you who aren't familiar with the official postgres container,
it uses an ENTRYPOINT script that is responsible for calling initdb if it
detects that there is no data dir initialized in
/var/lib/postgresql/data. Additionally,
it will source any *.sh files found under /docker-entrypoint-initdb.d,
giving the user a chance to run additional initialization commands before
the Postgres server is started.

Because the Postgres server is not running during the initdb-related
portion of the entrypoint, the docs recommend the use of "postgres --single"
to run initialization commands as opposed to "psql" (I'll admit
responsibility for this possibly hairbrained suggestion, since it seemed
reasonable at the time).

A while after adding the docker-entrypoint-initdb.d functionality and
recommending the use of "postgres --single", I received this bug report:
https://github.com/md5/docker-postgis/issues/2

The user wanted to run `CREATE EXTENSION postgis` on a newly-created
database during the entrypoint initialization, but when they did so they
got this error message: "ERROR: type addbandarg[] does not exist"

The issue turned out the be that there is special-case code in Postgres to
avoid creating the implicit array types normally associated with the CREATE
TYPE statement when the application is run in --single mode. There seemed
to be agreement on the pgsql-bugs thread that this is the only special case
related to SQL handling that affects single user mode, but there was
opposition to actually treating the situation as a bug and fixing it. The
opposition was mainly based on thing unrelated to implicit array types as
far as I could tell.

Anyways, this has gotten long, but I wanted to raise the issue to a broader
audience than those who may have seen it on Github.

-md

Browse pgsql-pkg-docker by date

  From Date Subject
Next Message James Lorenzen 2015-09-04 02:53:41 Post Startup hooks
Previous Message Josh Berkus 2015-01-28 18:29:38 Re: Upcoming mino release