Using or Not Using the OID in PostgreSQL

Back to main page

There is an OID (Object Identification number) hidden on every row of every table in PostgreSQL. It is unique across all rows in your database. You can't get rid of it, so it seems like you might as well use it. As part of creating/organizing our database architecture I considered and attempted a number of strategies, and ended up deciding not to make use of the OID's as keys.

The final pro's and con's are listed below, as are related links. If anyone out there has anything to add to this list, especially in disagreement, please let me know.

Using OID as primary/foreign key

Pro Con
Inserts are easier to Prove, simpler and safer to generate than anything else
Less storage (of course we are only talking 4 bytes for each key)
Simpler (looking) schema
There anyway, might as well use
No way of using referential integrity using oid
Tool phpPgAdmin 2.3 doesn't support it
Complicates Database Loads (in order to retain OID values
Possible OID conflicts after loads
Non-standard SQLusage
Not included as part of select *
Changes configuration of dbdump, dbcopy


Related Links:

mjf