Support for multiple database connections
|Reported by:||Simon Willison||Owned by:||Alex Gaynor|
|Component:||Database layer (models, ORM)||Version:|
|Severity:||normal||Keywords:||multiple database feature|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||yes|
Django currently assumes that all models will be stored in a single database, and that only one database connection will be used for the duration of a request. This assumption does not scale to really large applications, where it is common for multiple database connections to be used in non-obvious ways.
Three examples include:
- Traditional replication, where all writes go to a single master database while reads are distributed across a number of slave databases.
- Sharding, where (for example) user accounts 1-1000 live on db1, 1001-2000 live on db2 etc.
- Different types of data live on different servers / clusters. Frequently accessed user profile data might be stored on a seperate database/cluster from log data which is frequently written but very rarely accessed.
At the very least, Django needs to allow more than one database connection to be maintained by the DB wrapper. The default should still be a single connection as this is the common case, but Django should not get in the way should multiple connections be desired.
Rather than having a single connection, how about maintaining a dictionary of connections? A "default" key could correspond to the connection that is used in most cases, but other connections can be configured in the settings file and assigned names. There would need to be a mechanism somewhere for Django model classes to be told which named connection they should use.
Simple replication may end up being a different issue entirely - it's possible that could be handled just with a custom DB backend that knows to send writes to one server and distribute reads across several others. The above change (where Django allows multiple DB connections) is still essential for more complex configurations.
More about this on the mailing list: http://groups.google.com/group/django-users/browse_thread/thread/d08f4975da831bb/75ede5e9c7f0db53
Change History (81)
comment:12 Changed 11 years ago by
|Component:||Database wrapper → Validators|
|milestone:||→ Version 0.91|
|priority:||low → high|
|Severity:||normal → blocker|
|Type:||defect → enhancement|
comment:13 Changed 11 years ago by
|Component:||Validators → django-admin.py|
|priority:||high → highest|
|Severity:||blocker → trivial|
|Type:||enhancement → task|
|Version:||new-admin → SVN|
comment:14 Changed 11 years ago by
|Cc:||hi-world cup added; gary.wilson@… farcepest@… removed|
|Keywords:||rthml tab space editor js added|
|Summary:||Support for multiple database connections → hi-world cup|
comment:15 Changed 11 years ago by
|Summary:||hi-world cup → Support for multiple database connections|
comment:21 Changed 10 years ago by
|Component:||django-admin.py → Database wrapper|
|Keywords:||rthml tab space editor js removed|
|Type:||task → enhancement|
comment:22 Changed 10 years ago by
|Keywords:||multiple database added|
|Triage Stage:||Unreviewed → Design decision needed|
comment:25 Changed 10 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Design decision needed → Accepted|
comment:34 Changed 10 years ago by
|Cc:||lindemann@… added; gary.wilson@… farcepest@… eikke@… peter.kese@… chris.mcavoy@… ferringb@… removed|
|Component:||Database wrapper → Uncategorized|
|Owner:||changed from Adrian Holovaty to Jacob|
comment:35 Changed 10 years ago by
|Cc:||gary.wilson@… farcepest@… eikke@… peter.kese@… chris.mcavoy@… ferringb@… added; lindemann@… removed|
|Component:||Uncategorized → Database wrapper|
|Owner:||changed from Jacob to Adrian Holovaty|
comment:64 Changed 8 years ago by
|Owner:||changed from darylspitzer to Alex Gaynor|
|Status:||assigned → new|
|Triage Stage:||Someday/Maybe → Accepted|
comment:80 Changed 7 years ago by
|Cc:||erik.engbrecht@… gary.wilson@… farcepest@… eikke@… peter.kese@… chris.mcavoy@… ferringb@… iacobs@… andrewjwilkinson@… email@… daryl.spitzer@… remco@… mzdaniel@… rik24d@… stuartw@… jholloway7+django@… simeonf+django@… knyght+django@… spoof@… django@… flori@… tarkatronic@… alexandru.palade@… Jay Hargis lao Alexander Koshelev _wilane daemondazz S2nek swapon@… andrew.krasnoff@… david@… Robin Breathe removed|