Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Make pg_dump acquire lock on partitioned tables that are to be dumped.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 16 Oct 2021 16:23:57 +0000 (12:23 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 16 Oct 2021 16:24:24 +0000 (12:24 -0400)
It was clearly the intent to do so all along, but the original coding
fat-fingered this by checking the wrong array element.  We fixed it
in passing in 403a3d91c, but that later got reverted, and we forgot
to keep this bug fix.

Most of the time this'd be relatively harmless, since once we lock
any of the partitioned table's leaf partitions, that would suffice
to prevent major DDL on the partitioned table itself.  However, a
childless partitioned table would get dumped with no relevant lock
whatsoever, possibly allowing dump failure or inconsistent output.

Unlike 403a3d91c, there are no versioning concerns, since every server
version that has partitioned tables will allow you to lock one.

Back-patch to v10 where partitioned tables were introduced.

Discussion: https://postgr.es/m/1018205.1634346327@sss.pgh.pa.us

src/bin/pg_dump/pg_dump.c

index 63efccfa9e430977c6c7e7e44c3d7c81652571fa..bb17cf3400f781934e0c11e1d447597b83cc8cad 100644 (file)
@@ -6737,7 +6737,7 @@ getTables(Archive *fout, int *numTables)
         */
        if (tblinfo[i].dobj.dump &&
            (tblinfo[i].relkind == RELKIND_RELATION ||
-            tblinfo->relkind == RELKIND_PARTITIONED_TABLE) &&
+            tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE) &&
            (tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
        {
            resetPQExpBuffer(query);