I need to create a table for caching in the postgresql database. Transactions should be as fast as possible, so i thought of creating unlogged table and have a RAM disk as it's tablespace.

There is a warning in the official postgresql documentation:

Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster.

I know that unlogged tables are not replicate to the standby and it is okay for me to store unpersistent data in that table. So in case of crash i'm fine with losing it. Here is a questions:

  1. Is it safe after all to place a tablespace on the RAM disk in this configuration? (unlogged + RAM disk tablespace + unpersistent data)
  2. If it is a safe option should I create ram disk on a replica too, since creation of tablespace will be stored somewhere in wal?

I'm using EDB 13.9.13 with streaming replication. If this will workout I will do the same for Postgresql v14.7

1 Answer 1


No, that is not OK. After a restart of the machine, you will get nasty errors when you try to access the table. You can probably drop and re-create the table if you get nasty errors, but how would you reliably distinguish these nasty errors from other nasty errors that really are a problem?

I think that this is an overzealous attempt to optimize something that doesn't need it. Just give your machine enough RAM, then the unlogged table will be cached in RAM anyway if it is used often enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.