staticinlinevoid
sync_queue_init(void)
{ if (sync_queue_inited) return;
sync_queue_inited = true; for (int i = 0; i < SYNC_QUEUE_MAX_LEN; i++)
sync_queue[i] = palloc(MAXPGPATH);
}
staticinlinevoid
sync_queue_sync_all(void)
{ if (!sync_queue_inited) return;
for (int i = 0; i < sync_queue_len; i++)
{ if (fsync_fname(sync_queue[i], false) != 0)
pg_fatal("could not synchronize file \"%s\": %m", sync_queue[i]);
}
/* Scan the old cluster databases and transfer their files */ for (old_dbnum = new_dbnum = 0;
old_dbnum < old_db_arr->ndbs;
old_dbnum++, new_dbnum++)
{
DbInfo *old_db = &old_db_arr->dbs[old_dbnum],
*new_db = NULL;
FileNameMap *mappings; int n_maps;
/* Check that the database directory exists in the given tablespace. */ if (stat(old_db_dir, &st) != 0)
{ if (errno != ENOENT)
pg_fatal("could not stat file \"%s\": %m", old_db_dir); returnfalse;
}
/* Create directory for stuff that is moved aside. */ if (pg_mkdir_p(moved_tblspc, pg_dir_create_mode) != 0 && errno != EEXIST)
pg_fatal("could not create directory \"%s\": %m", moved_tblspc);
/* Create directory for old catalog files. */ if (pg_mkdir_p(old_catalog_dir, pg_dir_create_mode) != 0)
pg_fatal("could not create directory \"%s\": %m", old_catalog_dir);
/* Move the new cluster's database directory aside. */ if (rename(new_db_dir, moved_db_dir) != 0)
pg_fatal("could not rename directory \"%s\" to \"%s\": %m", new_db_dir, moved_db_dir);
/* Move the old cluster's database directory into place. */ if (rename(old_db_dir, new_db_dir) != 0)
pg_fatal("could not rename directory \"%s\" to \"%s\": %m", old_db_dir, new_db_dir);
/* Move the old catalog files aside. */
dir = opendir(new_db_dir); if (dir == NULL)
pg_fatal("could not open directory \"%s\": %m", new_db_dir); while (errno = 0, (de = readdir(dir)) != NULL)
{
snprintf(path, sizeof(path), "%s/%s", new_db_dir, de->d_name); if (get_dirent_type(path, de, false, PG_LOG_ERROR) != PGFILETYPE_REG) continue;
if (bsearch(&key, maps, size, sizeof(FileNameMap), FileNameMapCmp)) continue;
}
snprintf(dest, sizeof(dest), "%s/%s", old_catalog_dir, de->d_name); if (rename(path, dest) != 0)
pg_fatal("could not rename file \"%s\" to \"%s\": %m", path, dest);
} if (errno)
pg_fatal("could not read directory \"%s\": %m", new_db_dir);
(void) closedir(dir);
/* Move the new catalog files into place. */
dir = opendir(moved_db_dir); if (dir == NULL)
pg_fatal("could not open directory \"%s\": %m", moved_db_dir); while (errno = 0, (de = readdir(dir)) != NULL)
{
snprintf(path, sizeof(path), "%s/%s", moved_db_dir, de->d_name); if (get_dirent_type(path, de, false, PG_LOG_ERROR) != PGFILETYPE_REG) continue;
if (bsearch(&key, maps, size, sizeof(FileNameMap), FileNameMapCmp)) continue;
}
snprintf(dest, sizeof(dest), "%s/%s", new_db_dir, de->d_name); if (rename(path, dest) != 0)
pg_fatal("could not rename file \"%s\" to \"%s\": %m", path, dest);
/* *Wedon'tfsync()thedatabasefilesinthefilesynchronization *stageofpg_upgradeinswapmode,soweneedtosynchronizethem *ourselves.Weonlydothisforthecatalogfilesbecausetheywere *createdduringpg_restorewithfsync=off.Weassumethattheuser *datafileswereproperlypersistedtodiskwhentheuserlastshut *itdown.
*/ if (user_opts.do_sync)
sync_queue_push(dest);
} if (errno)
pg_fatal("could not read directory \"%s\": %m", moved_db_dir);
(void) closedir(dir);
/* Ensure the directory entries are persisted to disk. */ if (fsync_fname(new_db_dir, true) != 0)
pg_fatal("could not synchronize directory \"%s\": %m", new_db_dir); if (fsync_parent_path(new_db_dir) != 0)
pg_fatal("could not synchronize parent directory of \"%s\": %m", new_db_dir);
}
/* --swap has its own subroutine */ if (user_opts.transfer_mode == TRANSFER_MODE_SWAP)
{ /* *Wedon'tsupport--swaptoupgradefromversionsthatrequire *rewritingthevisibilitymap.Weshould'vefailedalreadyif *someonetriestodothat.
*/
Assert(!vm_must_add_frozenbit);
do_swap(maps, size, old_tablespace); return;
}
for (mapnum = 0; mapnum < size; mapnum++)
{ if (old_tablespace == NULL ||
strcmp(maps[mapnum].old_tablespace, old_tablespace) == 0)
{ /* transfer primary file */
transfer_relfile(&maps[mapnum], "", vm_must_add_frozenbit);
/* Is it an extent, fsm, or vm file? */ if (type_suffix[0] != '\0' || segno != 0)
{ /* Did file open fail? */ if (stat(old_file, &statbuf) != 0)
{ /* File does not exist? That's OK, just return */ if (errno == ENOENT) return; else
pg_fatal("error while checking for file existence \"%s.%s\" (\"%s\" to \"%s\"): %m",
map->nspname, map->relname, old_file, new_file);
}
/* If file is empty, just return */ if (statbuf.st_size == 0) return;
}
unlink(new_file);
/* Copying files might take some time, so give feedback. */
pg_log(PG_STATUS, "%s", old_file);
if (vm_must_add_frozenbit && strcmp(type_suffix, "_vm") == 0)
{ /* Need to rewrite visibility map format */
pg_log(PG_VERBOSE, "rewriting \"%s\" to \"%s\"",
old_file, new_file);
rewriteVisibilityMap(old_file, new_file, map->nspname, map->relname);
} else switch (user_opts.transfer_mode)
{ case TRANSFER_MODE_CLONE:
pg_log(PG_VERBOSE, "cloning \"%s\" to \"%s\"",
old_file, new_file);
cloneFile(old_file, new_file, map->nspname, map->relname); break; case TRANSFER_MODE_COPY:
pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"",
old_file, new_file);
copyFile(old_file, new_file, map->nspname, map->relname); break; case TRANSFER_MODE_COPY_FILE_RANGE:
pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\" with copy_file_range",
old_file, new_file);
copyFileByRange(old_file, new_file, map->nspname, map->relname); break; case TRANSFER_MODE_LINK:
pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"",
old_file, new_file);
linkFile(old_file, new_file, map->nspname, map->relname); break; case TRANSFER_MODE_SWAP: /* swap mode is handled in its own code path */
pg_fatal("should never happen"); break;
}
}
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.19Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.