Skip to content

Instantly share code, notes, and snippets.

@dnagir
Forked from freshtonic/gist:1390291
Created January 7, 2012 01:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save dnagir/1573414 to your computer and use it in GitHub Desktop.
Save dnagir/1573414 to your computer and use it in GitHub Desktop.
Run Postgres Specs in Ramdisk
  • This creates a 560mb ramdisk. Adjust the size accordingly. I think the number at the end of the command is the number of disk blocks. They are 2kb in size for me.
  • Restarting postgres is not necessary; you can create the ramdisk and tablespace while postgres is running.
  • You will lose all data in the ramdisk tablespace when you shut your machine down

  $ diskutil erasevolume HFS+ "postgres_ramdisk" `hdiutil attach -nomount ram://1165430`
  Started erase on disk1
  Unmounting disk
  Erasing
  Initialized /dev/rdisk1 as a 569 MB HFS Plus volume
  Mounting disk
  Finished erase on disk1 postgres_ramdisk
  $ sudo chown -R $(whoami) /Volumes/postgres_ramdisk/
  $ dropdb westfield_test
  $ bundle exec script/dbconsole
  psql> create tablespace foo_ramdisk location '/Volumes/postgres_ramdisk';
  psql> create database foo_test tablespace = foo_ramdisk;
  psql> \q
  $ time bundle exec rake spec

Also, update your config/database.yml to include the tablespace declaration:


test:
  adapter: postgresql
  database: foo_test
  tablespace: foo_ramdisk
  host: localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment