Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support database-level dump/restore (#108)
Added support for dumping a single Babelfish logical database. Changes are summarized in following bullet points: Added a new option --bbf-database-name in both pg_dumpall and pg_dump to let user provide the name of logical database to be dumped. Fetch all the physical schema names corresponding to the given logical database and add all of them into schema_include_patterns list. With this, existing dump logic will make sure to only dump all these schemas as well as all the objects contained by these schemas. Function bbf_selectDumpableTableData takes care of explicitly marking all Babelfish catalog table data to be dumped. We need to selectively dump the Babelfish catalog table data corresponding to given logical database which is being handled by function getCursorForBbfCatalogTableData for COLUMN-INSERT and fixCopyCommand for COPY. These function prepares query using joins and conditions to filter the data. We skip dumping the dbid column as it might conflict with the existing database's dbid so we generate the new dbid during restore. It has been handled for both COLUMN-INSERT and COPY options: a. COPY: Implemented a hook fill_missing_values_in_copyfrom_hook which will use the sequence to generate the new dbid. b. COLUMN-INSERT: Used existing pre_parse_analyze_hook hook to handle this case. Added a new file dumpall_babel_utils.c to implement Babelfish specific logic to selectively dump users. New file is needed since existing dump_babel_utils.c can't be used with pg_dumpall utility. Logins do not belong to a single database so we will not be dumping the logins so it and we will only dump default users of the database (dbo, db_owner and db_guest). Due to this CREATE and INSERT might fail for certain logins but it should be fine. Current implementation does not dump foreign servers and foreign data wrappers as these are global objects and does not belong to a single logical database. Note: A logical database with certain migration mode (single-db/multi-db) can only be restored on the Babelfish server with the same migration mode. Which means a single-db database can be restored only on single-db Babelfish server, same thing applies to multi-db. Although the builtin databases like master can be restored on any kind of server.
- Loading branch information