{"id":141,"date":"2012-03-10T00:49:32","date_gmt":"2012-03-09T22:49:32","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=141"},"modified":"2013-11-11T11:07:53","modified_gmt":"2013-11-11T09:07:53","slug":"mass-datafile-resizing","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/mass-datafile-resizing\/","title":{"rendered":"Mass datafile resizing"},"content":{"rendered":"<p>Recently I needed to extend many datafiles on a database with more than 500 tablespaces because a lot of tablespaces were reaching the critical threshold.<br \/>\nAutoextend was not an option due to a bug I encountered on 10gR2 RAC on ASM and AIX.<\/p>\n<p>The solution was the following script: it generates statements to autoextend datafiles with usage over a defined threshold (the &#8220;80&#8221; in the where clause) to low down the percentage below another defined threshold (the &#8220;75&#8221; in the select clause).<\/p>\n<pre lang=\"SQL\">\r\nSELECT 'alter database datafile '''||f.file_name||\r\n''' resize '||round(ceil(bytes\/1024\/1024\/75*t.pct_used+50),-2)||'M;'\r\n FROM\r\n   dba_data_files f, (\r\n   SELECT  a.tablespace_name tablespace_name, a.total mb_total, nvl(b.free,0) mb_free,\r\n          round((a.total-nvl(b.free,0))*100\/a.total) pct_used\r\n  FROM    (SELECT tablespace_name,round(sum(bytes)\/1024\/1024) free, max(bytes) maxfree\r\n          FROM dba_free_space GROUP BY tablespace_name) b,\r\n          (SELECT tablespace_name,decode(round(sum(bytes)\/1024\/1024),0,1,round(sum(bytes)\/1024\/1024)) total\r\n          FROM dba_data_files GROUP BY tablespace_name) a\r\n  WHERE a.tablespace_name = b.tablespace_name (+)) t  WHERE t.tablespace_name=f.tablespace_name\r\n  AND t.pct_used>80;\r\n  <\/pre>\n<p> Prior to extend it&#8217;s possible to show how much space is required to do this mass resizing:<\/p>\n<pre lang=\"SQL\">\r\n SELECT sum(mb_new-mb_old) FROM (\r\n  SELECT t.tablespace_name, f.file_name, bytes\/1024\/1024 mb_old, round(ceil(bytes\/1024\/1024\/75*t.pct_used+50),-2) mb_new FROM\r\n dba_data_files f, (\r\n SELECT  a.tablespace_name tablespace_name, a.total mb_total, nvl(b.free,0) mb_free,\r\n        round((a.total-nvl(b.free,0))*100\/a.total) pct_used\r\nFROM    (SELECT tablespace_name,round(sum(bytes)\/1024\/1024) free, max(bytes) maxfree\r\n        FROM dba_free_space GROUP BY tablespace_name) b,\r\n        (SELECT tablespace_name,decode(round(sum(bytes)\/1024\/1024),0,1,round(sum(bytes)\/1024\/1024)) total\r\n        FROM dba_data_files GROUP BY tablespace_name) a\r\nWHERE a.tablespace_name = b.tablespace_name (+)) t  WHERE t.tablespace_name=f.tablespace_name\r\nAND t.pct_used>80);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I needed to extend many datafiles on a database with more than 500 tablespaces because a lot of tablespaces were reaching the critical threshold. Autoextend was not an option due to a bug I encountered on 10gR2 RAC on &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/mass-datafile-resizing\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,132],"tags":[40,43,30,9,22,10],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-oracledb","category-triblog","tag-asm","tag-autoextend","tag-capacity-planning","tag-oracle","tag-oracle-database","tag-sqlplus"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":3,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/141\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}