Restoring DB backup of PostgreSQL >9.5

When you messed up your database of testing or production servers you usually want to restore a clean state as fast as possible with the backup and not mixing up date from the current state and the backup. An easy way to achieve this is to drop the database and create it again afterwards restore the dump.

But for PostgreSQL >9.5 there is the problem that you cannot drop a database if others are connected to the database which is very likely when you have services running.

Continue reading →