Now what could one do to prevent those sequence gaps?
There might be scenarios where it's important not to have gaps in the numbering even when one has to switch to the standby if there is a failiour on the master.
E.g. numbers of invoices need to be gapless.
Then you may need to find some other way within your application to assign invoice numbers, because sequences aren't GUARANTEED not to have gaps, especially if there is a failure of the primary server that results in a switch over to the standby server.
A transaction that is rolled back (such as due to an error) after the nextval() function has been called will not roll back the sequence value, for example.
You cannot issue a nextval() call on a standby server, because it is in read-only mode.