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ńskiAug 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 MarloweAug 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 RingerAug 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 RingerAug 11 '17 at 01:17
@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 RingerNov 19 '20 at 06:20