{"id":10452,"date":"2017-08-23T19:41:01","date_gmt":"2017-08-23T17:41:01","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/"},"modified":"2017-08-23T19:41:01","modified_gmt":"2017-08-23T17:41:01","slug":"improving-statspack-experience","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/","title":{"rendered":"Improving Statspack Experience"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nI&#8217;ve published a few month ago an article in the UKOUG OracleScene magazine on <a href=\"http:\/\/viewer.zmags.com\/publication\/dd9ed62b#\/dd9ed62b\/36\" target=\"_blank\" rel=\"noopener noreferrer\">Improving Statspack Experience<\/a>: quick setup script, changing settings, filling Idle Events,etc. In the article, I used dbms_job to schedule the snapshots, because I have this script for years and never took the time to do it with dbms_scheduler. Thanks to <a href=\"https:\/\/www.dbi-services.com\/on-the-company-and-its-associates\/our-associates-and-certified-experts\/nicolas-jardot\/\" target=\"_blank\" rel=\"noopener noreferrer\">Nicolas Jardot<\/a> here is the equivalent script using dbms_scheduler.<br \/>\n<!--more--><br \/>\nThe idea is to have a script to run on each instance (when in RAC) in order to have a job calling statspack.snap and statspack.purge on each instance.<\/p>\n<pre><code>\nDECLARE\n    instno NUMBER;\n    snapjob VARCHAR2(30);\n    purgejob VARCHAR2(30);\nBEGIN\n    select instance_number into instno from v$instance;\n    snapjob  := 'PERFSTAT.STATSPACK_SNAP_' || instno;\n    purgejob := 'PERFSTAT.STATSPACK_PURGE_' || instno;\n&nbsp;\n    DBMS_SCHEDULER.CREATE_JOB (\n       job_name =&gt; snapjob, \n       job_type =&gt; 'PLSQL_BLOCK', \n       job_action =&gt; 'statspack.snap;',\n       number_of_arguments =&gt; 0,\n       start_date =&gt; systimestamp,\n       repeat_interval =&gt; 'FREQ=HOURLY;BYTIME=0000;BYDAY=MON,TUE,WED,THU,FRI,SAT,SUN',\n       end_date =&gt; NULL,\n       enabled =&gt; TRUE,\n       auto_drop =&gt; FALSE,\n       comments =&gt; 'Take hourly Statspack snapshot');\n&nbsp;\n    DBMS_SCHEDULER.CREATE_JOB (\n       job_name =&gt; purgejob, \n       job_type =&gt; 'PLSQL_BLOCK', \n       job_action =&gt; 'statspack.purge(i_num_days=&gt;31,i_extended_purge=&gt;true);',\n       number_of_arguments =&gt; 0,\n       start_date =&gt; systimestamp,\n       repeat_interval =&gt; 'FREQ=WEEKLY;BYTIME=120000;BYDAY=SUN',\n       end_date =&gt; NULL,\n       enabled =&gt; TRUE,\n       auto_drop =&gt; FALSE,\n       comments =&gt; 'Weekly purge Statspack snapshot');\n&nbsp;\n    DBMS_SCHEDULER.SET_ATTRIBUTE( name =&gt; snapjob, attribute =&gt; 'logging_level', value =&gt; DBMS_SCHEDULER.LOGGING_OFF );\n    DBMS_SCHEDULER.SET_ATTRIBUTE( name =&gt; snapjob, attribute =&gt; 'INSTANCE_ID', value=&gt;instno);\n    DBMS_SCHEDULER.SET_ATTRIBUTE( name =&gt; snapjob, attribute =&gt; 'INSTANCE_STICKINESS', value=&gt;TRUE);\n&nbsp;\n    DBMS_SCHEDULER.SET_ATTRIBUTE( name =&gt; purgejob, attribute =&gt; 'logging_level', value =&gt; DBMS_SCHEDULER.LOGGING_OFF );\n    DBMS_SCHEDULER.SET_ATTRIBUTE( name =&gt; purgejob, attribute =&gt; 'INSTANCE_ID', value=&gt;instno);\n    DBMS_SCHEDULER.SET_ATTRIBUTE( name =&gt; purgejob, attribute =&gt; 'INSTANCE_STICKINESS', value=&gt;TRUE);  \nEND;\n\/\n<\/code><\/pre>\n<p>I used the Oracle Cloud Service to provision quickly a two nodes RAC database to validate, and I&#8217;ll check the scheduling:<\/p>\n<pre><code>\n[oracle@rac-dg01-1 admin]$ alias sql='JAVA_HOME=$ORACLE_HOME\/jdk bash $ORACLE_HOME\/sqldeveloper\/sqlcl\/bin\/sql'\n[oracle@rac-dg01-1 admin]$ TWO_TASK=\/\/10.31.143.86\/pdb1.a511644.oraclecloud.internal sql sys\/\"Ach1z0#d\" as sysdba\n&nbsp;\nSQLcl: Release 12.2.0.1.0 RC on Wed Aug 23 18:57:12 2017\n&nbsp;\nCopyright (c) 1982, 2017, Oracle.  All rights reserved.\n&nbsp;\nConnected to:\nOracle Database 12c EE Extreme Perf Release 12.2.0.1.0 - 64bit Production\n&nbsp;\nSQL&gt; set sqlformat ansiconsole\nSQL&gt; select job_name, state, enabled, next_run_date, instance_stickiness, instance_id from dba_scheduler_jobs where owner='PERFSTAT';\nJOB_NAME           STATE      ENABLED  NEXT_RUN_DATE                           INSTANCE_STICKINESS  INSTANCE_ID\n--------           -----      -------  -------------                           -------------------  -----------\nSTATSPACK_SNAP_1   SCHEDULED  TRUE     23-AUG-17 07.00.00.981193000 PM +00:00  TRUE                 1\nSTATSPACK_PURGE_1  SCHEDULED  TRUE     27-AUG-17 12.00.00.074939000 PM +00:00  TRUE                 1\nSTATSPACK_SNAP_2   SCHEDULED  TRUE     23-AUG-17 07.00.00.644681000 PM +00:00  TRUE                 2\nSTATSPACK_PURGE_2  SCHEDULED  TRUE     27-AUG-17 12.00.00.755685000 PM +00:00  TRUE                 2\n<\/code><\/pre>\n<p>One hour later, the job has run on each instance:<\/p>\n<pre><code>\nJOB_NAME           STATE      ENABLED  NEXT_RUN_DATE                           INSTANCE_STICKINESS  INSTANCE_ID\n--------           -----      -------  -------------                           -------------------  -----------\nSTATSPACK_SNAP_1   SCHEDULED  TRUE     23-AUG-17 08.00.00.325755000 PM +00:00  TRUE                 1\nSTATSPACK_PURGE_1  SCHEDULED  TRUE     27-AUG-17 12.00.00.074939000 PM +00:00  TRUE                 1\nSTATSPACK_SNAP_2   SCHEDULED  TRUE     23-AUG-17 08.00.00.644681000 PM +00:00  TRUE                 2\nSTATSPACK_PURGE_2  SCHEDULED  TRUE     27-AUG-17 12.00.00.755685000 PM +00:00  TRUE                 2\n<\/code><\/pre>\n<p>Now running a spreport to see the instances having snapshots:<\/p>\n<pre><code>\n[oracle@rac-dg01-1 admin]$ TWO_TASK=\/\/10.31.143.86\/pdb1.a511644.oraclecloud.internal\/cdb12 sqlplus sys\/\"Ach1z0#d\" as sysdba @ spreport\n&nbsp;\nInstances in this Statspack schema\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n&nbsp;\n   DB Id    Inst Num DB Name      Instance     Host\n----------- -------- ------------ ------------ ------------\n  924704606        2 CDB1         cdb12        rac-dg01-2\n  924704606        1 CDB1         cdb11        rac-dg01-1\n&nbsp;\nUsing  924704606 for database Id\nUsing          2 for instance number\n<\/code><\/pre>\n<p>Here it is. dbms_job is deprecated. Let&#8217;s use dbms_scheduler.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . I&#8217;ve published a few month ago an article in the UKOUG OracleScene magazine on Improving Statspack Experience: quick setup script, changing settings, filling Idle Events,etc. In the article, I used dbms_job to schedule the snapshots, because I have this script for years and never took the time to do it with [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[59],"tags":[96,69],"type_dbi":[],"class_list":["post-10452","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-oracle","tag-statspack"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Improving Statspack Experience - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Improving Statspack Experience\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . I&#8217;ve published a few month ago an article in the UKOUG OracleScene magazine on Improving Statspack Experience: quick setup script, changing settings, filling Idle Events,etc. In the article, I used dbms_job to schedule the snapshots, because I have this script for years and never took the time to do it with [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-23T17:41:01+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Improving Statspack Experience\",\"datePublished\":\"2017-08-23T17:41:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\"},\"wordCount\":158,\"commentCount\":0,\"keywords\":[\"Oracle\",\"Statspack\"],\"articleSection\":[\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\",\"name\":\"Improving Statspack Experience - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2017-08-23T17:41:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Improving Statspack Experience\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Improving Statspack Experience - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/","og_locale":"en_US","og_type":"article","og_title":"Improving Statspack Experience","og_description":"By Franck Pachot . I&#8217;ve published a few month ago an article in the UKOUG OracleScene magazine on Improving Statspack Experience: quick setup script, changing settings, filling Idle Events,etc. In the article, I used dbms_job to schedule the snapshots, because I have this script for years and never took the time to do it with [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/","og_site_name":"dbi Blog","article_published_time":"2017-08-23T17:41:01+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Improving Statspack Experience","datePublished":"2017-08-23T17:41:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/"},"wordCount":158,"commentCount":0,"keywords":["Oracle","Statspack"],"articleSection":["Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/","url":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/","name":"Improving Statspack Experience - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2017-08-23T17:41:01+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/improving-statspack-experience\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Improving Statspack Experience"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/10452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=10452"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/10452\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=10452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=10452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=10452"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=10452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}