4 pg_amcheck — checks for corruption in one or more PostgreSQL databases
8 pg_amcheck [option...] [dbname]
12 pg_amcheck supports running amcheck's corruption checking functions
13 against one or more databases, with options to select which schemas,
14 tables and indexes to check, which kinds of checking to perform, and
15 whether to perform the checks in parallel, and if so, the number of
16 parallel connections to establish and use.
18 Only ordinary and toast table relations, materialized views, sequences,
19 and btree indexes are currently supported. Other relation types are
22 If dbname is specified, it should be the name of a single database to
23 check, and no other database selection options should be present.
24 Otherwise, if any database selection options are present, all matching
25 databases will be checked. If no such options are present, the default
26 database will be checked. Database selection options include --all,
27 --database and --exclude-database. They also include --relation,
28 --exclude-relation, --table, --exclude-table, --index, and
29 --exclude-index, but only when such options are used with a three-part
30 pattern (e.g. mydb*.myschema*.myrel*). Finally, they include --schema
31 and --exclude-schema when such options are used with a two-part pattern
32 (e.g. mydb*.myschema*).
34 dbname can also be a connection string.
38 The following command-line options control what is checked:
42 Check all databases, except for any excluded via
47 Check databases matching the specified pattern, except for any
48 excluded by --exclude-database. This option can be specified
52 --exclude-database=pattern
53 Exclude databases matching the given pattern. This option can be
54 specified more than once.
58 Check indexes matching the specified pattern, unless they are
59 otherwise excluded. This option can be specified more than once.
61 This is similar to the --relation option, except that it applies
62 only to indexes, not to other relation types.
65 --exclude-index=pattern
66 Exclude indexes matching the specified pattern. This option can
67 be specified more than once.
69 This is similar to the --exclude-relation option, except that it
70 applies only to indexes, not other relation types.
74 Check relations matching the specified pattern, unless they are
75 otherwise excluded. This option can be specified more than once.
77 Patterns may be unqualified, e.g. myrel*, or they may be
78 schema-qualified, e.g. myschema*.myrel* or database-qualified
79 and schema-qualified, e.g. mydb*.myschema*.myrel*. A
80 database-qualified pattern will add matching databases to the
81 list of databases to be checked.
84 --exclude-relation=pattern
85 Exclude relations matching the specified pattern. This option
86 can be specified more than once.
88 As with --relation, the pattern may be unqualified,
89 schema-qualified, or database- and schema-qualified.
93 Check tables and indexes in schemas matching the specified
94 pattern, unless they are otherwise excluded. This option can be
95 specified more than once.
97 To select only tables in schemas matching a particular pattern,
98 consider using something like --table=SCHEMAPAT.*
99 --no-dependent-indexes. To select only indexes, consider using
100 something like --index=SCHEMAPAT.*.
102 A schema pattern may be database-qualified. For example, you may
103 write --schema=mydb*.myschema* to select schemas matching
104 myschema* in databases matching mydb*.
107 --exclude-schema=pattern
108 Exclude tables and indexes in schemas matching the specified
109 pattern. This option can be specified more than once.
111 As with --schema, the pattern may be database-qualified.
115 Check tables matching the specified pattern, unless they are
116 otherwise excluded. This option can be specified more than once.
118 This is similar to the --relation option, except that it applies
119 only to tables, materialized views, and sequences, not to
123 --exclude-table=pattern
124 Exclude tables matching the specified pattern. This option can
125 be specified more than once.
127 This is similar to the --exclude-relation option, except that it
128 applies only to tables, materialized views, and sequences, not
131 --no-dependent-indexes
132 By default, if a table is checked, any btree indexes of that
133 table will also be checked, even if they are not explicitly
134 selected by an option such as --index or --relation. This option
135 suppresses that behavior.
138 By default, if a table is checked, its toast table, if any, will
139 also be checked, even if it is not explicitly selected by an
140 option such as --table or --relation. This option suppresses
144 By default, if an argument to --database, --table, --index, or
145 --relation matches no objects, it is a fatal error. This option
146 downgrades that error to a warning.
148 The following command-line options control checking of tables:
150 --exclude-toast-pointers
151 By default, whenever a toast pointer is encountered in a table,
152 a lookup is performed to ensure that it references
153 apparently-valid entries in the toast table. These checks can be
154 quite slow, and this option can be used to skip them.
157 After reporting all corruptions on the first page of a table
158 where corruption is found, stop processing that table relation
159 and move on to the next table or index.
161 Note that index checking always stops after the first corrupt
162 page. This option only has meaning relative to table relations.
165 If all-frozen is given, table corruption checks will skip over
166 pages in all tables that are marked as all frozen.
168 If all-visible is given, table corruption checks will skip over
169 pages in all tables that are marked as all visible.
171 By default, no pages are skipped. This can be specified as none,
172 but since this is the default, it need not be mentioned.
175 Start checking at the specified block number. An error will
176 occur if the table relation being checked has fewer than this
177 number of blocks. This option does not apply to indexes, and is
178 probably only useful when checking a single table relation. See
179 --endblock for further caveats.
182 End checking at the specified block number. An error will occur
183 if the table relation being checked has fewer than this number
184 of blocks. This option does not apply to indexes, and is
185 probably only useful when checking a single table relation. If
186 both a regular table and a toast table are checked, this option
187 will apply to both, but higher-numbered toast blocks may still
188 be accessed while validating toast pointers, unless that is
189 suppressed using --exclude-toast-pointers.
191 The following command-line options control checking of B-tree indexes:
194 For each index with unique constraint checked, verify that no
195 more than one among duplicate entries is visible in the index
196 using amcheck's checkunique option.
199 For each index checked, verify the presence of all heap tuples
200 as index tuples in the index using amcheck's heapallindexed
204 For each btree index checked, use amcheck's
205 bt_index_parent_check function, which performs additional checks
206 of parent/child relationships during index checking.
208 The default is to use amcheck's bt_index_check function, but
209 note that use of the --rootdescend option implicitly selects
210 bt_index_parent_check.
213 For each index checked, re-find tuples on the leaf level by
214 performing a new search from the root page for each tuple using
215 amcheck's rootdescend option.
217 Use of this option implicitly also selects the --parent-check
220 This form of verification was originally written to help in the
221 development of btree index features. It may be of limited use or
222 even of no use in helping detect the kinds of corruption that
223 occur in practice. It may also cause corruption checking to take
224 considerably longer and consume considerably more resources on
229 The extra checks performed against B-tree indexes when the
230 --parent-check option or the --rootdescend option is specified require
231 relatively strong relation-level locks. These checks are the only
232 checks that will block concurrent data modification from INSERT,
233 UPDATE, and DELETE commands.
235 The following command-line options control the connection to the
240 Specifies the host name of the machine on which the server is
241 running. If the value begins with a slash, it is used as the
242 directory for the Unix domain socket.
246 Specifies the TCP port or local Unix domain socket file
247 extension on which the server is listening for connections.
251 User name to connect as.
255 Never issue a password prompt. If the server requires password
256 authentication and a password is not available by other means
257 such as a .pgpass file, the connection attempt will fail. This
258 option can be useful in batch jobs and scripts where no user is
259 present to enter a password.
263 Force pg_amcheck to prompt for a password before connecting to a
266 This option is never essential, since pg_amcheck will
267 automatically prompt for a password if the server demands
268 password authentication. However, pg_amcheck will waste a
269 connection attempt finding out that the server wants a password.
270 In some cases it is worth typing -W to avoid the extra
273 --maintenance-db=dbname
274 Specifies a database or connection string to be used to discover
275 the list of databases to be checked. If neither --all nor any
276 option including a database pattern is used, no such connection
277 is required and this option does nothing. Otherwise, any
278 connection string parameters other than the database name which
279 are included in the value for this option will also be used when
280 connecting to the databases being checked. If this option is
281 omitted, the default is postgres or, if that fails, template1.
283 Other options are also available:
287 Echo to stdout all SQL sent to the server.
291 Use num concurrent connections to the server, or one per object
292 to be checked, whichever is less.
294 The default is to use a single connection.
298 Show progress information. Progress information includes the
299 number of relations for which checking has been completed, and
300 the total size of those relations. It also includes the total
301 number of relations that will eventually be checked, and the
302 estimated size of those relations.
306 Print more messages. In particular, this will print a message
307 for each relation being checked, and will increase the level of
308 detail shown for server errors.
312 Print the pg_amcheck version and exit.
315 --install-missing=schema
316 Install any missing extensions that are required to check the
317 database(s). If not yet installed, each extension's objects will
318 be installed into the given schema, or if not specified into
321 At present, the only required extension is amcheck.
325 Show help about pg_amcheck command line arguments, and exit.
329 pg_amcheck, like most other PostgreSQL utilities, also uses the
330 environment variables supported by libpq (see Section 32.15).
332 The environment variable PG_COLOR specifies whether to use color in
333 diagnostic messages. Possible values are always, auto and never.
337 pg_amcheck is designed to work with PostgreSQL 14.0 and later.