Thread: Adding a new table to the system catalog

Adding a new table to the system catalog

From
Paul Howells
Date:
Hello All,

I am exploring and poking at the source code to inform a design for adding valid-time support to postgres.  The feature will required updating existing system catalog tables as well as adding one or more new tables.

Is there any documentation on how to update the system catalog?  What files need to be created/updated?  Do I need to run any utilities for generation manually or is this done as part of the build?  How do I assign a new OID?  

Thanks in advance
Paul

Re: Adding a new table to the system catalog

From
Tom Lane
Date:
Paul Howells <paul.steven.howells@gmail.com> writes:
> I am exploring and poking at the source code to inform a design for adding
> valid-time support to postgres.  The feature will required updating
> existing system catalog tables as well as adding one or more new tables.

> Is there any documentation on how to update the system catalog?  What files
> need to be created/updated?  Do I need to run any utilities for generation
> manually or is this done as part of the build?  How do I assign a new OID?

The traditional advice for this is to look at past patches that added new
catalogs.  Recent examples that look pretty small otherwise include commit
1753b1b02 ("Add pg_sequence system catalog") and commit 6c268df12 ("Add
new catalog called pg_init_privs").  Also look at patches that just added
a column to an existing catalog, since it sounds like you need to do that
too; perhaps 039eb6e92 ("Logical replication support for TRUNCATE").

However, if you're doing this against HEAD, as you should be if you harbor
any hopes of getting a patch accepted in the future, you need to be aware
that we just made drastic changes in the way we represent initial catalog
data (i.e., entries inserted during bootstrap).  The old way with DATA
lines in the catalog/*.h files is gone in favor of *.dat files.  The good
news is that it's better documented than before, and we got rid of some of
the more tedious manual steps like creating Anum_foo macros.  See

https://www.postgresql.org/docs/devel/static/bki.html

and be sure to study the current contents of the catalog/*.h files
rather than what was there up to a couple months ago.

            regards, tom lane