[Django] #33496: mirror database in django

73 views
Skip to first unread message

Django

unread,
Feb 6, 2022, 3:06:25 AM2/6/22
to django-...@googlegroups.com
#33496: mirror database in django
-------------------------------------+-------------------------------------
Reporter: M Hadi | Owner: nobody
Azarabad |
Type: New | Status: new
feature |
Component: Database | Version: 4.0
layer (models, ORM) | Keywords: multi-database /
Severity: Normal | mirror database
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi. I'm looking for a solution to save data on mirror database. using
database routers allow us to save a record and let's us decide which
database must be used and i think manual database selection is not optimal
because it uses ORM to create raw SQL twice or more (based on number of
mirror database).
```
model_obj.save(using='db_1')
model_obj.save(using='db_2')
```
i think django can handle this problem and optimize it by adding setting
list variable called MIRROR_DATABASES so all mirror databases place in
there and django save all of records by creating one raw SQL if mirror
databases using the same backend

--
Ticket URL: <https://code.djangoproject.com/ticket/33496>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 6, 2022, 10:00:37 PM2/6/22
to django-...@googlegroups.com
#33496: mirror database in django
-------------------------------------+-------------------------------------
Reporter: M Hadi Azarabad | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: multi-database / | Triage Stage:
mirror database | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Tim Graham:

Old description:

> Hi. I'm looking for a solution to save data on mirror database. using
> database routers allow us to save a record and let's us decide which
> database must be used and i think manual database selection is not
> optimal because it uses ORM to create raw SQL twice or more (based on
> number of mirror database).
> ```
> model_obj.save(using='db_1')
> model_obj.save(using='db_2')
> ```
> i think django can handle this problem and optimize it by adding setting
> list variable called MIRROR_DATABASES so all mirror databases place in
> there and django save all of records by creating one raw SQL if mirror
> databases using the same backend

New description:

Hi. I'm looking for a solution to save data on mirror database. Using
database routers allow us to save a record and lets us decide which
database must be used and I think manual database selection is not optimal
because it uses ORM to create raw SQL twice or more (based on the number


of mirror database).
{{{
model_obj.save(using='db_1')
model_obj.save(using='db_2')
}}}

I think django can handle this problem and optimize it by adding setting


list variable called `MIRROR_DATABASES` so all mirror databases place in

there and Django save all of records by creating one raw SQL if mirror
databases using the same backend.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33496#comment:1>

Django

unread,
Feb 7, 2022, 12:34:27 AM2/7/22
to django-...@googlegroups.com
#33496: Auto database mirroring.

-------------------------------------+-------------------------------------
Reporter: M Hadi Azarabad | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: multi-database / | Triage Stage:
mirror database | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

As far as I'm aware database mirroring is not something a web framework
should be responsible for, see a [https://www.postgresql.org/docs/14
/different-replication-solutions.html handy comparison of different
solutions in PostgreSQL's docs]. Duplicating all the operations would be
inefficient, very complex, and error-prone.

--
Ticket URL: <https://code.djangoproject.com/ticket/33496#comment:2>

Django

unread,
Feb 17, 2022, 3:54:12 AM2/17/22
to django-...@googlegroups.com
#33496: Auto database mirroring.
-------------------------------------+-------------------------------------
Reporter: M Hadi Azarabad | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: multi-database / | Triage Stage:
mirror database | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Steven Mapes):

Following on from Mariusz's reply with the Postgres reference on HA, load
balancing and replication here's [https://dev.mysql.com/doc/refman/8.0/en
/replication-solutions.html MySQL's replication solutions] and
[https://downloads.mysql.com/docs/mysql-proxy-en.pdf MySQL Proxy] which
can be used as load balancer to distribute requests and perform automatic
failover, here's a [https://www.digitalocean.com/community/tutorials/how-
to-use-proxysql-as-a-load-balancer-for-mysql-on-ubuntu-16-04 Digital Ocean
install guide] for the latter.

If you are using MariaDB then here's the [https://mariadb.com/kb/en
/standard-replication/ replication docs] to get you started.

If you are looking at Multi-Master using either then look into
[https://galeracluster.com/ Galera Cluster] but these will be better
solutions than writing twice from code

--
Ticket URL: <https://code.djangoproject.com/ticket/33496#comment:3>

Reply all
Reply to author
Forward
0 new messages