{"id":1286,"date":"2018-07-05T06:17:49","date_gmt":"2018-07-05T05:17:49","guid":{"rendered":"https:\/\/dbafox.com\/?p=1286"},"modified":"2018-07-10T06:30:13","modified_gmt":"2018-07-10T05:30:13","slug":"oracle-monitor-temp-tablespace","status":"publish","type":"post","link":"https:\/\/dbafox.com\/?p=1286","title":{"rendered":"Oracle &#8211; Monitor TEMP Tablespace"},"content":{"rendered":"<h2>Monitor TEMP Tablespace with a DBMS_SCHEDULER job<\/h2>\n<p>I was faced with a situation in which a process (Oracle pl\/sql procedure within a package, scheduled outside Oracle in the evenings) was exhausting the TEMP tablespace. In order to investigate, the following procedure was used to monitor TEMP tablespace usage during the period of time the job was executed. This allowed quick identification of the offending user and SQL that was causing TEMP tablesace exhaustion.<\/p>\n<p>Code is quick and dirty, no exception handling. I&#8217;m assuming the executing user has all the required privileges. There are other ways to investigate this, but this works.<\/p>\n<h3>Create a table to store data<\/h3>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE TABLE TEMPDATA\r\n(\r\n  CTIME       TIMESTAMP(6) WITH TIME ZONE,\r\n  TABLESPACE  VARCHAR2(30),\r\n  TEMP_SIZE   VARCHAR2(41),\r\n  INSTANCE    NUMBER,\r\n  SID_SERIAL  VARCHAR2(81),\r\n  USERNAME    VARCHAR2(30),\r\n  PROGRAM     VARCHAR2(48),\r\n  STATUS      VARCHAR2(8),\r\n  SQL_ID      VARCHAR2(13)\r\n)\r\n<\/pre>\n<h3>Create the procedure<\/h3>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE OR REPLACE procedure colltempdata as\r\nbegin\r\n\r\nbegin\r\n    insert into tempdata\r\n    SELECT systimestamp ctime,\r\n           b.tablespace,\r\n           ROUND(((b.blocks*p.value)\/1024\/1024),2)||'M' AS temp_size,\r\n           a.inst_id as Instance,\r\n           a.sid||','||a.serial# AS sid_serial,\r\n           NVL(a.username, '(oracle)') AS username,\r\n           a.program,\r\n           a.status,\r\n           a.sql_id\r\n    FROM   sys.gv$session a,\r\n           sys.gv$sort_usage b,\r\n           sys.gv$parameter p\r\n    WHERE  p.name  = 'db_block_size'\r\n    AND    a.saddr = b.session_addr\r\n    AND    a.inst_id=b.inst_id\r\n    AND    a.inst_id=p.inst_id;\r\nend;\r\n\r\nend;\r\n\/\r\n<\/pre>\n<h3>Create a job to execute the procedure<\/h3>\n<p>In this example, execute every minute for a specfied time period<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nbegin\r\n    DBMS_SCHEDULER.CREATE_JOB (\r\n         job_name             =&gt; 'colltempdatajob6',\r\n         job_type             =&gt; 'PLSQL_BLOCK',\r\n         job_action           =&gt; 'begin colltempdata;commit;end;',\r\n         start_date           =&gt; timestamp '2018-07-04 21:30:00',\r\n         repeat_interval      =&gt; 'FREQ=MINUTELY;INTERVAL=1;',\r\n         end_date             =&gt; timestamp '2018-07-04 22:45:00',\r\n         enabled              =&gt; TRUE);\r\nend;\r\n<\/pre>\n<h3>SQL to display jobs, check size of data, and query the collected data<\/h3>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n-- display job details\r\nselect job_name, start_date, run_count, last_start_date, next_run_date  from dba_scheduler_jobs where job_name like 'COLLTEMPDATAJOB%' order by start_date\r\n\r\n-- check size of data\r\nselect sum(bytes)\/1024\/1024\/1024 from dba_segments where segment_name = 'TEMPDATA'\r\n\r\n-- Query data collected\r\nselect * from tempdata order by ctime desc\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Monitor TEMP Tablespace with a DBMS_SCHEDULER job I was faced with a situation in which a process (Oracle pl\/sql procedure within a package, scheduled outside Oracle in the evenings) was exhausting the TEMP tablespace. In order to investigate, the following &hellip; <a href=\"https:\/\/dbafox.com\/?p=1286\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28,1],"tags":[],"class_list":["post-1286","post","type-post","status-publish","format-standard","hentry","category-oracle-technical","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Oracle - Monitor TEMP Tablespace - dbafox<\/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:\/\/dbafox.com\/?p=1286\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle - Monitor TEMP Tablespace - dbafox\" \/>\n<meta property=\"og:description\" content=\"Monitor TEMP Tablespace with a DBMS_SCHEDULER job I was faced with a situation in which a process (Oracle pl\/sql procedure within a package, scheduled outside Oracle in the evenings) was exhausting the TEMP tablespace. In order to investigate, the following &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbafox.com\/?p=1286\" \/>\n<meta property=\"og:site_name\" content=\"dbafox\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-05T05:17:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-07-10T05:30:13+00:00\" \/>\n<meta name=\"author\" content=\"Ray Fox\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ray Fox\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbafox.com\/?p=1286\",\"url\":\"https:\/\/dbafox.com\/?p=1286\",\"name\":\"Oracle - Monitor TEMP Tablespace - dbafox\",\"isPartOf\":{\"@id\":\"https:\/\/dbafox.com\/#website\"},\"datePublished\":\"2018-07-05T05:17:49+00:00\",\"dateModified\":\"2018-07-10T05:30:13+00:00\",\"author\":{\"@id\":\"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb\"},\"breadcrumb\":{\"@id\":\"https:\/\/dbafox.com\/?p=1286#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbafox.com\/?p=1286\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbafox.com\/?p=1286#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbafox.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle &#8211; Monitor TEMP Tablespace\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbafox.com\/#website\",\"url\":\"https:\/\/dbafox.com\/\",\"name\":\"dbafox\",\"description\":\"DBA Technical Information\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbafox.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb\",\"name\":\"Ray Fox\",\"sameAs\":[\"http:\/\/www.dbafox.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Oracle - Monitor TEMP Tablespace - dbafox","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:\/\/dbafox.com\/?p=1286","og_locale":"en_GB","og_type":"article","og_title":"Oracle - Monitor TEMP Tablespace - dbafox","og_description":"Monitor TEMP Tablespace with a DBMS_SCHEDULER job I was faced with a situation in which a process (Oracle pl\/sql procedure within a package, scheduled outside Oracle in the evenings) was exhausting the TEMP tablespace. In order to investigate, the following &hellip; Continue reading &rarr;","og_url":"https:\/\/dbafox.com\/?p=1286","og_site_name":"dbafox","article_published_time":"2018-07-05T05:17:49+00:00","article_modified_time":"2018-07-10T05:30:13+00:00","author":"Ray Fox","twitter_misc":{"Written by":"Ray Fox","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dbafox.com\/?p=1286","url":"https:\/\/dbafox.com\/?p=1286","name":"Oracle - Monitor TEMP Tablespace - dbafox","isPartOf":{"@id":"https:\/\/dbafox.com\/#website"},"datePublished":"2018-07-05T05:17:49+00:00","dateModified":"2018-07-10T05:30:13+00:00","author":{"@id":"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb"},"breadcrumb":{"@id":"https:\/\/dbafox.com\/?p=1286#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbafox.com\/?p=1286"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dbafox.com\/?p=1286#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbafox.com\/"},{"@type":"ListItem","position":2,"name":"Oracle &#8211; Monitor TEMP Tablespace"}]},{"@type":"WebSite","@id":"https:\/\/dbafox.com\/#website","url":"https:\/\/dbafox.com\/","name":"dbafox","description":"DBA Technical Information","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbafox.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/dbafox.com\/#\/schema\/person\/287adc474c1aebd398752ac4dcfe27eb","name":"Ray Fox","sameAs":["http:\/\/www.dbafox.com"]}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3ecMb-kK","_links":{"self":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts\/1286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1286"}],"version-history":[{"count":10,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1296,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/posts\/1286\/revisions\/1296"}],"wp:attachment":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}