PostgreSQL Source Code  git master
pg_checksums.c File Reference
#include "postgres_fe.h"
#include <dirent.h>
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include "access/xlog_internal.h"
#include "common/controldata_utils.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/logging.h"
#include "getopt_long.h"
#include "pg_getopt.h"
#include "storage/bufpage.h"
#include "storage/checksum.h"
#include "storage/checksum_impl.h"
Include dependency graph for pg_checksums.c:

Go to the source code of this file.

Data Structures

struct  exclude_list_item
 

Macros

#define PG_TEMP_FILES_DIR   "pgsql_tmp"
 
#define PG_TEMP_FILE_PREFIX   "pgsql_tmp"
 

Enumerations

enum  PgChecksumMode { PG_MODE_CHECK, PG_MODE_DISABLE, PG_MODE_ENABLE }
 

Functions

static void usage (void)
 
static void progress_report (bool finished)
 
static bool skipfile (const char *fn)
 
static void scan_file (const char *fn, BlockNumber segmentno)
 
static int64 scan_directory (const char *basedir, const char *subdir, bool sizeonly)
 
int main (int argc, char *argv[])
 

Variables

static int64 files = 0
 
static int64 blocks = 0
 
static int64 badblocks = 0
 
static ControlFileDataControlFile
 
static char * only_filenode = NULL
 
static bool do_sync = true
 
static bool verbose = false
 
static bool showprogress = false
 
static PgChecksumMode mode = PG_MODE_CHECK
 
static const char * progname
 
int64 total_size = 0
 
int64 current_size = 0
 
static pg_time_t last_progress_report = 0
 
static const struct exclude_list_item skip []
 

Macro Definition Documentation

◆ PG_TEMP_FILE_PREFIX

#define PG_TEMP_FILE_PREFIX   "pgsql_tmp"

◆ PG_TEMP_FILES_DIR

#define PG_TEMP_FILES_DIR   "pgsql_tmp"

Enumeration Type Documentation

◆ PgChecksumMode

Enumerator
PG_MODE_CHECK 
PG_MODE_DISABLE 
PG_MODE_ENABLE 

Definition at line 44 of file pg_checksums.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 444 of file pg_checksums.c.

References _, badblocks, ControlFileData::blcksz, blocks, ControlFileData::data_checksum_version, DataDir, DB_SHUTDOWNED, DB_SHUTDOWNED_IN_RECOVERY, do_sync, files, fprintf, get_controlfile(), get_progname(), getopt_long(), INT64_FORMAT, mode, no_argument, only_filenode, optarg, optind, PG_CONTROL_VERSION, ControlFileData::pg_control_version, PG_DATA_CHECKSUM_VERSION, pg_log_error, pg_log_info, pg_logging_init(), PG_MODE_CHECK, PG_MODE_DISABLE, PG_MODE_ENABLE, PG_TEXTDOMAIN, printf, progname, progress_report(), psprintf(), pstrdup(), required_argument, scan_directory(), set_pglocale_pgservice(), showprogress, ControlFileData::state, total_size, update_controlfile(), usage(), and verbose.

