]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Improve database detection logic in datachecksumsworker
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Thu, 30 Apr 2026 11:41:55 +0000 (13:41 +0200)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Thu, 30 Apr 2026 11:41:55 +0000 (13:41 +0200)
The worker need to know whether a database which failed checksum
processing still exists, or has been dropped.  This improves the
detection logic by checking for being partially dropped.

Author: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/9197F930-DDEB-4CAC-82A2-16FEC715CCE8@yesql.se

src/backend/postmaster/datachecksum_state.c

index bd41a1fac19bbc0bc25eb98cee93b511ac7bb7a6..d0d6acdd6a2d76e7e60085863858a651435d60da 100644 (file)
@@ -848,8 +848,7 @@ ProcessDatabase(DataChecksumsWorkerDatabase *db)
 
                /*
                 * Heuristic to see if the database was dropped, and if it was we can
-                * treat it as not an error, else treat as fatal and error out. TODO:
-                * this could probably be improved with a tighter check.
+                * treat it as not an error, else treat as fatal and error out.
                 */
                if (DatabaseExists(db->dboid))
                        return DATACHECKSUMSWORKER_FAILED;
@@ -1314,7 +1313,9 @@ DataChecksumsShmemRequest(void *arg)
  * DatabaseExists
  *
  * Scans the system catalog to check if a database with the given Oid exists
- * and returns true if it is found, else false.
+ * and returns true if it is found and valid, else false. Note, we cannot use
+ * database_is_invalid_oid here as it will ERROR out, and we want to gracefully
+ * handle errors.
  */
 static bool
 DatabaseExists(Oid dboid)
@@ -1324,6 +1325,7 @@ DatabaseExists(Oid dboid)
        SysScanDesc scan;
        bool            found;
        HeapTuple       tuple;
+       Form_pg_database pg_database_tuple;
 
        StartTransactionCommand();
 
@@ -1337,6 +1339,14 @@ DatabaseExists(Oid dboid)
        tuple = systable_getnext(scan);
        found = HeapTupleIsValid(tuple);
 
+       /* If the Oid exists, ensure that it's not partially dropped */
+       if (found)
+       {
+               pg_database_tuple = (Form_pg_database) GETSTRUCT(tuple);
+               if (database_is_invalid_form(pg_database_tuple))
+                       found = false;
+       }
+
        systable_endscan(scan);
        table_close(rel, AccessShareLock);