PG_AMCHECK(1)
β¨ PG_AMCHECK β¨
okay so this is the manual page for pg_amcheck, from the PostgreSQL 18.6 Documentation. bestie. it's giving corruption detective energy and honestly? we're obsessed π
πΈ NAME πΈ
pg_amcheck β the girl who checks for corruption in one or more PostgreSQL databases. yes, that's her job. and she eats. π
π SYNOPSIS π
pg_amcheck [option...] [dbname]
literally just that.</purgle> options and maybe a db name. simple as. β¨
quick typo check: that was meant to be `... no wait, i already closed it. moving on. π
π¦ DESCRIPTION π¦
okay so here's the tea. pg_amcheck supports running amcheck's corruption checking functions against one or more databases. one or more! plural! the range! π
and she's got options, bestie, so many options, for:
- selecting which schemas, tables and indexes to check π―
- which kinds of checking to perform π
- whether to perform the checks in parallel β‘
- and if so, the number of parallel connections to establish and use π―π―π―
π§ what can she even check, tho
only these relation types are supported right now:
- ordinary table relations
- toast table relations
- materialized views
- sequences
- btree indexes
that's the list. and the rest? other relation types are silently skipped. no drama, no error, no nothing. she just π» ghosts them. not a single word. iconic behaviour honestly.
π which database are we checking
okay so this part is important, pay attention bestie:
if dbname is specified β it should be the name of a single database to check, and no other database selection options should be present. periodt. π
otherwise, two paths:
- 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 π
π the database selection options, spelled all the way out
here's who counts as a "database selection option", no cap:
--allβ¨--databaseβ¨--exclude-databaseβ¨
and also these ones:
--relation--exclude-relation--table--exclude-table--index--exclude-index
but lowkey only when they're used with a three-part pattern, like:
mydb*.myschema*.myrel*
see the three parts? db, schema, rel. three. π―
finally, also these:
--schema--exclude-schema
and these only count when used with a two-part pattern, like:
mydb*.myschema*
two parts, bestie. not three. two. π
π one last thing
dbname can also be a connection string. not just a plain name. she's flexible like that. π
to be continuedβ¦ π¦
β¨ OPTIONS β¨
okay bestie, this is where you tell pg_amcheck what to actually look at. No cap, there are a lot of knobs, but we're gonna go through every single one. π
π The following command-line options control what is checked:
-a,--allβ Check all databases, except for any excluded via--exclude-database.-dpattern,--database=patternβ Check databases matching the specified pattern, except for any excluded by--exclude-database. This option can be specified more than once.-Dpattern,--exclude-database=patternβ Exclude databases matching the given pattern. This option can be specified more than once.-ipattern,--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 --relation option, except that it applies only to indexes, not to other relation types.
-Ipattern,--exclude-index=patternβ Exclude indexes matching the specified pattern. This option can be specified more than once.
This is similar to the --exclude-relation option, except that it applies only to indexes, not other relation types.
-rpattern,--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.
-Rpattern,--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.
-spattern,--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 matching myschema* in databases matching mydb*.
-Spattern,--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.
-tpattern,--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 --relation option, except that it applies only to tables, materialized views, and sequences, not to indexes.
-Tpattern,--exclude-table=patternβ Exclude tables matching the specified pattern. This option can be specified more than once.
This is similar to the --exclude-relation option, except that it applies only to tables, materialized views, and sequences, not to indexes.
--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-visible is 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.
--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:
--checkuniqueβ For each index with unique constraint checked, verify that no more than one among duplicate entries is visible in the index using amcheck'scheckuniqueoption.--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_check function, but note that use of the --rootdescend option implicitly selects bt_index_parent_check.
--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-check option.
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.
β οΈ 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:
-hhostname,--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.-pport,--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_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 -W to avoid the extra connection attempt.
--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.-jnum,--jobs=numβ Usenumconcurrent 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.
-?,--helpβ Show help aboutpg_amcheckcommand line arguments, and exit.
πΈ ENVIRONMENT πΈ
ok so pg_amcheck, literally just like basically every other PostgreSQL utility out there, also reads the environment variables that libpq supports β yes, those ones. if you wanna go deep on what those are, check out Section 32.15. iykyk π
The environment variable PG_COLOR decides whether diagnostic messages get the cute little color treatment or not. The possible values are:
alwaysβ bestie, we're coloring, no questions asked πautoβ let the vibes decide (it figures it out itself) β¨neverβ monochrome mode, no color, we stay neutral π
β NOTES β
pg_amcheck is built to work with PostgreSQL 14.0 and later. that's the vibe check on compatibility, fr fr π¦
π SEE ALSO π
amcheckπ
and that's the whole page, bestie β go forth and check those indexes π β¨
signing off from the PostgreSQL 18.6 era, dated 2026, on the iconic PG_AMCHECK(1) page itself π«Άπ
π¦ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql 18.6-4 Β· PostgreSQL
- fedora 43: postgresql-contrib 18.6-1.fc43 Β· PostgreSQL
- fedora 44: postgresql-contrib 18.6-1.fc44 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms