如何在 django 0.97 上分离读数据库服务器和写数据库服务器?

发布于 2024-10-14 19:32:04 字数 480 浏览 4 评论 0原文

我正在使用 Django 0.97 版本和 postgresql 9.0。我已经在主数据库服务器和从数据库服务器上配置了热流复制。我的应用程序在数据库上有大量由机器人驱动的写入操作,并且仅从用户处读取。因此,如果我为用户创建读访问从属数据库,为机器人写访问创建写访问主数据库,那么它会变得非常优化。不幸的是,只有 Django 1.2 具有多种数据库支持,并且在我的应用程序中升级需要付出巨大的努力。我通过以下链接获得了一些线索: http://www .eflorenzano.com/blog/post/easy-multi-database-support-django/ 但是,这也要求我更改应用程序中数据库访问的所有实例。有没有更简单的方法通过摆弄 django core db 模块来分配单独的数据库服务器进行读取访问和写入访问?

I am using Django 0.97 version with postgresql 9.0. I have configured hot streaming replication on a master db server and a slave db server. My application has heavy bot-driven writes on the DB and reads only from the users. So, it makes it very optimized if I make the read-access slave db for the users' and write-access master db for the bot write access. Unfortunately only Django 1.2 has multiple database support and its a huge effort to upgrade in my application. I got some leads through the following link : http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/ However, this also requires me to change all instances of db access in my application. Is there any simpler way to assign separate db servers for read access and write access by fiddling with the the django core db module?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久伴你 2024-10-21 19:32:04

最好的选择是升级到 1.2,因为它比将现有功能拼凑在一起的工作量要少得多。如果你长期坚持 0.97,你以后的生活只会更加困难。

我猜您可能对 Django 1.2 中如何使用多个数据库有一些误解。如果您使用 数据库路由器 Django 功能。

使用路由器,您可以指定使用哪个数据库进行读取和写入。所有现有的 django 模型都应该可以工作并开始向正确的数据库发送请求。设置路由器非常简单,只需检查 文档。所需要做的就是创建路由器类,将其放在某处,然后在设置中添加一行。

它工作得非常好,而且并不像您想象的那么繁重。您可能会遇到其他未告诉我们的升级问题,但就模型而言,您应该不会遇到太多问题。

Your best bet is to upgrade to 1.2 as it will be significantly less work than hacking together features that already exist. If you stick with 0.97 for much longer your life will only be more difficult down the road.

I'm guessing you may have some misconceptions on how using multiple DBs works in Django 1.2. You do not have to "change all instances of db access in [your] application" if you use the Database Routers feature of Django.

With a router, you can specify which database to use for reads and writes. All of your existing django models should work and begin sending requests to the proper database. It's pretty simple to set up a router, just check the docs. All that is required is to create the router class, put it somewhere, then add a line in your settings.

It works really nicely and is not as much work as you may expect. You may have other issues with upgrading that you aren't telling us, but as far as models go you shouldn't have many problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文