Django and postgres 15

โ€”

by

in ,

Connecting to postgres 15 is a bit of a challenge.

Hope this helps:

su - postgres
psql -c "CREATE DATABASE pghcdb"
psql -c "CREATE USER pghcuser WITH PASSWORD 'kaboom5000'"
psql -d pghcdb -c "CREATE SCHEMA pghcschema AUTHORIZATION pghcuser"
psql -c "ALTER ROLE pghcuser SET client_encoding TO 'utf8'"
psql -c "ALTER ROLE pghcuser SET default_transaction_isolation TO 'read committed'"
psql -c "ALTER ROLE pghcuser SET timezone TO 'UTC'"

As for the django part:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'OPTIONS': {
                'options': '-c search_path=pghcschema'
            },
        'NAME': 'pghcdb',
        'USER': 'pghcuser',
        'PASSWORD': 'kaboom5000',
        'HOST': 'localhost'
    }
}


And you need to set pg_hba.conf to (see noted line, and restart postgres):

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
#local   all             all                                     peer
########### vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ##############
local   all             all                                     password 
########### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ##############
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256