445 {
446  static struct option long_options[] = {
447  {"check", no_argument, NULL, 'c'},
448  {"pgdata", required_argument, NULL, 'D'},
449  {"disable", no_argument, NULL, 'd'},
450  {"enable", no_argument, NULL, 'e'},
451  {"filenode", required_argument, NULL, 'f'},
452  {"no-sync", no_argument, NULL, 'N'},
453  {"progress", no_argument, NULL, 'P'},
454  {"verbose", no_argument, NULL, 'v'},
455  {NULL, 0, NULL, 0}
456  };
457 
458  char *DataDir = NULL;
459  int c;
460  int option_index;
461  bool crc_ok;
462 
463  pg_logging_init(argv[0]);
464  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_checksums"));
465  progname = get_progname(argv[0]);
466 
467  if (argc > 1)
468  {
469  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
470  {
471  usage();
472  exit(0);
473  }
474  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
475  {
476  puts("pg_checksums (PostgreSQL) " PG_VERSION);
477  exit(0);
478  }
479  }
480 
481  while ((c = getopt_long(argc, argv, "cD:deNPf:v", long_options, &option_index)) != -1)
482  {
483  switch (c)
484  {
485  case 'c':
487  break;
488  case 'd':
490  break;
491  case 'e':
493  break;
494  case 'f':
495  if (atoi(optarg) == 0)
496  {
497  pg_log_error("invalid filenode specification, must be numeric: %s", optarg);
498  exit(1);
499  }
501  break;
502  case 'N':
503  do_sync = false;
504  break;
505  case 'v':
506  verbose = true;
507  break;
508  case 'D':
509  DataDir = optarg;
510  break;
511  case 'P':
512  showprogress = true;
513  break;
514  default:
515  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
516  exit(1);
517  }
518  }
519 
520  if (DataDir == NULL)
521  {
522  if (optind < argc)
523  DataDir = argv[optind++];
524  else
525  DataDir = getenv("PGDATA");
526 
527  /* If no DataDir was specified, and none could be found, error out */
528  if (DataDir == NULL)
529  {
530  pg_log_error("no data directory specified");
531  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
532  exit(1);
533  }
534  }
535 
536  /* Complain if any arguments remain */
537  if (optind < argc)
538  {
539  pg_log_error("too many command-line arguments (first is \"%s\")",
540  argv[optind]);
541  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
542  progname);
543  exit(1);
544  }
545 
546  /* filenode checking only works in --check mode */
547  if (mode != PG_MODE_CHECK && only_filenode)
548  {
549  pg_log_error("option -f/--filenode can only be used with --check");
550  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
551  progname);
552  exit(1);
553  }
554 
555  /* Read the control file and check compatibility */
556  ControlFile = get_controlfile(DataDir, &crc_ok);
557  if (!crc_ok)
558  {
559  pg_log_error("pg_control CRC value is incorrect");
560  exit(1);
561  }
562 
564  {
565  pg_log_error("cluster is not compatible with this version of pg_checksums");
566  exit(1);
567  }
568 
569  if (ControlFile->blcksz != BLCKSZ)
570  {
571  pg_log_error("database cluster is not compatible");
572  fprintf(stderr, _("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.\n"),
573  ControlFile->blcksz, BLCKSZ);
574  exit(1);
575  }
576 
577  /*
578  * Check if cluster is running. A clean shutdown is required to avoid
579  * random checksum failures caused by torn pages. Note that this doesn't
580  * guard against someone starting the cluster concurrently.
581  */
582  if (ControlFile->state != DB_SHUTDOWNED &&
584  {
585  pg_log_error("cluster must be shut down");
586  exit(1);
587  }
588 
590  mode == PG_MODE_CHECK)
591  {
592  pg_log_error("data checksums are not enabled in cluster");
593  exit(1);
594  }
595 
598  {
599  pg_log_error("data checksums are already disabled in cluster");
600  exit(1);
601  }
602 
604  mode == PG_MODE_ENABLE)
605  {
606  pg_log_error("data checksums are already enabled in cluster");
607  exit(1);
608  }
609 
610  /* Operate on all files if checking or enabling checksums */
611  if (mode == PG_MODE_CHECK || mode == PG_MODE_ENABLE)
612  {
613  /*
614  * If progress status information is requested, we need to scan the
615  * directory tree twice: once to know how much total data needs to be
616  * processed and once to do the real work.
617  */
618  if (showprogress)
619  {
620  total_size = scan_directory(DataDir, "global", true);
621  total_size += scan_directory(DataDir, "base", true);
622  total_size += scan_directory(DataDir, "pg_tblspc", true);
623  }
624 
625  (void) scan_directory(DataDir, "global", false);
626  (void) scan_directory(DataDir, "base", false);
627  (void) scan_directory(DataDir, "pg_tblspc", false);
628 
629  if (showprogress)
630  progress_report(true);
631 
632  printf(_("Checksum operation completed\n"));
633  printf(_("Files scanned: %s\n"), psprintf(INT64_FORMAT, files));
634  printf(_("Blocks scanned: %s\n"), psprintf(INT64_FORMAT, blocks));
635  if (mode == PG_MODE_CHECK)
636  {
637  printf(_("Bad checksums: %s\n"), psprintf(INT64_FORMAT, badblocks));
638  printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);
639 
640  if (badblocks > 0)
641  exit(1);
642  }
643  }
644 
645  /*
646  * Finally make the data durable on disk if enabling or disabling
647  * checksums. Flush first the data directory for safety, and then update
648  * the control file to keep the switch consistent.
649  */
651  {
654 
655  if (do_sync)
656  {
657  pg_log_info("syncing data directory");
658  fsync_pgdata(DataDir, PG_VERSION_NUM);
659  }
660 
661  pg_log_info("updating control file");
663 
664  if (verbose)
665  printf(_("Data checksum version: %d\n"), ControlFile->data_checksum_version);
666  if (mode == PG_MODE_ENABLE)
667  printf(_("Checksums enabled in cluster\n"));
668  else
669  printf(_("Checksums disabled in cluster\n"));
670  }
671 
672  return 0;
673 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
static const char * progname
Definition: pg_checksums.c:63
const char * get_progname(const char *argv0)
Definition: path.c:453
#define pg_log_error(...)
Definition: logging.h:80
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
static void usage(void)
Definition: pg_checksums.c:73
char * pstrdup(const char *in)
Definition: mcxt.c:1187
void pg_logging_init(const char *argv0)
Definition: logging.c:81
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static ControlFileData * ControlFile
Definition: pg_checksums.c:37
#define PG_CONTROL_VERSION
Definition: pg_control.h:25
uint32 pg_control_version
Definition: pg_control.h:121
#define printf(...)
Definition: port.h:221
static int64 files
Definition: pg_checksums.c:34
static bool showprogress
Definition: pg_checksums.c:42
#define fprintf
Definition: port.h:219
void update_controlfile(const char *DataDir, ControlFileData *ControlFile, bool do_sync)
#define required_argument
Definition: getopt_long.h:25
int optind
Definition: getopt.c:50
uint32 data_checksum_version
Definition: pg_control.h:220
char * c
static bool do_sync
Definition: pg_checksums.c:40
static int64 scan_directory(const char *basedir, const char *subdir, bool sizeonly)
Definition: pg_checksums.c:299
static bool verbose
Definition: pg_checksums.c:41
#define no_argument
Definition: getopt_long.h:24
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1157
int64 total_size
Definition: pg_checksums.c:68
ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p)
static int64 blocks
Definition: pg_checksums.c:35
#define INT64_FORMAT
Definition: c.h:417
static void progress_report(bool finished)
Definition: pg_checksums.c:128
static char * only_filenode
Definition: pg_checksums.c:39
static int64 badblocks
Definition: pg_checksums.c:36
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:200
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:434
char * optarg
Definition: getopt.c:52
char * DataDir
Definition: globals.c:62
#define _(x)
Definition: elog.c:88
#define pg_log_info(...)
Definition: logging.h:88

