So as to restore a database from a dump, I want to temporarily disable all the constraints in all the tables of my database, which content I have emptied ( postregsql 8.3).
Is there a safe way to modify a field in the pg_constraint table that easily allows to bypass the constraint ?
I don’t think so when I look at the documentation pg_constraint.
Is it possible to drop the pg_constraint table content, then refill it again ?
If not, how people do restore/copy databases with tables that are full of constraints and foreign keys ? (my destination database has the schema but all the columns are empty).
Edit: althought Erwin Brandstetter’s answer is the good answer (with wise warning) to my precise question… the solution to my general problem for avoiding foreign key errors during restore is to use the flag –disable-triggers when using pg_restore.
finally, my two lines commands are now:
pg_dump.exe -h %ipAddress% -p 5432 -U postgres -F c -a -v -f %file% mydb
pg_restore.exe -h localhost -p 5432 -U postgres -d mydb -v %file% --disable-triggers
and it works ok.
You can …
This disables all triggers of the table permanently. So don’t forget to later run:
-> 8.3 manual
You can …
This makes all deferrable constraints wait until the end of the transaction.
-> 8.3 manual
You should never tinker with tables in the system catalog manually unless you are a hacker and know exactly what you are doing. Mortal humans should use DDL commands exclusively to affect the system catalog.