如何使用 MongoDB 作为 Postgresql 的缓存?
我有一个不能丢失数据的应用程序,所以 Postgresql 是我的数据库选择(ACID)。
但是,MongoDB 的速度和查询优势非常有吸引力,但根据我到目前为止所读到的内容,MongoDB 可以报告成功写入可能没有写入磁盘,所以我不能将其作为我的关键任务数据库(我还需要事务)
我看到有人一起使用 mysql 和 MongoDB,一个用于事务,另一个用于查询。请注意,我并不是在谈论将一些数据保存在一个数据库中,而将其余数据保存在另一个数据库中。我想使用 Postgresql 作为数据输入的网关,并使用 MongoDB 进行读取。
是否有任何资源以这种方式提供 Postgresql + MongoDB 使用的架构/指南?我记得在 Postgresql 会议议程中看到过这个主题,但我找不到链接。
I have an application that can not afford to lose data, so Postgresql is my choice for database (ACID)
However, speed and query advantages of MongoDB are very attractive, but based on what I've read so far, MongoDB can report a successful write which may not have gone to disk, so I can't make it my mission critical db (I'll also need transactions)
I've seen references to people using mysql and MongoDB together, one for the transactions and the other for queries. Please not that I'm not talking about keeping some data in one DB and the rest in another. I want to use Postgresql as a gateway to data entry, and MongoDB for reads.
Are there any resources that offer an architecture/guide for Postgresql + MongoDB usage in this way? I can remember seeing this topic in Postgresql conference agenda, but I could not find the link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我认为仅使用 MongoDB 作为缓存不会获得太多速度。它的优点是复制和水平可扩展性。在一台计算机上,您可以让 Mongo 和 Postgres 竞争内存、IO 带宽和处理器时间。
由于您无法承担丢失事务的后果,因此仅使用 Postgres 会更好。它具有高效的缓存、复杂的查询规划器、准备好的查询和广泛的索引支持,因此只读查询将非常快 - 确实可以与单台计算机上的 MongoDB 相媲美。
Postgres 现在甚至可以使用异步复制进行水平扩展,或者从 9.1 版本开始使用同步复制。
I don't think you'll get much speed using MongoDB just as a cache. It's strengths are replication and horizontal scalability. On one computer you'd make Mongo and Postgres compete for memory, IO bandwidth and processor time.
As you can not afford to loose transactions you'll be better with Postgres only. Its has efficient caching, sophisticated query planner, prepared queries and wide indexing support cause that read-only queries will be very fast - really comparable to MongoDB on a single computer.
Postgres can even scale horizontally now using asynchronous, or, from version 9.1, synchronous replication.
实现此目的的一种方法是设置主从复制,其中 PostgreSQL 数据库作为主数据库,MongoDB 数据库作为从数据库。然后,您将从 MongoDB 进行所有读取,并对 PostgreSQL 进行所有写入。
这篇文章讨论了使用名为 Bucardo 的工具进行的设置:
http://blog.endpoint.com/2011/06 /mongodb-replication-from-postgres-using.html
您也可以使用 Tungsten Replicator 来完成此操作,尽管它似乎设计为与 MySQL 一起使用:
http://code.google.com/p/tungsten-replicator/wiki/TRCHeterogeneousReplication
One way to achieve this would be to set up a master-slave replication with the PostgreSQL database as master, and the MongoDB database as slave. You would then do all reads from MongoDB, and all writes to PostgreSQL.
This post discusses such a setup using a tool called Bucardo:
http://blog.endpoint.com/2011/06/mongodb-replication-from-postgres-using.html
You may also be able to do it with Tungsten Replicator, although it seems designed to be used with MySQL:
http://code.google.com/p/tungsten-replicator/wiki/TRCHeterogeneousReplication
也许,您正在谈论这个: https://www.postgresqlconference .org/content/hybrid-applications-using-mongodb-and-postgres
Maybe, you are talking about this: https://www.postgresqlconference.org/content/hybrid-applications-using-mongodb-and-postgres
根据事务对您的重要性,一种选择是使用 MongoDb 驱动程序的安全模式并删除 Postgresql。
http://www.mongodb.org/display/DOCS/getLastError+Command
Depending how important transactions are to you, one option is to use MongoDb driver's safe mode and drop Postgresql.
http://www.mongodb.org/display/DOCS/getLastError+Command
你怎么能期望 Postgres 的事务一致性,却信任 MongoDB 的读取呢?在这种情况下,您将如何支持回滚?您如何检测它们何时不同步?
我认为你最好使用内存缓存并实现更高级别的对象缓存。或者,您可以考虑使用复制从属设备进行读取。如果您的性能需求超出了专用读取从属设备所能提供的范围,请考虑对从属系统上的表进行非规范化。
确保其中任何一个都是实际需要的。对于具有 PK 查找的精简表,大多数现代数据库引擎(例如 Postgres 或 InnoDB)通常会跟上 NoSQL 解决方案的步伐。不要陷入 ROFLSCALE 陷阱
http://www.youtube.com/watch?v=b2F-DItXtZs
How can you expect transactional consistency from Postgres but trust MongoDB for reads? How would you support rollbacks in this scenario? How do you detect when they've gotten out of sync?
I think you're better off going with memcache and implementing a higher level object cache. Alternatively, you could consider a replication slave for reads. If you have performance needs beyond what a dedicated read slave can provide, consider denormalizing your tables on your slave system.
Make sure that any of this is actually needed. For thin tables with PK lookups most modern database engines like Postgres or InnoDB are going to generally keep up with NoSQL solutions. Don't fall into the ROFLSCALE trap
http://www.youtube.com/watch?v=b2F-DItXtZs
我认为你可以运行一个 mongo 副本集。假设 3 个从站和 1 个主站< /a>.. 然后在您的应用程序中,您应该在 Postgresql 上运行所有写入事务,然后在 Mongo ReplicaSet 上运行。之后,您可以在 Mongo Replica Set 上查询读取操作。
但同步会是一个问题,你应该努力解决它。
I think you can run a mongo replica set.. Let say 3 Slave and 1 Master.. Then in your app you should run all write transactions on Postgresql and then on Mongo ReplicaSet.. After that you can query read operations on Mongo Replica set..
But Synchronizing will be a problem, you should work on it..
您可能会在 此处 或 这里 也更安全、更快速。
但我建议简化您的解决方案,而不是进行复杂的设计。
NoSQL 系统视觉指南
lucky
you may find some replacement for mongo in here or here that is safer and fast as well.
but I advise to simplify your solution instead of making a complicated design.
Visual Guide to NoSQL Systems
lucky
在 mongodb 中,我们可以指定 writeConcern 属性来指定它应该写入日志/实例,然后发送确认/确认,我认为即使 mongodb 也有事务的概念。不知道为什么我们需要 postgres。
In mongodb we can specify writeConcern property to specify that it should write to journal/ instances and then send confirmation/ acknowledgement and i think even mongodb has teh concept of transactions. Not sure why we need postgres behind it.