I have a number of constraints:
- I have binary custom format dump from Heroku that I need to load via
pg_restore
. - I need to load this onto an AWS RDS instance, where I don't have full superuser (only rds_superuser).
- The data is quite large (a few TB), and takes over 24 hours to load.
- I don't want to remove the constraints permanently, just during the restore.
Looking at the pg_restore
output it seems to spend a lot of time checking constraints (foreign keys, unique constraints, etc). That makes sense because we do have a lot of them, and a lot of data. The thing is, I know the constraints are valid for the data in the dump, because the database the data was dumped from has them enforced. I'd like to suppress these constraints just for the import and then resume enforcing them after the import is complete.
Here's what I've tried:
- Using
--disable-triggers
withpg_restore
. This seems like it's exactly what I want, but it doesn't seem possible to use with RDS. I get a lot of errors like this:ERROR: permission denied: "RI_ConstraintTrigger_c_172425" is a system trigger
and that seems to be because therds_superuser
is not super enough to use--disable-triggers
- Using
SET session_replication_role = replica;
. This also seems hopeful, but I can't find a way to use this with thepg_restore
. I can setsession_replication_role
, but I don't know how to then import the binary dump from that same session. I see a lot of people suggesting putting that at the top of a text dump, but I have a binary dump, and I don't think I can insert lines to it.
Any ideas?