Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f4fa4a8

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 0bdf1ef commit f4fa4a8

File tree

4 files changed

+7
-80
lines changed

4 files changed

+7
-80
lines changed

src/bin/pg_dump/pg_backup.h

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

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

src/bin/pg_dump/pg_backup_db.c

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -534,72 +534,6 @@ EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
534534
}
535535
}
536536

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

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
@@ -1168,9 +1168,6 @@ setup_connection(Archive *AH, const char *dumpencoding,
11681168
ExecuteSqlStatement(AH, "SET row_security = off");
11691169
}
11701170

1171-
/* Detect whether LOCK TABLE can handle non-table relations */
1172-
AH->hasGenericLockTable = IsLockTableGeneric(AH);
1173-
11741171
/*
11751172
* Start transaction-snapshot mode transaction to dump consistent data.
11761173
*/
@@ -6730,16 +6727,16 @@ getTables(Archive *fout, int *numTables)
67306727
* assume our lock on the child is enough to prevent schema
67316728
* alterations to parent tables.
67326729
*
6733-
* We only need to lock the relation for certain components; see
6734-
* pg_dump.h
6730+
* NOTE: it'd be kinda nice to lock other relations too, not only
6731+
* plain or partitioned tables, but the backend doesn't presently
6732+
* allow that.
67356733
*
6736-
* On server versions that support it, we lock all relations not just
6737-
* plain tables.
6734+
* We only need to lock the table for certain components; see
6735+
* pg_dump.h
67386736
*/
67396737
if (tblinfo[i].dobj.dump &&
6740-
(fout->hasGenericLockTable ||
6741-
tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE ||
6742-
tblinfo[i].relkind == RELKIND_RELATION) &&
6738+
(tblinfo[i].relkind == RELKIND_RELATION ||
6739+
tblinfo->relkind == RELKIND_PARTITIONED_TABLE) &&
67436740
(tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
67446741
{
67456742
resetPQExpBuffer(query);

0 commit comments

Comments
 (0)