I have a PostgreSQL database instance located in EU region. I plan on introducing another PostgreSQL database instance located in a new geographical region.
As part this work, I am to migrate data for selected customers from a database instance in EU to a database instance in this new geo region and am seeking for advice.
On a surface, this boils down to doing the following work:
- given a specific
accounts.id, - find and copy the record from
accountstable from EU database instance toaccountstable in another region's database instance, - identify and copy records across all tables that are related to given
accountrecord, recursively (e.g. as well as potentially from tables related to those tables...).
Effectively, having a specific DB record as starting point, I need to:
- build a hierarchy, or rather a graph of DB records across all available tables, all directly (or indirectly) related to the "starting point" record (all possible relations, perhaps, could be established based on a foreign key constraints),
- for each record found across all tables, generate a string containing an
INSERTstatement, - replay all
INSERTstatements, in a transaction, on another database instance.
It appears as if I might need to build a tool to do this kind of work. But before I do, I wonder:
- is there a common approach for implementing this?,
- if not, what might be a good starting point to approach this problem?