Search code examples
pythondjangodjango-database

django dj-database-url runs extrem slow


When i setup dj_database_url in my django project on local machine, the migrations and development server run extrem slow. They run already, but extrem slow. when i setup the database in this way everything works normal.

runs normal:

# settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'my_db',
        'USER': os.environ.get("USER"),
        'PASSWORD': os.environ.get("PASSWORD"),
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

runs slow:

# settings.py
import dj_database_url

DATABASES = {'default': dj_database_url.config(default=os.environ.get("DATABASE_URL"))}

my .env file

DATABASE_URL=postgres://user:passwd@localhost:5432/my_db

Solution

  • So in my case the soloution was a simple change. I just change the DATABASE_URL from

    DATABASE_URL=postgres://user:passwd@localhost:5432/my_db
    

    to

    DATABASE_URL=postgres://user:[email protected]:5432/my_db
    

    and it works!