PG_AMCHECK(1)
π PG_AMCHECK(1) π
okay so this is pg_amcheck, straight out of the PostgreSQL 14.24 Documentation, and bestie it is literally the corruption detector of your dreams π
β¨ NAME β¨
pg_amcheck β checks for corruption in one or more PostgreSQL databases ππ
β¨ SYNOPSIS β¨
pg_amcheck [option...] [dbname]
β¨ DESCRIPTION β¨
so what does it do? pg_amcheck runs amcheck's corruption checking functions against one or more databases β yes, plural, she's versatile π and you get options to pick which schemas, tables and indexes to check, which kinds of checking to perform, and whether to do the checks in parallel β and if so, how many parallel connections to establish and use πβ¨
heads up bestie: only table relations and btree indexes are currently supported. Other relation types are silently skipped π like they just don't get an invite to the party π
now let's talk about dbname, because this part is highkey important π«Ά
- if
dbnameis specified, it should be the name of a single database to check, and no other database selection options should be present, periodt β - 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 πΈ
and which options count as database selection options? glad you asked π they include --all, --database and --exclude-database β
they also include --relation, --exclude-relation, --table, --exclude-table, --index, and --exclude-index β but only when such options are used with a three-part pattern (e.g. mydb*.myschema*.myrel*) π
finally, they include --schema and --exclude-schema when such options are used with a two-part pattern (e.g. mydb*.myschema*) π¦
oh and one more thing β dbname can also be a connection string π slay
β¨ OPTIONS β¨
Okay so now we're telling pg_amcheck what to actually look at, and bestie there are so many knobs. Every single one is below, no cap. π
π΅οΈ The following command-line options control what is checked
-a,--allβ check all databases, except for any excluded via--exclude-database. β¨-d pattern,--database=patternβ check databases matching the specified pattern, except for any excluded by--exclude-database. This option can be specified more than once. π«Ά-D pattern,--exclude-database=patternβ exclude databases matching the given pattern. This option can be specified more than once. π-i pattern,--index=patternβ check indexes matching the specified pattern, unless they are otherwise excluded. This option can be specified more than once.- This is similar to the
--relationoption, except that it applies only to indexes, not tables. π
- This is similar to the
-I pattern,--exclude-index=patternβ exclude indexes matching the specified pattern. This option can be specified more than once.- This is similar to the
--exclude-relationoption, except that it applies only to indexes, not tables. π
- This is similar to the
-r pattern,--relation=patternβ check relations matching the specified pattern, unless they are otherwise excluded. This option can be specified more than once.- 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. π
- Patterns may be unqualified, e.g.
-R pattern,--exclude-relation=patternβ exclude relations matching the specified pattern. This option can be specified more than once.- As with
--relation, the pattern may be unqualified, schema-qualified, or database- and schema-qualified. π¦
- As with
-s pattern,--schema=patternβ check tables and indexes in schemas matching the specified pattern, unless they are otherwise excluded. This option can be specified more than once.- 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.*. - A schema pattern may be database-qualified. For example, you may write
--schema=mydb*.myschema*to select schemas matchingmyschema*in databases matchingmydb*. πΈ
- To select only tables in schemas matching a particular pattern, consider using something like
-S pattern,--exclude-schema=patternβ exclude tables and indexes in schemas matching the specified pattern. This option can be specified more than once.- As with
--schema, the pattern may be database-qualified. π
- As with
-t pattern,--table=patternβ check tables matching the specified pattern, unless they are otherwise excluded. This option can be specified more than once.- This is similar to the
--relationoption, except that it applies only to tables, not indexes. β¨
- This is similar to the
-T pattern,--exclude-table=patternβ exclude tables matching the specified pattern. This option can be specified more than once.- This is similar to the
--exclude-relationoption, except that it applies only to tables, not indexes. π«Ά
- This is similar to the
--no-dependent-indexesβ 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--indexor--relation. This option suppresses that behavior. π₯--no-dependent-toastβ 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--tableor--relation. This option suppresses that behavior. π--no-strict-namesβ by default, if an argument to--database,--table,--index, or--relationmatches no objects, it is a fatal error. This option downgrades that error to a warning. π
π The following command-line options control checking of tables
--exclude-toast-pointersβ 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. π--on-error-stopβ 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.- Note that index checking always stops after the first corrupt page. This option only has meaning relative to table relations. π
--skip=optionβ ifall-frozenis given, table corruption checks will skip over pages in all tables that are marked as all frozen.- If
all-visibleis given, table corruption checks will skip over pages in all tables that are marked as all visible. - By default, no pages are skipped. This can be specified as
none, but since this is the default, it need not be mentioned. π
- If
--startblock=blockβ 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--endblockfor further caveats. π--endblock=blockβ 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--exclude-toast-pointers. π
π³ The following command-line options control checking of B-tree indexes
--heapallindexedβ for each index checked, verify the presence of all heap tuples as index tuples in the index using amcheck'sheapallindexedoption. π₯--parent-checkβ for each btree index checked, use amcheck'sbt_index_parent_checkfunction, which performs additional checks of parent/child relationships during index checking.- The default is to use amcheck's
bt_index_checkfunction, but note that use of the--rootdescendoption implicitly selectsbt_index_parent_check. π
- The default is to use amcheck's
--rootdescendβ 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'srootdescendoption.- Use of this option implicitly also selects the
--parent-checkoption. - 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. π
- Use of this option implicitly also selects the
β οΈ Warning β the extra checks performed against B-tree indexes when the--parent-checkoption or the--rootdescendoption is specified require relatively strong relation-level locks. These checks are the only checks that will block concurrent data modification fromINSERT,UPDATE, andDELETEcommands. π
π The following command-line options control the connection to the server
-h hostname,--host=hostnameβ 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. πΈ-p port,--port=portβ specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. π¦-U,--username=usernameβ user name to connect as. π-w,--no-passwordβ never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. π«Ά-W,--passwordβ forcepg_amcheckto prompt for a password before connecting to a database.- This option is never essential, since
pg_amcheckwill automatically prompt for a password if the server demands password authentication. However,pg_amcheckwill waste a connection attempt finding out that the server wants a password. In some cases it is worth typing-Wto avoid the extra connection attempt. β¨
- This option is never essential, since
--maintenance-db=dbnameβ specifies a database or connection string to be used to discover the list of databases to be checked. If neither--allnor 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 ispostgresor, if that fails,template1. π
π Other options are also available
-e,--echoβ echo to stdout all SQL sent to the server. π-j num,--jobs=numβ use num concurrent connections to the server, or one per object to be checked, whichever is less.- The default is to use a single connection. π
-P,--progressβ 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. π¦-v,--verboseβ 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. π₯-V,--versionβ print thepg_amcheckversion and exit. β--install-missing,--install-missing=schemaβ install any missing extensions that are required to check the database(s). If not yet installed, each extension's objects will be installed into the given schema, or if not specified into schemapg_catalog.- At present, the only required extension is
amcheck. π
- At present, the only required extension is
-?,--helpβ show help aboutpg_amcheckcommand line arguments, and exit. π
π NOTES π
pg_amcheck is designed to work with PostgreSQL 14.0 and later. π«Ά
π SEE ALSO π
amcheckβ yes bestie, go read that one too. π
And that's the whole vibe check: PostgreSQL 14.24, 2026, PG_AMCHECK(1) β iconic footer behavior, periodt. πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14-contrib 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14-contrib 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14-contrib 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14-contrib 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms