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.
@Ł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.
initdba whole new DB in a tempfs. Never advise people to put tablespaces in temporary storage.