/* *Dothedatacopying.
*/
flush_offset = 0; for (offset = 0;; offset += nbytes)
{ /* If we got a cancel signal during the copy of the file, quit */
CHECK_FOR_INTERRUPTS();
pgstat_report_wait_start(WAIT_EVENT_COPY_FILE_READ);
nbytes = read(srcfd, buffer, COPY_BUF_SIZE);
pgstat_report_wait_end(); if (nbytes < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", fromfile))); if (nbytes == 0) break;
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_COPY_FILE_WRITE); if ((int) write(dstfd, buffer, nbytes) != nbytes)
{ /* if write didn't set errno, assume problem is no disk space */ if (errno == 0)
errno = ENOSPC;
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to file \"%s\": %m", tofile)));
}
pgstat_report_wait_end();
}
if (offset > flush_offset)
pg_flush_data(dstfd, flush_offset, offset - flush_offset);
if (CloseTransientFile(dstfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tofile)));
if (CloseTransientFile(srcfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", fromfile)));
pfree(buffer);
}
/* *cloneonefile
*/ staticvoid
clone_file(constchar *fromfile, constchar *tofile)
{ #ifdefined(HAVE_COPYFILE) && defined(COPYFILE_CLONE_FORCE) if (copyfile(fromfile, tofile, NULL, COPYFILE_CLONE_FORCE) < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not clone file \"%s\" to \"%s\": %m",
fromfile, tofile))); #elifdefined(HAVE_COPY_FILE_RANGE) int srcfd; int dstfd;
ssize_t nbytes;
srcfd = OpenTransientFile(fromfile, O_RDONLY | PG_BINARY); if (srcfd < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", fromfile)));
do
{ /* *Don'tcopytoomuchatonce,sowecancheckforinterruptsfrom *timetotimeifitfallsbacktoaslowcopy.
*/
CHECK_FOR_INTERRUPTS();
pgstat_report_wait_start(WAIT_EVENT_COPY_FILE_COPY);
nbytes = copy_file_range(srcfd, NULL, dstfd, NULL, 1024 * 1024, 0); if (nbytes < 0 && errno != EINTR)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not clone file \"%s\" to \"%s\": %m",
fromfile, tofile)));
pgstat_report_wait_end();
} while (nbytes != 0);
if (CloseTransientFile(dstfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tofile)));
if (CloseTransientFile(srcfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", fromfile))); #else /* If there is no CLONE support this function should not be called. */
pg_unreachable(); #endif
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-09-28)
¤
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.