1

Is there an efficient way to bulk import data into a PostgreSQL 9.4 database on RDS that makes extensive use of foreign key constraints? The standard method of using pg_restore fails because RDS does not appear to allow you to disable system triggers.

For example, using the command:

pg_restore --host foo.rds.amazonaws.com --port 5432 --username "bar" --role=rds_superuser --dbname "baz" --data-only --disable-triggers --no-owner --no-privileges --no-tablespaces --verbose --exit-on-error "baz.dump"

Results in error messages such as:

pg_restore: [archiver (db)] could not execute query: ERROR: permission denied: "RI_ConstraintTrigger_a_30548" is a system trigger Command was: ALTER TABLE xxxx DISABLE TRIGGER ALL;

1
  • That is not bulk import data, that is database import with data only. :) BTW you can export data only or schema. – Mladen Uzelac Apr 1 '15 at 18:11
2

Here's a workaround that works for me:

Create the schema then dump the tables only, in order such that no FK constraint checks fail:

pg_dump --username=postgres --data-only --table=table_1 --table=table_2 --table=table_3 --table=... --format=custom foo > foo.dump

pg_restore will now work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.