arc_purge.sql 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. { ************************************************************************* }
  2. { }
  3. { INFORMIX SOFTWARE, INC. }
  4. { }
  5. { Title: arc_purge.sql }
  6. { Sccsid: @(#)arc_purge.sql 9.1 10/27/92 11:37:42 }
  7. { Description: }
  8. { cleanup archive tables by getting rid of inconsistent info }
  9. { }
  10. { ************************************************************************* }
  11. { --------------------------------------------------------------------------}
  12. { FILE : ARC_PURGE_INCONSISTENT.SQL }
  13. { PRODUCT : ARCHIVE*SQL }
  14. { MODULE : TOOLS PROCEDURES }
  15. { VERSION : 2.3.1 }
  16. { CONTENT : SQL statements to remove all inconsistent information from the }
  17. { catalog and to then update the "VOL_NB_SVST" field of the }
  18. { "ARC_VOLUME" table. }
  19. { }
  20. { Computertime Network Corporation }
  21. { Informix Version 6.0 }
  22. { Copyright 1988, 1991, 1992. All rights reserved. }
  23. { }
  24. { --------------------------------------------------------------------------}
  25. database sysmaster;
  26. begin work;
  27. lock table arc_request in exclusive mode;
  28. lock table arc_volume in exclusive mode;
  29. lock table arc_file in exclusive mode;
  30. lock table arc_save_set in exclusive mode;
  31. { --------------------------------------------------------------------------}
  32. { Remove "dangling" objects }
  33. { --------------------------------------------------------------------------}
  34. DELETE FROM ARC_REQUEST WHERE (REQ_STATUS IN ('SU','UC','PA') AND
  35. REQ_TYPE = 'AR' AND
  36. NOT EXISTS (select file_rid from arc_file
  37. where file_rid = req_rid));
  38. DELETE FROM ARC_VOL_LOCK WHERE NOT EXISTS (SELECT req_rid from arc_request
  39. where req_rid = vlck_rid);
  40. DELETE FROM ARC_VOLUME WHERE NOT EXISTS (SELECT vset_vid from arc_vset
  41. where vset_vid = vol_vid);
  42. DELETE FROM ARC_REQ_VSET WHERE NOT EXISTS (SELECT req_rid from arc_request
  43. where req_rid = rv_rid and
  44. req_status in ('NE','EX','PA' ));
  45. DELETE FROM ARC_REQ_VSET WHERE NOT EXISTS (SELECT vset_vid from arc_vset
  46. where vset_vid = rv_vid);
  47. DELETE FROM ARC_VSET_USER WHERE NOT EXISTS (SELECT vset_vid from arc_vset
  48. where vset_vid = vu_vid);
  49. DELETE FROM ARC_SAVE_SET WHERE NOT EXISTS (SELECT vset_vid from arc_vset
  50. where vset_vid = svst_vid);
  51. DELETE FROM ARC_FILE WHERE NOT EXISTS (select req_rid from arc_request
  52. where req_rid = file_rid and
  53. req_status in ('SU','UC','EX','PA'));
  54. DELETE FROM ARC_FILE WHERE FILE_TYPE = 'D' AND NOT EXISTS
  55. (select dbf_rid from arc_db_file
  56. where dbf_rid = file_rid);
  57. DELETE FROM ARC_FILE WHERE NOT EXISTS (select fc_rid from arc_file_copy
  58. where fc_rid = file_rid);
  59. DELETE FROM ARC_FILE_COPY WHERE NOT EXISTS (select file_rid from arc_file
  60. where file_rid = fc_rid);
  61. DELETE FROM ARC_REQUEST WHERE (REQ_STATUS IN ('SU','UC','PA') AND
  62. REQ_TYPE = 'AR' AND
  63. NOT EXISTS (select file_rid from arc_file
  64. where file_rid = req_rid));
  65. DELETE FROM ARC_DB_FILE WHERE NOT EXISTS (select file_rid from arc_file
  66. where file_rid = dbf_rid);
  67. DELETE FROM ARC_DIRECTORY WHERE NOT EXISTS (select file_rid from arc_file
  68. where file_rid = dir_rid);
  69. DELETE FROM ARC_REQUEST WHERE (REQ_STATUS = 'SU' OR REQ_STATUS = 'UC') AND
  70. REQ_TYPE = 'AR' AND
  71. NOT EXISTS (select file_rid from arc_file
  72. where file_rid = req_rid);
  73. DELETE FROM ARC_SAVE_SET WHERE NOT EXISTS (select fc_rid from arc_file_copy
  74. where fc_rid = svst_rid and
  75. fc_vid = svst_vid);
  76. DELETE FROM ARC_SAVE_SET WHERE NOT EXISTS (select req_rid from arc_request
  77. where req_rid = svst_rid and
  78. req_status in ('SU','UC','EX','PA'));
  79. DELETE FROM ARC_PENDING_REQ WHERE NOT EXISTS (select req_rid from arc_request
  80. where req_rid = pend_rid and
  81. req_status in ('NE','EX','PA'));
  82. { --------------------------------------------------------------------------}
  83. { Update the vol_nb_svst (nb of save-sets in a volume) field in ARC_VOLUME. }
  84. { --------------------------------------------------------------------------}
  85. UPDATE ARC_VOLUME SET VOL_NB_SVST = (select count (distinct fc_rid)
  86. from arc_file_copy
  87. where fc_vid = vol_vid
  88. and fc_vno = vol_vno)
  89. WHERE VOL_VID IN (select vset_vid
  90. from arc_vset
  91. where vset_dev_driver = 'DISK');
  92. UPDATE ARC_VOLUME SET VOL_FULL = 'N'
  93. , VOL_SPACE_EXACT = 'N'
  94. WHERE VOL_NB_SVST = 0
  95. OR VOL_SPACE_EXACT = 'N';
  96. { --------------------------------------------------------------------------}
  97. { Update the number of file copy field in ARC_FILE. }
  98. { --------------------------------------------------------------------------}
  99. UPDATE ARC_FILE SET FILE_NB_COPIES = (select count (distinct fc_vid)
  100. from arc_file_copy
  101. where fc_rid = file_rid
  102. and fc_fno = file_fno);
  103. { --------------------------------------------------------------------------}
  104. { Reset all parent request without child to UNCOMPLETED }
  105. { --------------------------------------------------------------------------}
  106. UPDATE ARC_REQUEST_VIEW SET REQ_STATUS = 'UC' WHERE REQ_STATUS = 'PA' AND
  107. NOT EXISTS (select pend_parent_rid
  108. from arc_pending_req
  109. where pend_parent_rid = req_rid);
  110. commit work;
  111. close database;