In-memory table in PostgreSQL

那年仲夏 提交于 2019-11-30 08:46:08

Create a RAM disk using software appropriate to your OS. Use CREATE TABLESPACE to create a DB cluster on the RAM disk. When you create your table, use the TABLESPACE clause. Obviously, your RAM tables will not persist across system reboots unless you save the RAM disk.

Well, it's not technically a in memory table, but, you can create a global temporary table:

create global temporary table foo (a char(1));

It's not guaranteed that it will remain in memory the whole time, but it probably will (unless is a huge table).

You can also consider PostgreSQL 9.1's unlogged tables, which will give you better performance at the cost of not being able to be part of transactions (their write operations are not maintained in WAL).

You can also consider PostgreSQL 9.1's unlogged tables, which will give you better performance at the cost of not being able to be part of transactions (their write operations are not maintained in WAL).

from @PabloSantaCruz

sample from https://www.compose.com/articles/faster-performance-with-unlogged-tables-in-postgresql/

CREATE UNLOGGED TABLE "EUR/USD_ticks"  
(
  dt timestamp without time zone NOT NULL,
  bid numeric NOT NULL,
  ask numeric NOT NULL,
  bid_vol numeric,
  ask_vol numeric,
  CONSTRAINT "EUR/USD_ticks_pkey" PRIMARY KEY (dt)
)

I plan to try this, and thought it deserved it's own answer for users to vote on this option (i.e. the "long tail").

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