在docker-entrypoint.sh中为特定数据库创建架构

时间:2018-03-08 15:22:23

标签: postgresql psql

如何在docker的shell脚本docker-entrypoint.sh中为特定数据库创建新架构。

sudo -u postgres psql -c "ALTER user postgres WITH PASSWORD 'postgres'"
sudo -u postgres psql -c "CREATE DATABASE example;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE example TO postgres;"
sudo -u postgres psql -c "CREATE SCHEMA production;"
sudo -u postgres psql -c "\dn"

在postgres中没有像mysql这样的“使用数据库”,所以如何将其指定给example数据库。目前,新架构production默认转到postgres中的postgres数据库。

1 个答案:

答案 0 :(得分:2)

如果未指定,psql将连接到与用户同名的数据库。如果您不想这样做,请提供它应连接到的数据库名称:

sudo -u postgres psql -d example -c "CREATE SCHEMA production;"