PostgreSQL Source Code  git master
pg_checksums.c File Reference
#include "postgres_fe.h"
#include <dirent.h>
#include <limits.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 "fe_utils/option_utils.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, int segmentno)
 
static int64 scan_directory (const char *basedir, const char *subdir, bool sizeonly)
 
int main (int argc, char *argv[])
 

Variables

static int64 files_scanned = 0
 
static int64 files_written = 0
 
static int64 blocks_scanned = 0
 
static int64 blocks_written = 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"

Definition at line 63 of file pg_checksums.c.

◆ PG_TEMP_FILES_DIR

#define PG_TEMP_FILES_DIR   "pgsql_tmp"

Definition at line 62 of file pg_checksums.c.

Enumeration Type Documentation

◆ PgChecksumMode

Enumerator
PG_MODE_CHECK 
PG_MODE_DISABLE 
PG_MODE_ENABLE 

Definition at line 48 of file pg_checksums.c.

49 {
PgChecksumMode
Definition: pg_checksums.c:49
@ PG_MODE_CHECK
Definition: pg_checksums.c:50
@ PG_MODE_DISABLE
Definition: pg_checksums.c:51
@ PG_MODE_ENABLE
Definition: pg_checksums.c:52

Function Documentation

◆ main()

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

Definition at line 441 of file pg_checksums.c.

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

References _, badblocks, ControlFileData::blcksz, blocks_scanned, blocks_written, ControlFile, ControlFileData::data_checksum_version, DataDir, DB_SHUTDOWNED, DB_SHUTDOWNED_IN_RECOVERY, do_sync, exit(), files_scanned, files_written, get_controlfile(), get_progname(), getopt_long(), mode, no_argument, only_filenode, optarg, optind, option_parse_int(), PG_CONTROL_VERSION, ControlFileData::pg_control_version, PG_DATA_CHECKSUM_VERSION, pg_fatal, pg_log_error, pg_log_error_detail, pg_log_error_hint, pg_log_info, pg_logging_init(), PG_MODE_CHECK, PG_MODE_DISABLE, PG_MODE_ENABLE, PG_TEXTDOMAIN, printf, progname, progress_report(), pstrdup(), required_argument, scan_directory(), set_pglocale_pgservice(), showprogress, ControlFileData::state, total_size, update_controlfile(), usage(), and verbose.

◆ progress_report()

static void progress_report ( bool  finished)
static

Definition at line 132 of file pg_checksums.c.

133 {
134  int percent;
135  pg_time_t now;
136 
138 
139  now = time(NULL);
140  if (now == last_progress_report && !finished)
141  return; /* Max once per second */
142 
143  /* Save current time */
145 
146  /* Adjust total size if current_size is larger */
147  if (current_size > total_size)
149 
150  /* Calculate current percentage of size done */
151  percent = total_size ? (int) ((current_size) * 100 / total_size) : 0;
152 
153  fprintf(stderr, _("%lld/%lld MB (%d%%) computed"),
154  (long long) (current_size / (1024 * 1024)),
155  (long long) (total_size / (1024 * 1024)),
156  percent);
157 
158  /*
159  * Stay on the same line if reporting to a terminal and we're not done
160  * yet.
161  */
162  fputc((!finished && isatty(fileno(stderr))) ? '\r' : '\n', stderr);
163 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1538
Assert(fmt[strlen(fmt) - 1] !='\n')
int64 current_size
Definition: pg_checksums.c:73
static pg_time_t last_progress_report
Definition: pg_checksums.c:74
int64 pg_time_t
Definition: pgtime.h:23
#define fprintf
Definition: port.h:229

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

Referenced by main(), and scan_file().

◆ scan_directory()

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

Definition at line 308 of file pg_checksums.c.

309 {
310  int64 dirsize = 0;
311  char path[MAXPGPATH];
312  DIR *dir;
313  struct dirent *de;
314 
315  snprintf(path, sizeof(path), "%s/%s", basedir, subdir);
316  dir = opendir(path);
317  if (!dir)
318  pg_fatal("could not open directory \"%s\": %m", path);
319  while ((de = readdir(dir)) != NULL)
320  {
321  char fn[MAXPGPATH];
322  struct stat st;
323 
324  if (strcmp(de->d_name, ".") == 0 ||
325  strcmp(de->d_name, "..") == 0)
326  continue;
327 
328  /* Skip temporary files */
329  if (strncmp(de->d_name,
331  strlen(PG_TEMP_FILE_PREFIX)) == 0)
332  continue;
333 
334  /* Skip temporary folders */
335  if (strncmp(de->d_name,
337  strlen(PG_TEMP_FILES_DIR)) == 0)
338  continue;
339 
340  snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
341  if (lstat(fn, &st) < 0)
342  pg_fatal("could not stat file \"%s\": %m", fn);
343  if (S_ISREG(st.st_mode))
344  {
345  char fnonly[MAXPGPATH];
346  char *forkpath,
347  *segmentpath;
348  int segmentno = 0;
349 
350  if (skipfile(de->d_name))
351  continue;
352 
353  /*
354  * Cut off at the segment boundary (".") to get the segment number
355  * in order to mix it into the checksum. Then also cut off at the
356  * fork boundary, to get the filenode the file belongs to for
357  * filtering.
358  */
359  strlcpy(fnonly, de->d_name, sizeof(fnonly));
360  segmentpath = strchr(fnonly, '.');
361  if (segmentpath != NULL)
362  {
363  *segmentpath++ = '\0';
364  segmentno = atoi(segmentpath);
365  if (segmentno == 0)
366  pg_fatal("invalid segment number %d in file name \"%s\"",
367  segmentno, fn);
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  pg_fatal("could not stat file \"%s\": %m",
416  tblspc_path);
417 
418  /*
419  * Move backwards once as the scan needs to happen for the
420  * contents of TABLESPACE_VERSION_DIRECTORY.
421  */
422  snprintf(tblspc_path, sizeof(tblspc_path), "%s/%s",
423  path, de->d_name);
424 
425  /* Looks like a valid tablespace location */
426  dirsize += scan_directory(tblspc_path,
428  sizeonly);
429  }
430  else
431  {
432  dirsize += scan_directory(path, de->d_name, sizeonly);
433  }
434  }
435  }
436  closedir(dir);
437  return dirsize;
438 }
int closedir(DIR *)
Definition: dirent.c:123
struct dirent * readdir(DIR *)
Definition: dirent.c:78
DIR * opendir(const char *)
Definition: dirent.c:33
static char * basedir
static void scan_file(const char *fn, int segmentno)
Definition: pg_checksums.c:184
#define PG_TEMP_FILES_DIR
Definition: pg_checksums.c:62
#define PG_TEMP_FILE_PREFIX
Definition: pg_checksums.c:63
static bool skipfile(const char *fn)
Definition: pg_checksums.c:166
#define MAXPGPATH
#define snprintf
Definition: port.h:225
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
Definition: dirent.c:26
Definition: dirent.h:10
char d_name[MAX_PATH]
Definition: dirent.h:15
static void * fn(void *arg)
#define lstat(path, sb)
Definition: win32_port.h:284
#define S_ISDIR(m)
Definition: win32_port.h:324
bool pgwin32_is_junction(const char *path)
#define S_ISREG(m)
Definition: win32_port.h:327

References basedir, closedir(), dirent::d_name, fn(), lstat, MAXPGPATH, only_filenode, opendir(), pg_fatal, 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().

◆ scan_file()

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

Definition at line 184 of file pg_checksums.c.

185 {
187  PageHeader header = (PageHeader) buf.data;
188  int f;
189  BlockNumber blockno;
190  int flags;
191  int64 blocks_written_in_file = 0;
192 
194  mode == PG_MODE_CHECK);
195 
196  flags = (mode == PG_MODE_ENABLE) ? O_RDWR : O_RDONLY;
197  f = open(fn, PG_BINARY | flags, 0);
198 
199  if (f < 0)
200  pg_fatal("could not open file \"%s\": %m", fn);
201 
202  files_scanned++;
203 
204  for (blockno = 0;; blockno++)
205  {
206  uint16 csum;
207  int r = read(f, buf.data, BLCKSZ);
208 
209  if (r == 0)
210  break;
211  if (r != BLCKSZ)
212  {
213  if (r < 0)
214  pg_fatal("could not read block %u in file \"%s\": %m",
215  blockno, fn);
216  else
217  pg_fatal("could not read block %u in file \"%s\": read %d of %d",
218  blockno, fn, r, BLCKSZ);
219  }
220  blocks_scanned++;
221 
222  /*
223  * Since the file size is counted as total_size for progress status
224  * information, the sizes of all pages including new ones in the file
225  * should be counted as current_size. Otherwise the progress reporting
226  * calculated using those counters may not reach 100%.
227  */
228  current_size += r;
229 
230  /* New pages have no checksum yet */
231  if (PageIsNew(header))
232  continue;
233 
234  csum = pg_checksum_page(buf.data, blockno + segmentno * RELSEG_SIZE);
235  if (mode == PG_MODE_CHECK)
236  {
237  if (csum != header->pd_checksum)
238  {
240  pg_log_error("checksum verification failed in file \"%s\", block %u: calculated checksum %X but block contains %X",
241  fn, blockno, csum, header->pd_checksum);
242  badblocks++;
243  }
244  }
245  else if (mode == PG_MODE_ENABLE)
246  {
247  int w;
248 
249  /*
250  * Do not rewrite if the checksum is already set to the expected
251  * value.
252  */
253  if (header->pd_checksum == csum)
254  continue;
255 
256  blocks_written_in_file++;
257 
258  /* Set checksum in page header */
259  header->pd_checksum = csum;
260 
261  /* Seek back to beginning of block */
262  if (lseek(f, -BLCKSZ, SEEK_CUR) < 0)
263  pg_fatal("seek failed for block %u in file \"%s\": %m", blockno, fn);
264 
265  /* Write block with checksum */
266  w = write(f, buf.data, BLCKSZ);
267  if (w != BLCKSZ)
268  {
269  if (w < 0)
270  pg_fatal("could not write block %u in file \"%s\": %m",
271  blockno, fn);
272  else
273  pg_fatal("could not write block %u in file \"%s\": wrote %d of %d",
274  blockno, fn, w, BLCKSZ);
275  }
276  }
277 
278  if (showprogress)
279  progress_report(false);
280  }
281 
282  if (verbose)
283  {
284  if (mode == PG_MODE_CHECK)
285  pg_log_info("checksums verified in file \"%s\"", fn);
286  if (mode == PG_MODE_ENABLE)
287  pg_log_info("checksums enabled in file \"%s\"", fn);
288  }
289 
290  /* Update write counters if any write activity has happened */
291  if (blocks_written_in_file > 0)
292  {
293  files_written++;
294  blocks_written += blocks_written_in_file;
295  }
296 
297  close(f);
298 }
uint32 BlockNumber
Definition: block.h:31
PageHeaderData * PageHeader
Definition: bufpage.h:166
#define PageIsNew(page)
Definition: bufpage.h:228
unsigned short uint16
Definition: c.h:451
#define PG_BINARY
Definition: c.h:1279
uint16 pg_checksum_page(char *page, BlockNumber blkno)
#define close(a)
Definition: win32.h:12
#define write(a, b, c)
Definition: win32.h:14
#define read(a, b, c)
Definition: win32.h:13
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:212
static char * buf
Definition: pg_test_fsync.c:67

References Assert(), badblocks, blocks_scanned, blocks_written, buf, close, ControlFile, current_size, ControlFileData::data_checksum_version, files_scanned, files_written, fn(), header(), mode, PageIsNew, PG_BINARY, pg_checksum_page(), PG_DATA_CHECKSUM_VERSION, pg_fatal, pg_log_error, pg_log_info, PG_MODE_CHECK, PG_MODE_ENABLE, progress_report(), read, showprogress, verbose, and write.

Referenced by scan_directory().

◆ skipfile()

static bool skipfile ( const char *  fn)
static

Definition at line 166 of file pg_checksums.c.

167 {
168  int excludeIdx;
169 
170  for (excludeIdx = 0; skip[excludeIdx].name != NULL; excludeIdx++)
171  {
172  int cmplen = strlen(skip[excludeIdx].name);
173 
174  if (!skip[excludeIdx].match_prefix)
175  cmplen++;
176  if (strncmp(skip[excludeIdx].name, fn, cmplen) == 0)
177  return true;
178  }
179 
180  return false;
181 }
const char * name
Definition: encode.c:561
static const struct exclude_list_item skip[]
Definition: pg_checksums.c:116
const char * name
Definition: basebackup.c:116

References fn(), exclude_list_item::match_prefix, exclude_list_item::name, name, and skip.

Referenced by scan_directory().

◆ usage()

static void usage ( void  )
static

Definition at line 77 of file pg_checksums.c.

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

Referenced by main().

Variable Documentation

◆ badblocks

int64 badblocks = 0
static

Definition at line 40 of file pg_checksums.c.

Referenced by main(), and scan_file().

◆ blocks_scanned

int64 blocks_scanned = 0
static

Definition at line 38 of file pg_checksums.c.

Referenced by main(), and scan_file().

◆ blocks_written

int64 blocks_written = 0
static

Definition at line 39 of file pg_checksums.c.

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

◆ ControlFile

ControlFileData* ControlFile
static

Definition at line 41 of file pg_checksums.c.

Referenced by main(), and scan_file().

◆ current_size

int64 current_size = 0

Definition at line 73 of file pg_checksums.c.

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

◆ do_sync

bool do_sync = true
static

Definition at line 44 of file pg_checksums.c.

Referenced by main().

◆ files_scanned

int64 files_scanned = 0
static

Definition at line 36 of file pg_checksums.c.

Referenced by main(), and scan_file().

◆ files_written

int64 files_written = 0
static

Definition at line 37 of file pg_checksums.c.

Referenced by main(), and scan_file().

◆ last_progress_report

pg_time_t last_progress_report = 0
static

Definition at line 74 of file pg_checksums.c.

Referenced by progress_report().

◆ mode

Definition at line 65 of file pg_checksums.c.

Referenced by _allocAH(), _copyFunctionParameter(), _copyLockStmt(), _equalFunctionParameter(), _equalLockStmt(), AllocateFile(), be_lo_open(), brinGetTupleForHeapBlock(), BufFileOpenFileSet(), cfopen(), cfopen_read(), cfopen_write(), column_privilege_check(), compute_new_xmax_infomask(), create_file_for_extract(), CreateArchive(), dump_variables(), ECPGsetcommit(), extract_directory(), FileSetOpen(), 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(), heap_acquire_tuplock(), heap_lock_tuple(), heap_lock_updated_tuple(), heap_lock_updated_tuple_rec(), heapam_tuple_lock(), lo_creat(), lo_open(), LockBuffer(), logfile_open(), LWLockAcquire(), LWLockAcquireOrWait(), LWLockAttemptLock(), LWLockConditionalAcquire(), LWLockHeldByMeInMode(), LWLockQueueSelf(), LWLockRelease(), main(), open_direct(), open_target_file(), OpenPipeStream(), parseArchiveFormat(), PathNameOpenTemporaryFile(), pg_attribute_aclcheck(), pg_attribute_aclcheck_all(), pg_attribute_aclcheck_ext(), pg_class_aclcheck(), pg_class_aclcheck_ext(), pg_database_aclcheck(), pg_foreign_data_wrapper_aclcheck(), pg_foreign_server_aclcheck(), 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_language_aclcheck(), pg_largeobject_aclcheck_snapshot(), pg_lock_status(), pg_namespace_aclcheck(), pg_parameter_acl_aclcheck(), pg_parameter_aclcheck(), pg_proc_aclcheck(), pg_role_aclcheck(), pg_tablespace_aclcheck(), pg_type_aclcheck(), pgp_s2k_fill(), pgp_set_s2k_mode(), pgp_set_text_mode(), pgp_set_unicode_mode(), popen_check(), raw_parser(), ReadBuffer_common(), ReadBufferBI(), ReadBufferExtended(), ReadBufferWithoutRelcache(), scan_file(), SyncRepQueueInsert(), SyncRepWaitForLSN(), SyncRepWakeQueue(), table_tuple_lock(), TargetPrivilegesCheck(), tarOpen(), test_lockmode_for_conflict(), WaitForWorkers(), whenever_action(), XLogReadBufferExtended(), and XLogReadBufferForRedoExtended().

◆ only_filenode

char* only_filenode = NULL
static

Definition at line 43 of file pg_checksums.c.

Referenced by main(), and scan_directory().

◆ progname

const char* progname
static

Definition at line 67 of file pg_checksums.c.

Referenced by main().

◆ showprogress

bool showprogress = false
static

Definition at line 46 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 77 of file pg_checksums.c.

Referenced by array_replace_internal(), DefineVirtualRelation(), dependencies_clauselist_selectivity(), filter_partitions(), heap_hot_search_buffer(), initTrie(), json_build_object_worker(), json_object_agg_transfn_worker(), jsonb_build_object_worker(), jsonb_object_agg_transfn_worker(), skipfile(), and verify_heapam().

◆ total_size

int64 total_size = 0

Definition at line 72 of file pg_checksums.c.

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

◆ verbose

bool verbose = false
static

Definition at line 45 of file pg_checksums.c.

Referenced by main(), and scan_file().