My Django application has to read RDS (maridadb) a lot. So I thought, how I solve this performance problem? RDS has a replica. I want to set Django to use multi DB. How can I do this?
You want to set up a second database in Django conf. Read here https://docs.djangoproject.com/en/2.0/topics/db/multi-db/
Like so:
DATABASES = {
    'default': {
        'NAME': 'user_data',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'superS3cret'
    },
    'read_replica': {
        'NAME': 'customer_data',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_cust',
        'PASSWORD': 'veryPriv@ate'
    } 
}
Then, use a Database Router (django.db.router). (Also in those docs). There's a DATABASE_ROUTERS config as well.
You can also use route53 to load balance multiple read replicas, if you want: https://aws.amazon.com/premiumsupport/knowledge-center/requests-rds-read-replicas/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With