Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimise PostgreSQL for fast testing
    primarykey
    data
    text
    <p>I am switching to PostgreSQL from SQLite for a typical Rails application.</p> <p>The problem is that running specs became slow with PG.<br> On SQLite it took ~34 seconds, on PG it's ~76 seconds which is <strong>more than 2x slower</strong>.</p> <p>So now I want to apply some techniques to <strong>bring the performance of the specs on par with SQLite</strong> with no code modifications (ideally just by setting the connection options, which is probably not possible).</p> <p>Couple of obvious things from top of my head are:</p> <ul> <li>RAM Disk (good setup with RSpec on OSX would be good to see)</li> <li>Unlogged tables (can it be applied on the whole database so I don't have change all the scripts?)</li> </ul> <p>As you may have understood I don't care about reliability and the rest (the DB is just a throwaway thingy here).<br> I need to get the most out of the PG and make it <strong>as fast as it can possibly be</strong>.</p> <p><strong>Best answer</strong> would ideally describe the <em>tricks</em> for doing just that, setup and the drawbacks of those tricks.</p> <p><strong>UPDATE:</strong> <code>fsync = off</code> + <code>full_page_writes = off</code> only decreased time to ~65 seconds (~-16 secs). Good start, but far from the target of 34.</p> <p><strong>UPDATE 2:</strong> I <a href="https://gist.github.com/1573414" rel="noreferrer">tried to use RAM disk</a> but the performance gain was within an error margin. So doesn't seem to be worth it.</p> <p><strong>UPDATE 3:*</strong> I found the biggest bottleneck and now my specs run as fast as the SQLite ones.</p> <p>The issue was the database cleanup that did the <strong>truncation</strong>. Apparently SQLite is way too fast there.</p> <p>To "fix" it I open a <strong>transaction</strong> before each test and roll it back at the end.</p> <p>Some numbers for ~700 tests.</p> <ul> <li>Truncation: SQLite - 34s, PG - 76s.</li> <li>Transaction: SQLite - 17s, PG - 18s.</li> </ul> <p>2x speed increase for SQLite. 4x speed increase for PG.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload