What are the available options to identify and remove the invalid objects in Postgres
However, There is no way list up 'invalid' objects in PostgreSQL, since other objects cannot become invalid in PostgreSQL. Oracle and PostgreSQL work quite differently in that respect : In Oracle, you can always ALTER an object (for example a table) even if there are dependent objects (for example views).
Detects indexes that are not recognized as valid in Postgres and creates an issue with severity "info", one for each table (or table hierarchy in case of inheritance or partitioning). These indexes typically are left over when using CREATE INDEX CONCURRENTLY and the command fails or is aborted by the user.
One way to do this is to shut down the server and start a single-user PostgreSQL server with the -P option included on its command line. Then, REINDEX DATABASE , REINDEX SYSTEM , REINDEX TABLE , or REINDEX INDEX can be issued, depending on how much you want to reconstruct.
If you're referring to detecting "invalid" (poorly created) indexes, apparently Postgres can "fail" in an attempt to create an index, and then the query planner won't use them, though they exist in your system. This query will detect "failed" indexes:
https://www.enterprisedb.com/blog/pgupgrade-bug-invalid-concurrently-created-indexes
SELECT n.nspname, c.relname
FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n,
pg_catalog.pg_index i
WHERE (i.indisvalid = false OR i.indisready = false) AND
i.indexrelid = c.oid AND c.relnamespace = n.oid AND
n.nspname != 'pg_catalog' AND
n.nspname != 'information_schema' AND
n.nspname != 'pg_toast'
though I suppose detecting TOAST table indexes wouldn't hurt, so you can remove that portion of the query :)
Related, for me sometimes just running a fresh ANALYZE on a table also makes indexes suddenly start being used in production (i.e. even if indexes aren't "invalid" they may be unused until an ANALYZE run). Weird.
Have you tried running vacuum full pg_class
as superuser?
Also, auto-vacuum should take care of it eventually. Your objects seem to be temporary tables/indexes, and the catalog is (usually) not being updated as frequently as your data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With