sch_tasks.sql 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004
  1. {**************************************************************************}
  2. {* *}
  3. {* Licensed Materials - Property of IBM and/or HCL *}
  4. {* *}
  5. {* IBM Informix Dynamic Server *}
  6. {* Copyright IBM Corporation 1996, 2017 *}
  7. {* (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved. *}
  8. {* *}
  9. {**************************************************************************}
  10. { }
  11. { Title: sch_tasks.sql }
  12. { Description: }
  13. { system default set of tasks }
  14. DATABASE sysadmin;
  15. EXECUTE PROCEDURE ifx_allow_newline('t');
  16. INSERT INTO ph_group VALUES (0,"DISK","Disk Subsystem");
  17. INSERT INTO ph_group VALUES (0,"NETWORK","Network subsystem");
  18. INSERT INTO ph_group VALUES (0,"MEMORY","Memory Utilization");
  19. INSERT INTO ph_group VALUES (0,"CPU","CPU Utilization");
  20. INSERT INTO ph_group VALUES (0,"TABLES","Tables");
  21. INSERT INTO ph_group VALUES (0,"INDEXES","Indexes");
  22. INSERT INTO ph_group VALUES (0,"SERVER","Global Server Information");
  23. INSERT INTO ph_group VALUES (0,"USER","User Information");
  24. INSERT INTO ph_group VALUES (0,"BACKUP","Backup and Restore Information");
  25. INSERT INTO ph_group VALUES (0,"PERFORMANCE","Performance Information");
  26. {**************************************************************************
  27. Monitor for the command history table
  28. **************************************************************************}
  29. INSERT INTO ph_threshold(id,name,task_name,value,description)
  30. VALUES
  31. (0,"COMMAND HISTORY RETENTION", "mon_command_history","30 0:00:00",
  32. "The amount of time the command_history table should contain information about SQL ADMIN commands that habe been executed. Any SQL ADMIN commands older than this will be purged.");
  33. INSERT INTO ph_task
  34. (
  35. tk_name,
  36. tk_type,
  37. tk_group,
  38. tk_description,
  39. tk_execute,
  40. tk_start_time,
  41. tk_stop_time,
  42. tk_frequency
  43. )
  44. VALUES
  45. (
  46. "mon_command_history",
  47. "TASK",
  48. "TABLES",
  49. "Monitor how much data is kept in the command history table",
  50. "delete from command_history where cmd_exec_time < (
  51. select current - value::INTERVAL DAY to SECOND
  52. from ph_threshold
  53. where name = 'COMMAND HISTORY RETENTION' ) ",
  54. DATETIME(02:00:00) HOUR TO SECOND,
  55. NULL,
  56. INTERVAL ( 1 ) DAY TO DAY
  57. );
  58. {**************************************************************************
  59. Task to track the onconfig paramaters
  60. **************************************************************************}
  61. CREATE FUNCTION informix.onconfig_save_diffs(task_id INTEGER, ID INTEGER)
  62. RETURNING INTEGER
  63. DEFINE value LVARCHAR(1024);
  64. DEFINE conf_value LVARCHAR(1024);
  65. DEFINE conf_id INTEGER;
  66. LET value = NULL;
  67. FOREACH select cf_id, trim(cf_effective)
  68. INTO conf_id, conf_value
  69. FROM sysmaster:syscfgtab
  70. FOREACH select FIRST 1 config_value
  71. INTO value
  72. FROM sysadmin:mon_config
  73. WHERE mon_config.config_id = conf_id
  74. ORDER BY id DESC
  75. END FOREACH
  76. IF conf_value == value THEN
  77. CONTINUE FOREACH;
  78. END IF
  79. INSERT INTO mon_config VALUES( ID, conf_id, conf_value );
  80. END FOREACH
  81. return 0;
  82. END FUNCTION;
  83. INSERT INTO ph_task
  84. (
  85. tk_name,
  86. tk_type,
  87. tk_group,
  88. tk_description,
  89. tk_result_table,
  90. tk_create,
  91. tk_execute,
  92. tk_start_time,
  93. tk_stop_time,
  94. tk_delete,
  95. tk_frequency,
  96. tk_next_execution
  97. )
  98. VALUES
  99. (
  100. "mon_config",
  101. "SENSOR",
  102. "SERVER",
  103. "Collect information about database server's configuration file (onconfig). Only modified parameters are collected.",
  104. "mon_config",
  105. "create table informix.mon_config (ID integer, config_id integer, config_value lvarchar(1024)); create index mon_config_idx1 on mon_config(config_id);create index mon_config_idx2 on mon_config(id,config_id);create view mon_onconfig as select ID ID, cf_name name, config_value value from mon_config, sysmaster:sysconfig where mon_config.config_id = sysmaster:sysconfig.cf_id;grant select on mon_config TO 'db_monitor' as informix;",
  106. "onconfig_save_diffs",
  107. NULL,
  108. NULL,
  109. INTERVAL ( 60 ) DAY TO DAY,
  110. INTERVAL ( 1 ) DAY TO DAY,
  111. DATETIME(05:00:00) HOUR TO SECOND
  112. );
  113. INSERT INTO ph_task
  114. (
  115. tk_name,
  116. tk_type,
  117. tk_group,
  118. tk_description,
  119. tk_result_table,
  120. tk_create,
  121. tk_execute,
  122. tk_start_time,
  123. tk_stop_time,
  124. tk_delete,
  125. tk_frequency,
  126. tk_next_execution
  127. )
  128. VALUES
  129. (
  130. "mon_config_startup",
  131. "STARTUP SENSOR",
  132. "SERVER",
  133. "Collect information about database servers configuration file (onconfig). This
  134. will only collect paramaters which have changed.",
  135. "mon_config",
  136. "create table informix.mon_config (ID integer, config_id integer, config_value lvarchar(1024)); create view mon_onconfig as select ID ID, cf_name name, config_value value from mon_config, sysmaster:sysconfig where mon_config.config_id = sysmaster:sysconfig.cf_id;",
  137. "onconfig_save_diffs",
  138. NULL,
  139. NULL,
  140. INTERVAL ( 99 ) DAY TO DAY,
  141. NULL,
  142. NULL
  143. );
  144. {**************************************************************************
  145. Task to track the database servers environment information
  146. **************************************************************************}
  147. INSERT INTO ph_task
  148. (
  149. tk_name,
  150. tk_type,
  151. tk_group,
  152. tk_description,
  153. tk_result_table,
  154. tk_create,
  155. tk_execute,
  156. tk_stop_time,
  157. tk_start_time,
  158. tk_frequency,
  159. tk_delete
  160. )
  161. VALUES
  162. (
  163. "mon_sysenv",
  164. "STARTUP SENSOR",
  165. "SERVER",
  166. "Tracks the database servers startup environment.",
  167. "mon_sysenv",
  168. "create table informix.mon_sysenv (ID integer, name varchar(250), value lvarchar(1024));grant select on mon_sysenv TO 'db_monitor' as informix;",
  169. "insert into mon_sysenv select $DATA_SEQ_ID, TRIM(env_name), TRIM(env_value) FROM sysmaster:sysenv;",
  170. NULL,
  171. NULL,
  172. "0 0:01:00",
  173. INTERVAL ( 60 ) DAY TO DAY
  174. );
  175. {**************************************************************************
  176. Task to track the general system profile information
  177. **************************************************************************}
  178. INSERT INTO ph_task
  179. (
  180. tk_name,
  181. tk_type,
  182. tk_group,
  183. tk_description,
  184. tk_result_table,
  185. tk_create,
  186. tk_execute,
  187. tk_start_time,
  188. tk_stop_time,
  189. tk_frequency,
  190. tk_delete
  191. )
  192. VALUES
  193. (
  194. "mon_profile",
  195. "SENSOR",
  196. "PERFORMANCE",
  197. "Collect the general profile information",
  198. "mon_prof",
  199. "create table informix.mon_prof (ID integer, number integer, value int8 );create view informix.mon_profile as select ID, A.name, B.value from sysmaster:sysshmhdr A, mon_prof B where B.number = A.number; create index mon_prof_idx1 on mon_prof(ID, number);create index mon_prof_idx2 on mon_prof(number);grant select on mon_profile TO 'db_monitor' as informix;grant select on mon_prof TO 'db_monitor' as informix;",
  200. "insert into mon_prof select $DATA_SEQ_ID, number, value from sysmaster:sysshmhdr where name != 'unused'",
  201. NULL,
  202. NULL,
  203. INTERVAL ( 1 ) HOUR TO HOUR,
  204. INTERVAL ( 30 ) DAY TO DAY
  205. );
  206. {**************************************************************************
  207. Task to track the chunk information
  208. **************************************************************************}
  209. INSERT INTO ph_task
  210. (
  211. tk_name,
  212. tk_type,
  213. tk_group,
  214. tk_description,
  215. tk_result_table,
  216. tk_create,
  217. tk_execute,
  218. tk_start_time,
  219. tk_stop_time,
  220. tk_frequency,
  221. tk_delete
  222. )
  223. VALUES
  224. (
  225. "mon_chunk",
  226. "SENSOR",
  227. "PERFORMANCE",
  228. "Collect the general chunk information",
  229. "mon_chunk",
  230. "create table informix.mon_chunk (ID integer, number smallint, dbsnum smallint, nfree integer,udfree integer, reads bigint, writes bigint, pagesread bigint, pageswritten bigint, readtime float, writetime float);grant select on mon_chunk TO 'db_monitor' as informix;",
  231. "insert into mon_chunk select * from ( select $DATA_SEQ_ID, chknum, dbsnum, nfree, udfree, reads, writes,pagesread,pageswritten,readtime,writetime from sysmaster:syschktab_fast union select $DATA_SEQ_ID, chknum, dbsnum, nfree, udfree, reads,writes,pagesread, pageswritten,readtime,writetime from sysmaster:sysmchktab_fast)",
  232. NULL,
  233. NULL,
  234. INTERVAL ( 1 ) HOUR TO HOUR,
  235. INTERVAL ( 30 ) DAY TO DAY
  236. );
  237. {**************************************************************************
  238. Task to track the general cpu usage by process class
  239. **************************************************************************}
  240. INSERT INTO ph_task
  241. (
  242. tk_name,
  243. tk_type,
  244. tk_group,
  245. tk_description,
  246. tk_result_table,
  247. tk_create,
  248. tk_execute,
  249. tk_stop_time,
  250. tk_start_time,
  251. tk_frequency,
  252. tk_delete
  253. )
  254. VALUES
  255. (
  256. "mon_vps",
  257. "SENSOR",
  258. "CPU",
  259. "Process time of the Virtual Processors",
  260. "mon_vps",
  261. "create table informix.mon_vps (ID integer, vpid smallint, num_ready smallint, class integer, usecs_user float, usecs_sys float);grant select on mon_vps TO 'db_monitor' as informix;",
  262. "insert into mon_vps select $DATA_SEQ_ID, vpid, num_ready, class, usecs_user, usecs_sys FROM sysmaster:sysvplst",
  263. NULL,
  264. NULL,
  265. INTERVAL ( 4 ) HOUR TO HOUR,
  266. INTERVAL ( 15 ) DAY TO DAY
  267. );
  268. {**************************************************************************
  269. Task to track the checkpoint information
  270. **************************************************************************}
  271. INSERT INTO ph_task
  272. (
  273. tk_name,
  274. tk_type,
  275. tk_group,
  276. tk_description,
  277. tk_result_table,
  278. tk_create,
  279. tk_execute,
  280. tk_stop_time,
  281. tk_start_time,
  282. tk_frequency,
  283. tk_delete
  284. )
  285. VALUES
  286. (
  287. "mon_checkpoint",
  288. "SENSOR",
  289. "SERVER",
  290. "Track the checkpoint information",
  291. "mon_checkpoint",
  292. "create table informix.mon_checkpoint (ID integer, intvl integer, type char(12), caller char(10), clock_time int, crit_time float, flush_time float, cp_time float, n_dirty_buffs int, plogs_per_sec int, llogs_per_sec int, dskflush_per_sec int, ckpt_logid int, ckpt_logpos int, physused int, logused int, n_crit_waits int, tot_crit_wait float, longest_crit_wait float, block_time float);create unique index idx_mon_ckpt_1 on mon_checkpoint(intvl);grant select on mon_checkpoint TO 'db_monitor' as informix;",
  293. "insert into mon_checkpoint select $DATA_SEQ_ID, intvl, type, caller, clock_time, crit_time, flush_time, cp_time, n_dirty_buffs, plogs_per_sec, llogs_per_sec, dskflush_per_sec, ckpt_logid, ckpt_logpos, physused, logused, n_crit_waits, tot_crit_wait, longest_crit_wait, block_time FROM sysmaster:syscheckpoint WHERE intvl > (select NVL(max(intvl),0) from mon_checkpoint)",
  294. NULL,
  295. NULL,
  296. INTERVAL ( 60 ) MINUTE TO MINUTE,
  297. INTERVAL ( 7 ) DAY TO DAY
  298. );
  299. {**************************************************************************
  300. Task to track the server memory information
  301. **************************************************************************}
  302. INSERT INTO ph_task
  303. (
  304. tk_name,
  305. tk_type,
  306. tk_group,
  307. tk_description,
  308. tk_result_table,
  309. tk_create,
  310. tk_execute,
  311. tk_stop_time,
  312. tk_start_time,
  313. tk_frequency,
  314. tk_delete
  315. )
  316. VALUES
  317. (
  318. "mon_memory_system",
  319. "SENSOR",
  320. "MEMORY",
  321. "Server memory consumption",
  322. "mon_memory_system",
  323. "create table informix.mon_memory_system (ID integer, class smallint, size int8, used int8, free int8 );grant select on mon_memory_system TO 'db_monitor' as informix;",
  324. "insert into mon_memory_system select $DATA_SEQ_ID, seg_class, seg_size, seg_blkused, seg_blkfree FROM sysmaster:sysseglst",
  325. NULL,
  326. NULL,
  327. INTERVAL ( 2 ) HOUR TO HOUR,
  328. INTERVAL ( 15 ) DAY TO DAY
  329. );
  330. {**************************************************************************
  331. Task to track the table level statistics
  332. **************************************************************************}
  333. INSERT INTO ph_task
  334. (
  335. tk_name,
  336. tk_group,
  337. tk_description,
  338. tk_result_table,
  339. tk_create,
  340. tk_execute,
  341. tk_stop_time,
  342. tk_start_time,
  343. tk_frequency,
  344. tk_delete
  345. )
  346. VALUES
  347. (
  348. "mon_table_profile",
  349. "TABLES",
  350. "Collect SQL profile information by table/fragment, index information is excluded from this collection",
  351. "mon_table_profile",
  352. "create table informix.mon_table_profile ( id integer, partnum integer, nextns smallint, serialval int8, nptotal integer, npused integer, npdata integer, lockid integer, nrows bigint, ucount smallint, ocount smallint, pf_rqlock int8, pf_lockwait int8, pf_isread int8, pf_iswrite int8, pf_isrwrite int8, pf_isdelete int8, pf_bfcread int8, pf_bfcwrite int8, pf_seqscans int8, pf_dskreads int8, pf_dskwrites int8);grant select on mon_table_profile TO 'db_monitor' as informix; ",
  353. "insert into mon_table_profile select $DATA_SEQ_ID, partnum, nextns, decode(cur_serial8, 1, cur_serial4::int8, cur_serial8), nptotal, npused, npdata, lockid, nrows, ucount, ocount, pf_rqlock, pf_wtlock + pf_deadlk + pf_dltouts, pf_isread, pf_iswrite, pf_isrwrite, pf_isdelete, pf_bfcread, pf_bfcwrite, pf_seqscans, pf_dskreads, pf_dskwrites FROM sysmaster:sysactptnhdr WHERE (nkeys >0 AND nrows > 0 ) OR nkeys=0",
  354. NULL,
  355. NULL,
  356. INTERVAL ( 1 ) DAY TO DAY,
  357. INTERVAL ( 7 ) DAY TO DAY
  358. );
  359. {**************************************************************************
  360. Task to track the tabnames paramaters
  361. **************************************************************************}
  362. CREATE FUNCTION informix.tabnames_save_diffs(task_id INTEGER, ID INTEGER)
  363. RETURNING INTEGER
  364. DEFINE cur_dbsname VARCHAR(128);
  365. DEFINE cur_owner VARCHAR(32);
  366. DEFINE cur_tabname VARCHAR(128);
  367. DEFINE cur_created INTEGER;
  368. DEFINE cur_partnum INTEGER;
  369. DEFINE cur_lockid INTEGER;
  370. FOREACH select tab.dbsname, tab.owner, tab.tabname ,
  371. ptn.created, ptn.partnum, ptn.lockid
  372. INTO cur_dbsname, cur_owner, cur_tabname,
  373. cur_created, cur_partnum, cur_lockid
  374. FROM sysmaster:systabnames tab, sysmaster:sysptnhdr ptn
  375. WHERE tab.partnum = ptn.partnum
  376. AND sysmaster:bitval(ptn.flags,'0x20')==0
  377. AND ptn.created NOT IN
  378. (
  379. SELECT created
  380. FROM mon_table_names
  381. WHERE mon_table_names.partnum = ptn.partnum
  382. AND mon_table_names.lockid = ptn.lockid
  383. )
  384. INSERT INTO sysadmin:mon_table_names
  385. (ID, partnum, dbsname, owner, tabname, created, lockid)
  386. VALUES
  387. (ID, cur_partnum, TRIM(cur_dbsname), TRIM(cur_owner),
  388. TRIM(cur_tabname), cur_created, cur_lockid );
  389. END FOREACH
  390. return 0;
  391. END FUNCTION;
  392. INSERT INTO ph_task
  393. (
  394. tk_name,
  395. tk_type,
  396. tk_group,
  397. tk_description,
  398. tk_result_table,
  399. tk_create,
  400. tk_execute,
  401. tk_stop_time,
  402. tk_start_time,
  403. tk_frequency,
  404. tk_delete
  405. )
  406. VALUES
  407. (
  408. "mon_table_names",
  409. "SENSOR",
  410. "TABLES",
  411. "Collect table names from the system",
  412. "mon_table_names",
  413. "create table informix.mon_table_names ( id integer, partnum integer, dbsname varchar(128), owner varchar(32), tabname varchar(128), created integer,lockid integer ); create index informix.mon_table_names_idx1 on mon_table_names(partnum);grant select on mon_table_names TO 'db_monitor' as informix;",
  414. "tabnames_save_diffs",
  415. NULL,
  416. DATETIME(02:00:00) HOUR TO SECOND,
  417. INTERVAL ( 1 ) DAY TO DAY,
  418. INTERVAL ( 30 ) DAY TO DAY
  419. );
  420. {**************************************************************************
  421. Task to track the general system profile information
  422. **************************************************************************}
  423. INSERT INTO ph_task
  424. (
  425. tk_name,
  426. tk_type,
  427. tk_group,
  428. tk_description,
  429. tk_result_table,
  430. tk_create,
  431. tk_execute,
  432. tk_start_time,
  433. tk_stop_time,
  434. tk_frequency,
  435. tk_delete
  436. )
  437. VALUES
  438. (
  439. "mon_users",
  440. "SENSOR",
  441. "PERFORMANCE",
  442. "Collect information about each user",
  443. "mon_users",
  444. "CREATE TABLE informix.mon_users (ID integer, sid integer, uid integer, username varchar(16), pid integer, progname varchar(16),hostname varchar(16), memtotal integer, memused integer, upf_rqlock bigint, upf_wtlock bigint, upf_deadlk bigint, upf_lktouts bigint, upf_lgrecs bigint, upf_isread bigint, upf_iswrite bigint, upf_isrwrite bigint, upf_isdelete bigint, upf_iscommit bigint, upf_isrollback bigint, upf_longtxs bigint, upf_bufreads bigint, upf_idxbufreads integer, upf_diskreads integer, upf_bufwrites bigint, upf_diskwrites integer, upf_logspuse bigint, upf_logspmax bigint, upf_seqscans bigint, upf_totsorts bigint, upf_dsksorts bigint, upf_srtspmax bigint, nlocks integer, lkwaittime float, iowaittime float, upf_niowaits integer, net_read_cnt int8, net_read_bytes int8, net_write_cnt int8, net_write_bytes int8, net_open_time integer, net_last_read integer, net_last_write integer, wreason integer);grant select on mon_users TO 'db_monitor' as informix;",
  445. "insert into mon_users (ID, sid, uid, username, pid, progname, hostname, memtotal, memused, upf_rqlock, upf_wtlock, upf_deadlk, upf_lktouts, upf_lgrecs, upf_isread, upf_iswrite, upf_isrwrite, upf_isdelete, upf_iscommit, upf_isrollback, upf_longtxs, upf_bufreads, upf_idxbufreads, upf_diskreads, upf_bufwrites, upf_diskwrites, upf_logspuse, upf_logspmax, upf_seqscans, upf_totsorts, upf_dsksorts, upf_srtspmax, nlocks, lkwaittime, iowaittime, upf_niowaits, net_read_cnt, net_read_bytes, net_write_cnt, net_write_bytes, net_open_time, net_last_read, net_last_write, wreason) SELECT $DATA_SEQ_ID, scb.sid, scb.uid, TRIM(scb.username), scb.pid, TRIM(scb.progname), TRIM(scb.hostname), scb.memtotal, scb.memused, rstcb.upf_rqlock, rstcb.upf_wtlock, rstcb.upf_deadlk, rstcb.upf_lktouts, rstcb.upf_lgrecs, rstcb.upf_isread, rstcb.upf_iswrite, rstcb.upf_isrwrite, rstcb.upf_isdelete , rstcb.upf_iscommit, rstcb.upf_isrollback, rstcb.upf_longtxs, rstcb.upf_bufreads, rstcb.upf_idxbufreads, rstcb.nreads, rstcb.upf_bufwrites, rstcb.nwrites, rstcb.upf_logspuse, rstcb.upf_logspmax, rstcb.upf_seqscans, rstcb.upf_totsorts, rstcb.upf_dsksorts, rstcb.upf_srtspmax, rstcb.nlocks, rstcb.lkwaittime, rstcb.iowaittime, rstcb.upf_niowaits, net_read_cnt, net_read_bytes, net_write_cnt, net_write_bytes, net_open_time, net_last_read, net_last_write, wreason FROM sysmaster:sysrstcb rstcb, sysmaster:sysscblst scb, sysmaster:sysnetworkio net, sysmaster:systcblst tcb where rstcb.sid = scb.sid and scb.netscb = net.net_netscb and tcb.tid = rstcb.tid",
  446. NULL,
  447. NULL,
  448. INTERVAL ( 4 ) HOUR TO HOUR,
  449. INTERVAL ( 7 ) DAY TO DAY
  450. );
  451. {**************************************************************************
  452. Tasks and functions to register database extensions on-first-use
  453. **************************************************************************}
  454. create table informix.autoreg_migrate (
  455. kind varchar(20),
  456. name varchar(130)
  457. );
  458. insert into autoreg_migrate
  459. values ('serverversion', dbinfo('version','full'));
  460. INSERT INTO ph_task
  461. (
  462. tk_name,
  463. tk_type,
  464. tk_group,
  465. tk_description,
  466. tk_execute,
  467. tk_start_time,
  468. tk_stop_time,
  469. tk_delete,
  470. tk_frequency,
  471. tk_dbs,
  472. tk_enable,
  473. tk_attributes
  474. )
  475. VALUES
  476. (
  477. "autoreg exe",
  478. "TASK",
  479. "SERVER",
  480. "Register a database extension on-first-use",
  481. "autoregexe",
  482. NULL,
  483. NULL,
  484. NULL,
  485. NULL,
  486. "sysadmin",
  487. "f",
  488. "0x4004"
  489. );
  490. INSERT INTO ph_task
  491. (
  492. tk_name,
  493. tk_type,
  494. tk_group,
  495. tk_description,
  496. tk_execute,
  497. tk_start_time,
  498. tk_stop_time,
  499. tk_delete,
  500. tk_frequency,
  501. tk_dbs,
  502. tk_enable,
  503. tk_attributes
  504. )
  505. VALUES
  506. (
  507. "autoreg vp",
  508. "TASK",
  509. "SERVER",
  510. "Create a VP on-first-use",
  511. "autoregvp",
  512. NULL,
  513. NULL,
  514. NULL,
  515. NULL,
  516. "sysadmin",
  517. "f",
  518. "0x4004"
  519. );
  520. insert into ph_task
  521. (
  522. tk_name,
  523. tk_dbs,
  524. tk_type,
  525. tk_execute,
  526. tk_delete,
  527. tk_start_time,
  528. tk_stop_time,
  529. tk_frequency,
  530. tk_enable
  531. ) values
  532. (
  533. "autoreg migrate-console",
  534. "sysadmin",
  535. "STARTUP TASK",
  536. "
  537. INSERT INTO ph_task
  538. (
  539. tk_name,
  540. tk_dbs,
  541. tk_type,
  542. tk_execute,
  543. tk_delete,
  544. tk_start_time,
  545. tk_stop_time,
  546. tk_frequency
  547. )
  548. SELECT
  549. ""autoreg migrate ""||partnum,
  550. name,
  551. ""STARTUP TASK"",
  552. ""EXECUTE FUNCTION SYSBldPrepare('any','migrate');"",
  553. NULL::DATETIME YEAR TO SECOND,
  554. CURRENT::DATETIME YEAR TO SECOND,
  555. NULL::DATETIME YEAR TO SECOND,
  556. NULL::DATETIME YEAR TO SECOND
  557. FROM sysmaster:sysdatabases a
  558. WHERE
  559. (is_logging = 1 OR is_buff_log = 1) AND
  560. name NOT LIKE 'sys%' AND
  561. 0 = ( SELECT count(*) FROM ph_task
  562. WHERE tk_name like 'autoreg migrate %' AND tk_dbs = a.name );
  563. ",
  564. NULL::DATETIME YEAR TO SECOND,
  565. CURRENT::DATETIME YEAR TO SECOND,
  566. NULL::DATETIME YEAR TO SECOND,
  567. NULL::DATETIME YEAR TO SECOND,
  568. 'f'
  569. );
  570. insert into ph_task (
  571. tk_name,tk_type,tk_group,
  572. tk_description,
  573. tk_execute,
  574. tk_start_time,tk_stop_time,tk_delete,tk_frequency,tk_dbs,
  575. tk_enable,tk_priority) VALUES (
  576. 'autoreg reset migrate','STARTUP TASK','SERVER',
  577. 'Reset for 12.10.xC4* and *C5',
  578. 'update ph_task set tk_enable = "t"
  579. where tk_name like "autoreg migrate%"
  580. and dbinfo("version", "major") = 12
  581. and dbinfo("version", "minor") = 10
  582. and (substr(dbinfo("version","level"), 2,1) = 4 or
  583. substr(dbinfo("version","level"), 2,1) = 5);',
  584. NULL,NULL,NULL,NULL,'sysadmin','t',4);
  585. {**************************************************************************
  586. HEALTH CHECKS
  587. **************************************************************************}
  588. {**************************************************************************
  589. Check to make sure backups have been taken
  590. **************************************************************************}
  591. INSERT INTO ph_threshold(id,name,task_name,value,description)
  592. VALUES
  593. (0,"REQUIRED LEVEL BACKUP", "check_backup","2",
  594. "Maximum number of days between backups of any level.");
  595. INSERT INTO ph_threshold(id,name,task_name,value,description)
  596. VALUES
  597. (0,"REQUIRED LEVEL 0 BACKUP", "check_backup","2",
  598. "Maximum number of days between level 0 backups.");
  599. CREATE FUNCTION informix.check_backup(task_id INT, task_seq INT) RETURNING INTEGER
  600. DEFINE dbspace_num INTEGER;
  601. DEFINE dbspace_name CHAR(257);
  602. DEFINE req_level INTEGER;
  603. DEFINE req_level0 INTEGER;
  604. DEFINE level_0 INTEGER;
  605. DEFINE level_1 INTEGER;
  606. DEFINE level_2 INTEGER;
  607. DEFINE arcdist INTERVAL DAY(5) TO SECOND;
  608. {*** Select the configuration values ***}
  609. select value::integer INTO req_level FROM ph_threshold where name
  610. = "REQUIREDLEVEL BACKUP";
  611. select value::integer INTO req_level0 FROM ph_threshold where name
  612. = "REQUIRED LEVEL 0 BACKUP";
  613. {*** If not found or are bad values then set better values ***}
  614. IF req_level < 1 THEN
  615. LET req_level = 1;
  616. END IF
  617. IF req_level0 < 1 THEN
  618. LET req_level0 = 1;
  619. END IF
  620. {*** Check each dbspaces backup time ***}
  621. FOREACH SELECT dbsnum, name, level0, level1, level2
  622. INTO dbspace_num, dbspace_name, level_0, level_1, level_2
  623. FROM sysmaster:sysdbstab
  624. WHERE dbsnum > 0
  625. AND sysmaster:bitval(flags, '0x2000')=0
  626. AND
  627. ( ((CURRENT - DBINFO("utc_to_datetime",level0) > req_level units day ) AND
  628. (CURRENT - DBINFO("utc_to_datetime",level1) > req_level units day ) AND
  629. (CURRENT - DBINFO("utc_to_datetime",level2) > req_level units day ) )
  630. OR
  631. (CURRENT - DBINFO("utc_to_datetime",level0) > req_level0 units day ) )
  632. {*** Check the dbspaces backup for a level 0 backup ***}
  633. IF level_0 == 0 THEN
  634. INSERT INTO ph_alert
  635. (ID, alert_task_id,alert_task_seq,alert_type,
  636. alert_color, alert_object_type,
  637. alert_object_name, alert_message,alert_action)
  638. VALUES
  639. (0,task_id, task_seq, "WARNING", "red", "SERVER",dbspace_name,
  640. "Dbspace ["||trim(dbspace_name)|| "] has never had a level 0 backup.
  641. Recommend taking a level 0 backup immediately."
  642. ,
  643. NULL
  644. );
  645. ELIF CURRENT-DBINFO("utc_to_datetime",level_0) > req_level0 units day THEN
  646. LET arcdist = CURRENT - DBINFO("utc_to_datetime",level_0);
  647. INSERT INTO ph_alert
  648. (ID, alert_task_id,alert_task_seq,alert_type,
  649. alert_color, alert_object_type,
  650. alert_object_name, alert_message,alert_action)
  651. VALUES
  652. (0,task_id, task_seq, "WARNING", "red", "SERVER",dbspace_name,
  653. "Dbspace ["||trim(dbspace_name)|| "] has not had a level 0 backup for "
  654. || arcdist|| ".
  655. Recommend taking a level 0 backup immediately."
  656. ,
  657. NULL
  658. );
  659. CONTINUE FOREACH;
  660. END IF
  661. IF level_0 > level_1 THEN
  662. LET arcdist = CURRENT - DBINFO("utc_to_datetime",level_0);
  663. ELIF level_1 > level_2 THEN
  664. LET arcdist = CURRENT - DBINFO("utc_to_datetime",level_1);
  665. ELSE
  666. LET arcdist = CURRENT - DBINFO("utc_to_datetime",level_2);
  667. END IF
  668. INSERT INTO ph_alert
  669. (ID, alert_task_id,alert_task_seq,alert_type, alert_color, alert_object_type,
  670. alert_object_name, alert_message,alert_action)
  671. VALUES
  672. (0,task_id,task_seq, "WARNING", "red", "SERVER",dbspace_name,
  673. "Dbspace ["||trim(dbspace_name)|| "] has not had a backup for "
  674. || arcdist||".
  675. Recommend taking a backup immediately."
  676. ,
  677. NULL
  678. );
  679. END FOREACH
  680. RETURN 0;
  681. END FUNCTION;
  682. INSERT INTO ph_task
  683. (
  684. tk_name,
  685. tk_type,
  686. tk_group,
  687. tk_description,
  688. tk_execute,
  689. tk_start_time,
  690. tk_stop_time,
  691. tk_frequency
  692. )
  693. VALUES
  694. (
  695. "check_backup",
  696. "TASK",
  697. "BACKUP",
  698. "Checks to ensure a backup has been taken of the data server.",
  699. "check_backup",
  700. DATETIME(05:00:00) HOUR TO SECOND,
  701. NULL,
  702. INTERVAL ( 1 ) DAY TO DAY
  703. );
  704. {**************************************************************************
  705. HA/MACH11 LOG REPLAY POSITION MONITOR
  706. **************************************************************************}
  707. --DROP PROCEDURE "informix".ifx_ha_monitor_log_replay ( INTEGER, INTEGER );
  708. CREATE PROCEDURE "informix".ifx_ha_monitor_log_replay ( v_taskid INTEGER,
  709. v_seqnum INTEGER )
  710. DEFINE v_rss_servername VARCHAR(128);
  711. DEFINE v_state CHAR(1);
  712. DEFINE v_replay_loguniq INTEGER;
  713. DEFINE v_replay_logpage INTEGER;
  714. DEFINE v_capacity LIKE sysmaster:syslogs.size;
  715. DEFINE v_distance LIKE sysmaster:syslogs.size;
  716. DEFINE v_result INTEGER;
  717. /*
  718. * We give up easily.
  719. */
  720. ON EXCEPTION
  721. RETURN;
  722. END EXCEPTION;
  723. SET LOCK MODE TO WAIT 5;
  724. /*
  725. * Get the logical log capacity. It's not very likely
  726. * to change while we iterate over the HA secondaries.
  727. */
  728. SELECT SUM ( size )
  729. INTO v_capacity
  730. FROM sysmaster:syslogs
  731. WHERE is_pre_dropped = 0
  732. AND is_new = 0
  733. AND is_temp = 0;
  734. /*
  735. * Iterate over the HA secondaries,
  736. * and retrieve their replay positions
  737. */
  738. FOREACH SELECT rss_servername
  739. , state
  740. , replay_loguniq
  741. , replay_logpage
  742. INTO v_rss_servername
  743. , v_state
  744. , v_replay_loguniq
  745. , v_replay_logpage
  746. FROM sysha:rss_tab
  747. IF (v_state != 'C' )
  748. THEN
  749. CONTINUE FOREACH;
  750. END IF
  751. /*
  752. * Calculate the distance between the
  753. * clone's replay and source's current position
  754. */
  755. SELECT NVL ( SUM ( size ), 0 ) + v_replay_logpage
  756. INTO v_distance
  757. FROM sysmaster:syslogs
  758. WHERE uniqid < v_replay_loguniq
  759. AND is_pre_dropped = 0
  760. AND is_new = 0
  761. AND is_temp = 0;
  762. /*
  763. * Is this clone's replay position in danger
  764. * of being overtaken by the source's current
  765. * log position ?
  766. * If so, invoke the alarm function.
  767. */
  768. IF ( ( ( v_distance / v_capacity ) * 100 ) < 25 )
  769. THEN
  770. CALL ifx_ha_fire_logwrap_alarm ( v_rss_servername )
  771. RETURNING v_result;
  772. END IF
  773. END FOREACH
  774. END PROCEDURE;
  775. /******************************************************************************/
  776. /* */
  777. /* */
  778. /* */
  779. /******************************************************************************/
  780. INSERT INTO ph_task
  781. (
  782. tk_name,
  783. tk_type,
  784. tk_group,
  785. tk_description,
  786. tk_execute,
  787. tk_start_time,
  788. tk_stop_time,
  789. tk_frequency,
  790. tk_next_execution
  791. )
  792. VALUES
  793. (
  794. "ifx_ha_monitor_log_replay_task",
  795. "TASK",
  796. "SERVER",
  797. "Monitors HA secondary log replay position",
  798. "ifx_ha_monitor_log_replay",
  799. NULL,
  800. NULL,
  801. NULL,
  802. NULL
  803. );
  804. /*
  805. **************************************************************
  806. * Create a task which will cleanup the alert table.
  807. **************************************************************
  808. */
  809. DELETE from ph_threshold WHERE name = "ALERT HISTORY RETENTION";
  810. INSERT INTO ph_threshold
  811. (name,task_name,value,value_type,description)
  812. VALUES
  813. ("ALERT HISTORY RETENTION", "Alert Cleanup","15 0:00:00","NUMERIC",
  814. "Remove all alerts that are older than then the threshold.");
  815. MERGE
  816. INTO ph_threshold AS t
  817. USING ( SELECT
  818. "ALERT HISTORY MAX ROWS", "Alert Cleanup","100000","NUMERIC",
  819. "Stop cleaning the ph_alert and ph_run tables after exceeding the cleanup threshold."
  820. FROM sysmaster:sysdual)
  821. AS s(name,task_name,value,value_type,description)
  822. ON t.name = s.name
  823. WHEN MATCHED THEN UPDATE
  824. SET (t.value_type, t.description) = (s.value_type,s.description )
  825. WHEN NOT MATCHED THEN INSERT
  826. (t.name,t.task_name,t.value,t.value_type,t.description)
  827. VALUES
  828. (s.name,s.task_name,s.value,s.value_type,s.description);
  829. CREATE FUNCTION informix.AlertCleanup(task_id INTEGER, seq_id INTEGER)
  830. RETURNING INTEGER
  831. DEFINE cur_run_id LIKE ph_run.run_id;
  832. DEFINE cur_id LIKE ph_alert.id;
  833. DEFINE count INTEGER;
  834. DEFINE duration DATETIME YEAR TO SECOND;
  835. DEFINE max_rows INTEGER;
  836. LET count =0;
  837. LET duration = (
  838. SELECT CURRENT - MAX(value)::INTERVAL DAY to SECOND
  839. FROM ph_threshold
  840. WHERE name = 'ALERT HISTORY RETENTION' );
  841. LET max_rows = (
  842. SELECT MAX(value)::INTEGER
  843. FROM ph_threshold
  844. WHERE name = 'ALERT HISTORY MAX ROWS' );
  845. IF max_rows IS NULL OR max_rows < 100 THEN
  846. LET max_rows = 100;
  847. END IF
  848. FOREACH SELECT id, run_id
  849. INTO cur_id, cur_run_id
  850. FROM ph_alert, OUTER ph_run
  851. WHERE ph_alert.alert_task_id = ph_run.run_task_id
  852. AND ph_alert.alert_task_seq = ph_run.run_task_seq
  853. AND alert_time < duration
  854. ORDER BY id, run_id
  855. IF cur_id > 0 THEN
  856. DELETE FROM ph_run WHERE run_id < cur_run_id AND run_task_id = cur_id;
  857. ELSE
  858. DELETE FROM ph_run where run_id = cur_run_id;
  859. END IF
  860. LET count = count + DBINFO('sqlca.sqlerrd2');
  861. DELETE FROM ph_alert where id = cur_id;
  862. LET count = count + 1;
  863. IF count > max_rows THEN
  864. EXIT FOREACH;
  865. END IF
  866. END FOREACH
  867. RETURN count;
  868. END FUNCTION;
  869. DELETE from ph_task WHERE tk_name = "Alert Cleanup";
  870. INSERT INTO ph_task
  871. (
  872. tk_name,
  873. tk_type,
  874. tk_group,
  875. tk_description,
  876. tk_execute,
  877. tk_start_time,
  878. tk_stop_time,
  879. tk_frequency
  880. )
  881. VALUES
  882. (
  883. "Alert Cleanup",
  884. "TASK",
  885. "SERVER",
  886. "Remove all old alert entries from the system.",
  887. "AlertCleanup",
  888. DATETIME(02:00:00) HOUR TO SECOND,
  889. NULL,
  890. INTERVAL ( 1 ) DAY TO DAY
  891. );
  892. DELETE FROM ph_task WHERE tk_name="post_alarm_message";
  893. INSERT INTO ph_task
  894. (
  895. tk_name,
  896. tk_type,
  897. tk_group,
  898. tk_description,
  899. tk_execute,
  900. tk_start_time,
  901. tk_stop_time,
  902. tk_frequency,
  903. tk_next_execution,
  904. tk_attributes
  905. )
  906. VALUES
  907. (
  908. "post_alarm_message",
  909. "TASK",
  910. "SERVER",
  911. "System function to post alerts",
  912. "ph_dbs_alert",
  913. NULL,
  914. NULL,
  915. NULL,
  916. NULL,
  917. "0x4000"
  918. );
  919. DELETE FROM ph_task WHERE tk_name="Job Runner";
  920. INSERT INTO ph_task
  921. (
  922. tk_name,
  923. tk_type,
  924. tk_group,
  925. tk_description,
  926. tk_execute,
  927. tk_start_time,
  928. tk_stop_time,
  929. tk_delete,
  930. tk_frequency,
  931. tk_next_execution,
  932. tk_attributes,
  933. tk_enable
  934. )
  935. VALUES
  936. (
  937. "Job Runner",
  938. "TASK",
  939. "SERVER",
  940. "Run server tasks in background with a private dbWorker thread.",
  941. "run_job",
  942. NULL,
  943. NULL,
  944. INTERVAL ( 30 ) DAY TO DAY,
  945. NULL,
  946. NULL,
  947. 8,
  948. 'f'
  949. );
  950. /*
  951. **************************************************************
  952. * Create a task to cleanup the ph_bg_jobs_results table.
  953. **************************************************************
  954. */
  955. DELETE from ph_threshold WHERE name = "JOB RUNNER HISTORY RETENTION";
  956. INSERT INTO ph_threshold (
  957. name,
  958. task_name,
  959. value,
  960. value_type,
  961. description)
  962. VALUES (
  963. "JOB RUNNER HISTORY RETENTION",
  964. "Job Results Cleanup",
  965. "30 0:00:00",
  966. "NUMERIC",
  967. "Remove all job results that are older than then the threshold.");
  968. DELETE from ph_task WHERE tk_name = "Job Results Cleanup";
  969. INSERT INTO ph_task
  970. (
  971. tk_name,
  972. tk_type,
  973. tk_group,
  974. tk_description,
  975. tk_execute,
  976. tk_start_time,
  977. tk_stop_time,
  978. tk_frequency,
  979. tk_delete,
  980. tk_enable
  981. )
  982. VALUES
  983. (
  984. "Job Results Cleanup",
  985. "TASK",
  986. "TABLES",
  987. "Remove all old job results entries from the system.",
  988. "DELETE FROM ph_bg_jobs_results WHERE ph_bgr_starttime < (
  989. SELECT CURRENT - value::INTERVAL DAY TO SECOND
  990. FROM ph_threshold
  991. WHERE name = 'JOB RUNNER HISTORY RETENTION') ",
  992. DATETIME(03:00:00) HOUR TO SECOND,
  993. NULL,
  994. INTERVAL ( 1 ) DAY TO DAY,
  995. INTERVAL ( 30 ) DAY TO DAY,
  996. 't'
  997. );
  998. /* IDLE USERS TIMEOUT */
  999. DELETE FROM ph_threshold WHERE name = "IDLE TIMEOUT";
  1000. {*** CREATE THE THRESHOLD : Default = 60 minutes ***}
  1001. INSERT INTO ph_threshold(name,task_name,value,value_type,description)
  1002. VALUES("IDLE TIMEOUT", "idle_user_timeout","60","NUMERIC","Maximum amount of time in minutes for non-informix users to be idle.");
  1003. DELETE FROM ph_task WHERE tk_name = "idle_user_timeout";
  1004. {*** CREATE THE task
  1005. by default the task will not be enabled
  1006. and is scheduled for every 2 hours ***}
  1007. INSERT INTO ph_task
  1008. (
  1009. tk_name,
  1010. tk_type,
  1011. tk_group,
  1012. tk_description,
  1013. tk_execute,
  1014. tk_next_execution,
  1015. tk_start_time,
  1016. tk_stop_time,
  1017. tk_frequency,
  1018. tk_delete,
  1019. tk_enable
  1020. )
  1021. VALUES
  1022. (
  1023. "idle_user_timeout",
  1024. "TASK",
  1025. "SERVER",
  1026. "Terminate idle users",
  1027. "idle_user_timeout",
  1028. NULL,
  1029. NULL,
  1030. NULL,
  1031. INTERVAL ( 2 ) HOUR TO HOUR,
  1032. INTERVAL ( 30 ) DAY TO DAY,
  1033. 'f'
  1034. );
  1035. --DROP FUNCTION idle_user_timeout( INTEGER , INTEGER );
  1036. {*** CREATE the function that will be run by the task ***}
  1037. CREATE FUNCTION informix.idle_user_timeout( task_id INTEGER, task_seq INTEGER)
  1038. RETURNING INTEGER
  1039. DEFINE time_allowed INTEGER;
  1040. DEFINE sys_hostname CHAR(256);
  1041. DEFINE sys_username CHAR(32);
  1042. DEFINE sys_sid INTEGER;
  1043. DEFINE rc INTEGER;
  1044. {*** Get the maximum amount of time to be idle ***}
  1045. SELECT value::integer INTO time_allowed FROM ph_threshold
  1046. WHERE name = "IDLE TIMEOUT";
  1047. {*** Check the value for IDLE TIMEOUT is reasonable , ie: >= 5 minutes ***}
  1048. IF time_allowed < 5 THEN
  1049. INSERT INTO ph_alert ( ID, alert_task_id,alert_task_seq, alert_type, alert_color, alert_state,
  1050. alert_object_type, alert_object_name,
  1051. alert_message, alert_action )
  1052. VALUES
  1053. ( 0,task_id, task_seq, "WARNING", "GREEN", "ADDRESSED", "USER",
  1054. "TIMEOUT", "Invalid IDLE TIMEOUT value("||time_allowed||"). Needs to be greater than 4", NULL );
  1055. RETURN -1;
  1056. END IF
  1057. {*** Find all users who have been idle longer than the threshold and try to
  1058. terminate the session. ***}
  1059. FOREACH
  1060. SELECT admin("onmode","z",A.sid), A.username, A.sid, hostname
  1061. INTO rc, sys_username, sys_sid, sys_hostname
  1062. FROM sysmaster:sysrstcb A , sysmaster:systcblst B
  1063. , sysmaster:sysscblst C
  1064. WHERE A.tid = B.tid
  1065. AND C.sid = A.sid
  1066. AND LOWER(name) IN ("sqlexec")
  1067. AND CURRENT - DBINFO("utc_to_datetime",last_run_time) > time_allowed UNITS MINUTE
  1068. AND LOWER(A.username) NOT IN( "informix", "root")
  1069. {*** If we sucessfully terminated a user log ***}
  1070. {*** the information into the alert table ***}
  1071. IF rc > 0 THEN
  1072. INSERT INTO ph_alert ( ID, alert_task_id,alert_task_seq, alert_type, alert_color, alert_state,
  1073. alert_object_type, alert_object_name,
  1074. alert_message, alert_action )
  1075. VALUES
  1076. ( 0,task_id, task_seq, "INFO", "GREEN", "ADDRESSED", "USER",
  1077. "TIMEOUT", "User "||TRIM(sys_username)||"@"||TRIM(sys_hostname)||" sid("||sys_sid||")"||" terminated due to idle timeout.", NULL );
  1078. END IF
  1079. END FOREACH;
  1080. RETURN 0;
  1081. END FUNCTION;
  1082. { ***** CREATE THE bad_index_alert task ***** }
  1083. DELETE FROM ph_task WHERE tk_name = "bad_index_alert";
  1084. INSERT INTO ph_task
  1085. (
  1086. tk_name,
  1087. tk_type,
  1088. tk_group,
  1089. tk_description,
  1090. tk_execute,
  1091. tk_next_execution,
  1092. tk_start_time,
  1093. tk_stop_time,
  1094. tk_frequency,
  1095. tk_delete,
  1096. tk_enable
  1097. )
  1098. VALUES
  1099. (
  1100. "bad_index_alert",
  1101. "TASK",
  1102. "SERVER",
  1103. "Find indices marked as bad and create alert",
  1104. "bad_index_alert",
  1105. NULL,
  1106. DATETIME(04:00:00) HOUR TO SECOND,
  1107. NULL,
  1108. INTERVAL ( 1 ) DAY TO DAY,
  1109. INTERVAL ( 30 ) DAY TO DAY,
  1110. 'f'
  1111. );
  1112. {*** CREATE the function that will be run by the task ***}
  1113. --DROP FUNCTION bad_index_alert( int , int );
  1114. CREATE FUNCTION informix.bad_index_alert ( task_id INTEGER, task_seq INTEGER)
  1115. RETURNING INTEGER
  1116. DEFINE p_partnum INTEGER;
  1117. DEFINE p_fullname CHAR(300);
  1118. DEFINE p_database CHAR(128);
  1119. FOREACH
  1120. SELECT k.partnum
  1121. , dbsname
  1122. , trim(owner)||"."||
  1123. tabname AS fullname
  1124. INTO p_partnum ,p_database , p_fullname
  1125. FROM
  1126. sysmaster:sysptnkey k,sysmaster:systabnames t
  1127. WHERE sysmaster:bitand(flags,"0x00000040") > 0
  1128. and k.partnum = t.partnum
  1129. and dbsname not in ("sysmaster")
  1130. INSERT INTO ph_alert ( ID, alert_task_id ,alert_task_seq ,alert_type ,alert_color
  1131. , alert_object_type ,alert_object_name ,alert_message
  1132. , alert_action_dbs ,alert_action )
  1133. VALUES
  1134. ( 0,task_id, task_seq, "WARNING", "red", "SERVER", p_fullname
  1135. , "Index "||trim(p_database)||":"||trim(p_fullname)||" is marked as bad."
  1136. , p_database ,NULL );
  1137. END FOREACH;
  1138. RETURN 0;
  1139. END FUNCTION;
  1140. {**************************************************************************
  1141. Task to add storage, and task to detect low free space
  1142. **************************************************************************}
  1143. INSERT INTO ph_task
  1144. (
  1145. tk_name,
  1146. tk_type,
  1147. tk_group,
  1148. tk_description,
  1149. tk_execute,
  1150. tk_start_time,
  1151. tk_stop_time,
  1152. tk_delete,
  1153. tk_frequency,
  1154. tk_next_execution,
  1155. tk_attributes
  1156. )
  1157. VALUES
  1158. (
  1159. "add_storage",
  1160. "TASK",
  1161. "DISK",
  1162. "Add storage",
  1163. "adm_add_storage",
  1164. NULL,
  1165. NULL,
  1166. INTERVAL ( 30 ) DAY TO DAY,
  1167. NULL,
  1168. NULL,
  1169. "0x408"
  1170. );
  1171. INSERT INTO ph_task
  1172. (
  1173. tk_name,
  1174. tk_type,
  1175. tk_group,
  1176. tk_description,
  1177. tk_execute,
  1178. tk_start_time,
  1179. tk_stop_time,
  1180. tk_frequency,
  1181. tk_delete
  1182. )
  1183. VALUES
  1184. (
  1185. "mon_low_storage",
  1186. "TASK",
  1187. "DISK",
  1188. "Monitor storage and add space when necessary",
  1189. "mon_low_storage",
  1190. NULL,
  1191. NULL,
  1192. INTERVAL ( 1 ) HOUR TO HOUR,
  1193. INTERVAL ( 30 ) DAY TO DAY
  1194. );
  1195. {**************************************************************************
  1196. Task to keep track of I/O statistics
  1197. **************************************************************************}
  1198. DELETE FROM ph_threshold WHERE name = "IO_SAMPLES_PER_HOUR";
  1199. INSERT INTO ph_threshold
  1200. (name,task_name,value,value_type,description)
  1201. VALUES
  1202. ("IO_SAMPLES_PER_HOUR", "mon_iohistory","1","NUMERIC",
  1203. "Number of samples per chunk saved on disk every hour. Allowable values are between 1 and 60.");
  1204. INSERT INTO ph_task
  1205. (
  1206. tk_name,
  1207. tk_type,
  1208. tk_group,
  1209. tk_description,
  1210. tk_result_table,
  1211. tk_create,
  1212. tk_execute,
  1213. tk_start_time,
  1214. tk_stop_time,
  1215. tk_delete,
  1216. tk_frequency,
  1217. tk_next_execution
  1218. )
  1219. VALUES
  1220. (
  1221. "mon_iohistory",
  1222. "SENSOR",
  1223. "PERFORMANCE",
  1224. "Collect performance information about chunk I/O.",
  1225. "mon_iohistory",
  1226. "create table informix.mon_iohist (ID integer, gfd smallint, time integer, read_ops_minute integer, read_time_minute smallfloat, write_ops_minute integer, write_time_minute smallfloat); create view informix.mon_iohistory (id,gfd,time,read_ops_minute,read_time_minute,avg_read_time, write_ops_minute, write_time_minute, avg_write_time ) as SELECT id, gfd, DBINFO('utc_to_datetime',time) as time, read_ops_minute,read_time_minute::decimal(12,6), decode(read_time_minute,0,0, read_time_minute/read_ops_minute)::decimal(12,6) , write_ops_minute, write_time_minute::decimal(12,6), decode(write_time_minute,0,0, write_time_minute/write_ops_minute)::decimal(12,6) from mon_iohist; grant select on mon_iohistory TO 'db_monitor' as informix;grant select on mon_iohist TO 'db_monitor' as informix;",
  1227. "INSERT INTO informix.mon_iohist(ID,gfd,time, read_ops_minute, read_time_minute, write_ops_minute, write_time_minute) SELECT $DATA_SEQ_ID,gfd,time,read_ops_minute,read_time_minute, write_ops_minute, write_time_minute FROM sysmaster:sysiohistory WHERE time > ( select NVL(max(run_mttime),0) from ph_task , outer ph_run where tk_name='mon_iohistory' and tk_id = run_task_id) AND MOD(minute, 60/NVL((select value FROM ph_threshold WHERE name = 'IO_SAMPLES_PER_HOUR'),'1')::char(4)::integer)=0",
  1228. NULL,
  1229. NULL,
  1230. INTERVAL ( 30 ) DAY TO DAY,
  1231. INTERVAL ( 58 ) MINUTE TO MINUTE,
  1232. DATETIME(01:00:00) HOUR TO SECOND
  1233. );
  1234. {**************************************************************************
  1235. Auto compress task
  1236. ****************************************************************************}
  1237. INSERT INTO ph_task
  1238. (
  1239. tk_name,
  1240. tk_type,
  1241. tk_group,
  1242. tk_description,
  1243. tk_execute,
  1244. tk_start_time,
  1245. tk_stop_time,
  1246. tk_delete,
  1247. tk_frequency,
  1248. tk_next_execution,
  1249. tk_attributes,
  1250. tk_enable
  1251. )
  1252. VALUES
  1253. (
  1254. "auto_compress",
  1255. "TASK",
  1256. "SERVER",
  1257. "Auto compress",
  1258. "adm_auto_compress",
  1259. NULL,
  1260. NULL,
  1261. INTERVAL ( 30 ) DAY TO DAY,
  1262. NULL,
  1263. NULL,
  1264. "0x4008",
  1265. 'f'
  1266. );
  1267. /* AUTO TUNE CPU VPS */
  1268. INSERT INTO ph_task
  1269. (
  1270. tk_name,
  1271. tk_type,
  1272. tk_group,
  1273. tk_description,
  1274. tk_execute,
  1275. tk_start_time,
  1276. tk_stop_time,
  1277. tk_frequency,
  1278. tk_next_execution,
  1279. tk_delete,
  1280. tk_enable
  1281. )
  1282. VALUES
  1283. (
  1284. "auto_tune_cpu_vps",
  1285. "STARTUP TASK",
  1286. "SERVER",
  1287. "Automatically allocate additional cpu vps at system start.",
  1288. "auto_tune_cpu_vps",
  1289. NULL,
  1290. NULL,
  1291. NULL,
  1292. NULL,
  1293. INTERVAL ( 30 ) DAY TO DAY,
  1294. 'f'
  1295. );
  1296. {*** CREATE the function that will be run by the task auto_tune_cpu_vps ***}
  1297. {*** The number of desired cpu vps is limited to 8 *** }
  1298. {*** if the os has 3 or more cpus then we use 50% *** }
  1299. {*** if the os has 3 then we use 2 *** }
  1300. {*** if the os has < 3 we use 1 *** }
  1301. CREATE FUNCTION informix.auto_tune_cpu_vps(task_id INTEGER, task_seq INTEGER)
  1302. RETURNING INTEGER
  1303. DEFINE current_cpu_vps INTEGER;
  1304. DEFINE desired_cpu_vps INTEGER;
  1305. DEFINE add_cpu_vps INTEGER;
  1306. DEFINE rc INTEGER;
  1307. LET add_cpu_vps = 0;
  1308. {* check the value of SINGLE_CPU_VP , if it is set then
  1309. we cannot add any additional cpu vps so we can return early *}
  1310. SELECT cf_effective INTO add_cpu_vps FROM sysmaster:sysconfig
  1311. WHERE cf_name = "SINGLE_CPU_VP";
  1312. IF add_cpu_vps != 0 THEN
  1313. RETURN 0;
  1314. END IF
  1315. SELECT count(*) INTO current_cpu_vps
  1316. FROM sysmaster:sysvplst
  1317. WHERE classname="cpu";
  1318. SELECT CASE
  1319. WHEN os_num_procs > 16 THEN
  1320. 8
  1321. WHEN os_num_procs > 3 THEN
  1322. os_num_procs/2
  1323. WHEN os_num_procs = 3 THEN
  1324. 2
  1325. ELSE
  1326. 1
  1327. END::INTEGER
  1328. INTO desired_cpu_vps
  1329. FROM sysmaster:sysmachineinfo;
  1330. LET add_cpu_vps = desired_cpu_vps - current_cpu_vps;
  1331. IF add_cpu_vps > 0 THEN
  1332. INSERT INTO ph_alert
  1333. (ID, alert_task_id,alert_task_seq,alert_type,
  1334. alert_color, alert_object_type,
  1335. alert_object_name, alert_message,alert_action)
  1336. VALUES
  1337. (0,task_id, task_seq, "INFO", "YELLOW",
  1338. "SERVER","CPU VPS",
  1339. "Dynamically adding "||add_cpu_vps|| " cpu vp(s)." ,
  1340. NULL);
  1341. LET rc = admin( "onmode", "p",add_cpu_vps,"cpu");
  1342. ELSE
  1343. LET rc = 0;
  1344. END IF
  1345. RETURN rc;
  1346. END FUNCTION;
  1347. {*** Automatically find and address compress, repack, ***
  1348. *** shrink, defragment candiates ***}
  1349. DELETE FROM ph_threshold WHERE name IN (
  1350. "AUTOCOMPRESS_ENABLED", "AUTOCOMPRESS_ROWS"
  1351. , "AUTOREPACK_ENABLED", "AUTOREPACK_SPACE"
  1352. , "AUTOSHRINK_ENABLED", "AUTOSHRINK_UNUSED"
  1353. , "AUTODEFRAG_ENABLED", "AUTODEFRAG_EXTENTS"
  1354. );
  1355. {*** CREATE THE auto_crsd THRESHOLDS ***}
  1356. {********** compress parameters ****************}
  1357. MERGE
  1358. INTO ph_threshold AS t
  1359. USING ( SELECT
  1360. "AUTOCOMPRESS_ENABLED", "auto_crsd","F","STRING",
  1361. "Auto Compression of tables/fragments is enabled."
  1362. FROM sysmaster:sysdual)
  1363. AS s(name,task_name,value,value_type,description)
  1364. ON t.name = s.name
  1365. WHEN MATCHED THEN UPDATE
  1366. SET (t.value_type, t.description) = (s.value_type,s.description )
  1367. WHEN NOT MATCHED THEN INSERT
  1368. (t.name,t.task_name,t.value,t.value_type,t.description)
  1369. VALUES
  1370. (s.name,s.task_name,s.value,s.value_type,s.description);
  1371. MERGE
  1372. INTO ph_threshold AS t
  1373. USING ( SELECT
  1374. "AUTOCOMPRESS_ROWS", "auto_crsd","50000","NUMERIC",
  1375. "Number of rows required in the table/fragment."
  1376. FROM sysmaster:sysdual)
  1377. AS s(name,task_name,value,value_type,description)
  1378. ON t.name = s.name
  1379. WHEN MATCHED THEN UPDATE
  1380. SET (t.value_type, t.description) = (s.value_type,s.description )
  1381. WHEN NOT MATCHED THEN INSERT
  1382. (t.name,t.task_name,t.value,t.value_type,t.description)
  1383. VALUES
  1384. (s.name,s.task_name,s.value,s.value_type,s.description);
  1385. {********** repack parameters ****************}
  1386. MERGE
  1387. INTO ph_threshold AS t
  1388. USING ( SELECT
  1389. "AUTOREPACK_ENABLED", "auto_crsd","F","STRING",
  1390. "Auto Repack of tables is enabled."
  1391. FROM sysmaster:sysdual)
  1392. AS s(name,task_name,value,value_type,description)
  1393. ON t.name = s.name
  1394. WHEN MATCHED THEN UPDATE
  1395. SET (t.value_type, t.description) = (s.value_type,s.description )
  1396. WHEN NOT MATCHED THEN INSERT
  1397. (t.name,t.task_name,t.value,t.value_type,t.description)
  1398. VALUES
  1399. (s.name,s.task_name,s.value,s.value_type,s.description);
  1400. MERGE
  1401. INTO ph_threshold AS t
  1402. USING ( SELECT
  1403. "AUTOREPACK_SPACE", "auto_crsd","50","NUMERIC",
  1404. "The percentage of space free before a repack is run."
  1405. FROM sysmaster:sysdual)
  1406. AS s(name,task_name,value,value_type,description)
  1407. ON t.name = s.name
  1408. WHEN MATCHED THEN UPDATE
  1409. SET (t.value_type, t.description) = (s.value_type,s.description )
  1410. WHEN NOT MATCHED THEN INSERT
  1411. (t.name,t.task_name,t.value,t.value_type,t.description)
  1412. VALUES
  1413. (s.name,s.task_name,s.value,s.value_type,s.description);
  1414. {********** shrink parameters ****************}
  1415. MERGE
  1416. INTO ph_threshold AS t
  1417. USING ( SELECT
  1418. "AUTOSHRINK_ENABLED", "auto_crsd","F","STRING",
  1419. "Auto Shrink of tables is enabled."
  1420. FROM sysmaster:sysdual)
  1421. AS s(name,task_name,value,value_type,description)
  1422. ON t.name = s.name
  1423. WHEN MATCHED THEN UPDATE
  1424. SET (t.value_type, t.description) = (s.value_type,s.description )
  1425. WHEN NOT MATCHED THEN INSERT
  1426. (t.name,t.task_name,t.value,t.value_type,t.description)
  1427. VALUES
  1428. (s.name,s.task_name,s.value,s.value_type,s.description);
  1429. MERGE
  1430. INTO ph_threshold AS t
  1431. USING ( SELECT
  1432. "AUTOSHRINK_UNUSED", "auto_crsd","50","NUMERIC",
  1433. "Percentage of unused space."
  1434. FROM sysmaster:sysdual)
  1435. AS s(name,task_name,value,value_type,description)
  1436. ON t.name = s.name
  1437. WHEN MATCHED THEN UPDATE
  1438. SET (t.value_type, t.description) = (s.value_type,s.description )
  1439. WHEN NOT MATCHED THEN INSERT
  1440. (t.name,t.task_name,t.value,t.value_type,t.description)
  1441. VALUES
  1442. (s.name,s.task_name,s.value,s.value_type,s.description);
  1443. {********* defrag parameters ********}
  1444. MERGE
  1445. INTO ph_threshold AS t
  1446. USING ( SELECT
  1447. "AUTODEFRAG_ENABLED", "auto_crsd","F","STRING",
  1448. "Auto Defrag of tables is enabled."
  1449. FROM sysmaster:sysdual)
  1450. AS s(name,task_name,value,value_type,description)
  1451. ON t.name = s.name
  1452. WHEN MATCHED THEN UPDATE
  1453. SET (t.value_type, t.description) = (s.value_type,s.description )
  1454. WHEN NOT MATCHED THEN INSERT
  1455. (t.name,t.task_name,t.value,t.value_type,t.description)
  1456. VALUES
  1457. (s.name,s.task_name,s.value,s.value_type,s.description);
  1458. MERGE
  1459. INTO ph_threshold AS t
  1460. USING ( SELECT
  1461. "AUTODEFRAG_EXTENTS", "auto_crsd","100","NUMERIC","Number of extents."
  1462. FROM sysmaster:sysdual)
  1463. AS s(name,task_name,value,value_type,description)
  1464. ON t.name = s.name
  1465. WHEN MATCHED THEN UPDATE
  1466. SET (t.value_type, t.description) = (s.value_type,s.description )
  1467. WHEN NOT MATCHED THEN INSERT
  1468. (t.name,t.task_name,t.value,t.value_type,t.description)
  1469. VALUES
  1470. (s.name,s.task_name,s.value,s.value_type,s.description);
  1471. {********** outstanding in-place alter parameters ****************}
  1472. MERGE
  1473. INTO ph_threshold AS t
  1474. USING ( SELECT
  1475. "REMOVE_IPA_ENABLED", "auto_crsd","F","STRING",
  1476. "Outstanding removal of in-place alters."
  1477. FROM sysmaster:sysdual)
  1478. AS s(name,task_name,value,value_type,description)
  1479. ON t.name = s.name
  1480. WHEN MATCHED THEN UPDATE
  1481. SET (t.value_type, t.description) = (s.value_type,s.description )
  1482. WHEN NOT MATCHED THEN INSERT
  1483. (t.name,t.task_name,t.value,t.value_type,t.description)
  1484. VALUES
  1485. (s.name,s.task_name,s.value,s.value_type,s.description);
  1486. UPDATE ph_task SET tk_attributes = BITANDNOT(tk_attributes, 4)
  1487. WHERE tk_name = "auto_crsd";
  1488. DELETE FROM ph_task WHERE tk_name = "auto_crsd";
  1489. {*** CREATE THE task
  1490. by default the task will not be enabled
  1491. and is scheduled for every 7 days at 3:00am
  1492. ***}
  1493. INSERT INTO ph_task
  1494. (
  1495. tk_name,
  1496. tk_type,
  1497. tk_group,
  1498. tk_description,
  1499. tk_execute,
  1500. tk_start_time,
  1501. tk_stop_time,
  1502. tk_next_execution,
  1503. tk_frequency,
  1504. tk_delete,
  1505. tk_enable
  1506. )
  1507. VALUES
  1508. (
  1509. "auto_crsd",
  1510. "TASK",
  1511. "SERVER",
  1512. "Automatic Compress/Repack/Shrink and Defrag",
  1513. "auto_crsd",
  1514. DATETIME(03:00:00) HOUR TO SECOND,
  1515. NULL,
  1516. NULL,
  1517. INTERVAL ( 7 ) DAY TO DAY,
  1518. INTERVAL ( 30 ) DAY TO DAY,
  1519. 'f'
  1520. );
  1521. DROP FUNCTION IF EXISTS auto_crsd( INTEGER , INTEGER );
  1522. CREATE FUNCTION informix.auto_crsd( g_task_id INTEGER, g_task_seq INTEGER)
  1523. RETURNING INTEGER
  1524. DEFINE p_enabled LIKE sysadmin:ph_threshold.value;
  1525. DEFINE p_value INTEGER;
  1526. DEFINE p_fulltabname LVARCHAR(300);
  1527. DEFINE p_dbsname LIKE sysmaster:sysdatabases.name;
  1528. DEFINE p_owner LIKE sysmaster:systabnames.owner;
  1529. DEFINE p_tabname LIKE sysmaster:systabnames.tabname;
  1530. DEFINE p_partnum LIKE sysmaster:systabnames.partnum;
  1531. DEFINE p_beforedatacnt LIKE sysmaster:sysptnhdr.npdata;
  1532. DEFINE p_beforepagecnt LIKE sysmaster:sysptnhdr.nptotal;
  1533. DEFINE p_afterdatacnt LIKE sysmaster:sysptnhdr.npdata;
  1534. DEFINE p_afterpagecnt LIKE sysmaster:sysptnhdr.nptotal;
  1535. DEFINE p_retcode INTEGER;
  1536. DEFINE p_alerttype LIKE sysadmin:ph_alert.alert_type;
  1537. DEFINE p_alertcolor LIKE sysadmin:ph_alert.alert_color;
  1538. DEFINE p_alerttext LIKE sysadmin:ph_alert.alert_message;
  1539. DEFINE sys_dbs_list SET ( VARCHAR(255) NOT NULL );
  1540. LET sys_dbs_list = SET { "system", "sysmaster", "sysutils", "sysuser","syscdr", "syscdcv1" };
  1541. --SET DEBUG FILE TO "/tmp/compress."||g_task_seq;
  1542. --TRACE ON;
  1543. {*********** Check if AUTOCOMPRESS is enabled ***********}
  1544. LET p_enabled = "F";
  1545. SELECT UPPER(value) INTO p_enabled FROM sysadmin:ph_threshold
  1546. WHERE name = "AUTOCOMPRESS_ENABLED";
  1547. IF ( p_enabled == 'T' ) THEN
  1548. {*** SELECT tables that qualify *** }
  1549. SELECT value::INTEGER INTO p_value FROM sysadmin:ph_threshold
  1550. WHERE name = "AUTOCOMPRESS_ROWS";
  1551. IF p_value IS NOT NULL AND p_value >= 2000 THEN
  1552. FOREACH SELECT TRIM(T.dbsname) , TRIM(T.owner)
  1553. , TRIM(T.tabname) , T.partnum
  1554. , H.npdata, H.nptotal
  1555. INTO p_dbsname , p_owner , p_tabname , p_partnum
  1556. ,p_beforedatacnt , p_beforepagecnt
  1557. FROM sysmaster:sysptnhdr H , sysmaster:systabnames T
  1558. WHERE
  1559. (H.nkeys=0) -- only data partnums
  1560. AND H.nrows > p_value -- qualifying number of rows
  1561. -- do no include system database tables.
  1562. AND dbsname NOT IN sys_dbs_list
  1563. -- do not include partitions that do not
  1564. -- qualify to avoid unnecessary errors
  1565. AND bitand(H.partnum,"0xFFFFF") != 1
  1566. AND bitand(H.flags,'0xA32F6084') ==0
  1567. AND H.partnum = T.partnum
  1568. AND T.tabname NOT IN
  1569. ( SELECT N.tabname FROM systables N where N.tabid < 100 )
  1570. LET p_fulltabname = TRIM(p_dbsname)||":"||TRIM(p_owner)||"."||TRIM(p_tabname);
  1571. EXECUTE FUNCTION admin('fragment compress',p_partnum)
  1572. INTO p_retcode;
  1573. IF p_retcode < 0 THEN
  1574. LET p_alerttype = "ERROR";
  1575. LET p_alertcolor = "RED";
  1576. LET p_alerttext = "Error ["||p_retcode||"] when auto compressing partnum: "||p_partnum||" ["||TRIM(p_fulltabname)||"].";
  1577. ELSE
  1578. SELECT npdata, nptotal
  1579. INTO p_afterdatacnt , p_afterpagecnt
  1580. FROM sysmaster:sysptnhdr H
  1581. WHERE H.partnum = p_partnum;
  1582. LET p_alerttype = "INFO";
  1583. LET p_alertcolor = "GREEN";
  1584. LET p_alerttext = "Automatically compressed table:["||p_partnum||"] ["||TRIM(p_fulltabname)||"] went from "||p_beforedatacnt||"/"||p_beforepagecnt||" data/total pages to "||p_afterdatacnt||"/"||p_afterpagecnt||" data/total pages.";
  1585. END IF
  1586. INSERT INTO ph_alert
  1587. (ID, alert_task_id,alert_task_seq, alert_type, alert_color,
  1588. alert_object_type, alert_object_name,
  1589. alert_message,alert_action)
  1590. VALUES
  1591. (0,g_task_id, g_task_seq, p_alerttype, p_alertcolor,
  1592. "DATABASE",TRIM(p_fulltabname),
  1593. p_alerttext, NULL);
  1594. END FOREACH;
  1595. END IF
  1596. END IF
  1597. {*********** Check if AUTOREPACK is enabled ***********}
  1598. LET p_enabled = "F";
  1599. LET p_retcode = 0;
  1600. SELECT UPPER(value) INTO p_enabled FROM sysadmin:ph_threshold
  1601. WHERE name = "AUTOREPACK_ENABLED";
  1602. IF ( p_enabled == 'T' ) THEN
  1603. {*** SELECT tables that qualify *** }
  1604. SELECT value::INTEGER INTO p_value FROM sysadmin:ph_threshold
  1605. WHERE name = "AUTOREPACK_SPACE";
  1606. IF p_value IS NOT NULL AND p_value > 0 AND p_value < 100 THEN
  1607. FOREACH SELECT TRIM(dbsname) as dbsname, TRIM(owner) as owner
  1608. , TRIM(tabname) as tabname , T.partnum
  1609. INTO p_dbsname , p_owner , p_tabname , p_partnum
  1610. FROM
  1611. (
  1612. SELECT pnum , count(*) f
  1613. FROM
  1614. ( SELECT pe_extnum as extnum
  1615. , pe_size as size
  1616. , pe_partnum as pnum
  1617. , count(*) as free
  1618. FROM sysmaster:sysptnext E, sysmaster:sysptnbit B
  1619. WHERE
  1620. E.pe_partnum = B.PB_partnum
  1621. AND ( bitand(pb_bitmap,12) = 0 or bitand(pb_bitmap,12) = 4 )
  1622. AND E.pe_log <= B.pb_pagenum
  1623. AND B.pb_pagenum < E.pe_log + E.pe_size
  1624. GROUP BY 1,2,3
  1625. ) as Y
  1626. , sysmaster:sysptnhdr as H
  1627. , sysmaster:systabnames as T
  1628. WHERE pnum = H.partnum
  1629. AND T.partnum = H.partnum
  1630. AND (H.nkeys=0) -- only data partnums
  1631. GROUP BY 1
  1632. )
  1633. , sysmaster:sysptnhdr as H
  1634. , sysmaster:systabnames as T
  1635. WHERE
  1636. pnum = T.partnum
  1637. AND T.partnum = H.partnum
  1638. AND nextns > 4
  1639. AND (H.nkeys=0) -- only data partnums
  1640. AND (f/nextns)*100::decimal(10,2) > p_value
  1641. -- do no include system database tables.
  1642. AND dbsname NOT IN sys_dbs_list
  1643. -- do not include partitions that do not
  1644. -- qualify to avoid unnecessary errors
  1645. AND bitand(H.partnum,"0xFFFFF") != 1
  1646. AND bitand(H.flags,'0xA32F6084') ==0
  1647. AND T.tabname NOT IN
  1648. ( SELECT N.tabname FROM systables N where N.tabid < 100 )
  1649. LET p_fulltabname = TRIM(p_dbsname)||":"||TRIM(p_owner)||"."||TRIM(p_tabname);
  1650. EXECUTE FUNCTION admin('fragment repack',p_partnum)
  1651. INTO p_retcode;
  1652. IF p_retcode < 0 THEN
  1653. LET p_alerttype = "ERROR";
  1654. LET p_alertcolor = "RED";
  1655. LET p_alerttext = "Error ["||p_retcode||"] when auto repacking partnum: "||p_partnum||" ["||TRIM(p_fulltabname)||"].";
  1656. ELSE
  1657. SELECT npdata, nptotal
  1658. INTO p_afterdatacnt , p_afterpagecnt
  1659. FROM sysmaster:sysptnhdr H
  1660. WHERE H.partnum = p_partnum;
  1661. LET p_alerttype = "INFO";
  1662. LET p_alertcolor = "GREEN";
  1663. LET p_alerttext = "Automatically repacked table:["||p_partnum||"] ["||TRIM(p_fulltabname);
  1664. END IF
  1665. INSERT INTO ph_alert
  1666. (ID, alert_task_id,alert_task_seq, alert_type, alert_color,
  1667. alert_object_type, alert_object_name,
  1668. alert_message,alert_action)
  1669. VALUES
  1670. (0,g_task_id, g_task_seq, p_alerttype, p_alertcolor,
  1671. "DATABASE",TRIM(p_fulltabname),
  1672. p_alerttext, NULL);
  1673. END FOREACH;
  1674. END IF
  1675. END IF
  1676. {*********** Check if AUTOSHRINK is enabled ***********}
  1677. LET p_enabled = "F";
  1678. LET p_retcode = 0;
  1679. SELECT UPPER(value) INTO p_enabled FROM sysadmin:ph_threshold
  1680. WHERE name = "AUTOSHRINK_ENABLED";
  1681. IF ( p_enabled == 'T' ) THEN
  1682. {*** SELECT tables that qualify *** }
  1683. SELECT value::INTEGER INTO p_value FROM sysadmin:ph_threshold
  1684. WHERE name = "AUTOSHRINK_UNUSED";
  1685. IF p_value IS NOT NULL AND p_value > 0 AND p_value < 100 THEN
  1686. FOREACH SELECT TRIM(T.dbsname) , TRIM(T.owner)
  1687. , TRIM(T.tabname) , T.partnum
  1688. , H.npdata, H.nptotal
  1689. INTO p_dbsname , p_owner , p_tabname , p_partnum
  1690. ,p_beforedatacnt , p_beforepagecnt
  1691. FROM sysmaster:sysptnhdr H , sysmaster:systabnames T
  1692. WHERE
  1693. (H.nkeys=0) -- only data partnums
  1694. AND (
  1695. (SELECT count(*)
  1696. FROM sysmaster:sysptnbit B
  1697. WHERE B.pb_partnum = H.partnum
  1698. AND B. pb_bitmap in ( 0 , 8 )
  1699. AND B. pb_pagenum > (H.nptotal*(1-p_value/100))-3
  1700. ) + (H.nptotal - H.npused)
  1701. > TRUNC(H.nptotal * (p_value/100)) - 1
  1702. )
  1703. AND H.nptotal > 8
  1704. AND H.nptotal > fextsiz
  1705. AND H.nextns > 0
  1706. AND H.partnum = T.partnum
  1707. -- do no include system database tables.
  1708. AND dbsname NOT IN sys_dbs_list
  1709. -- do not include partitions that do not
  1710. -- qualify to avoid unnecessary errors
  1711. AND bitand(H.partnum,"0xFFFFF") != 1
  1712. AND bitand(H.flags,'0xA32F6084') ==0
  1713. AND T.tabname NOT IN
  1714. ( SELECT N.tabname FROM systables N where N.tabid < 100 )
  1715. LET p_fulltabname = TRIM(p_dbsname)||":"||TRIM(p_owner)||"."||TRIM(p_tabname);
  1716. EXECUTE FUNCTION admin('fragment shrink',p_partnum)
  1717. INTO p_retcode;
  1718. IF p_retcode < 0 THEN
  1719. LET p_alerttype = "ERROR";
  1720. LET p_alertcolor = "RED";
  1721. LET p_alerttext = "Error ["||p_retcode||"] when auto shrinking partnum: "||p_partnum||" ["||TRIM(p_fulltabname)||"].";
  1722. ELSE
  1723. SELECT npdata, nptotal
  1724. INTO p_afterdatacnt , p_afterpagecnt
  1725. FROM sysmaster:sysptnhdr H
  1726. WHERE H.partnum = p_partnum;
  1727. LET p_alerttype = "INFO";
  1728. LET p_alertcolor = "GREEN";
  1729. LET p_alerttext = "Automatically shrunk table:["||p_partnum||"] ["||TRIM(p_fulltabname)||"] went from "||p_beforedatacnt||"/"||p_beforepagecnt||" data/total pages to "||p_afterdatacnt||"/"||p_afterpagecnt||" data/total pages.";
  1730. END IF
  1731. INSERT INTO ph_alert
  1732. (ID, alert_task_id,alert_task_seq, alert_type, alert_color,
  1733. alert_object_type, alert_object_name,
  1734. alert_message,alert_action)
  1735. VALUES
  1736. (0,g_task_id, g_task_seq, p_alerttype, p_alertcolor,
  1737. "DATABASE",TRIM(p_fulltabname),
  1738. p_alerttext, NULL);
  1739. END FOREACH;
  1740. END IF
  1741. END IF
  1742. {*********** Check if AUTODEFRAG is enabled ***********}
  1743. LET p_enabled = "F";
  1744. LET p_retcode = 0;
  1745. SELECT UPPER(value) INTO p_enabled FROM sysadmin:ph_threshold
  1746. WHERE name = "AUTODEFRAG_ENABLED";
  1747. IF ( p_enabled == 'T' ) THEN
  1748. {*** SELECT tables that qualify *** }
  1749. SELECT value::INTEGER INTO p_value FROM sysadmin:ph_threshold
  1750. WHERE name = "AUTODEFRAG_EXTENTS";
  1751. IF p_value IS NOT NULL AND p_value > 0 THEN
  1752. FOREACH SELECT TRIM(T.dbsname) , TRIM(T.owner)
  1753. , TRIM(T.tabname) , T.partnum
  1754. , H.nextns
  1755. INTO p_dbsname , p_owner , p_tabname , p_partnum
  1756. ,p_beforedatacnt
  1757. FROM sysmaster:sysptnhdr H , sysmaster:systabnames T
  1758. WHERE
  1759. H.partnum = T.partnum
  1760. AND H.nextns > p_value -- qualifying number of extents
  1761. -- do no include system database tables.
  1762. AND dbsname NOT IN sys_dbs_list
  1763. -- do not include partitions that do not
  1764. -- qualify to avoid unnecessary errors
  1765. AND bitand(H.partnum,"0xFFFFF") != 1
  1766. AND bitand(H.flags,'0xA32F6084') ==0
  1767. LET p_fulltabname = TRIM(p_dbsname)||":"||TRIM(p_owner)||"."||TRIM(p_tabname);
  1768. EXECUTE FUNCTION admin('defragment partnum',p_partnum)
  1769. INTO p_retcode;
  1770. IF p_retcode < 0 THEN
  1771. LET p_alerttype = "ERROR";
  1772. LET p_alertcolor = "RED";
  1773. LET p_alerttext = "Error ["||p_retcode||"] when auto defragging partnum: "||p_partnum||" ["||TRIM(p_fulltabname)||"].";
  1774. ELSE
  1775. SELECT nextns
  1776. INTO p_afterdatacnt
  1777. FROM sysmaster:sysptnhdr H
  1778. WHERE H.partnum = p_partnum;
  1779. LET p_alerttype = "INFO";
  1780. LET p_alertcolor = "GREEN";
  1781. LET p_alerttext = "Automatically defragged table:["||p_partnum||"] ["||TRIM(p_fulltabname)||"] went from "||p_beforedatacnt||" extents to "||p_afterdatacnt||" extents.";
  1782. END IF
  1783. INSERT INTO ph_alert
  1784. (ID, alert_task_id,alert_task_seq, alert_type, alert_color,
  1785. alert_object_type, alert_object_name,
  1786. alert_message,alert_action)
  1787. VALUES
  1788. (0,g_task_id, g_task_seq, p_alerttype, p_alertcolor,
  1789. "DATABASE",TRIM(p_fulltabname),
  1790. p_alerttext, NULL);
  1791. END FOREACH;
  1792. END IF
  1793. END IF
  1794. {*********** Check if REMOVE_IPA_ENABLED is enabled ***********}
  1795. LET p_enabled = "F";
  1796. SELECT UPPER(value) INTO p_enabled FROM sysadmin:ph_threshold
  1797. WHERE name = "REMOVE_IPA_ENABLED";
  1798. IF ( p_enabled == 'T' ) THEN
  1799. {*** SELECT tables that qualify *** }
  1800. FOREACH SELECT dbsname
  1801. , trim(owner)||"."|| tabname AS fullname
  1802. INTO p_dbsname , p_tabname
  1803. FROM
  1804. sysmaster:sysptnhdr h,sysmaster:systabnames t
  1805. WHERE
  1806. h.partnum = t.partnum
  1807. and dbsname not in ("sysmaster")
  1808. and pta_totpgs != 0
  1809. LET p_fulltabname = TRIM(p_dbsname)||":"||TRIM(p_tabname);
  1810. EXECUTE FUNCTION admin('table update_ipa', p_tabname, p_dbsname)
  1811. INTO p_retcode;
  1812. IF p_retcode < 0 THEN
  1813. LET p_alerttype = "ERROR";
  1814. LET p_alertcolor = "RED";
  1815. LET p_alerttext = "Error ["||p_retcode||"] when removing outstanding in-place alters for: ["||TRIM(p_fulltabname)||"].";
  1816. ELSE
  1817. LET p_alerttype = "INFO";
  1818. LET p_alertcolor = "GREEN";
  1819. LET p_alerttext = "Automatically removed outstanding in-place alters for:["||TRIM(p_fulltabname)||"].";
  1820. END IF
  1821. INSERT INTO ph_alert
  1822. (ID, alert_task_id,alert_task_seq, alert_type, alert_color,
  1823. alert_object_type, alert_object_name,
  1824. alert_message,alert_action)
  1825. VALUES
  1826. (0,g_task_id, g_task_seq, p_alerttype, p_alertcolor,
  1827. "DATABASE",TRIM(p_fulltabname),
  1828. p_alerttext, NULL);
  1829. END FOREACH;
  1830. END IF
  1831. RETURN 0;
  1832. END FUNCTION;
  1833. {*** CHECK for in place alters ***}
  1834. DELETE FROM ph_task WHERE tk_name = "check_for_ipa";
  1835. {*** CREATE THE task
  1836. by default the task will not be enabled
  1837. and is scheduled for every 7 days ***}
  1838. INSERT INTO ph_task
  1839. (
  1840. tk_name,
  1841. tk_type,
  1842. tk_group,
  1843. tk_description,
  1844. tk_execute,
  1845. tk_next_execution,
  1846. tk_start_time,
  1847. tk_stop_time,
  1848. tk_frequency,
  1849. tk_delete,
  1850. tk_enable
  1851. )
  1852. VALUES
  1853. (
  1854. "check_for_ipa",
  1855. "TASK",
  1856. "SERVER",
  1857. "Find tables with outstanding in place alters",
  1858. "check_for_ipa",
  1859. NULL,
  1860. DATETIME(04:00:00) HOUR TO SECOND,
  1861. NULL,
  1862. INTERVAL ( 7 ) DAY TO DAY,
  1863. INTERVAL ( 30 ) DAY TO DAY,
  1864. 'f'
  1865. );
  1866. {*** CREATE the function that will be run by the task ***}
  1867. DROP FUNCTION IF EXISTS informix.check_for_ipa( int , int );
  1868. CREATE FUNCTION informix.check_for_ipa ( task_id INTEGER, task_seq INTEGER)
  1869. RETURNING INTEGER
  1870. DEFINE p_fullname CHAR(300);
  1871. DEFINE p_database CHAR(128);
  1872. FOREACH
  1873. SELECT dbsname
  1874. , trim(owner)||"."|| tabname AS fullname
  1875. INTO p_database , p_fullname
  1876. FROM
  1877. sysmaster:sysptnhdr h,sysmaster:systabnames t
  1878. WHERE
  1879. h.partnum = t.partnum
  1880. and dbsname not in ("sysmaster")
  1881. and pta_totpgs != 0
  1882. INSERT INTO ph_alert ( ID, alert_task_id ,alert_task_seq ,alert_type ,alert_color
  1883. , alert_object_type ,alert_object_name ,alert_message
  1884. , alert_action_dbs ,alert_action )
  1885. VALUES
  1886. ( 0,task_id, task_seq, "INFO", "red", "SERVER", p_fullname
  1887. , "Table "||trim(p_database)||":"||trim(p_fullname)||" has outstanding in place alters."
  1888. , p_database ,NULL );
  1889. END FOREACH;
  1890. RETURN 0;
  1891. END FUNCTION;
  1892. DELETE FROM ph_task WHERE tk_name="refresh_table_stats";
  1893. INSERT INTO ph_task
  1894. (
  1895. tk_name,
  1896. tk_type,
  1897. tk_group,
  1898. tk_description,
  1899. tk_execute,
  1900. tk_start_time,
  1901. tk_stop_time,
  1902. tk_frequency,
  1903. tk_next_execution,
  1904. tk_enable
  1905. )
  1906. VALUES
  1907. (
  1908. "refresh_table_stats",
  1909. "TASK",
  1910. "SERVER",
  1911. "System function to refresh table statistics",
  1912. "refreshstats",
  1913. NULL,
  1914. NULL,
  1915. NULL,
  1916. NULL,
  1917. 'f'
  1918. );
  1919. /********************
  1920. * LOG FILE ROTATION *
  1921. *********************/
  1922. DELETE FROM ph_threshold WHERE name = "MAX_MSGPATH_VERSIONS";
  1923. DELETE FROM ph_threshold WHERE name = "MAX_BAR_ACT_LOG_VERSIONS";
  1924. DELETE FROM ph_threshold WHERE name = "MAX_BAR_DEBUG_LOG_VERSIONS";
  1925. INSERT INTO ph_threshold(id,name,task_name,value,value_type,description)
  1926. VALUES
  1927. (0,"MAX_MSGPATH_VERSIONS", "online_log_rotate","12","NUMERIC"
  1928. ,"Maximum number of online log files to keep.");
  1929. INSERT INTO ph_threshold(id,name,task_name,value,value_type,description)
  1930. VALUES
  1931. (0,"MAX_BAR_ACT_LOG_VERSIONS", "bar_act_log_rotate","12","NUMERIC"
  1932. ,"Maximum number of bar act log files to keep.");
  1933. INSERT INTO ph_threshold(id,name,task_name,value,value_type,description)
  1934. VALUES
  1935. (0,"MAX_BAR_DEBUG_LOG_VERSIONS", "bar_debug_log_rotate","12","NUMERIC"
  1936. ,"Maximum number of bar debug log files to keep.");
  1937. --DROP FUNCTION IF EXISTS admin_message_log_rotate(INT,INT,VARCHAR(255),INT);
  1938. CREATE FUNCTION informix.admin_message_log_rotate(task_id INT, task_seq INT
  1939. , param VARCHAR(255) , max_files_to_keep INT DEFAULT NULL)
  1940. RETURNING INTEGER;
  1941. DEFINE path_to_message_log LVARCHAR(513);
  1942. DEFINE is_default BOOLEAN;
  1943. DEFINE ret_code INTEGER;
  1944. DEFINE temp_max_files_to_keep INTEGER;
  1945. DEFINE p_alert_type LIKE ph_alert.alert_type;
  1946. DEFINE p_alert_color LIKE ph_alert.alert_color;
  1947. DEFINE p_alert_obj_type LIKE ph_alert.alert_object_type;
  1948. DEFINE p_alert_obj_name LIKE ph_alert.alert_object_name;
  1949. DEFINE p_alert_message LIKE ph_alert.alert_message;
  1950. DEFINE p_alert_action LIKE ph_alert.alert_action;
  1951. LET ret_code = 0;
  1952. { check we have a valid param }
  1953. IF param IS NULL
  1954. OR param = ""
  1955. OR param = "ROOTPATH"
  1956. OR param = "MIRRORPATH"
  1957. THEN
  1958. LET ret_code = -1;
  1959. LET p_alert_type = "WARNING";
  1960. LET p_alert_color = "GREEN";
  1961. LET p_alert_obj_type = "SERVER";
  1962. LET p_alert_obj_name = "PARAM";
  1963. LET p_alert_message = "Invalid param("||param||") passed to admin_message_log_rotate";
  1964. LET p_alert_action = NULL;
  1965. GOTO ALERT_RETURN;
  1966. END IF
  1967. { check max_files_to_keep
  1968. if its not passed in then look in sysadmin:ph_threshold
  1969. for MAX_param_VERSIONS
  1970. if thats not found use the default of 12
  1971. }
  1972. IF max_files_to_keep IS NULL THEN
  1973. SELECT value::integer INTO temp_max_files_to_keep
  1974. FROM sysadmin:ph_threshold
  1975. WHERE name = "MAX_"||param||"_VERSIONS";
  1976. IF temp_max_files_to_keep IS NULL THEN
  1977. LET temp_max_files_to_keep = 12;
  1978. END IF
  1979. LET max_files_to_keep = temp_max_files_to_keep;
  1980. END IF
  1981. { bound check the max_files_to_keep }
  1982. IF max_files_to_keep <= 0
  1983. OR max_files_to_keep > 99
  1984. THEN
  1985. LET ret_code = -1;
  1986. LET p_alert_type = "WARNING";
  1987. LET p_alert_color = "GREEN";
  1988. LET p_alert_obj_type = "SERVER";
  1989. LET p_alert_obj_name = "VERSIONS";
  1990. LET p_alert_message = "Invalid value for the number of versions to keep("||max_files_to_keep||") It must be greater than 0 and less than 99.";
  1991. LET p_alert_action = NULL;
  1992. GOTO ALERT_RETURN;
  1993. END IF
  1994. { get the path name to the file }
  1995. { first check if its an onconfig param }
  1996. SELECT TRIM(cf_effective) INTO path_to_message_log
  1997. FROM sysmaster:syscfgtab WHERE cf_name = param;
  1998. { quick check that we are not using STDOUT }
  1999. IF ( path_to_message_log == "/dev/tty" ) THEN
  2000. LET ret_code = -1;
  2001. LET p_alert_type = "WARNING";
  2002. LET p_alert_color = "GREEN";
  2003. LET p_alert_obj_type = "SERVER";
  2004. LET p_alert_obj_name = "PATH_NAME";
  2005. LET p_alert_message = param||" maybe using STDOUT. Cannot rotate.";
  2006. LET p_alert_action = NULL;
  2007. GOTO ALERT_RETURN;
  2008. END IF
  2009. { check if the param is a ph_threshold PATH_FOR_xxx }
  2010. IF path_to_message_log IS NULL THEN
  2011. SELECT value::lvarchar INTO path_to_message_log
  2012. FROM sysadmin:ph_threshold
  2013. WHERE name = "PATH_FOR_"||param;
  2014. IF path_to_message_log IS NULL THEN
  2015. LET path_to_message_log = param;
  2016. END IF
  2017. END IF
  2018. EXECUTE FUNCTION sysadmin:admin("file rotate",path_to_message_log,max_files_to_keep)
  2019. INTO ret_code;
  2020. IF ret_code < 0 THEN
  2021. LET p_alert_type = "WARNING";
  2022. LET p_alert_color = "GREEN";
  2023. LET p_alert_obj_type = "SERVER";
  2024. LET p_alert_obj_name = "PATH_NAME";
  2025. LET p_alert_message = "FILE ROTATE failed ";
  2026. LET p_alert_action = NULL;
  2027. GOTO ALERT_RETURN;
  2028. END IF
  2029. RETURN ret_code;
  2030. <<ALERT_RETURN>>
  2031. INSERT INTO ph_alert
  2032. (ID, alert_task_id,alert_task_seq,alert_type,
  2033. alert_color, alert_object_type,
  2034. alert_object_name, alert_message,alert_action)
  2035. VALUES
  2036. (0,task_id, task_seq, p_alert_type
  2037. , p_alert_color ,p_alert_obj_type ,p_alert_obj_name
  2038. , p_alert_message , p_alert_action);
  2039. RETURN ret_code;
  2040. END FUNCTION;
  2041. DELETE FROM ph_task WHERE tk_name = "online_log_rotate";
  2042. DELETE FROM ph_task WHERE tk_name = "bar_act_log_rotate";
  2043. DELETE FROM ph_task WHERE tk_name = "bar_debug_log_rotate";
  2044. INSERT INTO ph_task
  2045. (
  2046. tk_name,
  2047. tk_type,
  2048. tk_group,
  2049. tk_description,
  2050. tk_execute,
  2051. tk_start_time,
  2052. tk_stop_time,
  2053. tk_next_execution,
  2054. tk_frequency,
  2055. tk_delete,
  2056. tk_enable
  2057. )
  2058. VALUES
  2059. (
  2060. "online_log_rotate",
  2061. "TASK",
  2062. "SERVER",
  2063. "Rotate the Online Log",
  2064. "execute function admin_message_log_rotate($DATA_TASK_ID,$DATA_SEQ_ID,'MSGPATH')",
  2065. DATETIME(03:00:00) HOUR TO SECOND,
  2066. DATETIME(03:01:00) HOUR TO SECOND,
  2067. NULL,
  2068. INTERVAL ( 30 ) DAY TO DAY,
  2069. INTERVAL ( 30 ) DAY TO DAY,
  2070. 'f'
  2071. );
  2072. INSERT INTO ph_task
  2073. (
  2074. tk_name,
  2075. tk_type,
  2076. tk_group,
  2077. tk_description,
  2078. tk_execute,
  2079. tk_start_time,
  2080. tk_stop_time,
  2081. tk_next_execution,
  2082. tk_frequency,
  2083. tk_delete,
  2084. tk_enable
  2085. )
  2086. VALUES
  2087. (
  2088. "bar_act_log_rotate",
  2089. "TASK",
  2090. "SERVER",
  2091. "Rotate the BAR ACT Log",
  2092. "execute function admin_message_log_rotate($DATA_TASK_ID,$DATA_SEQ_ID,'BAR_ACT_LOG')",
  2093. DATETIME(03:00:00) HOUR TO SECOND,
  2094. DATETIME(03:01:00) HOUR TO SECOND,
  2095. NULL,
  2096. INTERVAL ( 30 ) DAY TO DAY,
  2097. INTERVAL ( 30 ) DAY TO DAY,
  2098. 'f'
  2099. );
  2100. INSERT INTO ph_task
  2101. (
  2102. tk_name,
  2103. tk_type,
  2104. tk_group,
  2105. tk_description,
  2106. tk_execute,
  2107. tk_start_time,
  2108. tk_stop_time,
  2109. tk_next_execution,
  2110. tk_frequency,
  2111. tk_delete,
  2112. tk_enable
  2113. )
  2114. VALUES
  2115. (
  2116. "bar_debug_log_rotate",
  2117. "TASK",
  2118. "SERVER",
  2119. "Rotate the Bar Debug Log",
  2120. "execute function admin_message_log_rotate($DATA_TASK_ID,$DATA_SEQ_ID,'BAR_DEBUG_LOG')",
  2121. DATETIME(03:00:00) HOUR TO SECOND,
  2122. DATETIME(03:01:00) HOUR TO SECOND,
  2123. NULL,
  2124. INTERVAL ( 30 ) DAY TO DAY,
  2125. INTERVAL ( 30 ) DAY TO DAY,
  2126. 'f'
  2127. );
  2128. {**************************************************************************
  2129. Compression task
  2130. **************************************************************************}
  2131. DELETE FROM ph_threshold WHERE name in ( "COMPRESSION TABLE TIMEOUT",
  2132. "COMPRESSION TABLE ROW COUNT");
  2133. INSERT INTO ph_threshold
  2134. (id,name,task_name,value,value_type,description)
  2135. VALUES
  2136. (0,"COMPRESSION TABLE TIMEOUT", "compress_table","900", "NUMERIC",
  2137. "The amount of time in seconds we will wait for tables to have data in them.");
  2138. INSERT INTO ph_threshold
  2139. (id,name,task_name,value,value_type,description)
  2140. VALUES
  2141. (0,"COMPRESSION TABLE ROW COUNT", "compress_table","2000", "NUMERIC",
  2142. "The number of pages we must find in a fragment of a table before a compression dictionary will be created."
  2143. );
  2144. DROP FUNCTION IF EXISTS compress_table;
  2145. CREATE FUNCTION compress_table(task_id INTEGER, task_seq INTEGER, tabname LVARCHAR )
  2146. RETURNING INTEGER
  2147. DEFINE timeout INTEGER;
  2148. DEFINE fragments_left INTEGER;
  2149. DEFINE row_count INTEGER;
  2150. DEFINE fragid INTEGER;
  2151. DEFINE rc INTEGER;
  2152. DEFINE cnt INTEGER;
  2153. DEFINE created_at DATETIME YEAR TO SECOND;
  2154. -- To debug enable uncomment these lines
  2155. --SET DEBUG FILE TO "/tmp/debug.out."||task_id;
  2156. --TRACE ON;
  2157. --TRACE "CALLING function compress_table ("||task_id||","||task_seq||","||tabname||")";
  2158. -- Get the config thresholds
  2159. SELECT MAX(value::integer) INTO timeout
  2160. FROM sysadmin:ph_threshold
  2161. WHERE name = "COMPRESSION TABLE TIMEOUT";
  2162. IF timeout IS NULL THEN
  2163. LET timeout = 900;
  2164. ELIF timeout < 0 THEN
  2165. LET timeout = 10;
  2166. ELIF timeout > 3600 THEN
  2167. LET timeout = 3600;
  2168. END IF
  2169. SELECT MAX(value::integer) INTO row_count
  2170. FROM sysadmin:ph_threshold
  2171. WHERE name = "COMPRESSION TABLE ROW COUNT";
  2172. IF row_count IS NULL OR row_count < 1000 THEN
  2173. LET row_count = 1000;
  2174. END IF
  2175. BEGIN
  2176. ON EXCEPTION
  2177. DROP TABLE IF EXISTS pt_list;
  2178. INSERT INTO ph_alert
  2179. (ID, alert_task_id,alert_task_seq,alert_type,
  2180. alert_color, alert_object_type,
  2181. alert_object_name, alert_message,alert_action)
  2182. VALUES
  2183. (0,task_id, task_seq, "INFO", "YELLOW",
  2184. "SERVER","compress_table",
  2185. "Failed to build compression dictionaries on " ||TRIM(tabname),
  2186. NULL);
  2187. END EXCEPTION
  2188. IF tabname IS NULL THEN
  2189. RETURN -1;
  2190. END IF
  2191. LET fragments_left = 99;
  2192. LET cnt = 0;
  2193. SELECT P.lockid
  2194. FROM sysmaster:systabnames T, sysmaster:sysptnhdr P
  2195. WHERE TRIM(t.dbsname)||":"||TRIM(T.tabname) = tabname
  2196. --WHERE T.tabname = tabname
  2197. AND P.lockid = T.partnum
  2198. AND P.nkeys = 0
  2199. AND bitand( P.flags, '0x08000000' ) = 0
  2200. INTO TEMP pt_list WITH NO LOG;
  2201. CREATE INDEX ix_temp_pt_list ON pt_list(lockid);
  2202. WHILE ( timeout > 0 AND fragments_left > 0 )
  2203. FOREACH SELECT P.partnum
  2204. INTO fragid
  2205. FROM pt_list L, sysmaster:sysptnhdr P
  2206. WHERE l.lockid = P.partnum
  2207. AND P.nrows > row_count
  2208. AND bitand( P.flags, '0x08000000' ) = 0
  2209. LET rc = admin('fragment create_dictionary', fragid);
  2210. IF rc >= 0 THEN
  2211. DELETE FROM pt_list WHERE lockid = fragid;
  2212. LET cnt = cnt + 1;
  2213. END IF
  2214. END FOREACH
  2215. SELECT NVL( count(*) , 0 )
  2216. INTO fragments_left
  2217. FROM pt_list L, sysmaster:sysptnhdr P
  2218. WHERE l.lockid = p.partnum
  2219. AND P.nkeys = 0
  2220. AND bitand( P.flags, '0x08000000' ) = 0;
  2221. LET rc = yieldn(1);
  2222. LET timeout = timeout - 1;
  2223. END WHILE
  2224. END
  2225. DROP TABLE IF EXISTS pt_list;
  2226. INSERT INTO ph_alert
  2227. (ID, alert_task_id,alert_task_seq,alert_type,
  2228. alert_color, alert_object_type,
  2229. alert_object_name, alert_message,alert_action)
  2230. VALUES
  2231. (0,task_id, task_seq, "INFO", "GREEN",
  2232. "SERVER","compress_table",
  2233. "Built "||cnt||" compression dictionaries on " ||TRIM(tabname),
  2234. NULL);
  2235. RETURN 0;
  2236. END FUNCTION;
  2237. DELETE FROM ph_task WHERE tk_name = "compress_table";
  2238. INSERT INTO ph_task
  2239. (
  2240. tk_name,
  2241. tk_type,
  2242. tk_group,
  2243. tk_description,
  2244. tk_execute,
  2245. tk_start_time,
  2246. tk_stop_time,
  2247. tk_frequency,
  2248. tk_delete,
  2249. tk_enable
  2250. )
  2251. VALUES
  2252. (
  2253. "compress_table",
  2254. "TASK",
  2255. "TABLES",
  2256. "Task to be kicked off when loading a table to ensure data is compressed",
  2257. "compress_table",
  2258. NULL,
  2259. NULL,
  2260. INTERVAL ( 1 ) DAY TO DAY,
  2261. INTERVAL ( 30 ) DAY TO DAY,
  2262. 'f'
  2263. );
  2264. DROP FUNCTION IF EXISTS informix.sync_registry( INTEGER, INTEGER);
  2265. {**************************************************************************
  2266. Task to sync the windows registry
  2267. **************************************************************************}
  2268. CREATE FUNCTION informix.sync_registry(task_id INTEGER, ID INTEGER)
  2269. RETURNING INTEGER
  2270. DEFINE old_file_time INTEGER;
  2271. DEFINE new_file_time INTEGER;
  2272. DEFINE command_id INTEGER;
  2273. DEFINE osname VARCHAR(255);
  2274. --SET DEBUG FILE TO "/tmp/debug.out."||task_id;
  2275. --TRACE ON;
  2276. LET new_file_time = 0;
  2277. {* This taks utilizes the ph_run table.
  2278. * If the tk_delete time is shorter than
  2279. * the tk_frequency then this task will
  2280. * not cache the saved results
  2281. *}
  2282. SELECT NVL(run_retcode,0)
  2283. INTO old_file_time
  2284. FROM ph_task, OUTER ph_run
  2285. WHERE run_task_id = tk_id
  2286. AND run_task_seq = tk_sequence
  2287. AND tk_name = "sync_registry";
  2288. IF old_file_time == 0 THEN
  2289. SELECT os_name INTO osname FROM sysmaster:sysmachineinfo;
  2290. IF osname <> 'Windows' THEN
  2291. -- If this is not windows turn off this task
  2292. UPDATE ph_task SET tk_enable='f' WHERE tk_name = "sync_registry";
  2293. RETURN 0;
  2294. END IF
  2295. END IF
  2296. LET command_id = ABS(admin("export sqlhosts", old_file_time));
  2297. SELECT cmd_ret_status
  2298. INTO new_file_time
  2299. FROM command_history
  2300. WHERE cmd_number = command_id;
  2301. RETURN new_file_time;
  2302. END FUNCTION;
  2303. DELETE FROM ph_task where tk_name = "sync_registry";
  2304. INSERT INTO ph_task
  2305. (
  2306. tk_name,
  2307. tk_type,
  2308. tk_group,
  2309. tk_description,
  2310. tk_execute,
  2311. tk_delete,
  2312. tk_start_time,
  2313. tk_stop_time,
  2314. tk_frequency
  2315. )
  2316. VALUES
  2317. (
  2318. "sync_registry",
  2319. "TASK",
  2320. "SERVER",
  2321. "Sync the sqlhost file to the Windows Registery",
  2322. "sync_registry",
  2323. INTERVAL ( 60 ) MINUTE TO MINUTE,
  2324. NULL,
  2325. NULL,
  2326. INTERVAL ( 15 ) MINUTE TO MINUTE
  2327. );
  2328. {**************************************************************************
  2329. Rolling Window Tables
  2330. **************************************************************************}
  2331. DELETE FROM ph_task
  2332. WHERE tk_name IN ("purge_tables", "db_purge_tables");
  2333. DELETE FROM ph_threshold
  2334. WHERE name IN ("RWT LOGLEVEL", "RWT IMMEDIATE", "RWT LOCKMODE");
  2335. INSERT INTO ph_task
  2336. (
  2337. tk_name,
  2338. tk_type,
  2339. tk_group,
  2340. tk_description,
  2341. tk_execute,
  2342. tk_start_time,
  2343. tk_stop_time,
  2344. tk_frequency,
  2345. tk_next_execution,
  2346. tk_delete,
  2347. tk_enable
  2348. )
  2349. VALUES
  2350. (
  2351. "purge_tables",
  2352. "TASK",
  2353. "TABLES",
  2354. "Daily task to ensure that rolling window tables stay within limits",
  2355. "rwt_purge_tables",
  2356. DATETIME(00:45:00) HOUR TO SECOND,
  2357. NULL,
  2358. INTERVAL (1) DAY TO DAY,
  2359. (TODAY + 1)::DATETIME HOUR TO SECOND + 45 UNITS MINUTE,
  2360. NULL,
  2361. 't'
  2362. );
  2363. INSERT INTO ph_task
  2364. (
  2365. tk_name,
  2366. tk_type,
  2367. tk_group,
  2368. tk_description,
  2369. tk_execute,
  2370. tk_start_time,
  2371. tk_stop_time,
  2372. tk_frequency,
  2373. tk_delete,
  2374. tk_enable
  2375. )
  2376. VALUES
  2377. (
  2378. "db_purge_tables",
  2379. "TASK",
  2380. "TABLES",
  2381. "Task to ensure that rolling window tables stay within limits for a database",
  2382. "rwt_db_purge_tables",
  2383. NULL,
  2384. NULL,
  2385. INTERVAL (1) DAY TO DAY,
  2386. NULL,
  2387. 'f'
  2388. );
  2389. { RWT tasks run in private threads }
  2390. UPDATE ph_task SET tk_attributes = BITOR(tk_attributes, 8)
  2391. WHERE tk_name IN ('purge_tables', 'db_purge_tables');
  2392. {**************************************************************************
  2393. Task to automatically start json listener if present
  2394. **************************************************************************}
  2395. DROP FUNCTION IF EXISTS informix.json_listener(INT, INT);
  2396. CREATE FUNCTION informix.json_listener(task_id INT, task_seq INT)
  2397. RETURNING INTEGER
  2398. DEFINE rc INTEGER;
  2399. DEFINE tmp INTEGER;
  2400. DEFINE prop_file VARCHAR(130);
  2401. DEFINE msg LVARCHAR;
  2402. FOREACH SELECT TRIM(value)
  2403. INTO prop_file
  2404. FROM ph_threshold
  2405. WHERE name MATCHES "JSON LISTENER PROP*"
  2406. EXECUTE FUNCTION admin("json listener start", prop_file) INTO rc;
  2407. IF rc < 0 THEN
  2408. LET msg = "";
  2409. SELECT cmd_ret_msg INTO msg FROM command_history WHERE cmd_number = rc;
  2410. INSERT INTO ph_alert
  2411. (ID, alert_task_id,alert_task_seq,alert_type,
  2412. alert_color, alert_object_type,
  2413. alert_object_name, alert_message,alert_action)
  2414. VALUES
  2415. (0,task_id, task_seq, "INFO", "GREEN", "SERVER", prop_file,
  2416. "JSON Listener "||TRIM(prop_file)||" failed to started. "||TRIM(msg),
  2417. NULL);
  2418. ELSE
  2419. INSERT INTO ph_alert
  2420. (ID, alert_task_id,alert_task_seq,alert_type,
  2421. alert_color, alert_object_type,
  2422. alert_object_name, alert_message,alert_action)
  2423. VALUES
  2424. (0,task_id, task_seq, "INFO", "GREEN", "SERVER", prop_file,
  2425. "JSON Listener "||TRIM(prop_file)||" started",
  2426. NULL);
  2427. END IF
  2428. END FOREACH
  2429. END FUNCTION;
  2430. UPDATE ph_task SET tk_attributes = 0 WHERE tk_name = "json listener";
  2431. DELETE FROM ph_task where tk_name = "json listener";
  2432. INSERT INTO ph_task
  2433. (
  2434. tk_name,
  2435. tk_type,
  2436. tk_group,
  2437. tk_description,
  2438. tk_execute,
  2439. tk_start_time,
  2440. tk_stop_time,
  2441. tk_frequency,
  2442. tk_next_execution,
  2443. tk_delete,
  2444. tk_enable
  2445. )
  2446. VALUES
  2447. (
  2448. "json listener",
  2449. "STARTUP TASK",
  2450. "SERVER",
  2451. "Start JSON Listener",
  2452. "json_listener",
  2453. NULL,
  2454. NULL,
  2455. INTERVAL ( 10 ) SECOND TO SECOND,
  2456. NULL,
  2457. INTERVAL ( 30 ) DAY TO DAY,
  2458. 't'
  2459. );
  2460. {**************************************************************************
  2461. Task to start LO cleaner (sbspclean) thread
  2462. **************************************************************************}
  2463. DROP FUNCTION IF EXISTS informix.locleaner(INT, INT);
  2464. CREATE FUNCTION informix.locleaner(task_id INT, task_seq INT)
  2465. RETURNING INTEGER
  2466. DEFINE rc INTEGER;
  2467. DEFINE msg LVARCHAR;
  2468. EXECUTE FUNCTION admin("start locleaner") INTO rc;
  2469. IF rc < 0 THEN
  2470. LET msg = "";
  2471. SELECT cmd_ret_msg INTO msg FROM command_history WHERE cmd_number = rc;
  2472. INSERT INTO ph_alert
  2473. (ID, alert_task_id,alert_task_seq,alert_type,
  2474. alert_color, alert_object_type,
  2475. alert_object_name, alert_message,alert_action)
  2476. VALUES
  2477. (0,task_id, task_seq, "INFO", "GREEN", "SERVER", "LO Cleaner",
  2478. "LO Cleaner (sbspclean thread) failed to started. "||TRIM(msg),
  2479. NULL);
  2480. ELSE
  2481. INSERT INTO ph_alert
  2482. (ID, alert_task_id,alert_task_seq,alert_type,
  2483. alert_color, alert_object_type,
  2484. alert_object_name, alert_message,alert_action)
  2485. VALUES
  2486. (0,task_id, task_seq, "INFO", "GREEN", "SERVER", "LO Cleaner",
  2487. "LO Cleaner (sbspclean thread) started. ",
  2488. NULL);
  2489. END IF
  2490. END FUNCTION;
  2491. UPDATE ph_task SET tk_attributes = 0 WHERE tk_name = "LO Cleaner Startup";
  2492. DELETE FROM ph_task where tk_name = "LO Cleaner Startup";
  2493. INSERT INTO ph_task
  2494. (
  2495. tk_name,
  2496. tk_type,
  2497. tk_group,
  2498. tk_description,
  2499. tk_execute,
  2500. tk_start_time,
  2501. tk_stop_time,
  2502. tk_frequency,
  2503. tk_next_execution,
  2504. tk_delete,
  2505. tk_enable
  2506. )
  2507. VALUES
  2508. (
  2509. "LO Cleaner Startup",
  2510. "STARTUP TASK",
  2511. "SERVER",
  2512. "Start LO Cleaner on startup",
  2513. "locleaner",
  2514. NULL,
  2515. NULL,
  2516. INTERVAL ( 10 ) SECOND TO SECOND,
  2517. NULL,
  2518. INTERVAL ( 30 ) DAY TO DAY,
  2519. 'f'
  2520. );
  2521. UPDATE ph_task SET tk_attributes = 0 WHERE tk_name = "LO Cleaner Task";
  2522. DELETE FROM ph_task where tk_name = "LO Cleaner Task";
  2523. INSERT INTO ph_task
  2524. (
  2525. tk_name,
  2526. tk_type,
  2527. tk_group,
  2528. tk_description,
  2529. tk_execute,
  2530. tk_start_time,
  2531. tk_stop_time,
  2532. tk_frequency,
  2533. tk_next_execution,
  2534. tk_delete,
  2535. tk_enable
  2536. )
  2537. VALUES
  2538. (
  2539. "LO Cleaner Task",
  2540. "TASK",
  2541. "SERVER",
  2542. "LO Cleaner Task that can be scheduled",
  2543. "locleaner",
  2544. DATETIME ( 00:30:00 ) HOUR TO SECOND,
  2545. NULL,
  2546. INTERVAL ( 01 00:00:00 ) DAY TO SECOND,
  2547. NULL,
  2548. INTERVAL ( 30 ) DAY TO DAY,
  2549. 'f'
  2550. );
  2551. EXECUTE PROCEDURE IFX_ALLOW_NEWLINE('T');
  2552. UPDATE ph_task SET tk_attributes = BITANDNOT(tk_attributes, 4)
  2553. WHERE tk_name = "mongo_pam_auth";
  2554. DELETE FROM ph_task where tk_name = "mongo_pam_auth";
  2555. INSERT INTO ph_task
  2556. (
  2557. tk_name,
  2558. tk_type,
  2559. tk_group,
  2560. tk_description,
  2561. tk_result_table,
  2562. tk_dbs,
  2563. tk_execute,
  2564. tk_create,
  2565. tk_frequency,
  2566. tk_next_execution,
  2567. tk_delete,
  2568. tk_enable
  2569. )
  2570. VALUES
  2571. (
  2572. "mongo_pam_auth",
  2573. "STARTUP SENSOR",
  2574. "MISC",
  2575. "Create if required and load the sysmongouser_ext from sysmongousers for the wire listener client to authenticate via pam.",
  2576. NULL,
  2577. "sysuser",
  2578. "select count(*) FROM sysmongousers;",
  2579. "CREATE FUNCTION IF NOT EXISTS informix.sync_mongo_users(task_id INT DEFAULT -1,
  2580. task_seq INT DEFAULT -1)
  2581. RETURNING INTEGER
  2582. DEFINE ifxdir VARCHAR(130);
  2583. DEFINE cmd VARCHAR(255);
  2584. CREATE TABLE IF NOT EXISTS sysmongousers (
  2585. username nchar(32),
  2586. hashed_password varchar(128)
  2587. ) lock mode row;
  2588. CREATE UNIQUE INDEX IF NOT EXISTS sysmongousers_idx_username ON
  2589. sysmongousers(username) IN TABLE;
  2590. SELECT TRIM(NVL(env_value,'/usr/informix'))
  2591. INTO ifxdir
  2592. FROM sysmaster:sysenv
  2593. WHERE env_name = 'INFORMIXDIR';
  2594. LET cmd = 'CREATE EXTERNAL TABLE IF NOT EXISTS ' ||
  2595. 'sysmongousers_ext SAMEAS sysmongousers ' ||
  2596. 'USING ( DATAFILES ( ''DISK:' || ifxdir || '/etc/mongohash'') ) ';
  2597. EXECUTE IMMEDIATE cmd;
  2598. REVOKE ALL ON sysmongousers FROM PUBLIC AS INFORMIX;
  2599. GRANT SELECT ON sysmongousers TO PUBLIC AS INFORMIX;
  2600. INSERT into sysmongousers_ext select * FROM sysmongousers ORDER BY username;
  2601. drop table sysmongousers_ext;
  2602. RETURN DBINFO('sqlca.sqlerrd2');
  2603. END FUNCTION;
  2604. ",
  2605. INTERVAL ( 5 ) SECOND TO SECOND,
  2606. NULL,
  2607. INTERVAL ( 30 ) DAY TO DAY,
  2608. 'f'
  2609. );
  2610. {**************************************************************************
  2611. MARK THE ABOVE TASKS AS SYSTEM TASKS
  2612. **************************************************************************}
  2613. UPDATE ph_task SET tk_attributes = BITOR(tk_attributes, 4)
  2614. WHERE tk_name
  2615. IN ('mon_command_history',
  2616. 'mon_config', 'mon_config_startup',
  2617. 'mon_sysenv', 'mon_profile', 'mon_vps',
  2618. 'mon_checkpoint', 'mon_memory_system',
  2619. 'mon_table_profile', 'mon_table_names',
  2620. 'mon_users', 'check_backup',
  2621. 'ifx_ha_monitor_log_replay_task',
  2622. 'Alert Cleanup',
  2623. 'post_alarm_message',
  2624. 'Job Runner',
  2625. 'Job Results Cleanup',
  2626. 'idle_user_timeout', 'auto_tune_cpu_vps', 'auto_crsd',
  2627. 'add_storage', 'mon_low_storage', 'refresh_table_stats',
  2628. 'online_log_rotate','bar_act_log_rotate','bar_debug_log_rotate',
  2629. 'autoreg exe', 'autoreg vp', 'autoreg migrate-console',
  2630. 'bad_index_alert','check_for_ipa','compress_table', 'mon_chunk',
  2631. 'purge_tables', 'db_purge_tables', 'mon_iohistory', 'json listener',
  2632. 'mongo_pam_auth', 'mongo_pam_init'
  2633. );
  2634. {**************************************************************************
  2635. UPDATE STATISTICS
  2636. **************************************************************************}
  2637. UPDATE STATISTICS;
  2638. EXECUTE FUNCTION TASK("tenant load");
  2639. CLOSE DATABASE;