3 # shell script to create Bacula database(s)
6 PATH="@POSTGRESQL_BINDIR@:$PATH"
7 db_name=${db_name:-@db_name@}
10 # use SQL_ASCII to be able to put any filename into
11 # the database even those created with unusual character sets
13 PSQLVERSION=`psql -d template1 -c 'select version()' $* | awk '/PostgreSQL/ {print $2}' | cut -d '.' -f 1,2`
16 # Note, LC_COLLATE and LC_TYPE are needed on 8.4 and beyond, but are
17 # not implemented in 8.3 or below.
18 # This must be updated for future versions of PostgreSQL
20 case ${PSQLVERSION} in
22 ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
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 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
55 if psql -l ${dbname} | grep " ${db_name}.*SQL_ASCII" >/dev/null; then
56 echo "Database encoding OK"
59 echo "Database encoding bad. Do not use this database"