Skip to content

Commit e1b120a

Browse files
committed
Only issue LOCK TABLE commands when necessary
Reviewing the cases where we need to LOCK a given table during a dump, it was pointed out by Tom that we really don't need to LOCK a table if we are only looking to dump the ACL for it, or certain other components. After reviewing the queries run for all of the component pieces, a list of components were determined to not require LOCK'ing of the table. This implements a check to avoid LOCK'ing those tables. Initial complaint from Rushabh Lathia, discussed with Robert and Tom, the patch is mine.
1 parent 5d58999 commit e1b120a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5953,8 +5953,11 @@ getTables(Archive *fout, int *numTables)
59535953
*
59545954
* NOTE: it'd be kinda nice to lock other relations too, not only
59555955
* plain tables, but the backend doesn't presently allow that.
5956+
*
5957+
* We only need to lock the table for certain components; see pg_dump.h
59565958
*/
5957-
if (tblinfo[i].dobj.dump && tblinfo[i].relkind == RELKIND_RELATION)
5959+
if (tblinfo[i].dobj.dump && tblinfo[i].relkind == RELKIND_RELATION &&
5960+
(tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
59585961
{
59595962
resetPQExpBuffer(query);
59605963
appendPQExpBuffer(query,

src/bin/pg_dump/pg_dump.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ typedef uint32 DumpComponents; /* a bitmask of dump object components */
9393
#define DUMP_COMPONENT_USERMAP (1 << 6)
9494
#define DUMP_COMPONENT_ALL (0xFFFF)
9595

96+
/*
97+
* component types which require us to obtain a lock on the table
98+
*
99+
* Note that some components only require looking at the information
100+
* in the pg_catalog tables and, for those components, we do not need
101+
* to lock the table. Be careful here though- some components use
102+
* server-side functions which pull the latest information from
103+
* SysCache and in those cases we *do* need to lock the table.
104+
*
105+
* We do not need locks for the COMMENT and SECLABEL components as
106+
* those simply query their associated tables without using any
107+
* server-side functions. We do not need locks for the ACL component
108+
* as we pull that information from pg_class without using any
109+
* server-side functions that use SysCache. The USERMAP component
110+
* is only relevant for FOREIGN SERVERs and not tables, so no sense
111+
* locking a table for that either (that can happen if we are going
112+
* to dump "ALL" components for a table).
113+
*
114+
* We DO need locks for DEFINITION, due to various server-side
115+
* functions that are used and POLICY due to pg_get_expr(). We set
116+
* this up to grab the lock except in the cases we know to be safe.
117+
*/
118+
#define DUMP_COMPONENTS_REQUIRING_LOCK (\
119+
DUMP_COMPONENT_DEFINITION |\
120+
DUMP_COMPONENT_DATA |\
121+
DUMP_COMPONENT_POLICY)
122+
96123
typedef struct _dumpableObject
97124
{
98125
DumpableObjectType objType;

0 commit comments

Comments
 (0)