PostgreSQL equivalent of MySQL memory tables?
Asked Answered
V

2

43

Does PostgreSQL have an equivalent of MySQL memory tables?

These MySQL memory tables can persist across sessions (i.e., different from temporary tables which drop at the end of the session). I haven't been able to find anything with PostgreSQL that can do the same.

Valletta answered 30/7, 2012 at 21:14 Comment(2)
possible duplicate of in-memory table in PostgreSQLViridissa
I'd say this is not a duplicate. A MySQL memory table refers to something more specific than a table that is merely created on a RAM disk: dev.mysql.com/doc/refman/5.5/en/memory-storage-engine.htmlValletta
Y
47

No, at the moment they don't exist in PostgreSQL. If you truly need a memory table you can create a RAM disk, add a tablespace for it, and create tables on it.

If you only need the temporary table that is visible between different sessions, you can use an UNLOGGED table. These are not true memory tables but they'll behave surprisingly similarly when the table data is significantly smaller than the system RAM.

Global temporary tables would be another option but are not supported in PostgreSQL as of 9.2 (see comments).

Yoon answered 30/7, 2012 at 21:24 Comment(7)
We've been talking about adding global temporary tables in 9.3 as a new feature. In existing releases the keyword is accepted, but ignored. The closest you can come in PostgreSQL is an UNLOGGED table. postgresql.org/docs/current/interactive/sql-createtable.htmlAnnatto
Oh, i didn't know it is ignored now ... Thank you, i thought was already working. Thanks .Yoon
Updated answer to reflect @kgrittn's comments. Hope that's OK. Added some docs links too.Inconstant
Also it looks like Postgresql [v10 will provide][1] Pluggable storage engine (columnar, in-memory, etc) [1]: infoq.com/news/2017/04/postgresql-10-featuresToaster
The docs say that you should NOT use transient storage for a tablespace... "The location must not be on removable or transient storage, as the cluster might fail to function if the tablespace is missing or lost."Barker
Isn't that feature added yet? On SQL Server, Microsoft even added a persisted in-memory table implementation called "in-memory OLTP"!Daysidayspring
Probably not fully in memory, but depending on the temp_buffers configuration, temporary tables should be mostly in memory, if I don't get it wrong. See also my answer here.Reviere
C
20

Answering a four year old question but since it comes on top of google search results even now.

There is no built in way to cache a full table in memory, but there is an extension that can do this.

In Memory Column Store is a library that acts as a drop in extension and also as a columnar storage and execution engine. You can refer here for the documentation. There is a load function that you can use to load the entire table into memory.

The advantage is the table is stored inside postgres shared_buffers, so when executing a query postgres immediately senses that the pages are in memory and fetches from there.

The downside is that shared_buffers is not really designed to operate in such a way and instabilities might occur (usually it doesn't), but you can probably have this in a secondary cluster/machine with this configuration just to be safe.

All other usual caveats about postgres and shared_buffers still apply.

Culet answered 6/1, 2016 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.