title: psycopg2.OperationalError: FATAL: password authentication failed for user "<my UNIX user>"
body: <p>I am a fairly new to web developement.</p>
  
  <p>First I deployed a static website on my vps (Ubuntu 16.04) without problem and then I tried to add a blog app to it.</p>
  
  <p>It works well locally with PostgreSQL but I can't make it work on my server.
  It seems like it tries to connect to Postgres with my Unix user. </p>
  
  <p>Why would my server try to do that?</p>
  
  <p>I did create a database and a owner via the postgres user, matching the login information in settings.py, I was expecting psycopg2 to try to connect to the database using these login informations:</p>
  
  <p>Settings.py + python-decouple:</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': config ('NAME'),
          'USER': config ('USER'),
          'PASSWORD': config ('PASSWORD'),
          'HOST': 'localhost',
          'PORT': '',
      }
  }
  </code></pre>
  
  <p>This is the error message I get each time I try to <code>./manage.py migrate</code></p>
  
  <p>'myportfolio' is my Unix user name, the database username is different:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
      self.connect()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 194, in connect
      self.connection = self.get_new_connection(conn_params)
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
      connection = Database.connect(**conn_params)
    File "/home/myportfolio/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
      conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
  psycopg2.OperationalError: FATAL:  password authentication failed for user "myportfolio"
  FATAL:  password authentication failed for user "myportfolio"
  
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File "./manage.py", line 15, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
      utility.execute()
    File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
      output = self.handle(*args, **options)
    File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 79, in handle
      executor = MigrationExecutor(connection, self.migration_progress_callback)
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/executor.py", line 18, in __init__
      self.loader = MigrationLoader(self.connection)
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/loader.py", line 49, in __init__
      self.build_graph()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/loader.py", line 206, in build_graph
      self.applied_migrations = recorder.applied_migrations()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
      if self.has_table():
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 44, in has_table
      return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 255, in cursor
      return self._cursor()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 232, in _cursor
      self.ensure_connection()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
      self.connect()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
      raise dj_exc_value.with_traceback(traceback) from exc_value
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
      self.connect()
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 194, in connect
      self.connection = self.get_new_connection(conn_params)
    File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
      connection = Database.connect(**conn_params)
    File "/home/myportfolio/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
      conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
  django.db.utils.OperationalError: FATAL:  password authentication failed for user "myportfolio"
  FATAL:  password authentication failed for user "myportfolio"
  </code></pre>
  
  <p>I tried to: </p>
  
  <ul>
  <li>delete my django code, re install </li>
  <li>delete/purge postgres and reinstall</li>
  <li>modify pg_hba.conf local to trust</li>
  </ul>
  
  <p>At one point I did create a django superuser called 'myportfolio' as my unix user: could this have create a problem ?</p>