<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.hacks.be/wiki/index.php?action=history&amp;feed=atom&amp;title=Reclaiming_free_space_in_datafiles</id>
	<title>Reclaiming free space in datafiles - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.hacks.be/wiki/index.php?action=history&amp;feed=atom&amp;title=Reclaiming_free_space_in_datafiles"/>
	<link rel="alternate" type="text/html" href="https://www.hacks.be/wiki/index.php?title=Reclaiming_free_space_in_datafiles&amp;action=history"/>
	<updated>2026-04-30T13:14:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://www.hacks.be/wiki/index.php?title=Reclaiming_free_space_in_datafiles&amp;diff=94&amp;oldid=prev</id>
		<title>Tom at 15:00, 30 May 2016</title>
		<link rel="alternate" type="text/html" href="https://www.hacks.be/wiki/index.php?title=Reclaiming_free_space_in_datafiles&amp;diff=94&amp;oldid=prev"/>
		<updated>2016-05-30T15:00:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:00, 30 May 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l33&quot; &gt;Line 33:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 33:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Use rang &amp;lt; 11 to see the 10 last segments for each datafile.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Use rang &amp;lt; 11 to see the 10 last segments for each datafile.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Rebuild statements:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;source lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;alter table TABLE_NAME move;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;alter index INDEX_NAME rebuild online;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;alter index INDEX_NAME rebuild partition PARTITION online;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/source&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Tom</name></author>
	</entry>
	<entry>
		<id>https://www.hacks.be/wiki/index.php?title=Reclaiming_free_space_in_datafiles&amp;diff=93&amp;oldid=prev</id>
		<title>Tom: Created page with &quot;See the amount of free space in each datafile: &lt;source lang=&quot;sql&quot;&gt; select df.file_name, round(max(df.bytes) / 1048576) file_mb, round(sum(dfs.bytes) / 1048576) file_free_mb...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.hacks.be/wiki/index.php?title=Reclaiming_free_space_in_datafiles&amp;diff=93&amp;oldid=prev"/>
		<updated>2016-05-30T12:21:10Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;See the amount of free space in each datafile: &amp;lt;source lang=&amp;quot;sql&amp;quot;&amp;gt; select df.file_name, round(max(df.bytes) / 1048576) file_mb, round(sum(dfs.bytes) / 1048576) file_free_mb...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;See the amount of free space in each datafile:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
select df.file_name, round(max(df.bytes) / 1048576) file_mb, round(sum(dfs.bytes) / 1048576) file_free_mb&lt;br /&gt;
  from dba_data_files df&lt;br /&gt;
     , dba_free_space dfs&lt;br /&gt;
 where df.tablespace_name = &amp;#039;&amp;lt;tablespace_name&amp;gt;&amp;#039;&lt;br /&gt;
   and dfs.file_id = df.file_id&lt;br /&gt;
 group by df.file_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What is the last block and how much can we shrink a datafile?&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
select file_name, owner, segment_name, partition_name, segment_type, round(file_bytes / 1048576) data_file_mb, round((block_id + blocks) * block_size / 1048576) object_end_mb&lt;br /&gt;
     , &amp;#039;alter database datafile &amp;#039;&amp;#039;&amp;#039; || file_name || &amp;#039;&amp;#039;&amp;#039; resize &amp;#039; || round((block_id + blocks) * block_size / 1048576) || &amp;#039;M;&amp;#039;&lt;br /&gt;
  from (&lt;br /&gt;
select df.file_name file_name&lt;br /&gt;
     , df.bytes file_bytes&lt;br /&gt;
     , rank() over (partition by df.file_name order by block_id desc) rang&lt;br /&gt;
     , de.owner&lt;br /&gt;
     , de.segment_name&lt;br /&gt;
     , de.partition_name&lt;br /&gt;
     , de.segment_type&lt;br /&gt;
     , de.block_id&lt;br /&gt;
     , de.blocks&lt;br /&gt;
     , ts.block_size&lt;br /&gt;
  from dba_data_files df&lt;br /&gt;
     , dba_extents de&lt;br /&gt;
     , dba_tablespaces ts&lt;br /&gt;
 where df.tablespace_name = &amp;#039;&amp;lt;tablespace_name&amp;gt;&amp;#039;&lt;br /&gt;
   and de.file_id = df.file_id&lt;br /&gt;
   and ts.tablespace_name = df.tablespace_name)&lt;br /&gt;
where rang &amp;lt; 2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Use rang &amp;lt; 11 to see the 10 last segments for each datafile.&lt;/div&gt;</summary>
		<author><name>Tom</name></author>
	</entry>
</feed>