Skip to content

Commit 802c460

Browse files
committed
Revert "pg_dump: Lock all relations, not just plain tables".
Revert 403a3d9, as well as the followup fix 7f42350, in all branches. We need to think a bit harder about what the behavior of LOCK TABLE on views should be, and there's no time for that before next week's releases. We'll take another crack at this later. Discussion: https://postgr.es/m/16703-e348f58aab3cf6cc@postgresql.org
1 parent 7dc18c6 commit 802c460

File tree

4 files changed

+7
-81
lines changed

4 files changed

+7
-81
lines changed

src/bin/pg_dump/pg_backup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ typedef struct Archive
200200
int minRemoteVersion; /* allowable range */
201201
int maxRemoteVersion;
202202

203-
bool hasGenericLockTable; /* can LOCK TABLE do non-table rels */
204-
205203
int numWorkers; /* number of parallel processes */
206204
char *sync_snapshot_id; /* sync snapshot id for parallel operation */
207205

src/bin/pg_dump/pg_backup_db.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -537,73 +537,6 @@ EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
537537
}
538538
}
539539

540-
/*
541-
* Does LOCK TABLE work on non-table relations on this server?
542-
*
543-
* Note: assumes it is called out of any transaction
544-
*/
545-
bool
546-
IsLockTableGeneric(Archive *AHX)
547-
{
548-
ArchiveHandle *AH = (ArchiveHandle *) AHX;
549-
PGresult *res;
550-
char *sqlstate;
551-
bool retval;
552-
553-
if (AHX->remoteVersion >= 140000)
554-
return true;
555-
else if (AHX->remoteVersion < 90500)
556-
return false;
557-
558-
StartTransaction(AHX);
559-
560-
/*
561-
* Try a LOCK TABLE on a well-known non-table catalog; WRONG_OBJECT_TYPE
562-
* tells us that this server doesn't support locking non-table rels, while
563-
* LOCK_NOT_AVAILABLE and INSUFFICIENT_PRIVILEGE tell us that it does.
564-
* Report anything else as a fatal problem.
565-
*/
566-
#define ERRCODE_INSUFFICIENT_PRIVILEGE "42501"
567-
#define ERRCODE_WRONG_OBJECT_TYPE "42809"
568-
#define ERRCODE_LOCK_NOT_AVAILABLE "55P03"
569-
res = PQexec(AH->connection,
570-
"LOCK TABLE pg_catalog.pg_class_tblspc_relfilenode_index IN ACCESS SHARE MODE NOWAIT");
571-
switch (PQresultStatus(res))
572-
{
573-
case PGRES_COMMAND_OK:
574-
retval = true;
575-
break;
576-
case PGRES_FATAL_ERROR:
577-
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
578-
if (sqlstate &&
579-
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
580-
{
581-
retval = false;
582-
break;
583-
}
584-
else if (sqlstate &&
585-
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
586-
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
587-
{
588-
retval = true;
589-
break;
590-
}
591-
/* else, falls through */
592-
default:
593-
warn_or_exit_horribly(AH, modulename,
594-
"LOCK TABLE failed for \"%s\": %s",
595-
"pg_catalog.pg_class_tblspc_relfilenode_index",
596-
PQerrorMessage(AH->connection));
597-
retval = false; /* not reached */
598-
break;
599-
}
600-
PQclear(res);
601-
602-
CommitTransaction(AHX);
603-
604-
return retval;
605-
}
606-
607540
void
608541
StartTransaction(Archive *AHX)
609542
{

src/bin/pg_dump/pg_backup_db.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ extern PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, const char *query);
2020

2121
extern void EndDBCopyMode(Archive *AHX, const char *tocEntryTag);
2222

23-
extern bool IsLockTableGeneric(Archive *AHX);
24-
2523
extern void StartTransaction(Archive *AHX);
2624
extern void CommitTransaction(Archive *AHX);
2725

src/bin/pg_dump/pg_dump.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,6 @@ setup_connection(Archive *AH, const char *dumpencoding,
11151115
ExecuteSqlStatement(AH, "SET row_security = off");
11161116
}
11171117

1118-
/* Detect whether LOCK TABLE can handle non-table relations */
1119-
AH->hasGenericLockTable = IsLockTableGeneric(AH);
1120-
11211118
/*
11221119
* Start transaction-snapshot mode transaction to dump consistent data.
11231120
*/
@@ -6665,16 +6662,16 @@ getTables(Archive *fout, int *numTables)
66656662
* assume our lock on the child is enough to prevent schema
66666663
* alterations to parent tables.
66676664
*
6668-
* We only need to lock the relation for certain components; see
6669-
* pg_dump.h
6665+
* NOTE: it'd be kinda nice to lock other relations too, not only
6666+
* plain or partitioned tables, but the backend doesn't presently
6667+
* allow that.
66706668
*
6671-
* On server versions that support it, we lock all relations not just
6672-
* plain tables.
6669+
* We only need to lock the table for certain components; see
6670+
* pg_dump.h
66736671
*/
66746672
if (tblinfo[i].dobj.dump &&
6675-
(fout->hasGenericLockTable ||
6676-
tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE ||
6677-
tblinfo[i].relkind == RELKIND_RELATION) &&
6673+
(tblinfo[i].relkind == RELKIND_RELATION ||
6674+
tblinfo->relkind == RELKIND_PARTITIONED_TABLE) &&
66786675
(tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
66796676
{
66806677
resetPQExpBuffer(query);

0 commit comments

Comments
 (0)