◆ progress_report()

static void progress_report ( bool  finished)
static

Definition at line 128 of file pg_checksums.c.

References _, Assert, current_size, fprintf, INT64_FORMAT, last_progress_report, now(), showprogress, snprintf, and total_size.

Referenced by main(), and scan_file().

129 {
130  int percent;
131  char total_size_str[32];
132  char current_size_str[32];
133  pg_time_t now;
134 
136 
137  now = time(NULL);
138  if (now == last_progress_report && !finished)
139  return; /* Max once per second */
140 
141  /* Save current time */
143 
144  /* Adjust total size if current_size is larger */
145  if (current_size > total_size)
147 
148  /* Calculate current percentage of size done */
149  percent = total_size ? (int) ((current_size) * 100 / total_size) : 0;
150 
151  /*
152  * Separate step to keep platform-dependent format code out of
153  * translatable strings. And we only test for INT64_FORMAT availability
154  * in snprintf, not fprintf.
155  */
156  snprintf(total_size_str, sizeof(total_size_str), INT64_FORMAT,
157  total_size / (1024 * 1024));
158  snprintf(current_size_str, sizeof(current_size_str), INT64_FORMAT,
159  current_size / (1024 * 1024));
160 
161  fprintf(stderr, _("%*s/%s MB (%d%%) computed"),
162  (int) strlen(current_size_str), current_size_str, total_size_str,
163  percent);
164 
165  /*
166  * Stay on the same line if reporting to a terminal and we're not done
167  * yet.
168  */
169  fputc((!finished && isatty(fileno(stderr))) ? '\r' : '\n', stderr);
170 }
int64 pg_time_t
Definition: pgtime.h:23
static bool showprogress
Definition: pg_checksums.c:42
#define fprintf
Definition: port.h:219
int64 total_size
Definition: pg_checksums.c:68
#define Assert(condition)
Definition: c.h:746
static pg_time_t last_progress_report
Definition: pg_checksums.c:70
#define INT64_FORMAT
Definition: c.h:417
int64 current_size
Definition: pg_checksums.c:69
#define snprintf
Definition: port.h:215
#define _(x)
Definition: elog.c:88
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1542

