I have seen this in the official docs: https://www.postgresql.org/docs/9.1/static/populate.html

"Therefore it may be necessary, not just desirable, to drop and re-apply foreign keys when loading large amounts of data. If temporarily removing the constraint isn't acceptable, the only other recourse may be to split up the load operation into smaller transactions."

Ok, but how do you do either the drop and re-apply or the split without losing the relationship which is the whole point of a foreign key constraint? There must be some other mechanism which maintains the link somehow. What is it? How does it work? etc.

I have seen this post, so I know it CAN be done: Recreate all foreign keys in all tables as deferrable (batch) answer by @a_horse_with_no_name. My question is, how? I can copy and paste the code given, but that doesn't mean I understand what it is doing. Most of the tutorials I've seen online are far more basic than this. Can someone refer me to a text that covers this issue (preferably available free online or in a library)? Or give an explanation here if it wouldn't be too long or too much trouble? Thanks.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.