Skip to content

Commit 768ab4d

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 583fcf2 commit 768ab4d

File tree

4 files changed

+5
-81
lines changed

4 files changed

+5
-81
lines changed

src/bin/pg_dump/pg_backup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ typedef struct Archive
188188
int minRemoteVersion; /* allowable range */
189189
int maxRemoteVersion;
190190

191-
bool hasGenericLockTable; /* can LOCK TABLE do non-table rels */
192-
193191
int numWorkers; /* number of parallel processes */
194192
char *sync_snapshot_id; /* sync snapshot id for parallel
195193
* operation */

src/bin/pg_dump/pg_backup_db.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -552,73 +552,6 @@ EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
552552
}
553553
}
554554

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

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, 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: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,6 @@ setup_connection(Archive *AH, const char *dumpencoding,
10811081
ExecuteSqlStatement(AH, "SET row_security = off");
10821082
}
10831083

1084-
/* Detect whether LOCK TABLE can handle non-table relations */
1085-
AH->hasGenericLockTable = IsLockTableGeneric(AH);
1086-
10871084
/*
10881085
* Start transaction-snapshot mode transaction to dump consistent data.
10891086
*/
@@ -6200,15 +6197,13 @@ getTables(Archive *fout, int *numTables)
62006197
* assume our lock on the child is enough to prevent schema
62016198
* alterations to parent tables.
62026199
*
6203-
* We only need to lock the relation for certain components; see
6204-
* pg_dump.h
6200+
* NOTE: it'd be kinda nice to lock other relations too, not only
6201+
* plain tables, but the backend doesn't presently allow that.
62056202
*
6206-
* On server versions that support it, we lock all relations not just
6207-
* plain tables.
6203+
* We only need to lock the table for certain components; see
6204+
* pg_dump.h
62086205
*/
6209-
if (tblinfo[i].dobj.dump &&
6210-
(fout->hasGenericLockTable ||
6211-
tblinfo[i].relkind == RELKIND_RELATION) &&
6206+
if (tblinfo[i].dobj.dump && tblinfo[i].relkind == RELKIND_RELATION &&
62126207
(tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
62136208
{
62146209
resetPQExpBuffer(query);

0 commit comments

Comments
 (0)