<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>spilling disk &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/spilling-disk/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Thu, 02 Feb 2017 03:15:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL: Improve the performance of Query Sort operation by setting work_mem</title>
		<link>https://www.dbrnd.com/2017/02/postgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 03 Feb 2017 16:16:45 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Sort Operation]]></category>
		<category><![CDATA[spilling disk]]></category>
		<category><![CDATA[work_mem]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4452</guid>

					<description><![CDATA[Yesterday, I was doing performance tuning for one our long running queries. I have checked the execution plan of the query and found that query sort operations are spilling to disk instead of fitting in memory. Every time, just tuning the Table Indexes should not be the ultimate solution to improve the query performance. There [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&amp;linkname=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem%2F&#038;title=PostgreSQL%3A%20Improve%20the%20performance%20of%20Query%20Sort%20operation%20by%20setting%20work_mem" data-a2a-url="https://www.dbrnd.com/2017/02/postgresql-improve-the-performance-of-query-sort-operation-by-setting-work_mem/" data-a2a-title="PostgreSQL: Improve the performance of Query Sort operation by setting work_mem"></a></p><p>Yesterday, I was doing performance tuning for one our long running queries. I have checked the execution plan of the query and found that query sort operations are spilling to disk instead of fitting in memory. </p>
<p>Every time, just tuning the Table Indexes should not be the ultimate solution to improve the query performance. </p>
<p>There are always N factors behind the bad performance shape of your query. </p>
<p><strong>How can you know that your operations are spilling to disk?</strong></p>
<blockquote><p>When you execute EXPLAIN ANALYZE for your query and if you see a line like <code>Sort Method: external merge Disk: 88342kB</code>, your operations are spilling to disk.</p></blockquote>
<p><strong>Is spilling to disk a bad operation?</strong></p>
<blockquote><p>Yes: Because it requires more CPU/IO for the disk operation and it leads to biggest performance cause.</p></blockquote>
<p><strong>What is the solution?</strong></p>
<blockquote><p>The simple solution is, validate the configuration of a work_mem parameter.<br />
If you do a lot of complex sorts and have a lot of memory, then increasing the work_mem parameter allows PostgreSQL to do larger in-memory sorts which, unsurprisingly, will be faster than disk-based equivalents.</p></blockquote>
<p><strong>How can you configure work_mem?</strong></p>
<blockquote><p>A work_mem of at least 16MB would keep the intermediate data in memory and likely improve the query response time.<br />
You can set at the server level for the general use (in postgresql.conf). </p>
<p>You can also set at your session level using below sample query. Increase the setting until you see Memory instead of Disk in the EXPLAIN output.</p></blockquote>
<pre class="crayon-plain-tag">BEGIN;

SET LOCAL work_mem = '50MB';

SELECT *FROM Table_Name;

COMMIT;</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
