Skip to content

Latest commit

 

History

History
91 lines (63 loc) · 3.76 KB

20230104_01.md

File metadata and controls

91 lines (63 loc) · 3.76 KB

PostgreSQL 16 preview - pg_dump 批量加表级共享访问锁减少加锁交互时长

作者

digoal

日期

2023-01-04

标签

PostgreSQL , PolarDB , pg_dump , 批量加锁


背景

PostgreSQL 16 preview - pg_dump 批量加表级共享访问锁减少加锁交互时长, 一次query batch length reaches 100K.

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=5f53b42cfd053a724fcbe0712a9d5716e576a3e6

+           /*  
+            * Tables are locked in batches.  When dumping from a remote  
+            * server this can save a significant amount of time by reducing  
+            * the number of round trips.  
+            */  
+           if (query->len == 0)  
+               appendPQExpBuffer(query, "LOCK TABLE %s",  
+                                 fmtQualifiedDumpable(&tblinfo[i]));  
+           else  
+           {  
+               appendPQExpBuffer(query, ", %s",  
+                                 fmtQualifiedDumpable(&tblinfo[i]));  
+  
+               /* Arbitrarily end a batch when query length reaches 100K. */  
+               if (query->len >= 100000)  
+               {  
+                   /* Lock another batch of tables. */  
+                   appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");  
+                   ExecuteSqlStatement(fout, query->data);  
+                   resetPQExpBuffer(query);  
+               }  
+           }  
During pg_dump startup, acquire table locks in batches.  
author	Tom Lane <tgl@sss.pgh.pa.us>	  
Tue, 3 Jan 2023 22:56:37 +0000 (17:56 -0500)  
committer	Tom Lane <tgl@sss.pgh.pa.us>	  
Tue, 3 Jan 2023 22:56:44 +0000 (17:56 -0500)  
commit	5f53b42cfd053a724fcbe0712a9d5716e576a3e6  
tree	34bbc9ea111022775683c7f6ad5e900b1fc6f3bb	tree  
parent	b23837dde48028f9e31983c765c32e3f42cb7ef2	commit | diff  
During pg_dump startup, acquire table locks in batches.  
  
Combine multiple LOCK TABLE commands to reduce the number of  
round trips to the server.  This is particularly helpful when  
dumping from a remote server, but it seems useful even without  
that.  In particular, shortening the time from seeing a table  
in pg_class to acquiring lock on it reduces the window for  
trouble from concurrent DDL.  
  
Aleksander Alekseev, reviewed by Fabrízio de Royes Mello,  
Gilles Darold, and Andres Freund  
  
Discussion: https://postgr.es/m/CAJ7c6TO4z1+OBa-R+fC8FnaUgbEWJUf2Kq=nRngTW5EXtKru2g@mail.gmail.com  

digoal's wechat