]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Add index modification in update_sqlite/sqlite3/postgresql scripts
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
1 #!/bin/sh
2 #
3 # Shell script to update PostgreSQL tables from version 2.0.0 to 3.0.0 or higher
4 #
5 echo " "
6 echo "This script will update a Bacula PostgreSQL database from version 10 to 11"
7 echo " which is needed to convert from Bacula version 2.0.0 to 3.0.x or higher"
8 echo " "
9 bindir=@SQL_BINDIR@
10 db_name=@db_name@
11
12 if $bindir/psql -f - -d ${db_name} $* <<END-OF-DATA
13
14 -- The alter table operation can be faster with a big maintenance_work_mem
15 -- Uncomment and adapt this value to your environment
16 -- SET maintenance_work_mem = '1GB';
17
18 BEGIN;
19 ALTER TABLE file ALTER fileid TYPE bigint ;
20 ALTER TABLE basefiles ALTER fileid TYPE bigint;
21 ALTER TABLE job ADD COLUMN readbytes bigint default 0;
22 ALTER TABLE media ADD COLUMN ActionOnPurge smallint default 0;
23 ALTER TABLE pool ADD COLUMN ActionOnPurge smallint default 0;
24
25 -- Create a table like Job for long term statistics
26 CREATE TABLE JobHisto (LIKE Job);
27 CREATE INDEX jobhisto_idx ON JobHisto ( starttime );
28
29 UPDATE Version SET VersionId=11;
30 COMMIT;
31
32 BEGIN;
33 -- Replace the broken file_fp_idx by a better one
34 DROP INDEX file_fp_idx;
35 CREATE INDEX file_jpfid_idx on file (jobid, pathid, filenameid);
36 ANALYSE;
37 COMMIT;
38
39 -- If you have already this table, you can remove it with:
40 -- DROP TABLE JobHistory;
41
42 -- vacuum analyse;
43 END-OF-DATA
44 then
45    echo "Update of Bacula PostgreSQL tables succeeded."
46 else
47    echo "Update of Bacula PostgreSQL tables failed."
48 fi
49 exit 0