Reputation: 45
When running pg_restore we encounter some (unexpected) executions from some other programs resulting in errors in the restoration.
Is there a way to lock the DB while restoring to insure no modifications are done ?
This is the command executed :
pg_restore --clean --verbose --no-owner /home/postgres/backup/bkp --if-exists -j 7 -d restdb01 -p 5432
Upvotes: 0
Views: 1046
Reputation: 246818
revoke connect permissions from the database or reject connections in pg_hba.conf
(remember that by default, PUBLIC
can connect to the database)
use pg_terminate_backend
to cancel all existing connections
run pg_restore
as a user that can still connect to the database
Upvotes: 1
Reputation: 1620
PostgreSQL documentation of pg_restore does not provide any info of such functionality.
According to wiki postgresql does not support database locking.
I suggest using permission mechanism to prevent anyone connecting to the database beeing restored:
Unless you have applications connecting to your server as superusers, that will prevent applications from reading or changing
Upvotes: 1