]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/create_postgresql_database.in
Use correct SQL table encoding for Postgresql 10.x
[bacula/bacula] / bacula / src / cats / create_postgresql_database.in
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2017 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
6 # shell script to create Bacula database(s)
7 #
8
9 PATH="@POSTGRESQL_BINDIR@:$PATH"
10 db_name=${db_name:-@db_name@}
11
12 #
13 # use SQL_ASCII to be able to put any filename into
14 #  the database even those created with unusual character sets
15
16 PSQLVERSION=`psql -d template1 -c 'select version()' $* | awk '/PostgreSQL/ {print $2}' | cut -d '.' -f 1,2`
17
18 #
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
22 #
23 case ${PSQLVERSION} in
24    8.[456789] | 9.* | 10.*)
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 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    exit 1
55 fi
56 if psql -l | grep " ${db_name}.*SQL_ASCII" >/dev/null; then 
57    echo "Database encoding OK"
58 else
59    echo " "
60    echo "Database encoding bad. Do not use this database"
61    echo " "
62    exit 1
63 fi