◆ scan_directory()

static int64 scan_directory ( const char *  basedir,
const char *  subdir,
bool  sizeonly 
)
static

Definition at line 299 of file pg_checksums.c.

References closedir(), dirent::d_name, fn(), lstat, MAXPGPATH, only_filenode, opendir(), pg_log_error, PG_TEMP_FILE_PREFIX, PG_TEMP_FILES_DIR, pgwin32_is_junction(), readdir(), S_ISDIR, S_ISREG, scan_file(), skipfile(), snprintf, stat::st_mode, stat::st_size, strlcpy(), and TABLESPACE_VERSION_DIRECTORY.

Referenced by main().

300 {
301  int64 dirsize = 0;
302  char path[MAXPGPATH];
303  DIR *dir;
304  struct dirent *de;
305 
306  snprintf(path, sizeof(path), "%s/%s", basedir, subdir);
307  dir = opendir(path);
308  if (!dir)
309  {
310  pg_log_error("could not open directory \"%s\": %m", path);
311  exit(1);
312  }
313  while ((de = readdir(dir)) != NULL)
314  {
315  char fn[MAXPGPATH];
316  struct stat st;
317 
318  if (strcmp(de->d_name, ".") == 0 ||
319  strcmp(de->d_name, "..") == 0)
320  continue;
321 
322  /* Skip temporary files */
323  if (strncmp(de->d_name,
325  strlen(PG_TEMP_FILE_PREFIX)) == 0)
326  continue;
327 
328  /* Skip temporary folders */
329  if (strncmp(de->d_name,
331  strlen(PG_TEMP_FILES_DIR)) == 0)
332  continue;
333 
334  snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
335  if (lstat(fn, &st) < 0)
336  {
337  pg_log_error("could not stat file \"%s\": %m", fn);
338  exit(1);
339  }
340  if (S_ISREG(st.st_mode))
341  {
342  char fnonly[MAXPGPATH];
343  char *forkpath,
344  *segmentpath;
345  BlockNumber segmentno = 0;
346 
347  if (skipfile(de->d_name))
348  continue;
349 
350  /*
351  * Cut off at the segment boundary (".") to get the segment number
352  * in order to mix it into the checksum. Then also cut off at the
353  * fork boundary, to get the filenode the file belongs to for
354  * filtering.
355  */
356  strlcpy(fnonly, de->d_name, sizeof(fnonly));
357  segmentpath = strchr(fnonly, '.');
358  if (segmentpath != NULL)
359  {
360  *segmentpath++ = '\0';
361  segmentno = atoi(segmentpath);
362  if (segmentno == 0)
363  {
364  pg_log_error("invalid segment number %d in file name \"%s\"",
365  segmentno, fn);
366  exit(1);
367  }
368  }
369 
370  forkpath = strchr(fnonly, '_');
371  if (forkpath != NULL)
372  *forkpath++ = '\0';
373 
374  if (only_filenode && strcmp(only_filenode, fnonly) != 0)
375  /* filenode not to be included */
376  continue;
377 
378  dirsize += st.st_size;
379 
380  /*
381  * No need to work on the file when calculating only the size of
382  * the items in the data folder.
383  */
384  if (!sizeonly)
385  scan_file(fn, segmentno);
386  }
387 #ifndef WIN32
388  else if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
389 #else
390  else if (S_ISDIR(st.st_mode) || pgwin32_is_junction(fn))
391 #endif
392  {
393  /*
394  * If going through the entries of pg_tblspc, we assume to operate
395  * on tablespace locations where only TABLESPACE_VERSION_DIRECTORY
396  * is valid, resolving the linked locations and dive into them
397  * directly.
398  */
399  if (strncmp("pg_tblspc", subdir, strlen("pg_tblspc")) == 0)
400  {
401  char tblspc_path[MAXPGPATH];
402  struct stat tblspc_st;
403 
404  /*
405  * Resolve tablespace location path and check whether
406  * TABLESPACE_VERSION_DIRECTORY exists. Not finding a valid
407  * location is unexpected, since there should be no orphaned
408  * links and no links pointing to something else than a
409  * directory.
410  */
411  snprintf(tblspc_path, sizeof(tblspc_path), "%s/%s/%s",
413 
414  if (lstat(tblspc_path, &tblspc_st) < 0)
415  {
416  pg_log_error("could not stat file \"%s\": %m",
417  tblspc_path);
418  exit(1);
419  }
420 
421  /*
422  * Move backwards once as the scan needs to happen for the
423  * contents of TABLESPACE_VERSION_DIRECTORY.
424  */
425  snprintf(tblspc_path, sizeof(tblspc_path), "%s/%s",
426  path, de->d_name);
427 
428  /* Looks like a valid tablespace location */
429  dirsize += scan_directory(tblspc_path,
431  sizeonly);
432  }
433  else
434  {
435  dirsize += scan_directory(path, de->d_name, sizeonly);
436  }
437  }
438  }
439  closedir(dir);
440  return dirsize;
441 }
#define pg_log_error(...)
Definition: logging.h:80
int closedir(DIR *)
Definition: dirent.c:123
#define PG_TEMP_FILES_DIR
Definition: pg_checksums.c:58
uint32 BlockNumber
Definition: block.h:31
Definition: dirent.h:9
static char * basedir
Definition: dirent.c:25
#define PG_TEMP_FILE_PREFIX
Definition: pg_checksums.c:59
#define MAXPGPATH
DIR * opendir(const char *)
Definition: dirent.c:33
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
static int64 scan_directory(const char *basedir, const char *subdir, bool sizeonly)
Definition: pg_checksums.c:299
#define S_ISREG(m)
Definition: win32_port.h:319
static void * fn(void *arg)
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static void scan_file(const char *fn, BlockNumber segmentno)
Definition: pg_checksums.c:191
struct dirent * readdir(DIR *)
Definition: dirent.c:78
#define S_ISDIR(m)
Definition: win32_port.h:316
#define lstat(path, sb)
Definition: win32_port.h:276
static char * only_filenode
Definition: pg_checksums.c:39
char d_name[MAX_PATH]
Definition: dirent.h:15
#define snprintf
Definition: port.h:215
static bool skipfile(const char *fn)
Definition: pg_checksums.c:173
bool pgwin32_is_junction(const char *path)

◆ scan_file()

static void scan_file ( const char *  fn,
BlockNumber  segmentno 
)
static

Definition at line 191 of file pg_checksums.c.

References Assert, badblocks, blocks, buf, close, current_size, PGAlignedBlock::data, ControlFileData::data_checksum_version, files, header(), mode, PageIsNew, PageHeaderData::pd_checksum, PG_BINARY, pg_checksum_page(), PG_DATA_CHECKSUM_VERSION, pg_log_error, pg_log_info, PG_MODE_CHECK, PG_MODE_ENABLE, progress_report(), read, showprogress, verbose, and write.

Referenced by scan_directory().

192 {
195  int f;
196  BlockNumber blockno;
197  int flags;
198 
200  mode == PG_MODE_CHECK);
201 
202  flags = (mode == PG_MODE_ENABLE) ? O_RDWR : O_RDONLY;
203  f = open(fn, PG_BINARY | flags, 0);
204 
205  if (f < 0)
206  {
207  pg_log_error("could not open file \"%s\": %m", fn);
208  exit(1);
209  }
210 
211  files++;
212 
213  for (blockno = 0;; blockno++)
214  {
215  uint16 csum;
216  int r = read(f, buf.data, BLCKSZ);
217 
218  if (r == 0)
219  break;
220  if (r != BLCKSZ)
221  {
222  if (r < 0)
223  pg_log_error("could not read block %u in file \"%s\": %m",
224  blockno, fn);
225  else
226  pg_log_error("could not read block %u in file \"%s\": read %d of %d",
227  blockno, fn, r, BLCKSZ);
228  exit(1);
229  }
230  blocks++;
231 
232  /* New pages have no checksum yet */
233  if (PageIsNew(header))
234  continue;
235 
236  csum = pg_checksum_page(buf.data, blockno + segmentno * RELSEG_SIZE);
237  current_size += r;
238  if (mode == PG_MODE_CHECK)
239  {
240  if (csum != header->pd_checksum)
241  {
243  pg_log_error("checksum verification failed in file \"%s\", block %u: calculated checksum %X but block contains %X",
244  fn, blockno, csum, header->pd_checksum);
245  badblocks++;
246  }
247  }
248  else if (mode == PG_MODE_ENABLE)
249  {
250  int w;
251 
252  /* Set checksum in page header */
253  header->pd_checksum = csum;
254 
255  /* Seek back to beginning of block */
256  if (lseek(f, -BLCKSZ, SEEK_CUR) < 0)
257  {
258  pg_log_error("seek failed for block %u in file \"%s\": %m", blockno, fn);
259  exit(1);
260  }
261 
262  /* Write block with checksum */
263  w = write(f, buf.data, BLCKSZ);
264  if (w != BLCKSZ)
265  {
266  if (w < 0)
267  pg_log_error("could not write block %u in file \"%s\": %m",
268  blockno, fn);
269  else
270  pg_log_error("could not write block %u in file \"%s\": wrote %d of %d",
271  blockno, fn, w, BLCKSZ);
272  exit(1);
273  }
274  }
275 
276  if (showprogress)
277  progress_report(false);
278  }
279 
280  if (verbose)
281  {
282  if (mode == PG_MODE_CHECK)
283  pg_log_info("checksums verified in file \"%s\"", fn);
284  if (mode == PG_MODE_ENABLE)
285  pg_log_info("checksums enabled in file \"%s\"", fn);
286  }
287 
288  close(f);
289 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
#define write(a, b, c)
Definition: win32.h:14
#define pg_log_error(...)
Definition: logging.h:80
static ControlFileData * ControlFile
Definition: pg_checksums.c:37
uint32 BlockNumber
Definition: block.h:31
static int64 files
Definition: pg_checksums.c:34
static bool showprogress
Definition: pg_checksums.c:42
#define PG_BINARY
Definition: c.h:1213
uint16 pd_checksum
Definition: bufpage.h:156
char data[BLCKSZ]
Definition: c.h:1083
unsigned short uint16
Definition: c.h:374
uint32 data_checksum_version
Definition: pg_control.h:220
static char * buf
Definition: pg_test_fsync.c:68
static bool verbose
Definition: pg_checksums.c:41
static void * fn(void *arg)
PageHeaderData * PageHeader
Definition: bufpage.h:166
#define Assert(condition)
Definition: c.h:746
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:210
static int64 blocks
Definition: pg_checksums.c:35
static void progress_report(bool finished)
Definition: pg_checksums.c:128
static int64 badblocks
Definition: pg_checksums.c:36
#define PG_DATA_CHECKSUM_VERSION
Definition: bufpage.h:200
#define PageIsNew(page)
Definition: bufpage.h:229
int64 current_size
Definition: pg_checksums.c:69
#define close(a)
Definition: win32.h:12
uint16 pg_checksum_page(char *page, BlockNumber blkno)
#define read(a, b, c)
Definition: win32.h:13
#define pg_log_info(...)
Definition: logging.h:88

◆ skipfile()

static bool skipfile ( const char *  fn)
static

Definition at line 173 of file pg_checksums.c.

References exclude_list_item::match_prefix, and exclude_list_item::name.

Referenced by scan_directory().

174 {
175  int excludeIdx;
176 
177  for (excludeIdx = 0; skip[excludeIdx].name != NULL; excludeIdx++)
178  {
179  int cmplen = strlen(skip[excludeIdx].name);
180 
181  if (!skip[excludeIdx].match_prefix)
182  cmplen++;
183  if (strncmp(skip[excludeIdx].name, fn, cmplen) == 0)
184  return true;
185  }
186 
187  return false;
188 }
static const struct exclude_list_item skip[]
Definition: pg_checksums.c:112
static void * fn(void *arg)
const char * name
Definition: encode.c:561
const char * name
Definition: basebackup.c:141

◆ usage()

static void usage ( void  )
static

Definition at line 73 of file pg_checksums.c.

References _, exclude_list_item::match_prefix, exclude_list_item::name, printf, and progname.

Referenced by main().

74 {
75  printf(_("%s enables, disables, or verifies data checksums in a PostgreSQL database cluster.\n\n"), progname);
76  printf(_("Usage:\n"));
77  printf(_(" %s [OPTION]... [DATADIR]\n"), progname);
78  printf(_("\nOptions:\n"));
79  printf(_(" [-D, --pgdata=]DATADIR data directory\n"));
80  printf(_(" -c, --check check data checksums (default)\n"));
81  printf(_(" -d, --disable disable data checksums\n"));
82  printf(_(" -e, --enable enable data checksums\n"));
83  printf(_(" -f, --filenode=FILENODE check only relation with specified filenode\n"));
84  printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
85  printf(_(" -P, --progress show progress information\n"));
86  printf(_(" -v, --verbose output verbose messages\n"));
87  printf(_(" -V, --version output version information, then exit\n"));
88  printf(_(" -?, --help show this help, then exit\n"));
89  printf(_("\nIf no data directory (DATADIR) is specified, "
90  "the environment variable PGDATA\nis used.\n\n"));
91  printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
92  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
93 }
static const char * progname
Definition: pg_checksums.c:63
#define printf(...)
Definition: port.h:221
#define _(x)
Definition: elog.c:88

Variable Documentation

◆ badblocks

int64 badblocks = 0
static

Definition at line 36 of file pg_checksums.c.

Referenced by main(), and scan_file().

◆ blocks

int64 blocks = 0
static

Definition at line 35 of file pg_checksums.c.

Referenced by main(), RelationTruncate(), scan_file(), and smgr_redo().

◆ ControlFile

ControlFileData* ControlFile
static

Definition at line 37 of file pg_checksums.c.

◆ current_size

int64 current_size = 0

Definition at line 69 of file pg_checksums.c.

Referenced by progress_report(), scan_file(), and unicode_normalize().

◆ do_sync

bool do_sync = true
static

Definition at line 40 of file pg_checksums.c.

Referenced by main().

◆ files

int64 files = 0
static

Definition at line 34 of file pg_checksums.c.

Referenced by main(), scan_file(), and UpdateLogicalMappings().

◆ last_progress_report

pg_time_t last_progress_report = 0
static

Definition at line 70 of file pg_checksums.c.

Referenced by progress_report().

◆ mode

Definition at line 61 of file pg_checksums.c.

Referenced by _allocAH(), _copyFunctionParameter(), _copyLockStmt(), _equalFunctionParameter(), _equalLockStmt(), be_lo_open(), bf_load(), from_char_set_mode(), get_mxact_status_for_lock(), GetLockmodeName(), GetMultiXactIdHintBits(), has_any_column_privilege_id(), has_any_column_privilege_id_id(), has_any_column_privilege_id_name(), has_any_column_privilege_name(), has_any_column_privilege_name_id(), has_any_column_privilege_name_name(), has_column_privilege_id_attnum(), has_column_privilege_id_id_attnum(), has_column_privilege_id_id_name(), has_column_privilege_id_name(), has_column_privilege_id_name_attnum(), has_column_privilege_id_name_name(), has_column_privilege_name_attnum(), has_column_privilege_name_id_attnum(), has_column_privilege_name_id_name(), has_column_privilege_name_name(), has_column_privilege_name_name_attnum(), has_column_privilege_name_name_name(), has_database_privilege_id(), has_database_privilege_id_id(), has_database_privilege_id_name(), has_database_privilege_name(), has_database_privilege_name_id(), has_database_privilege_name_name(), has_foreign_data_wrapper_privilege_id(), has_foreign_data_wrapper_privilege_id_id(), has_foreign_data_wrapper_privilege_id_name(), has_foreign_data_wrapper_privilege_name(), has_foreign_data_wrapper_privilege_name_id(), has_foreign_data_wrapper_privilege_name_name(), has_function_privilege_id(), has_function_privilege_id_id(), has_function_privilege_id_name(), has_function_privilege_name(), has_function_privilege_name_id(), has_function_privilege_name_name(), has_language_privilege_id(), has_language_privilege_id_id(), has_language_privilege_id_name(), has_language_privilege_name(), has_language_privilege_name_id(), has_language_privilege_name_name(), has_schema_privilege_id(), has_schema_privilege_id_id(), has_schema_privilege_id_name(), has_schema_privilege_name(), has_schema_privilege_name_id(), has_schema_privilege_name_name(), has_sequence_privilege_id(), has_sequence_privilege_id_id(), has_sequence_privilege_id_name(), has_sequence_privilege_name(), has_sequence_privilege_name_id(), has_sequence_privilege_name_name(), has_server_privilege_id(), has_server_privilege_id_id(), has_server_privilege_id_name(), has_server_privilege_name(), has_server_privilege_name_id(), has_server_privilege_name_name(), has_table_privilege_id(), has_table_privilege_id_id(), has_table_privilege_id_name(), has_table_privilege_name(), has_table_privilege_name_id(), has_table_privilege_name_name(), has_tablespace_privilege_id(), has_tablespace_privilege_id_id(), has_tablespace_privilege_id_name(), has_tablespace_privilege_name(), has_tablespace_privilege_name_id(), has_tablespace_privilege_name_name(), has_type_privilege_id(), has_type_privilege_id_id(), has_type_privilege_id_name(), has_type_privilege_name(), has_type_privilege_name_id(), has_type_privilege_name_name(), lo_creat(), lo_open(), main(), open_target_file(), pg_has_role_id(), pg_has_role_id_id(), pg_has_role_id_name(), pg_has_role_name(), pg_has_role_name_id(), pg_has_role_name_name(), pg_lock_status(), pgp_s2k_fill(), pgp_set_s2k_mode(), pgp_set_text_mode(), pgtls_verify_peer_name_matches_certificate_guts(), rj_load(), scan_file(), SyncRepQueueInsert(), SyncRepUpdateSyncStandbysDefined(), SyncRepWaitForLSN(), SyncRepWakeQueue(), and tarOpen().

◆ only_filenode

char* only_filenode = NULL
static

Definition at line 39 of file pg_checksums.c.

Referenced by main(), and scan_directory().

◆ progname

const char* progname
static

Definition at line 63 of file pg_checksums.c.

Referenced by main(), and usage().

◆ showprogress

bool showprogress = false
static

Definition at line 42 of file pg_checksums.c.

Referenced by main(), progress_report(), and scan_file().

◆ skip

const struct exclude_list_item skip[]
static
Initial value:
= {
{"pg_control", false},
{"pg_filenode.map", false},
{"pg_internal.init", true},
{"PG_VERSION", false},
{NULL, false}
}

Definition at line 112 of file pg_checksums.c.

Referenced by array_replace_internal(), DefineVirtualRelation(), heap_hot_search_buffer(), initTrie(), and verify_heapam().

◆ total_size

int64 total_size = 0

Definition at line 68 of file pg_checksums.c.

Referenced by create_modifytable_path(), main(), make_new_segment(), and progress_report().

◆ verbose

bool verbose = false
static

Definition at line 41 of file pg_checksums.c.

Referenced by main(), and scan_file().