0

Is there a way to know the parent - child relations (in terms of foreign keys) of all the tables in postgresql database? We are planning a full database migration using AWS DMS, we need specify in what order we can migrate our tables.

asked Sep 24, 2020 at 6:45

1 Answer 1

2

The documentation suggests to disable constraint checks:

If the target is a PostgreSQL-compatible database, then you can see foreign key violation errors during the CDC phase. To resolve this error, set the session_replication_role parameter to replica.

If you really want to specify the table order manually, use any of the queries from this question to get a list; for example:

SELECT
 tc.table_schema, 
 tc.table_name, 
 ccu.table_name AS foreign_table_name
FROM 
 information_schema.table_constraints AS tc 
 JOIN information_schema.constraint_column_usage AS ccu
 USING (constraint_name, table_schema)
WHERE tc.constraint_type = 'FOREIGN KEY';
answered Sep 24, 2020 at 8:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.