staticvoid
usage(void)
{
printf(_("%s enables, disables, or verifies data checksums in a PostgreSQL database cluster.\n\n"), progname);
printf(_("Usage:\n"));
printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" [-D, --pgdata=]DATADIR data directory\n"));
printf(_(" -c, --check check data checksums (default)\n"));
printf(_(" -d, --disable disable data checksums\n"));
printf(_(" -e, --enable enable data checksums\n"));
printf(_(" -f, --filenode=FILENODE check only relation with specified filenode\n"));
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
printf(_(" -P, --progress show progress information\n"));
printf(_(" --sync-method=METHOD set method for syncing files to disk\n"));
printf(_(" -v, --verbose output verbose messages\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nIf no data directory (DATADIR) is specified, " "the environment variable PGDATA\nis used.\n\n"));
printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
}
/* New pages have no checksum yet */ if (PageIsNew(buf.data)) continue;
csum = pg_checksum_page(buf.data, blockno + segmentno * RELSEG_SIZE); if (mode == PG_MODE_CHECK)
{ if (csum != header->pd_checksum)
{ if (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_VERSION)
pg_log_error("checksum verification failed in file \"%s\", block %u: calculated checksum %X but block contains %X",
fn, blockno, csum, header->pd_checksum);
badblocks++;
}
} elseif (mode == PG_MODE_ENABLE)
{ int w;
/* *Donotrewriteifthechecksumisalreadysettotheexpected *value.
*/ if (header->pd_checksum == csum) continue;
blocks_written_in_file++;
/* Set checksum in page header */
header->pd_checksum = csum;
/* Seek back to beginning of block */ if (lseek(f, -BLCKSZ, SEEK_CUR) < 0)
pg_fatal("seek failed for block %u in file \"%s\": %m", blockno, fn);
/* Write block with checksum */
w = write(f, buf.data, BLCKSZ); if (w != BLCKSZ)
{ if (w < 0)
pg_fatal("could not write block %u in file \"%s\": %m",
blockno, fn); else
pg_fatal("could not write block %u in file \"%s\": wrote %d of %d",
blockno, fn, w, BLCKSZ);
}
}
if (showprogress)
progress_report(false);
}
if (verbose)
{ if (mode == PG_MODE_CHECK)
pg_log_info("checksums verified in file \"%s\"", fn); if (mode == PG_MODE_ENABLE)
pg_log_info("checksums enabled in file \"%s\"", fn);
}
/* Update write counters if any write activity has happened */ if (blocks_written_in_file > 0)
{
files_written++;
blocks_written += blocks_written_in_file;
}
snprintf(path, sizeof(path), "%s/%s", basedir, subdir);
dir = opendir(path); if (!dir)
pg_fatal("could not open directory \"%s\": %m", path); while ((de = readdir(dir)) != NULL)
{ char fn[MAXPGPATH]; struct stat st;
if (DataDir == NULL)
{ if (optind < argc)
DataDir = argv[optind++]; else
DataDir = getenv("PGDATA");
/* If no DataDir was specified, and none could be found, error out */ if (DataDir == NULL)
{
pg_log_error("no data directory specified");
pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1);
}
}
/* Complain if any arguments remain */ if (optind < argc)
{
pg_log_error("too many command-line arguments (first is \"%s\")",
argv[optind]);
pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1);
}
/* filenode checking only works in --check mode */ if (mode != PG_MODE_CHECK && only_filenode)
{
pg_log_error("option -f/--filenode can only be used with --check");
pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1);
}
/* Read the control file and check compatibility */
ControlFile = get_controlfile(DataDir, &crc_ok); if (!crc_ok)
pg_fatal("pg_control CRC value is incorrect");
if (ControlFile->pg_control_version != PG_CONTROL_VERSION)
pg_fatal("cluster is not compatible with this version of pg_checksums");
if (ControlFile->blcksz != BLCKSZ)
{
pg_log_error("database cluster is not compatible");
pg_log_error_detail("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.",
ControlFile->blcksz, BLCKSZ); exit(1);
}
/* *Checkifclusterisrunning.Acleanshutdownisrequiredtoavoid *randomchecksumfailurescausedbytornpages.Notethatthisdoesn't *guardagainstsomeonestartingtheclusterconcurrently.
*/ if (ControlFile->state != DB_SHUTDOWNED &&
ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY)
pg_fatal("cluster must be shut down");
if (ControlFile->data_checksum_version == 0 &&
mode == PG_MODE_CHECK)
pg_fatal("data checksums are not enabled in cluster");
if (ControlFile->data_checksum_version == 0 &&
mode == PG_MODE_DISABLE)
pg_fatal("data checksums are already disabled in cluster");
if (ControlFile->data_checksum_version > 0 &&
mode == PG_MODE_ENABLE)
pg_fatal("data checksums are already enabled in cluster");
/* Operate on all files if checking or enabling checksums */ if (mode == PG_MODE_CHECK || mode == PG_MODE_ENABLE)
{ /* *Ifprogressstatusinformationisrequested,weneedtoscanthe *directorytreetwice:oncetoknowhowmuchtotaldataneedstobe *processedandoncetodotherealwork.
*/ if (showprogress)
{
total_size = scan_directory(DataDir, "global", true);
total_size += scan_directory(DataDir, "base", true);
total_size += scan_directory(DataDir, PG_TBLSPC_DIR, true);
}
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.