It's possible with a ramdisk, but it's really inefficient. You'll have at least two, usually three, copies of data in RAM - the ramdisk, the OS buffers/cache, and PostgreSQL's shared_buffers
.
What you should do instead is allocate disk space for it anyway, but set Linux's dirty writeback thresholds very high, turn fsync off in PostgreSQL, use unlogged
tables, and basically let it run in non-crashsafe mode almost entirely from RAM.
Let the OS be smart about it - it can still write and flush data lazily, making more room in RAM.
If you feel you truly need an in-RAM database, you'd be better off finding one that's designed to work that way. But it's pretty rare to really need it.