[Postgres] Disable foreign key checks


I have to disable foreign key checks to perform a restore.

But when I hit the command

SET session_replication_role = 'replica'

I have permissions denied

What can I do?

Hey Martin,

You should be able to restore your database without updating this setting. As this is a managed Postgres database, most settings have to be changed, on a case-by-case basis.

You should be able to drop the constraints on your table and re-add them after the restore, e.g:

-- Check your table's contraints\d orders-- Drop foreign key constraintsALTER TABLE orders DROP CONSTRAINT orders_product_id_fkey; ALTER TABLE orders DROP CONSTRAINT orders_user_id_fkey;-----> Perform the restore-- Re-create foreign key constraintsALTER TABLE orders ADD CONSTRAINT orders_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE;ALTER TABLE orders ADD CONSTRAINT orders_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;

Render Support, UTC+3

Man, I have like 100 foreign key, it’s a big database. I will not do this on every field. Why I can’t do like I should be able to

SET session_replication_role = 'replica'



It looks like you’ve opened a chat with us, let’s follow up on the chat, so we can have a private conversation and avoid duplicates.

Render Support, UTC+3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.