Is it possible to access, particularly insert into, a database while it's being restored by pg_restore from a custom format. If yes, then should I care about preventing clients from accessing the database while pg_restore is running, or the restore operation is "transactional" so that after it ends all changes made by clients since its start will be lost?
1 Answer
If you want to keep concurrent sessions out of your database during pg_restore, you'll have to block them with a pg_hba.conf entry.
There is no protection from concurrent sessions inserting or otherwise modifying data while pg_restore is running.
2 Comments
A. Scherbaum
Plus you might run into problems, like if a client inserted something into an empty table, used a sequence value, and the restore wants to insert the very same value as well. The current sequence values (as of the time of the backup) are restored near the end of the restore process.
Ivan Alikin
@A.Scherbaum, yes, that's the issue I ran into. So the right way to restore a database is to prevent clients from accessing it until the restore completes.