{"id":280,"date":"2023-02-01T15:38:25","date_gmt":"2023-02-01T14:38:25","guid":{"rendered":"https:\/\/oracledba.fr\/?p=280"},"modified":"2023-02-01T15:40:26","modified_gmt":"2023-02-01T14:40:26","slug":"shrink-oracle-tablespace","status":"publish","type":"post","link":"https:\/\/oracledba.fr\/?p=280","title":{"rendered":"Shrink oracle tablespace"},"content":{"rendered":"\n<p>It is possible to resize a tablespace datafile is there is some free space at the end of the datafile. This is the quick and easy method. If you have data at the end of the datafile, you will need to move the objects so that segment will be recreated.<\/p>\n\n\n\n<p>View tablespace size with free space<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color\"><code lang=\"sql\" class=\"language-sql\">select  df.tablespace_name \"Tablespace\", df.totalspace \"Total MB\", totalusedspace \"Used MB\", (df.totalspace - tu.totalusedspace) \"Free MB\", round(100 * ( (df.totalspace - tu.totalusedspace)\/ df.totalspace)) \"Pct. Free\" from (select tablespace_name, round(sum(bytes) \/ 1048576) TotalSpace from dba_data_files group by tablespace_name) df, (select round(sum(bytes)\/(1024*1024)) totalusedspace, tablespace_name from dba_segments group by tablespace_name) tu where df.tablespace_name = tu.tablespace_name order by 2 desc ;<\/code><\/pre>\n\n\n\n<p>Generate command to reduce tablespace (specify block size and tablespace name)<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color\"><code lang=\"sql\" class=\"language-sql\">select 'alter database datafile '''||file_name||''' resize ' ||\r\nceil( (nvl(hwm,1)*&amp;&amp;blksize)\/1024\/1024 ) || 'm;' cmd\r\nfrom dba_data_files a,\r\n( select file_id, max(block_id+blocks-1) hwm\r\nfrom dba_extents where tablespace_name= '&amp;&amp;tbs_name' \r\ngroup by file_id ) b\r\nwhere a.file_id = b.file_id(+) and a.tablespace_name= '&amp;&amp;tbs_name'\r\nand ceil( blocks*&amp;&amp;blksize\/1024\/1024) -\r\nceil( (nvl(hwm,1)*&amp;&amp;blksize)\/1024\/1024 ) > 0;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to resize a tablespace datafile is there is some free space at the end of the datafile. This is the quick and easy method. If you have data at the end of the datafile, you will need to move the objects so that segment will be recreated. View tablespace size with free &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/oracledba.fr\/?p=280\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Shrink oracle tablespace&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/oracledba.fr\/index.php?rest_route=\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oracledba.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oracledba.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oracledba.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oracledba.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280"}],"version-history":[{"count":2,"href":"https:\/\/oracledba.fr\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":283,"href":"https:\/\/oracledba.fr\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions\/283"}],"wp:attachment":[{"href":"https:\/\/oracledba.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oracledba.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oracledba.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}