Line data Source code
1 : /* 2 : * dump.c 3 : * 4 : * dump functions 5 : * 6 : * Copyright (c) 2010-2025, PostgreSQL Global Development Group 7 : * src/bin/pg_upgrade/dump.c 8 : */ 9 : 10 : #include "postgres_fe.h" 11 : 12 : #include "fe_utils/string_utils.h" 13 : #include "pg_upgrade.h" 14 : 15 : void 16 8 : generate_old_dump(void) 17 : { 18 : int dbnum; 19 : 20 8 : prep_status("Creating dump of global objects"); 21 : 22 : /* run new pg_dumpall binary for globals */ 23 8 : exec_prog(UTILITY_LOG_FILE, NULL, true, true, 24 : "\"%s/pg_dumpall\" %s --globals-only --quote-all-identifiers " 25 : "--binary-upgrade %s --no-sync -f \"%s/%s\"", 26 : new_cluster.bindir, cluster_conn_opts(&old_cluster), 27 8 : log_opts.verbose ? "--verbose" : "", 28 : log_opts.dumpdir, 29 : GLOBALS_DUMP_FILE); 30 8 : check_ok(); 31 : 32 8 : prep_status_progress("Creating dump of database schemas"); 33 : 34 : /* create per-db dump files */ 35 32 : for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) 36 : { 37 : char sql_file_name[MAXPGPATH], 38 : log_file_name[MAXPGPATH]; 39 24 : DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; 40 : PQExpBufferData connstr, 41 : escaped_connstr; 42 : 43 24 : initPQExpBuffer(&connstr); 44 24 : appendPQExpBufferStr(&connstr, "dbname="); 45 24 : appendConnStrVal(&connstr, old_db->db_name); 46 24 : initPQExpBuffer(&escaped_connstr); 47 24 : appendShellString(&escaped_connstr, connstr.data); 48 24 : termPQExpBuffer(&connstr); 49 : 50 24 : pg_log(PG_STATUS, "%s", old_db->db_name); 51 24 : snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid); 52 24 : snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); 53 : 54 24 : parallel_exec_prog(log_file_name, NULL, 55 : "\"%s/pg_dump\" %s --schema-only --quote-all-identifiers " 56 : "--binary-upgrade --format=custom %s --no-sync --file=\"%s/%s\" %s", 57 : new_cluster.bindir, cluster_conn_opts(&old_cluster), 58 24 : log_opts.verbose ? "--verbose" : "", 59 : log_opts.dumpdir, 60 : sql_file_name, escaped_connstr.data); 61 : 62 24 : termPQExpBuffer(&escaped_connstr); 63 : } 64 : 65 : /* reap all children */ 66 8 : while (reap_child(true) == true) 67 : ; 68 : 69 8 : end_progress_output(); 70 8 : check_ok(); 71 8 : }