From 5ab567da5fca2fbe869d537d29d8ada4a9e3435d Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Mon, 14 Oct 2019 13:39:48 +0600 Subject: [PATCH 1/7] Modify for postgres as all DB's owner --- .idea/.gitignore | 3 +++ .idea/docker-postgresql-multiple-databases.iml | 11 +++++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ README.md | 10 ++++++---- create-multiple-postgresql-databases.sh | 3 +-- 8 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/docker-postgresql-multiple-databases.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/docker-postgresql-multiple-databases.iml b/.idea/docker-postgresql-multiple-databases.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/docker-postgresql-multiple-databases.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eeecf61 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..791f76f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 3db6ca3..11780e5 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ Clone the repository, mount its directory as a volume into - ../docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d environment: - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD= ### By building a custom image @@ -46,8 +44,6 @@ to the container: image: eu.gcr.io/your-project/postgres-multi-db environment: - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD= ### Non-standard database names @@ -55,3 +51,9 @@ If you need to use non-standard database names (hyphens, uppercase letters etc), environment: - POSTGRES_MULTIPLE_DATABASES="test-db-1","test-db-2" + +### Things should be noted + +- All DB's will be under master user, if not mentioned it will be `postgres` +- You can not add `postgres` in the DB list, it's the default db. It will be create anyway. +- All DB's password will be same, if not mentioned it will be blank diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index aa665fa..b55c7f6 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -7,9 +7,8 @@ function create_user_and_database() { local database=$1 echo " Creating user and database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - CREATE USER $database; CREATE DATABASE $database; - GRANT ALL PRIVILEGES ON DATABASE $database TO $database; + GRANT ALL PRIVILEGES ON DATABASE $database TO postgres; EOSQL } From cb331100102d43a60d6520edc6c1f085427f5c04 Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Mon, 14 Oct 2019 13:40:22 +0600 Subject: [PATCH 2/7] mend --- .idea/.gitignore | 3 --- .idea/docker-postgresql-multiple-databases.iml | 11 ----------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 6 files changed, 38 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/docker-postgresql-multiple-databases.iml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 0e40fe8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ - -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/docker-postgresql-multiple-databases.iml b/.idea/docker-postgresql-multiple-databases.iml deleted file mode 100644 index 6711606..0000000 --- a/.idea/docker-postgresql-multiple-databases.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index eeecf61..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 791f76f..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 349922ba0b4b713459ecfbd27629452a4e3d5168 Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Mon, 23 Mar 2020 12:14:23 +0600 Subject: [PATCH 3/7] Add schema to db --- create-multiple-postgresql-databases.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index b55c7f6..bb718aa 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -8,7 +8,9 @@ function create_user_and_database() { echo " Creating user and database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL CREATE DATABASE $database; - GRANT ALL PRIVILEGES ON DATABASE $database TO postgres; + GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER; + \connect $database; + CREATE SCHEMA IF NOT EXISTS $DB_SCHEMA; EOSQL } From 93ec55eaa5732b7b60f00b953cb0b1e12aa3f605 Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Tue, 12 May 2020 13:38:47 +0600 Subject: [PATCH 4/7] Upgrade base image to postgres 11 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ee9c3d0..7d0a427 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,2 @@ -FROM postgres:9.6 +FROM postgres:11 COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ From a5d6cf0dd33860e4e4230206172c60aee5bc1535 Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Thu, 9 Jul 2020 15:35:09 +0600 Subject: [PATCH 5/7] Update postgres version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7d0a427..acc88fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,2 @@ -FROM postgres:11 +FROM postgres:12.3 COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ From 8e6e3d8c9954f76340d721ed65fd084a7c9678f4 Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Thu, 9 Jul 2020 19:40:18 +0600 Subject: [PATCH 6/7] Create db if not exists --- create-multiple-postgresql-databases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index bb718aa..9455a8a 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -7,7 +7,7 @@ function create_user_and_database() { local database=$1 echo " Creating user and database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - CREATE DATABASE $database; + CREATE DATABASE IF NOT EXISTS $database; GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER; \connect $database; CREATE SCHEMA IF NOT EXISTS $DB_SCHEMA; From 86f946238e9d5c2b1b7fb705b8a08e0764a46408 Mon Sep 17 00:00:00 2001 From: Minuddin Ahmed Rana Date: Thu, 9 Jul 2020 21:12:42 +0600 Subject: [PATCH 7/7] Fix --- create-multiple-postgresql-databases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index 9455a8a..bb718aa 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -7,7 +7,7 @@ function create_user_and_database() { local database=$1 echo " Creating user and database '$database'" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL - CREATE DATABASE IF NOT EXISTS $database; + CREATE DATABASE $database; GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER; \connect $database; CREATE SCHEMA IF NOT EXISTS $DB_SCHEMA;