Does PostgreSQL have an equivalent of MySQL memory tables?
PostgreSQL有相同的MySQL内存表吗?
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.
这些MySQL内存表可以跨会话持续存在(即,与会话结束时丢弃的临时表不同)。我无法找到任何可以做同样事情的PostgreSQL。
2 个解决方案
#1
30
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.
不,目前它们在PostgreSQL中不存在。如果你真的需要一个内存表,你可以创建一个RAM磁盘,为它添加一个表空间,并在其上创建表。
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.
如果只需要在不同会话之间可见的临时表,则可以使用UNLOGGED表。这些不是真正的内存表,但当表数据明显小于系统RAM时,它们的行为会出乎意料地类似。
Global temporary tables would be another option but are not supported in PostgreSQL as of 9.2 (see comments).
全局临时表将是另一种选择,但在9.2版本的PostgreSQL中不受支持(参见注释)。
#2
9
Answering a four year old question but since it comes on top of google search results even now.
回答了一个有四年历史的问题但是现在它仍然是google搜索结果。
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.
优点是表存储在postgres shared_buffers中,因此在执行查询时,postgres立即感知页面在内存中并从那里获取。
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.
缺点是shared_buffers实际上并不是设计为以这种方式运行并且可能发生不稳定性(通常它不会),但是你可以在具有这种配置的辅助集群/机器中使用它来保证安全。
All other usual caveats about postgres and shared_buffers still apply.
关于postgres和shared_buffers的所有其他常见警告仍然适用。
#1
30
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.
不,目前它们在PostgreSQL中不存在。如果你真的需要一个内存表,你可以创建一个RAM磁盘,为它添加一个表空间,并在其上创建表。
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.
如果只需要在不同会话之间可见的临时表,则可以使用UNLOGGED表。这些不是真正的内存表,但当表数据明显小于系统RAM时,它们的行为会出乎意料地类似。
Global temporary tables would be another option but are not supported in PostgreSQL as of 9.2 (see comments).
全局临时表将是另一种选择,但在9.2版本的PostgreSQL中不受支持(参见注释)。
#2
9
Answering a four year old question but since it comes on top of google search results even now.
回答了一个有四年历史的问题但是现在它仍然是google搜索结果。
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.
优点是表存储在postgres shared_buffers中,因此在执行查询时,postgres立即感知页面在内存中并从那里获取。
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.
缺点是shared_buffers实际上并不是设计为以这种方式运行并且可能发生不稳定性(通常它不会),但是你可以在具有这种配置的辅助集群/机器中使用它来保证安全。
All other usual caveats about postgres and shared_buffers still apply.
关于postgres和shared_buffers的所有其他常见警告仍然适用。