From 0f7cf18ecbbace3617278839f2d7259760cb9c44 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Wed, 3 May 2023 18:41:58 +0530 Subject: [PATCH] make connection pool --- config/settings.py | 11 ++++++++++- custom-postgresql.conf | 2 +- requirements.txt | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config/settings.py b/config/settings.py index 5ede519..50a9e55 100644 --- a/config/settings.py +++ b/config/settings.py @@ -91,7 +91,7 @@ WSGI_APPLICATION = 'config.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.contrib.gis.db.backends.postgis', + 'ENGINE': 'dj_db_conn_pool.backends.postgresql', 'NAME': env("POSTGRES_DBNAME"), 'USER': env("POSTGRES_USER"), 'PASSWORD': env("POSTGRES_PASS"), @@ -100,6 +100,15 @@ DATABASES = { } } +DATABASES = { + 'default': { + 'POOL_OPTIONS' : { + 'POOL_SIZE': 200, + 'MAX_OVERFLOW': 10, + 'RECYCLE': 24 * 60 * 60 + } + } + } # Password validation # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators diff --git a/custom-postgresql.conf b/custom-postgresql.conf index 4ea5a9e..b2296de 100644 --- a/custom-postgresql.conf +++ b/custom-postgresql.conf @@ -61,7 +61,7 @@ external_pid_file = '/var/run/postgresql/12-main.pid' # write an extra PID fil # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5432 # (change requires restart) -max_connections = 600 # (change requires restart) +max_connections = 100 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories # (change requires restart) diff --git a/requirements.txt b/requirements.txt index 148477b..fbbfb00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -64,3 +64,4 @@ urllib3==1.26.7 django-extra-fields==3.0.2 django-phonenumber-field==6.1.0 django-rest-knox==4.2.0 +django-db-connection-pool[postgresql]