Thanks Andrew for some design related feedback.
Thanks Jian for the offline discussions, reviews, testing and delta patches.
Thanks Tushar for the detailed testing.
Brief about this patch:
new option to pg_dumpall: --format=d/t/c/p directory/tar/custam/plain
If the user gives a non-text format with pg_dumpall command, then the full cluster will be dumped and global objects (roles. tablespaces, databases) will be dumped into toc.glo file in custom format with drop commands and databases will be dumped into a given archive format one by one with oid.tar/oid.dmp/oid files/dir.
When restoring, if the user gives -g(globals-only) option, then creating commands of only global users/tablespaces/databases will be restored. (no drop commands will be executed)
toc.glo will be executed with -e(exit-on-error=false) and --transaction-size=0 as some user already created. If the user wants to restore a single database, they can restore it by a single dump file. For --clean and -g(globals-only), we added some error cases so that roles/databases/tablespaces will not be dropped.
Here, I am attaching an updated patch for the review and testing.