Sometimes, if your database is small enough, and you don’t want to pay for a database server, you can make up backup of the database by storing an archive file using pg_dump
.
Note that when restoring a database from file (psql --set ON_ERROR_STOP=on db_name < dumpfile
), this will reset the key sequence, and you get the error duplicate key value violates unique constraint
. To avoid this error, the following function manually brings the sequence back in sync.