summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/man1/pg_amcheck.1
blob: 273586b6e7849b37691d997a0dff5c42f72b2365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
'\" t
.\"     Title: pg_amcheck
.\"    Author: The PostgreSQL Global Development Group
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2024
.\"    Manual: PostgreSQL 15.6 Documentation
.\"    Source: PostgreSQL 15.6
.\"  Language: English
.\"
.TH "PG_AMCHECK" "1" "2024" "PostgreSQL 15.6" "PostgreSQL 15.6 Documentation"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
pg_amcheck \- checks for corruption in one or more PostgreSQL databases
.SH "SYNOPSIS"
.HP \w'\fBpg_amcheck\fR\ 'u
\fBpg_amcheck\fR [\fIoption\fR...] [\fIdbname\fR]
.SH "DESCRIPTION"
.PP
pg_amcheck
supports running
amcheck\*(Aqs corruption checking functions against one or more databases, with options to select which schemas, tables and indexes to check, which kinds of checking to perform, and whether to perform the checks in parallel, and if so, the number of parallel connections to establish and use\&.
.PP
Only ordinary and toast table relations, materialized views, sequences, and btree indexes are currently supported\&. Other relation types are silently skipped\&.
.PP
If
dbname
is specified, it should be the name of a single database to check, and no other database selection options should be present\&. Otherwise, if any database selection options are present, all matching databases will be checked\&. If no such options are present, the default database will be checked\&. Database selection options include
\fB\-\-all\fR,
\fB\-\-database\fR
and
\fB\-\-exclude\-database\fR\&. They also include
\fB\-\-relation\fR,
\fB\-\-exclude\-relation\fR,
\fB\-\-table\fR,
\fB\-\-exclude\-table\fR,
\fB\-\-index\fR, and
\fB\-\-exclude\-index\fR, but only when such options are used with a three\-part pattern (e\&.g\&.
\fBmydb*\&.myschema*\&.myrel*\fR)\&. Finally, they include
\fB\-\-schema\fR
and
\fB\-\-exclude\-schema\fR
when such options are used with a two\-part pattern (e\&.g\&.
\fBmydb*\&.myschema*\fR)\&.
.PP
\fIdbname\fR
can also be a
connection string\&.
.SH "OPTIONS"
.PP
The following command\-line options control what is checked:
.PP
\fB\-a\fR
.br
\fB\-\-all\fR
.RS 4
Check all databases, except for any excluded via
\fB\-\-exclude\-database\fR\&.
.RE
.PP
\fB\-d \fR\fB\fIpattern\fR\fR
.br
\fB\-\-database=\fR\fB\fIpattern\fR\fR
.RS 4
Check databases matching the specified
\fIpattern\fR, except for any excluded by
\fB\-\-exclude\-database\fR\&. This option can be specified more than once\&.
.RE
.PP
\fB\-D \fR\fB\fIpattern\fR\fR
.br
\fB\-\-exclude\-database=\fR\fB\fIpattern\fR\fR
.RS 4
Exclude databases matching the given
\fIpattern\fR\&. This option can be specified more than once\&.
.RE
.PP
\fB\-i \fR\fB\fIpattern\fR\fR
.br
\fB\-\-index=\fR\fB\fIpattern\fR\fR
.RS 4
Check indexes matching the specified
\fIpattern\fR, unless they are otherwise excluded\&. This option can be specified more than once\&.
.sp
This is similar to the
\fB\-\-relation\fR
option, except that it applies only to indexes, not to other relation types\&.
.RE
.PP
\fB\-I \fR\fB\fIpattern\fR\fR
.br
\fB\-\-exclude\-index=\fR\fB\fIpattern\fR\fR
.RS 4
Exclude indexes matching the specified
\fIpattern\fR\&. This option can be specified more than once\&.
.sp
This is similar to the
\fB\-\-exclude\-relation\fR
option, except that it applies only to indexes, not other relation types\&.
.RE
.PP
\fB\-r \fR\fB\fIpattern\fR\fR
.br
\fB\-\-relation=\fR\fB\fIpattern\fR\fR
.RS 4
Check relations matching the specified
\fIpattern\fR, unless they are otherwise excluded\&. This option can be specified more than once\&.
.sp
Patterns may be unqualified, e\&.g\&.
myrel*, or they may be schema\-qualified, e\&.g\&.
myschema*\&.myrel*
or database\-qualified and schema\-qualified, e\&.g\&.
mydb*\&.myschema*\&.myrel*\&. A database\-qualified pattern will add matching databases to the list of databases to be checked\&.
.RE
.PP
\fB\-R \fR\fB\fIpattern\fR\fR
.br
\fB\-\-exclude\-relation=\fR\fB\fIpattern\fR\fR
.RS 4
Exclude relations matching the specified
\fIpattern\fR\&. This option can be specified more than once\&.
.sp
As with
\fB\-\-relation\fR, the
\fIpattern\fR
may be unqualified, schema\-qualified, or database\- and schema\-qualified\&.
.RE
.PP
\fB\-s \fR\fB\fIpattern\fR\fR
.br
\fB\-\-schema=\fR\fB\fIpattern\fR\fR
.RS 4
Check tables and indexes in schemas matching the specified
\fIpattern\fR, unless they are otherwise excluded\&. This option can be specified more than once\&.
.sp
To select only tables in schemas matching a particular pattern, consider using something like
\-\-table=SCHEMAPAT\&.* \-\-no\-dependent\-indexes\&. To select only indexes, consider using something like
\-\-index=SCHEMAPAT\&.*\&.
.sp
A schema pattern may be database\-qualified\&. For example, you may write
\-\-schema=mydb*\&.myschema*
to select schemas matching
myschema*
in databases matching
mydb*\&.
.RE
.PP
\fB\-S \fR\fB\fIpattern\fR\fR
.br
\fB\-\-exclude\-schema=\fR\fB\fIpattern\fR\fR
.RS 4
Exclude tables and indexes in schemas matching the specified
\fIpattern\fR\&. This option can be specified more than once\&.
.sp
As with
\fB\-\-schema\fR, the pattern may be database\-qualified\&.
.RE
.PP
\fB\-t \fR\fB\fIpattern\fR\fR
.br
\fB\-\-table=\fR\fB\fIpattern\fR\fR
.RS 4
Check tables matching the specified
\fIpattern\fR, unless they are otherwise excluded\&. This option can be specified more than once\&.
.sp
This is similar to the
\fB\-\-relation\fR
option, except that it applies only to tables, materialized views, and sequences, not to indexes\&.
.RE
.PP
\fB\-T \fR\fB\fIpattern\fR\fR
.br
\fB\-\-exclude\-table=\fR\fB\fIpattern\fR\fR
.RS 4
Exclude tables matching the specified
\fIpattern\fR\&. This option can be specified more than once\&.
.sp
This is similar to the
\fB\-\-exclude\-relation\fR
option, except that it applies only to tables, materialized views, and sequences, not to indexes\&.
.RE
.PP
\fB\-\-no\-dependent\-indexes\fR
.RS 4
By default, if a table is checked, any btree indexes of that table will also be checked, even if they are not explicitly selected by an option such as
\-\-index
or
\-\-relation\&. This option suppresses that behavior\&.
.RE
.PP
\fB\-\-no\-dependent\-toast\fR
.RS 4
By default, if a table is checked, its toast table, if any, will also be checked, even if it is not explicitly selected by an option such as
\-\-table
or
\-\-relation\&. This option suppresses that behavior\&.
.RE
.PP
\fB\-\-no\-strict\-names\fR
.RS 4
By default, if an argument to
\-\-database,
\-\-table,
\-\-index, or
\-\-relation
matches no objects, it is a fatal error\&. This option downgrades that error to a warning\&.
.RE
.PP
The following command\-line options control checking of tables:
.PP
\fB\-\-exclude\-toast\-pointers\fR
.RS 4
By default, whenever a toast pointer is encountered in a table, a lookup is performed to ensure that it references apparently\-valid entries in the toast table\&. These checks can be quite slow, and this option can be used to skip them\&.
.RE
.PP
\fB\-\-on\-error\-stop\fR
.RS 4
After reporting all corruptions on the first page of a table where corruption is found, stop processing that table relation and move on to the next table or index\&.
.sp
Note that index checking always stops after the first corrupt page\&. This option only has meaning relative to table relations\&.
.RE
.PP
\fB\-\-skip=\fR\fB\fIoption\fR\fR
.RS 4
If
all\-frozen
is given, table corruption checks will skip over pages in all tables that are marked as all frozen\&.
.sp
If
all\-visible
is given, table corruption checks will skip over pages in all tables that are marked as all visible\&.
.sp
By default, no pages are skipped\&. This can be specified as
none, but since this is the default, it need not be mentioned\&.
.RE
.PP
\fB\-\-startblock=\fR\fB\fIblock\fR\fR
.RS 4
Start checking at the specified block number\&. An error will occur if the table relation being checked has fewer than this number of blocks\&. This option does not apply to indexes, and is probably only useful when checking a single table relation\&. See
\-\-endblock
for further caveats\&.
.RE
.PP
\fB\-\-endblock=\fR\fB\fIblock\fR\fR
.RS 4
End checking at the specified block number\&. An error will occur if the table relation being checked has fewer than this number of blocks\&. This option does not apply to indexes, and is probably only useful when checking a single table relation\&. If both a regular table and a toast table are checked, this option will apply to both, but higher\-numbered toast blocks may still be accessed while validating toast pointers, unless that is suppressed using
\fB\-\-exclude\-toast\-pointers\fR\&.
.RE
.PP
The following command\-line options control checking of B\-tree indexes:
.PP
\fB\-\-heapallindexed\fR
.RS 4
For each index checked, verify the presence of all heap tuples as index tuples in the index using
amcheck\*(Aqs
\fBheapallindexed\fR
option\&.
.RE
.PP
\fB\-\-parent\-check\fR
.RS 4
For each btree index checked, use
amcheck\*(Aqs
\fBbt_index_parent_check\fR
function, which performs additional checks of parent/child relationships during index checking\&.
.sp
The default is to use
amcheck\*(Aqs
\fBbt_index_check\fR
function, but note that use of the
\fB\-\-rootdescend\fR
option implicitly selects
\fBbt_index_parent_check\fR\&.
.RE
.PP
\fB\-\-rootdescend\fR
.RS 4
For each index checked, re\-find tuples on the leaf level by performing a new search from the root page for each tuple using
amcheck\*(Aqs
\fBrootdescend\fR
option\&.
.sp
Use of this option implicitly also selects the
\fB\-\-parent\-check\fR
option\&.
.sp
This form of verification was originally written to help in the development of btree index features\&. It may be of limited use or even of no use in helping detect the kinds of corruption that occur in practice\&. It may also cause corruption checking to take considerably longer and consume considerably more resources on the server\&.
.RE
.if n \{\
.sp
.\}
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBWarning\fR
.ps -1
.br
.PP
The extra checks performed against B\-tree indexes when the
\fB\-\-parent\-check\fR
option or the
\fB\-\-rootdescend\fR
option is specified require relatively strong relation\-level locks\&. These checks are the only checks that will block concurrent data modification from
\fBINSERT\fR,
\fBUPDATE\fR, and
\fBDELETE\fR
commands\&.
.sp .5v
.RE
.PP
The following command\-line options control the connection to the server:
.PP
\fB\-h \fR\fB\fIhostname\fR\fR
.br
\fB\-\-host=\fR\fB\fIhostname\fR\fR
.RS 4
Specifies the host name of the machine on which the server is running\&. If the value begins with a slash, it is used as the directory for the Unix domain socket\&.
.RE
.PP
\fB\-p \fR\fB\fIport\fR\fR
.br
\fB\-\-port=\fR\fB\fIport\fR\fR
.RS 4
Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&.
.RE
.PP
\fB\-U\fR
.br
\fB\-\-username=\fR\fB\fIusername\fR\fR
.RS 4
User name to connect as\&.
.RE
.PP
\fB\-w\fR
.br
\fB\-\-no\-password\fR
.RS 4
Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
\&.pgpass
file, the connection attempt will fail\&. This option can be useful in batch jobs and scripts where no user is present to enter a password\&.
.RE
.PP
\fB\-W\fR
.br
\fB\-\-password\fR
.RS 4
Force
pg_amcheck
to prompt for a password before connecting to a database\&.
.sp
This option is never essential, since
pg_amcheck
will automatically prompt for a password if the server demands password authentication\&. However,
pg_amcheck
will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
\fB\-W\fR
to avoid the extra connection attempt\&.
.RE
.PP
\fB\-\-maintenance\-db=\fR\fB\fIdbname\fR\fR
.RS 4
Specifies a database or
connection string
to be used to discover the list of databases to be checked\&. If neither
\fB\-\-all\fR
nor any option including a database pattern is used, no such connection is required and this option does nothing\&. Otherwise, any connection string parameters other than the database name which are included in the value for this option will also be used when connecting to the databases being checked\&. If this option is omitted, the default is
postgres
or, if that fails,
template1\&.
.RE
.PP
Other options are also available:
.PP
\fB\-e\fR
.br
\fB\-\-echo\fR
.RS 4
Echo to stdout all SQL sent to the server\&.
.RE
.PP
\fB\-j \fR\fB\fInum\fR\fR
.br
\fB\-\-jobs=\fR\fB\fInum\fR\fR
.RS 4
Use
\fInum\fR
concurrent connections to the server, or one per object to be checked, whichever is less\&.
.sp
The default is to use a single connection\&.
.RE
.PP
\fB\-P\fR
.br
\fB\-\-progress\fR
.RS 4
Show progress information\&. Progress information includes the number of relations for which checking has been completed, and the total size of those relations\&. It also includes the total number of relations that will eventually be checked, and the estimated size of those relations\&.
.RE
.PP
\fB\-v\fR
.br
\fB\-\-verbose\fR
.RS 4
Print more messages\&. In particular, this will print a message for each relation being checked, and will increase the level of detail shown for server errors\&.
.RE
.PP
\fB\-V\fR
.br
\fB\-\-version\fR
.RS 4
Print the
pg_amcheck
version and exit\&.
.RE
.PP
\fB\-\-install\-missing\fR
.br
\fB\-\-install\-missing=\fR\fB\fIschema\fR\fR
.RS 4
Install any missing extensions that are required to check the database(s)\&. If not yet installed, each extension\*(Aqs objects will be installed into the given
\fIschema\fR, or if not specified into schema
pg_catalog\&.
.sp
At present, the only required extension is
amcheck\&.
.RE
.PP
\fB\-?\fR
.br
\fB\-\-help\fR
.RS 4
Show help about
pg_amcheck
command line arguments, and exit\&.
.RE
.SH "NOTES"
.PP
pg_amcheck
is designed to work with
PostgreSQL
14\&.0 and later\&.
.SH "SEE ALSO"
amcheck