Skip to main content

Persistent database connection backends for Django

Project description

django-db-connection-pool

MySQL & Oracle & PostgreSQL connection pool backends of Django, Be based on SQLAlchemy.

Quickstart

  1. Install with pip with all engines:

    $ pip install django-db-connection-pool[all]
    

    or select specific engines:

    $ pip install django-db-connection-pool[mysql,oracle,postgresql]
    
  2. Configuration

    • MySQL

      change django.db.backends.mysql to dj_db_conn_pool.backends.mysql:

      DATABASES = {
          'default': {
              ...
              'ENGINE': 'dj_db_conn_pool.backends.mysql'
              ...
          }
      }
      
    • Oracle

      change django.db.backends.oracle to dj_db_conn_pool.backends.oracle:

      DATABASES = {
          'default': {
              ...
              'ENGINE': 'dj_db_conn_pool.backends.oracle'
              ...
          }
      }
      
    • PostgreSQL

      change django.db.backends.postgresql to dj_db_conn_pool.backends.postgresql:

      DATABASES = {
          'default': {
              ...
              'ENGINE': 'dj_db_conn_pool.backends.postgresql'
              ...
          }
      }
      
    • pool options(optional)

      you can provide additional options to pass to SQLAlchemy's pool creation, key's name is POOL_OPTIONS:

      DATABASES = {
          'default': {
              ...
              'POOL_OPTIONS' : {
                  'POOL_SIZE': 10,
                  'MAX_OVERFLOW': 10
              }
              ...
           }
       }
      

      Here's explanation of these options(from SQLAlchemy's Doc):

      • pool_size: The size of the pool to be maintained, defaults to 5. This is the largest number of connections that will be kept persistently in the pool. Note that the pool begins with no connections; once this number of connections is requested, that number of connections will remain. pool_size can be set to 0 to indicate no size limit; to disable pooling, use a :class:~sqlalchemy.pool.NullPool instead.

      • max_overflow: The maximum overflow size of the pool. When the number of checked-out connections reaches the size set in pool_size, additional connections will be returned up to this limit. When those additional connections are returned to the pool, they are disconnected and discarded. It follows then that the total number of simultaneous connections the pool will allow is pool_size + max_overflow, and the total number of "sleeping" connections the pool will allow is pool_size. max_overflow can be set to -1 to indicate no overflow limit; no limit will be placed on the total number of concurrent connections. Defaults to 10.

      or you can use dj_db_conn_pool.setup to change default arguments(for each pool's creation), before using database pool:

      import dj_db_conn_pool
      dj_db_conn_pool.setup(pool_size=100, max_overflow=50)
      

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-db-connection-pool-1.0.7.tar.gz (7.0 kB view details)

Uploaded Source

File details

Details for the file django-db-connection-pool-1.0.7.tar.gz.

File metadata

  • Download URL: django-db-connection-pool-1.0.7.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8

File hashes

Hashes for django-db-connection-pool-1.0.7.tar.gz
Algorithm Hash digest
SHA256 9974c34d3e658fad8c323a993a6111ce6bdad78d484037c8328a010c2c022da6
MD5 f84cd7dd5224e2daa37fa77adedcf398
BLAKE2b-256 22f5d49ac71a3c2a34ed35543923f45c863bc2b4bdbbdd9e28caf849b9afe02b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page