PostgreSQL(psql): ERROR: column c.relhasoids does not exist

 I’m trying to DESCRIBE TABLE with a command in Postgresql. For some types of relation, \d shows additional information for each column: column values for sequences, indexed expressions for indexes, and foreign data wrapper options for foreign tables.

So I punch in \d table_name, I keep getting an error below.
ERROR: column c.relhasoids does not exist LINE 1: ...riggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoi...

Solution

The error only appears if you are using Postgres v.12, 13, 14 (12 or newer) and older psql client v.11 or earlier. In my case, I used psql client 9.4.5 and Postgres server 14.4.

(jobsites_env)nksm@Ubuntu-1410 /home/nieuwejobs/trunk # python manage.py dbshell
psql (9.4.5, server 14.4 (Ubuntu 14.4-1.pgdg22.04+1))
WARNING: psql major version 9.4, server major version 14.4.
         Some psql features might not work.
Type "help" for help.

nieuwejobs_dev=> \d cv_cv
ERROR:  column c.relhasoids does not exist
LINE 1: ..., c.relhasindex, c.relhasrules, c.relhastriggers, c.relhasoi...
                                                             ^
nieuwejobs_dev=> \q

This is because in v. 12, table OIDs are no longer treated as special columns, and hence the relhasoids column is no longer necessary.
We have to make sure we are using psql client v. 12 or newer to avoid this error.

You may not necessarily be using psql, so the more general answer here is to make sure you’re using a compatible client.

Solution 1

To upgrade psql client to v. 12 or newer:

sudo apt-get install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
# Replace 14 with postgresql-12, 13 or newer to install desired client
sudo apt install postgresql-client-14
pg_basebackup -V --cluster 14/main

Output

pg_basebackup (PostgreSQL) 14.4 (Ubuntu 14.4-1.pgdg20.04+1)

Solution 2

To downgrade Postgres server to v. 11:

DONE! :)

NKSM

Comments

Popular posts from this blog

psql: error: connection to server at "localhost" (127.0.0.1), port 5433 failed: ERROR: failed to authenticate with backend using SCRAM DETAIL: valid password not found

Mount StorageBox to the server for backup

Keeping Your SSH Connections Alive: Configuring ServerAliveInterval and ServerAliveCountMax