Speed up 'archive stat cats' database upgrade user/dbs/speedier_0663_upgrade
authorDan Scott <dan@coffeecode.net>
Sat, 7 Jan 2012 21:31:38 +0000 (16:31 -0500)
committerDan Scott <dan@coffeecode.net>
Sat, 7 Jan 2012 21:31:38 +0000 (16:31 -0500)
The action.circulation table has four triggers that fire on UPDATE
events, and the 0663 database upgrade issues two updates that affect
every row in that table - which can take a long time to complete on
systems with relatively active circulation systems. We can speed things
up somewhat by preventing the triggers from firing during the update.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Open-ILS/src/sql/Pg/upgrade/0663.schema.archive_circ_stat_cats.sql

index 022b2dd..915a9d0 100644 (file)
@@ -32,6 +32,9 @@ ALTER TABLE actor.stat_cat
 ALTER TABLE asset.stat_cat
     ADD COLUMN checkout_archive BOOL NOT NULL DEFAULT FALSE;
 
+-- Speed up the upgrade process prevening the four UPDATE triggers from firing
+ALTER TABLE action.circulation DISABLE TRIGGER ALL;
+
 -- Circulation copy column
 ALTER TABLE action.circulation
     ADD COLUMN copy_location INT NOT NULL DEFAULT 1 REFERENCES asset.copy_location(id) DEFERRABLE INITIALLY DEFERRED;
@@ -39,6 +42,9 @@ ALTER TABLE action.circulation
 -- Update action.circulation with real copy_location numbers instead of all "Stacks"
 UPDATE action.circulation circ SET copy_location = ac.location FROM asset.copy ac WHERE ac.id = circ.target_copy;
 
+-- Re-enable the triggers now that the upgrade of the table is complete
+ALTER TABLE action.circulation ENABLE TRIGGER ALL;
+
 -- Create trigger function to auto-fill the copy_location field
 CREATE OR REPLACE FUNCTION action.fill_circ_copy_location () RETURNS TRIGGER AS $$
 BEGIN