Skip to content

Commit 23053b3

Browse files
author
Sameer Naik
committed
added DB_TEMPLATE variable to specify the database template
1 parent 4e936a9 commit 23053b3

File tree

5 files changed

+6
-1
lines changed

5 files changed

+6
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
**latest**
44
- removed use of single-user mode
5+
- added `DB_TEMPLATE` variable to specify the database template
56

67
**9.4-11**
78
- added `PG_PASSWORD` variable to specify password for `postgres` user

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ docker run --name postgresql -itd --restart always \
159159
sameersbn/postgresql:9.4-11
160160
```
161161

162+
By default databases are created by copying the standard system database named `template1`. You can specify a different template for your database using the `DB_TEMPLATE` parameter. Refer to [Template Databases](http://www.postgresql.org/docs/9.4/static/manage-ag-templatedbs.html) for further information.
163+
162164
Additionally, more than one database can be created by specifying a comma separated list of database names in `DB_NAME`. For example, the following command creates two new databases named `dbname1` and `dbname2`.
163165

164166
*This feature is only available in releases greater than `9.1-1`*

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PostgreSQL:
99
- DB_USER=
1010
- DB_PASS=
1111
- DB_NAME=
12+
- DB_TEMPLATE=
1213

1314
- DB_UNACCENT=
1415

runtime/env-defaults

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ REPLICATION_SSLMODE=${REPLICATION_SSLMODE:-prefer}
1616
DB_NAME=${DB_NAME:-}
1717
DB_USER=${DB_USER:-}
1818
DB_PASS=${DB_PASS:-}
19+
DB_TEMPLATE=${DB_TEMPLATE:-template1}
1920

2021
DB_UNACCENT=${DB_UNACCENT:-false}

runtime/functions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ create_database() {
316316
for database in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
317317
echo -n "${database} "
318318
if [[ -z $(psql -U ${PG_USER} -Atc "SELECT 1 FROM pg_catalog.pg_database WHERE datname = '${DB_NAME}'";) ]]; then
319-
psql -U ${PG_USER} -c "CREATE DATABASE \"${database}\";" >/dev/null
319+
psql -U ${PG_USER} -c "CREATE DATABASE \"${database}\" WITH TEMPLATE = \"${DB_TEMPLATE}\";" >/dev/null
320320
fi
321321

322322
if [[ ${DB_UNACCENT} == true ]]; then

0 commit comments

Comments
 (0)