0

I'm wondering when a table acquires an oid. Is it only when the transaction commits? Or does it have a hidden oid prior to commit? Especially in the context of a CREATE TABLE AS SELECT.

NO WAR WITH RUSSIA
  • 54,954
  • 34
  • 200
  • 411

1 Answers1

3

Table OIDs are assigned quite early in table creation, and are definitely present by the time the CREATE TABLE finishes (before xact commit), since the row is visible in pg_class by then.

The new pg_class row (and its oid) are not visible to concurrent transactions until commit, though.

It's not clear why you care, though. It shouldn't matter.

Craig Ringer
  • 51,279
  • 3
  • 136
  • 175
  • I want to understand it, and I would also like to know if I can use something like [`pgstattuple`](https://www.postgresql.org/docs/current/static/pgstattuple.html) to see the insertion status of large table creations (a billion rows) with CTAS. I do them pretty often for this site, just finished an answer with [100 million insertions in CTAS](https://dba.stackexchange.com/a/175233/2639). – NO WAR WITH RUSSIA Jun 02 '17 at 03:10