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