Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. -- Note, if you installed update 2.6.3 prior to the release of 2.6.4, this update will not change anything, but is still required to be installed to allow the extension version update chain to work.
  2. -- While upgrading to version 2.6.3 or later, if you encounter the error: "cannot ALTER TABLE "part_config_sub" because it has pending trigger events" (or for the part_config table), then you must install that update by itself first and then install the update to 2.6.4 separately in a different transaction. Changing the values of a column in the same transaction as altering it to add/remove a constraint can cause the pending triggers error. The only way around that is to do the steps as separate transactions, which this update separates out from the previous one that caused the issue. Unfortunately, all extension updates run in a single transaction unless you upgrade manually to a specific version to control the transaction state between versions. So, if you encounter this error, do the updates for 2.6.3 & 2.6.4 as follows:
  3.  
  4. /*
  5. BEGIN;
  6. ALTER EXTENSION pg_partman UPDATE TO '2.6.3';
  7. COMMIT;
  8.  
  9. BEGIN;
  10. ALTER EXTENSION pg_partman UPDATE TO '2.6.4';
  11. COMMIT;
  12. */
  13.  
  14. -- Redoing this again shouldn't matter
  15. ALTER TABLE @extschema@.part_config ALTER COLUMN epoch SET DEFAULT 'none';
  16.  
  17. ALTER TABLE @extschema@.part_config_sub ALTER COLUMN sub_epoch SET DEFAULT 'none';
  18.  
  19. -- Only recreate constraints if they don't already exist from a previous 2.6.3 update before 2.6.4 was available
  20. DO $$
  21. DECLARE
  22. v_exists text;
  23. BEGIN
  24. SELECT conname INTO v_exists
  25. FROM pg_catalog.pg_constraint t
  26. JOIN pg_catalog.pg_class c ON t.conrelid = c.oid
  27. JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
  28. WHERE t.conname = 'part_config_epoch_check'
  29. AND c.relname = 'part_config'
  30. AND n.nspname = '@extschema@';
  31. RAISE NOTICE 'v_exists: %', v_exists;
  32.  
  33. IF v_exists IS NULL THEN
  34. EXECUTE format('
  35. ALTER TABLE @extschema@.part_config
  36. ADD CONSTRAINT part_config_epoch_check
  37. CHECK (@extschema@.check_epoch_type(epoch))');
  38. END IF;
  39. v_exists := NULL;
  40.  
  41. SELECT conname INTO v_exists
  42. FROM pg_catalog.pg_constraint t
  43. JOIN pg_catalog.pg_class c ON t.conrelid = c.oid
  44. JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
  45. WHERE t.conname = 'part_config_sub_epoch_check'
  46. AND c.relname = 'part_config_sub'
  47. AND n.nspname = '@extschema@';
  48.  
  49. IF v_exists IS NULL THEN
  50. EXECUTE format('
  51. ALTER TABLE @extschema@.part_config_sub
  52. ADD CONSTRAINT part_config_sub_epoch_check
  53. CHECK (@extschema@.check_epoch_type(sub_epoch))');
  54. END IF;
  55. END
  56. $$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement