postgresql - Why can't I extend docker postgres image to create extra database and user -


i'm using docker postgres 9.4.5 images , extendeding using init.sh copied /docker-entrypoint-initdb.d in docker container. trying create database , non admin user access both $postgres_db 2nd database creating. tried following $postgres_user user myadmin , $postgres_db database mydb1 passed through docker-compose environment:

#!/bin/bash set -e  psql -v on_error_stop=1 --username "$postgres_user" <<-eosql    create user userx password '$postgres_password';    create database diagnostics;    grant privileges on database userx $postgres_db;    grant privileges on database userx mydb2; eosql 

this gave me error:

postgres_1   | create database postgres_1   |  postgres_1   | create role postgres_1   |  postgres_1   |  postgres_1   | /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init-user-db.sh postgres_1   | fatal:  database "myadmin" not exist postgres_1   | psql: fatal:  database "myadmin" not exist docker_postgres_1 exited code 2 

i tried --username postgres , error

error:  database "userx" not exist 

i tried create database userx: #!/bin/bash set -e

psql -v on_error_stop=1 --username "$postgres_user" <<-eosql    create database userx;           create user userx password '$postgres_password';    create database diagnostics;    grant privileges on database userx $postgres_db;    grant privileges on database userx mydb2; eosql 

but got:

postgres_1   | create database postgres_1   | error:  role "mydb1" not exist postgres_1   | statement:  grant privileges on database rwx analytics; postgres_1   | error:  role "mydb2" not exist docker_postgres_1 exited code 3 

can please help, real blocker me , have no idea how proceed feel should not need creating database userx or roles , or wrong?

your grant syntax not quite right - https://www.postgresql.org/docs/9.0/static/sql-grant.html

in short should that:

grant privileges on yourdbname not user user; 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -