Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

PostgreSQL error: column c.relhasoids does not exist

ErrorERROR: column c.relhasoids does not exist

Short answer

relhasoids was a flag in pg_class for tables created WITH OIDS. PostgreSQL 12 removed that feature, so the column is gone. A client tool or query written for PostgreSQL 11 or older still asks for it. Upgrade the client (psql, pgAdmin, your IDE's driver) to a current version, or remove relhasoids from your own SQL.

  • Applies to PostgreSQL 16, PostgreSQL 17, PostgreSQL 18
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the version of the client with the version of the server. A client older than 12 talking to a server at 12 or newer is the usual pairing.

    psql --version
    psql -c "SHOW server_version;"
  2. 2Match what you see, then jump to its fix

    1. 1The error appears from \d in psql or from a GUI tool's table browser, and the client is version 11 or olderA client tool older than the server runs a catalog queryFix
    2. 2The failing statement is one you wrote, and it selects relhasoids from pg_classYour own script or migration queries relhasoidsFix

What does the error look like?

  • ERROR: column c.relhasoids does not exist
  • column c.relhasoids does not exist

Cause 1 of 2

A client tool older than the server runs a catalog query

1Check

The psql manual says backslash commands are particularly likely to fail when the server is newer than psql. PostgreSQL 12 removed the special WITH OIDS behaviour, and pg_class has no relhasoids column now.

psql --version
psql -c "SELECT attname FROM pg_attribute WHERE attrelid = 'pg_catalog.pg_class'::regclass AND attname LIKE 'relhas%';"

2Fix

Install a psql (and any GUI or driver) at least as new as the server. On a machine with several PostgreSQL versions, make sure the newest psql is first on PATH.

which -a psql
psql --version

3Verify

Open the table description again.

psql -d mydb -c '\d my_table'

Confirmed by postgresql.org

Did this fix it?

Cause 2 of 2

Your own script or migration queries relhasoids

1Check

The PostgreSQL 12 release notes say the hidden oid column ability (WITH OIDS) was removed, and that code working with such tables needs adjustment. The pg_class reference lists no relhasoids column.

grep -rn "relhasoids" .

2Fix

Delete the relhasoids condition from the query. Nothing replaces it, because tables can no longer have hidden oids; where you need a row identifier, declare an explicit column.

-- before: SELECT relname FROM pg_class WHERE relhasoids
-- after: remove the condition, or use an ordinary key column
SELECT relname FROM pg_class WHERE relkind = 'r';

3Verify

Run the corrected statement against the PostgreSQL 12 or newer server.

psql -d mydb -f check.sql

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Keep psql, pgAdmin, your IDE and its JDBC or ODBC driver on versions at least as new as the server.
  • Test migration scripts against the target server version before the upgrade day.
  • Search custom monitoring and inventory queries for removed catalog columns when you plan a major upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.