title: Django cannot create superuser on PostgreSQL. "server closed the connection unexpectedly"
body: <p>I'm having an issue with a Django site that cannot create a superuser with a PostgreSQL database.</p>
  
  <p><strong>From the development machine</strong></p>
  
  <pre><code>python manage.py createsuperuser --username user1 --email email@email.com
  </code></pre>
  
  <p>returns:</p>
  
  <blockquote>
    <p>django.db.utils.OperationalError: server closed the connection
    unexpectedly
            This probably means the server terminated abnormally
            before or while processing the request.</p>
  </blockquote>
  
  <p>Now, the PostgreSQL server is up. I can run <code>python manage.py migrate</code> and create tables over there. I can also tell the server is up by putting in incorrect credentials, and receiving an error for having bad creds. I've got Dbeaver up and running on the same machine the Django site is being developed on, and it can connect and see the database as the user the Django site's <code>settings.py</code> is using.</p>
  
  <p><strong>From the PostgreSQL Server machine</strong></p>
  
  <p>Running <code>cat /var/lib/pgsql/data/pg_log/postgresql-Mon.log</code> yields the following after an attempted superuser creation:</p>
  
  <pre><code> LOG:  could not receive data from client: Connection reset by peer
   LOG:  unexpected EOF on client connection with an open transaction
  </code></pre>
  
  <p>Because I can connect to the server and have success with other queries, I'm not sure where this issue lies. </p>
  
  <p>Where should I look next to troubleshoot this issue?</p>
  
  <p><strong>EDIT: UPDATE</strong></p>
  
  <p>I changed <code>postgresql.conf</code> to reflect <code>log_statement = 'all'</code>. Now, upon running the createsuperuser command, I see the following in the PostgreSQL log:</p>
  
  <pre><code>LOG:  statement: 
                  SELECT c.relname, c.relkind
                  FROM pg_catalog.pg_class c
                  LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                  WHERE c.relkind IN ('r', 'v')
                      AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                      AND pg_catalog.pg_table_is_visible(c.oid)
  LOG:  statement: SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"
  LOG:  statement: SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" = 'user1'
  LOG:  statement: BEGIN
  LOG:  could not receive data from client: Connection reset by peer
  LOG:  unexpected EOF on client connection with an open transaction
  </code></pre>