0

Is it possible to configure PostgreSQL to run in-memory like H2 database?

I need this only in unit/integration tests.

Romper
  • 2,009
  • 3
  • 24
  • 43
  • You can create tablespace pointing to tmpfs or alternative RAM filesystem. Not sure if this is what you want. Only objects (tables, indexes, etc.) pointing to that tablespace will be stored in memory. – Łukasz Kamiński Aug 10 '17 at 13:51
  • You can also set PGDATA to a ramfs then initdb the db there. It'll all disappear when you reboot etc. – Scott Marlowe Aug 10 '17 at 16:30
  • 1
    @ŁukaszKamiński No, terrible advice, do not do that. Instead `initdb` a whole new DB in a tempfs. *Never* advise people to put tablespaces in temporary storage. – Craig Ringer Aug 11 '17 at 01:16
  • Downvoted due to obvious lack of effort with basic search before asking. https://stackoverflow.com/q/7872693/398670, https://stackoverflow.com/q/21288667/398670, https://stackoverflow.com/q/11764487/398670, ... – Craig Ringer Aug 11 '17 at 01:17
  • also https://stackoverflow.com/q/9407442/398670 – Craig Ringer Aug 11 '17 at 01:21
  • @CraigRinger what about local tests? – fider Nov 17 '20 at 11:40
  • @fider You can do it if you want, but it's pretty pointless. You can `initdb` a new db in a `tempfs` (Linux) which is much the same. But on a modern platform, you should see minimal performance difference if you `initdb` a throwaway instance on your regular file system instead, and run it with durability settings turned off - `fsync=off`, `synchronous_commit=off`, etc. The OS should keep most of it in memory anyway. When I test I see minimal performance difference between using a true ramdisk, a tempfs, or a non-durable postgres on real storage. – Craig Ringer Nov 19 '20 at 06:20

0 Answers0