Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have to use replica of AWS RDS, How should I set the django setting?

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?

like image 242
hahaha Avatar asked Oct 29 '22 10:10

hahaha


1 Answers

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/

like image 112
0____0 Avatar answered Nov 15 '22 06:11

0____0