/* *get_controlfile_by_exact_path() * *Asabove,butthecallerspecifiesthepathtothecontrolfileitself, *ratherthanthepathtothedatadirectory.
*/
ControlFileData *
get_controlfile_by_exact_path(constchar *ControlFilePath, bool *crc_ok_p)
{
ControlFileData *ControlFile; int fd;
pg_crc32c crc; int r; #ifdef FRONTEND
pg_crc32c last_crc; int retries = 0; #endif
Assert(crc_ok_p);
ControlFile = palloc_object(ControlFileData);
#ifdef FRONTEND
INIT_CRC32C(last_crc);
retry: #endif
#ifndef FRONTEND if ((fd = OpenTransientFile(ControlFilePath, O_RDONLY | PG_BINARY)) == -1)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open file \"%s\" for reading: %m",
ControlFilePath))); #else if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
pg_fatal("could not open file \"%s\" for reading: %m",
ControlFilePath); #endif
r = read(fd, ControlFile, sizeof(ControlFileData)); if (r != sizeof(ControlFileData))
{ if (r < 0) #ifndef FRONTEND
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", ControlFilePath))); #else
pg_fatal("could not read file \"%s\": %m", ControlFilePath); #endif else #ifndef FRONTEND
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
ControlFilePath, r, sizeof(ControlFileData)))); #else
pg_fatal("could not read file \"%s\": read %d of %zu",
ControlFilePath, r, sizeof(ControlFileData)); #endif
}
#ifndef FRONTEND if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
ControlFilePath))); #else if (close(fd) != 0)
pg_fatal("could not close file \"%s\": %m", ControlFilePath); #endif
/* Make sure the control file is valid byte order. */ if (ControlFile->pg_control_version % 65536 == 0 &&
ControlFile->pg_control_version / 65536 != 0) #ifndef FRONTEND
elog(ERROR, _("byte ordering mismatch")); #else
pg_log_warning("possible byte ordering mismatch\n" "The byte ordering used to store the pg_control file might not match the one\n" "used by this program. In that case the results below would be incorrect, and\n" "the PostgreSQL installation would be incompatible with this data directory."); #endif
/* *AllerrorsissueaPANIC,sononeedtouseOpenTransientFile()andto *worryaboutfiledescriptorleaks.
*/ if ((fd = BasicOpenFile(ControlFilePath, O_RDWR | PG_BINARY)) < 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m",
ControlFilePath))); #else if ((fd = open(ControlFilePath, O_WRONLY | PG_BINARY,
pg_file_create_mode)) == -1)
pg_fatal("could not open file \"%s\": %m", ControlFilePath); #endif
errno = 0; #ifndef FRONTEND
pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE); #endif if (write(fd, buffer, PG_CONTROL_FILE_SIZE) != PG_CONTROL_FILE_SIZE)
{ /* if write didn't set errno, assume problem is no disk space */ if (errno == 0)
errno = ENOSPC;
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.