70 printf(
_(
"%s enables, disables, or verifies data checksums in a PostgreSQL database cluster.\n\n"),
progname);
74 printf(
_(
" [-D, --pgdata=]DATADIR data directory\n"));
75 printf(
_(
" -c, --check check data checksums (default)\n"));
76 printf(
_(
" -d, --disable disable data checksums\n"));
77 printf(
_(
" -e, --enable enable data checksums\n"));
78 printf(
_(
" -f, --filenode=FILENODE check only relation with specified filenode\n"));
79 printf(
_(
" -N, --no-sync do not wait for changes to be written safely to disk\n"));
80 printf(
_(
" -P, --progress show progress information\n"));
81 printf(
_(
" --sync-method=METHOD set method for syncing files to disk\n"));
82 printf(
_(
" -v, --verbose output verbose messages\n"));
83 printf(
_(
" -V, --version output version information, then exit\n"));
84 printf(
_(
" -?, --help show this help, then exit\n"));
85 printf(
_(
"\nIf no data directory (DATADIR) is specified, "
86 "the environment variable PGDATA\nis used.\n\n"));
109 {
"pg_control",
false},
110 {
"pg_filenode.map",
false},
111 {
"pg_internal.init",
true},
112 {
"PG_VERSION",
false},
114 {
"config_exec_params",
true},
192 pg_fatal(
"could not open file \"%s\": %m",
fn);
196 for (blockno = 0;; blockno++)
206 pg_fatal(
"could not read block %u in file \"%s\": %m",
209 pg_fatal(
"could not read block %u in file \"%s\": read %d of %d",
232 pg_log_error(
"checksum verification failed in file \"%s\", block %u: calculated checksum %X but block contains %X",
255 pg_fatal(
"seek failed for block %u in file \"%s\": %m", blockno,
fn);
262 pg_fatal(
"could not write block %u in file \"%s\": %m",
265 pg_fatal(
"could not write block %u in file \"%s\": wrote %d of %d",
310 pg_fatal(
"could not open directory \"%s\": %m", path);
333 if (
strcmp(
de->d_name,
".DS_Store") == 0)
338 pg_fatal(
"could not stat file \"%s\": %m",
fn);
362 pg_fatal(
"invalid segment number %d in file name \"%s\"",
407 pg_fatal(
"could not stat file \"%s\": %m",
461 if (
strcmp(argv[1],
"--help") == 0 ||
strcmp(argv[1],
"-?") == 0)
466 if (
strcmp(argv[1],
"--version") == 0 ||
strcmp(argv[1],
"-V") == 0)
535 pg_log_error(
"too many command-line arguments (first is \"%s\")",
544 pg_log_error(
"option -f/--filenode can only be used with --check");
558 pg_log_error_detail(
"File \"%s\" contains \"%s\", which is not compatible with this program's version \"%s\".",
566 pg_fatal(
"pg_control CRC value is incorrect");
569 pg_fatal(
"cluster is not compatible with this version of pg_checksums");
574 pg_log_error_detail(
"The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.",
586 pg_fatal(
"cluster must be shut down");
590 pg_fatal(
"data checksums are not enabled in cluster");
594 pg_fatal(
"data checksums are already disabled in cluster");
598 pg_fatal(
"data checksums are already enabled in cluster");
622 printf(
_(
"Checksum operation completed\n"));
662 printf(
_(
"Checksums enabled in cluster\n"));
664 printf(
_(
"Checksums disabled in cluster\n"));
Datum now(PG_FUNCTION_ARGS)
PageHeaderData * PageHeader
static bool PageIsNew(const PageData *page)
#define PG_DATA_CHECKSUM_VERSION
#define Assert(condition)
#define PG_TEXTDOMAIN(domain)
uint16 pg_checksum_page(char *page, BlockNumber blkno)
void set_pglocale_pgservice(const char *argv0, const char *app)
void update_controlfile(const char *DataDir, ControlFileData *ControlFile, bool do_sync)
ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p)
#define fprintf(file, fmt, msg)
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
uint32 get_pg_version(const char *datadir, char **version_str)
#define PG_TEMP_FILES_DIR
#define PG_TEMP_FILE_PREFIX
@ DATA_DIR_SYNC_METHOD_FSYNC
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
void pg_logging_init(const char *argv0)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define pg_log_error_detail(...)
char * pstrdup(const char *in)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
bool parse_sync_method(const char *optarg, DataDirSyncMethod *sync_method)
static void scan_file(const char *fn, int segmentno)
static PgChecksumMode mode
static char * only_filenode
static int64 blocks_scanned
static int64 current_size
static void progress_report(bool finished)
static pg_time_t last_progress_report
static const struct exclude_list_item skip[]
static int64 scan_directory(const char *basedir, const char *subdir, bool sizeonly)
static int64 files_scanned
static bool skipfile(const char *fn)
static ControlFileData * ControlFile
static DataDirSyncMethod sync_method
static int64 blocks_written
static const char * progname
static int64 files_written
#define PG_CONTROL_VERSION
@ DB_SHUTDOWNED_IN_RECOVERY
PGDLLIMPORT char * optarg
static char buf[DEFAULT_XLOG_SEG_SIZE]
const char * get_progname(const char *argv0)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define TABLESPACE_VERSION_DIRECTORY
uint32 pg_control_version
uint32 data_checksum_version
static void * fn(void *arg)
#define GET_PG_MAJORVERSION_NUM(v)