PostgreSQL error: column c.relhasoids does not exist
ERROR: column c.relhasoids does not existShort 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.
Fix it fast
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;"2Match what you see, then jump to its fix
What does the error look like?
ERROR: column c.relhasoids does not existcolumn 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 --version3Verify
Open the table description again.
psql -d mydb -c '\d my_table'Confirmed by postgresql.org
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.sqlConfirmed by postgresql.org
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
Databases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
DBeaver cannot download the PostgreSQL driver from Maven
The PostgreSQL driver files are missing and the download does not complete
DBeaver downloads the PostgreSQL JDBC driver from a Maven repository the first time you connect.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fixDatabases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fix