4

TL;DR manage migrate fails but manage dbshell works.

This is a dockerized dev environment on OSX10.6, boot2docker with django 1.8.4 and postgresql 9.4.4.

/manage.py migrate throws:

django.db.utils.OperationalError: FATAL:  password authentication failed for user "xxxxx"

but here's the bit that confuses me, django dbshell works, copy and pasting the password out of the environment variable

root@df6501ab7341:/src/web# ./manage.py dbshell
Password for user xxxxx: 
psql (9.4.4)
Type "help" for help.

xxxxx=# \du
                               List of roles
  Role name   |                   Attributes                   | Member of 
--------------+------------------------------------------------+-----------
 xxxxx      | Superuser                                     +| {}
              | Password valid until infinity                  | 
 mpasysuser01 |                                                | {}
 postgres     | Superuser, Create role, Create DB, Replication | {}

xxxxx=# 

Django settings are:

# Database Configuration
DATABASES = {
    'default': {
        'ENGINE'   : 'django.db.backends.postgresql_psycopg2',
        'NAME'     : os.environ.get('DATABASE_ENV_POSTGRES_USER'    , ''),  # the database name is the same as the dbo username
        #ToDo Use unprivileged database user
        # 'USER'     : os.environ.get('DATABASE_ENV_UNPRIVILEGED_SQL_USER', ''),
        'USER'     : os.environ.get('DATABASE_ENV_POSTGRES_USER', ''),
        'PASSWORD' : os.environ.get('DATABASE_ENV_POSTGRES_PASSWORD', ''),
        'HOST'     : os.environ.get('DATABASE_PORT_5432_TCP_ADDR'   , ''),
        'PORT'     : os.environ.get('DATABASE_PORT_5432_TCP_PORT'   , ''),
    },
}

and the database logs show:

database_1 | FATAL:  password authentication failed for user "xxxxx"
database_1 | DETAIL:  Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"
5
  • Why not try to print the variable and see whats going on? Commented Sep 19, 2015 at 6:46
  • good idea. printing password from inside settings.py checks out as expected. Commented Sep 19, 2015 at 7:19
  • 1
    If error does not get triggered try on shell (not dbshell) from django.conf import settings settings.DATABASES['default']['PASSWORD']. Or just hardcode it and see what happens. Commented Sep 19, 2015 at 7:34
  • Thanks @LaraChicago, that got me moving. Root cause was somewhere in linux user level and su. Top tip for others banging heads, when debugging linked containers, make sure you pass a name alias to the --link parameter i.e --link c126ff7b1d28:DATABASE Commented Sep 19, 2015 at 13:43
  • 2
    did your password happen to contain a $ sign, i think im seeing a problem with this Commented Sep 30, 2016 at 13:29

1 Answer 1

3

I second what @larconda said.

I was racking my brain and decided to print by:

  1. Open the shell

  2. import os

  3. print(your variable here)

That should provide some input - it turned out to be a missing space for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.