Hook to run code when Postgres DB launches I need to run code when a database/catalog in a Postgres cluster comes online, before any client has connected. 

Specifically I need to do some cleanup such as dropping/truncating a particular table. 

Is there a place for my code to be automatically run with a guarantee it will finish before any incoming client connection is accepted?
You have two methods of doing this, 


Step back, your best bet is to use TEMPORARY TABLES


  TEMPORARY or TEMP
  If specified, the table is created as a temporary table. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see ON COMMIT below). Existing permanent tables with the same name are not visible to the current session while the temporary table exists, unless they are referenced with schema-qualified names. Any indexes created on a temporary table are automatically temporary as well.
  
  The autovacuum daemon cannot access and therefore cannot vacuum or analyze temporary tables. For this reason, appropriate vacuum and analyze operations should be performed via session SQL commands. For example, if a temporary table is going to be used in complex queries, it is wise to run ANALYZE on the temporary table after it is populated.
  
  Optionally, GLOBAL or LOCAL can be written before TEMPORARY or TEMP. This presently makes no difference in PostgreSQL and is deprecated; see Compatibility.

Alternatively, you could rig it into your daemon that starts the server by,


Creating two pg_hba.confs, 


One that denies external connections.
One that permits external conections.

Create two config files, one to each pg_hba.conf
Start the server with the config file that points to the pg_hba.conf that denies external connections.
Run the code you want.
Stop the server.
Run the server with the config file that points to the pg_hba.conf that permits external connections.



You could do a similar thing with postgresql.conf's listen_addresses parameter.