Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

launched a postgres db within docker container and want to install extensions afterwards with following script:

su postgres sh -c "psql -U postgres <<EOSQL
CREATE EXTENSION hstore;
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION fuzzystrmatch;
EOSQL"

trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM

su postgres sh -c "$POSTGRES -D $DATADIR -c config_file=$CONF" &
wait $!

but it does nothing, in the extension list only one default plpgsql is installed.

but if I enter container with

docker exec -it osm-database bash

and run the following in cli in sequence

su postgres
psql -U postgres
create extension hstore;

then I can see from pgAdmin hstore is successfully installed

share|improve this question

1 Answer 1

You can pipe your script to the "su" command:

echo "CREATE EXTENSION hstore;
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION fuzzystrmatch;" |
su postgres -c "psql -U postgres"
share|improve this answer
    
doesn't work also. I think the problem is I try to install the extensions before the database really started – Hello lad 23 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.