How to ensure a gapless auto-incremental id field when using PostgreSQL

I have noticed that the primary_key field (id field) of tables in PostgreSQL doesn’t guarantee auto-incremental values. The rows keys can be for example 1, 2, 3, 5, 6, 9, 10. This is related to the way PostgreSQL works and due to for example validation errors when creating new entities.

My question, how to avoid that? How to make sure that there would be no gaps in the id field? Thank you.