]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/create_postgresql_database.in
More create_postgresql_database.in tweaks
[bacula/bacula] / bacula / src / cats / create_postgresql_database.in
1 #!/bin/sh
2 #
3 # shell script to create Bacula database(s)
4 #
5
6 bindir=@SQL_BINDIR@
7 db_name=@db_name@
8
9 #
10 # use SQL_ASCII to be able to put any filename into
11 #  the database even those created with unusual character sets
12
13 PSQLVERSION=`$bindir/psql --version | head -n1  | cut -d ' ' -f 3 | cut -d '.' -f 1,2`
14
15 #
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
19 #
20 case ${PSQLVERSION} in
21    "9.*")
22         ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
23    ;;
24    "8.[456789]")
25         ENCODING="ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C'"
26     ;;
27     *)
28         ENCODING="ENCODING 'SQL_ASCII'"
29     ;;
30 esac
31
32
33
34 #
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 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40 #
41 #
42 if $bindir/psql -f - -d template1 $* <<END-OF-DATA
43 \set ON_ERROR_STOP on
44 CREATE DATABASE ${db_name} $ENCODING TEMPLATE template0;
45 ALTER DATABASE ${db_name} SET datestyle TO 'ISO, YMD';
46 END-OF-DATA
47 then
48    echo "Creation of ${db_name} database succeeded."
49 else
50    echo " "
51    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
52    echo "!!!! Creation of ${db_name} database failed. !!!!"
53    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
54 fi
55 if $bindir/psql -l ${dbname} | grep " ${db_name}.*SQL_ASCII" >/dev/null; then 
56    echo "Database encoding OK"
57 else
58    echo " "
59    echo "Database encoding bad. Do not use this database"
60    echo " "
61 fi