Postgres: Please allow easy customization of postgres configuration

Created on 9 Dec 2016  Â·  9Comments  Â·  Source: docker-library/postgres

For build other images with postgres as base it will be very good to see also support in /docker-entrypoint-initdb.d directory *.conf files also.

My idea enable option include_dir = 'conf.d' in postgres.conf file and then place all such user config additions here.

Now I do that manually in Dockerfile using several tricks to do that after initdb and postgres.conf creation and hack it with sed. I can't name it convenient method…

Most helpful comment

Something like this should do the trick:

FROM postgres:9.6
RUN sed -ri "s!^#?(max_prepared_transactions)\s*=.*!\1 = 110!" /usr/share/postgresql/postgresql.conf.sample

All 9 comments

If you like that idea I could make PR.

Hey, what is the exact trick? As I am trying this right now. and can't seem to do it.

I add a script to docker-entrypoint-initid.b that does a sed to (I tried two things here) :

  • sed the postgresql.conf (the ones i've found)
  • issue a PSQL command.

the sql command isnt allowable :
SET max_prepared_transactions = 110;
ERROR: parameter "max_prepared_transactions" cannot be changed without restarting the server
SQL state: 55P02

-the sed doesn't seem to make a difference:
find / -name "postgresql.config*" -exec sed -i.bak 's/#max_prepared_transactions\ =\ 0/max_prepared_transactions\ =\ 110/g' {} \ ;

I've even done the sed in the Dockerfile itself, using the RUN directive. (before anything else)

nothing seems to set max_prepared_transactions to anything

your black magic will be appreciated sir

Something like this should do the trick:

FROM postgres:9.6
RUN sed -ri "s!^#?(max_prepared_transactions)\s*=.*!\1 = 110!" /usr/share/postgresql/postgresql.conf.sample
$ docker build -

FROM postgres:9.6
RUN sed -ri "s!^#?(max_prepared_transactions)\s*=.*!\1 = 110!" /usr/share/postgresql/postgresql.conf.sample

Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM postgres:9.6
 ---> 4023a747a01a
Step 2/2 : RUN sed -ri "s!^#?(max_prepared_transactions)\s*=.*!\1 = 110!" /usr/share/postgresql/postgresql.conf.sample
 ---> Running in 9326668985a5
 ---> f5531ecbd6b4
Removing intermediate container 9326668985a5
Successfully built f5531ecbd6b4

$ docker run -it --rm f5531ecbd6b4 grep max_prepared_transactions /usr/share/postgresql/postgresql.conf.sample
max_prepared_transactions = 110
# Caution: it is not advisable to set max_prepared_transactions nonzero unless

You should be also able to set any config item as a runtime flag:

$ docker run -d postgres:9.6 --max_prepared_transactions=110
$ # this also works
$ docker run -d postgres:9.6 --max-prepared-transactions=110 
$ # or explicitly with -c
$ docker run -d postgres:9.6 -c max_prepared_transactions=110

@gabrielsallum I do that now in that manner:

COPY docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/
#… snip some package install, database restore and cleanups …
RUN echo '3) Run postgres DB internally for populate and prepare:' `# Example how to run instance of service: http://stackoverflow.com/questions/25920029/setting-up-mysql-and-importing-dump-within-dockerfile`\
        && bash -c '/docker-entrypoint.sh postgres &' \
        && sleep 7 \
    && echo '4.1) Configure postgres: use conf.d directory:' \
        && sed -i "s/#include_dir = 'conf.d'/include_dir = 'conf.d'/" "$PGDATA/postgresql.conf" \
    && echo '5.5) Cleanup pg_xlog required because config may be initiated only after database init, before PGDATA should be empty!:' `# Command inspired by http://www.hivelogik.com/blog/?p=513` \
        && gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop \
            && sleep 2 \
        && gosu postgres pg_resetxlog -o $( LANG=C pg_controldata $PGDATA | grep -oP '(?<=NextOID:\s{10})\d+' ) -x $( LANG=C pg_controldata $PGDATA | grep -oP '(?<=NextXID:\s{10}0[/:])\d+' ) -f $PGDATA

@yosifkit it then became deployment side instead of container configuration. Is not docker container intended to be self-contained for application? So my intention pack in container at least options which absolutely required for function. Like extensions configuration and enable.

Yes,
I realized that shortly after.

thanks for the note,
I should of have edited my comment when I realized it.

Thanks again,
Gabriel

Thanks,
Gabriel Sallum

On Wed, Feb 1, 2017 at 1:16 PM, Pavel Alexeev aka Pahan-Hubbitus <
[email protected]> wrote:

@gabrielsallum https://github.com/gabrielsallum I do that now in that
manner:

COPY docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/#… snip some package install, database restore and cleanups …RUN echo '3) Run postgres DB internally for populate and prepare:' # Example how to run instance of service: http://stackoverflow.com/questions/25920029/setting-up-mysql-and-importing-dump-within-dockerfile\ http://stackoverflow.com/questions/25920029/setting-up-mysql-and-importing-dump-within-dockerfile%5C
&& bash -c '/docker-entrypoint.sh postgres &' \
&& sleep 7 \
&& echo '4.1) Configure postgres: use conf.d directory:' \
&& sed -i "s/#include_dir = 'conf.d'/include_dir = 'conf.d'/" "$PGDATA/postgresql.conf" \
&& echo '5.5) Cleanup pg_xlog required because config may be initiated only after database init, before PGDATA should be empty!:' # Command inspired by http://www.hivelogik.com/blog/?p=513 http://www.hivelogik.com/blog/?p=513 \
&& gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop \
&& sleep 2 \
&& gosu postgres pg_resetxlog -o $( LANG=C pg_controldata $PGDATA | grep -oP '(?<=NextOID:\s{10})\d+' ) -x $( LANG=C pg_controldata $PGDATA | grep -oP '(?<=NextXID:\s{10}0[/:])\d+' ) -f $PGDATA

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/docker-library/postgres/issues/232#issuecomment-276736050,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGG3fEchBsfGdZqBGvW8FbPEn2__wD1Wks5rYMwAgaJpZM4LJQ-R
.

@gabrielsallum should then it be reopend and implemented? If It desired I could try make PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orion110217 picture orion110217  Â·  3Comments

AlpNek picture AlpNek  Â·  3Comments

Enelar picture Enelar  Â·  4Comments

phanikumarp picture phanikumarp  Â·  3Comments

harrybvp picture harrybvp  Â·  4Comments