XLogInsert in my opinion is the best place to call it and the hook can be something like this "void xlog_insert_hook(NULL)" as all the throttling logic required is the current flush position which can be obtained from GetFlushRecPtr and the ReplicationSlotCtl. Attached a draft patch.
IMHO, it is not a good idea to call an external hook function inside a critical section. Generally, we ensure that we do not call any code path within a critical section which can throw an error and if we start calling the external hook then we lose that control.
Thank you for the comment. XLogInsertRecord is inside a critical section but not XLogInsert. Am I missing something?
It should be blocked at the operation level itself e.g. ALTER TABLE READ ONLY, or by some other hook at a little higher level.
There is a lot of maintenance overhead with a custom implementation at individual databases and tables level. This doesn't provide the necessary control that I am looking for.