postgresql 将 postgres 完全保存在内存中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17736102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:01:37  来源:igfitidea点击:

Keeping postgres entirely in memory

postgresql

提问by bevanb

I am running various tests that spend a lot of time in the database.

我正在运行在数据库中花费大量时间的各种测试。

I'd like to keep it all in memory and have it not touch the db, hopefully that would speed things up. Like using sqlite3's in-memory option. I don't need persistence/durability/whatnot, everything is immediately discarded after the test.

我想把它全部保存在内存中,并且不接触数据库,希望这会加快速度。就像使用 sqlite3 的内存选项一样。我不需要持久性/耐用性/诸如此类,测试后立即丢弃所有内容。

Is that possible? I tried tweaking my postgres memory-related vars (as in the solution below), but that doesn't seem to affect the number of db writes it performs, and I couldn't find anything that looks like an 'in-memory' option.

那可能吗?我尝试调整与 postgres 内存相关的变量(如下面的解决方案所示),但这似乎不会影响它执行的 db 写入次数,而且我找不到任何看起来像“内存中”选项的内容.

https://dba.stackexchange.com/questions/18484/tuning-postgresql-for-large-amounts-of-ram

https://dba.stackexchange.com/questions/18484/tuning-postgresql-for-large-amounts-of-ram

回答by Craig Ringer

I wrote a detailed post on this some time ago:

前段时间我写了一篇详细的帖子:

Optimise PostgreSQL for fast testing

优化 PostgreSQL 以进行快速测试

You may find it informative; it covers options for making PostgreSQL run without durability and other tweaks that're useful for running tests.

您可能会发现它提供了丰富的信息;它涵盖了使 PostgreSQL 在没有持久性的情况下运行的选项以及对运行测试有用的其他调整。

You do not actually need in-memory operation. If PostgreSQL is set not to flush changes to disk then in practice there'll be little difference for DBs that fit in RAM, and for DBs that don't fit in RAM it won't crash.

您实际上并不需要内存中操作。如果 PostgreSQL 设置为不将更改刷新到磁盘,那么在实践中,适合 RAM 的 DB 几乎没有区别,而对于不适合 RAM 的 DB,它不会崩溃。

You should test with the same database engine you're using in production. Testing with SQLite, Derby, H2, etc then deploying live on PostgreSQL doesn't make tons of sense... as any Heroku/Rails user can tell you from experience.

您应该使用在生产中使用的相同数据库引擎进行测试。使用 SQLite、Derby、H2 等进行测试,然后在 PostgreSQL 上进行实时部署并没有多大意义……任何 Heroku/Rails 用户都可以从经验中告诉您。