将Postgres完全保留在内存中 [英] Keeping postgres entirely in memory

查看:135
本文介绍了将Postgres完全保留在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我想将其全部保留在内存中,并且不要让它接触数据库,希望可以加快速度。就像使用sqlite3的内存选项一样。我不需要持久性/持久性/什么,测试之后所有内容都会立即丢弃。

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.

有可能吗?我尝试调整与postgres内存相关的var(如下面的解决方案所示),但这似乎并不影响它执行的db写操作的数量,而且我找不到任何看起来像 in-memory(内存中)选项的东西。

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.

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

推荐答案

我前一段时间写了一篇详细的文章:

I wrote a detailed post on this some time ago:

优化PostgreSQL以进行快速测试

您可能会发现它具有参考价值;它涵盖了使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设置为不清除对磁盘的更改,那么实际上,适合RAM的DB不会有太大区别,而不适合RAM的DB不会崩溃。

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.

您应该使用生产中使用的相同数据库引擎进行测试。使用SQLite,Derby,H2等进行测试,然后在PostgreSQL上进行实时部署毫无意义……因为任何Heroku / Rails用户都可以从经验中得知。

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.

这篇关于将Postgres完全保留在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