PostgreSQL equivalent of MySQL memory tables?

北战南征 提交于 2020-02-17 06:58:06

问题


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.


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/11729690/postgresql-equivalent-of-mysql-memory-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!