On 2025-Apr-28, Shlok Kyal wrote: > 2. > + * We also take a ShareLock on pg_partitioned_table to restrict addition > + * of new partitioned table which may contain a foreign partition while > + * publication is being created. XXX this is quite weird actually. > > This change was added to resolve the concurrency issue shared by > Vignesh in [4]. I tried with different locks and found that lock with > severity >= ShareLock was needed to avoid the concurrency issue. > Initially I added ShareLock to pg_class, but to reduce the scope I > added it to pg_partitioned_table instead. I cannot think of an > alternate approach. Do you have any suggestions for this?
> [4]: > https://www.postgresql.org/message-id/CALDaNm2%2BeL22Sbvj74uS37xvt%3DhaQWcOwP15QnDuVeYsjHiffw%40mail.gmail.com I think this is the sticky point in this patch. I think you need a clearer explanation (in code comments) of why you need this lock, and whether a weaker lock would be enough in some cases (see below); also I suspect that these locking considerations are going to be important for users so they're going to need to be documented in the SGML docs. What operations are blocked when you hold this lock? Is replication going to block altogether until the transaction that runs publication_check_foreign_parts() commits/aborts? This is important because it might mean that that users need to keep such transactions short. If your publication is FOR TABLES IN SCHEMA, can you do with blocking creation of partitions only in that schema, or only partitions of partitioned tables in that schema? Another point that just occurred to me is that pg_upgrade --check may need to alert users that if they have an incompatible setup in 18 or earlier, then an upgrade to 19 does not work until they have fixed the publications, detached the partitions, or some other remediation has been applied. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Linux transformó mi computadora, de una `máquina para hacer cosas', en un aparato realmente entretenido, sobre el cual cada día aprendo algo nuevo" (Jaime Salinas)