What Are Oids

June 13, 2012

Object Identifiers (oids) were added to Postgres as a way to uniquely identify database objects, e.g. rows, tables, functions, etc. It is part of Postgres's object-relational heritage.

Because oids where assigned to every data row by default, and were only four-bytes in size, they were increasingly seen as unnecessary. In Postgres 7.2 (2002), they were made optional, and in Postgres 8.1 (2005), after much warning, oids were no longer assigned to user tables by default. They are still used by system tables, and can still be added to user tables using the with oids clause during create table. Server parameter default_with_oids controls the default mode for table creation (defaults to "false").

Oids as still used extensively for system table rows, and are used to join system tables, e.g.:

 

SELECT oid, relname FROM pg_class ORDER BY 1 LIMIT 1;
 
 oid |              relname
-----+----------------------------------
 112 | pg_foreign_data_wrapper_oid_index
(1 row)

 

Only system tables that need oids have them, e.g. pg_class has an oid column, but pg_attribute does not.

Share this

Relevant Blogs

More Blogs

pgAdmin config files

There are multiple configuration files that are read at startup by pgAdmin. These files can be used to modify the default configuration options or to add any configuration which a...
November 14, 2022

Postgres 15 Adds Copy Header and Matching

Postgres 15 is out, with 183 new features and changes. Many of these features are major, but I always try to highlight one feature that is simple and useful. For...
October 20, 2022

Postgres 15 is here!

Another year is passing by and another version of Postgres is here! The PostgreSQL project roadmap is quite simple for any Postgres user: there is a new major version each...
October 10, 2022