Esempio n. 1
0
/*
 * transfer_relfile()
 *
 * Copy or link file from old cluster to new one.
 */
static void
transfer_relfile(pageCnvCtx *pageConverter, const char *old_file,
			  const char *new_file, const char *nspname, const char *relname)
{
	const char *msg;

	if ((user_opts.transfer_mode == TRANSFER_MODE_LINK) && (pageConverter != NULL))
		pg_log(PG_FATAL, "this upgrade requires page-by-page conversion, "
			   "you must use copy-mode instead of link-mode\n");

	if (user_opts.transfer_mode == TRANSFER_MODE_COPY)
	{
		pg_log(PG_INFO, "copying %s to %s\n", old_file, new_file);

		if ((msg = copyAndUpdateFile(pageConverter, old_file, new_file, true)) != NULL)
			pg_log(PG_FATAL, "error while copying %s.%s (%s to %s): %s\n",
				   nspname, relname, old_file, new_file, msg);
	}
	else
	{
		pg_log(PG_INFO, "linking %s to %s\n", old_file, new_file);

		if ((msg = linkAndUpdateFile(pageConverter, old_file, new_file)) != NULL)
			pg_log(PG_FATAL,
				   "error while creating link from %s.%s (%s to %s): %s\n",
				   nspname, relname, old_file, new_file, msg);
	}
	return;
}
Esempio n. 2
0
/*
 * transfer_relfile()
 *
 * Copy or link file from old cluster to new one.
 */
static void
transfer_relfile(pageCnvCtx *pageConverter, FileNameMap *map,
				 const char *type_suffix)
{
	const char *msg;
	char		old_file[MAXPGPATH];
	char		new_file[MAXPGPATH];
	int			fd;
	int			segno;
	char		extent_suffix[65];
	
	/*
	 * Now copy/link any related segments as well. Remember, PG breaks
	 * large files into 1GB segments, the first segment has no extension,
	 * subsequent segments are named relfilenode.1, relfilenode.2,
	 * relfilenode.3.
	 * copied.
	 */
	for (segno = 0;; segno++)
	{
		if (segno == 0)
			extent_suffix[0] = '\0';
		else
			snprintf(extent_suffix, sizeof(extent_suffix), ".%d", segno);

		snprintf(old_file, sizeof(old_file), "%s/%u%s%s", map->old_dir,
				 map->old_relfilenode, type_suffix, extent_suffix);
		snprintf(new_file, sizeof(new_file), "%s/%u%s%s", map->new_dir,
				 map->new_relfilenode, type_suffix, extent_suffix);
	
		/* Is it an extent, fsm, or vm file? */
		if (type_suffix[0] != '\0' || segno != 0)
		{
			/* Did file open fail? */
			if ((fd = open(old_file, O_RDONLY, 0)) == -1)
			{
				/* File does not exist?  That's OK, just return */
				if (errno == ENOENT)
					return;
				else
					pg_log(PG_FATAL, "error while checking for file existance \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
						   map->nspname, map->relname, old_file, new_file,
						   getErrorText(errno));
			}
			close(fd);
		}

		unlink(new_file);
	
		/* Copying files might take some time, so give feedback. */
		pg_log(PG_REPORT, OVERWRITE_MESSAGE, old_file);
	
		if ((user_opts.transfer_mode == TRANSFER_MODE_LINK) && (pageConverter != NULL))
			pg_log(PG_FATAL, "This upgrade requires page-by-page conversion, "
				   "you must use copy mode instead of link mode.\n");
	
		if (user_opts.transfer_mode == TRANSFER_MODE_COPY)
		{
			pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"\n", old_file, new_file);
	
			if ((msg = copyAndUpdateFile(pageConverter, old_file, new_file, true)) != NULL)
				pg_log(PG_FATAL, "error while copying relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
					   map->nspname, map->relname, old_file, new_file, msg);
		}
		else
		{
			pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"\n", old_file, new_file);
	
			if ((msg = linkAndUpdateFile(pageConverter, old_file, new_file)) != NULL)
				pg_log(PG_FATAL,
					   "error while creating link for relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
					   map->nspname, map->relname, old_file, new_file, msg);
		}
   }

	return;
}