Postgresql version issues

I am in the initial stages of setting up a Django project, and I’m having an issue–the short version of my question is how do I find where Django is getting the postgresql version information from?

Here are the details:

Development environment: Linux Mint 20.3
Python version in the virtual environment: 3.8.10

When I run this from within the virtual environment, I get:

$ psql --version
psql (PostgreSQL) 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)

My installation within the venv has:

psycopg2 version: 2.9.3
Django version: 4.1.1

I set up my database, changed the relevant settings to postgresql requirements following the docs, but when I try

$ python runserver,

I get a NotSupportedError:

django.db.utils.NotSupportedError: PostgreSQL 11 or later is required (found 10.21).

So, where is Django seeing this version of PostgreSQL? I can provide further details of my setup if needed, but it seems like a basic installation issue to me…

Have you verified that you don’t have a second version of PostgreSQL installed?

Double-check your settings file to ensure you’re connecting to the right host/port.

Well, I have 5432 specified in my settings as my port, and when I run

(venv) $ psql -p 5432 dbname dbuser

I can connect to the database fine, and it shows the 12.12 version. You can probably guess from the fact that I am asking this question that I do not know how to figure out whether there is a second version of postgresql in that environment that Django is seeing. So any hints for how I might do that would be useful.

Post your DATABASES section of your settings file, that’ll help some.

I’m not specifically familiar with Mint - I don’t know what it uses for package management (apt/dpkg? yum? something else?) and therefore don’t know how to verify what packages may be installed.

(I’m assuming you’re running your database locally and not connecting to a remote server.)

You could do a ps -AF as root to see what all is running - it should be fairly obvious which entries are for postgresql.

Ah, yes, I do see that both 12 and 10 are installed on the system. This might be from an earlier version of Mint (which is like Ubuntu, Debian-based and uses apt and dpkg).

Here’s my DATABASES entry from settings:

‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql’,
‘NAME’: ‘dbname’,
‘USER’: ‘darkhelmet’,
‘HOST’: ‘localhost’,
‘PASSWORD’: ‘12345’,
‘PORT’: ‘’,
‘CONN_MAX_AGE’: 1000,
‘isolation_level’: psycopg2.extensions.

You’re not specifying a port on your connection, I don’t know how Django would figure out which to use. I’d suggest you either remove the version 10 or specify the version 12 port on your connection, or both.

Actually, nothing changes when I specify the port (5432, as in the previous post). It’s the default, and when I connect to the db outside Django, it works correctly.

Hmm, I’m not sure if it would be safe to remove version 10. Okay, I’ll keep tinkering.

If you don’t want to remove it, you could stop it from running - that may be sufficient. You could also change it such that it’s running on a different port.

I was having the same issue (in Ubuntu).

If you go to /etc/postgresql you’ll find subdirectories for each of the installed versions of postgres. Inside each you’ll find a postgresql.conf file that specifies the port each version is running on.

For instance, in my case etc/postgresql/10/main/postgres.conf specifies that version 10 is running on port 5432, while etc/postgresql/14/main/postgres.conf is running on port 5434. You can then modify your Just set the port to the one that the postgres version you want is running on.

Additionaly, notice that you may have a newer version of psql connecting to an older version of postgres. For instance, like you, if I do psql --version it shows the latest (14.5). However, actually going into sudo -u postgres psql will show:

psql (14.5 (Ubuntu 14.5-0ubuntu0.22.04.1), server 10.14 (Ubuntu 10.14-0ubuntu0.18.04.1))

The server is (I think) the postgres version that psql it is connecting to. I believe this is because psql is connecting to port 5432 by default. Hence, to create your database, user, etc. you should do sudo -u postgres psql -p [PORT].

Hope this helps!

Thanks, this was it–there was a lot of useful information in /etc/postgresql that sorted me out.