3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # shell script to create Bacula database(s)
9 PATH="@POSTGRESQL_BINDIR@:$PATH"
10 db_name=${db_name:-@db_name@}
13 # use SQL_ASCII to be able to put any filename into
14 # the database even those created with unusual character sets
16 PSQLVERSION=`psql -d template1 -c 'select version()' $* | awk '/PostgreSQL/ {print $2}' | cut -d '.' -f 1,2`
19 # Note, LC_COLLATE and LC_TYPE are needed on 8.4 and beyond, but are
20 # not implemented in 8.3 or below.
21 # This must be updated for future versions of PostgreSQL
23 case ${PSQLVERSION} in
24 8.[456789] | 9.* | 10.*)
25 ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
28 ENCODING="ENCODING 'SQL_ASCII'"
35 # Please note: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36 # We do not recommend that you use ENCODING 'SQL_UTF8'
37 # It can result in creating filenames in the database that
38 # cannot be seen or restored.
39 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 if psql -f - -d template1 $* <<END-OF-DATA
44 CREATE DATABASE ${db_name} $ENCODING TEMPLATE template0;
45 ALTER DATABASE ${db_name} SET datestyle TO 'ISO, YMD';
48 echo "Creation of ${db_name} database succeeded."
51 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
52 echo "!!!! Creation of ${db_name} database failed. !!!!"
53 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
56 if psql -l | grep " ${db_name}.*SQL_ASCII" >/dev/null; then
57 echo "Database encoding OK"
60 echo "Database encoding bad. Do not use this database"