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
25 ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
28 ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
31 ENCODING="ENCODING 'SQL_ASCII'"
38 # Please note: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
39 # We do not recommend that you use ENCODING 'SQL_UTF8'
40 # It can result in creating filenames in the database that
41 # cannot be seen or restored.
42 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 if psql -f - -d template1 $* <<END-OF-DATA
47 CREATE DATABASE ${db_name} $ENCODING TEMPLATE template0;
48 ALTER DATABASE ${db_name} SET datestyle TO 'ISO, YMD';
51 echo "Creation of ${db_name} database succeeded."
54 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
55 echo "!!!! Creation of ${db_name} database failed. !!!!"
56 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
59 if psql -l | grep " ${db_name}.*SQL_ASCII" >/dev/null; then
60 echo "Database encoding OK"
63 echo "Database encoding bad. Do not use this database"