Skip to content

Commit 8771792

Browse files
committed
Tweak pg_dump to handle default tablespaces correctly --- same logic
as the corrected pg_get_indexdef code.
1 parent edb1ba1 commit 8771792

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.388 2004/10/06 23:31:45 neilc Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.389 2004/10/18 00:20:41 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -108,6 +108,9 @@ static const CatalogId nilCatalogId = {0, 0};
108108
static NamespaceInfo *g_namespaces;
109109
static int g_numNamespaces;
110110

111+
/* need the name of the database's default tablespace */
112+
static char *dbDefaultTableSpace;
113+
111114
/* flag to turn on/off dollar quoting */
112115
static int disable_dollar_quoting = 0;
113116

@@ -1249,6 +1252,9 @@ dumpDatabase(Archive *AH)
12491252
encoding = PQgetvalue(res, 0, i_encoding);
12501253
tablespace = PQgetvalue(res, 0, i_tablespace);
12511254

1255+
/* save dattablespace name for later dump routines */
1256+
dbDefaultTableSpace = strdup(tablespace);
1257+
12521258
appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0",
12531259
fmtId(datname));
12541260
if (strlen(encoding) > 0)
@@ -1257,7 +1263,8 @@ dumpDatabase(Archive *AH)
12571263
appendStringLiteral(creaQry, encoding, true);
12581264
}
12591265
if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0)
1260-
appendPQExpBuffer(creaQry, " TABLESPACE = %s", fmtId(tablespace));
1266+
appendPQExpBuffer(creaQry, " TABLESPACE = %s",
1267+
fmtId(tablespace));
12611268
appendPQExpBuffer(creaQry, ";\n");
12621269

12631270
appendPQExpBuffer(delQry, "DROP DATABASE %s;\n",
@@ -4428,7 +4435,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
44284435
appendPQExpBuffer(q, "CREATE SCHEMA %s AUTHORIZATION %s",
44294436
qnspname, fmtId(nspinfo->usename));
44304437

4431-
/* Add tablespace qualifier, if not default */
4438+
/* Add tablespace qualifier, if not default for database */
44324439
if (strlen(nspinfo->nsptablespace) != 0)
44334440
appendPQExpBuffer(q, " TABLESPACE %s",
44344441
fmtId(nspinfo->nsptablespace));
@@ -6652,13 +6659,16 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
66526659
appendPQExpBuffer(q, ")");
66536660
}
66546661

6655-
/* Output tablespace clause if necessary */
6656-
if (strlen(tbinfo->reltablespace) != 0 &&
6657-
strcmp(tbinfo->reltablespace,
6662+
/* Output tablespace clause if different from parent schema's */
6663+
if (strcmp(tbinfo->reltablespace,
66586664
tbinfo->dobj.namespace->nsptablespace) != 0)
66596665
{
6660-
appendPQExpBuffer(q, " TABLESPACE %s",
6661-
fmtId(tbinfo->reltablespace));
6666+
if (strlen(tbinfo->reltablespace) != 0)
6667+
appendPQExpBuffer(q, " TABLESPACE %s",
6668+
fmtId(tbinfo->reltablespace));
6669+
else if (strlen(dbDefaultTableSpace) != 0)
6670+
appendPQExpBuffer(q, " TABLESPACE %s",
6671+
fmtId(dbDefaultTableSpace));
66626672
}
66636673

66646674
appendPQExpBuffer(q, ";\n");
@@ -6947,13 +6957,16 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
69476957

69486958
appendPQExpBuffer(q, ")");
69496959

6950-
/* Output tablespace clause if necessary */
6951-
if (strlen(indxinfo->tablespace) != 0 &&
6952-
strcmp(indxinfo->tablespace,
6960+
/* Output tablespace clause if different from parent table's */
6961+
if (strcmp(indxinfo->tablespace,
69536962
indxinfo->indextable->reltablespace) != 0)
69546963
{
6955-
appendPQExpBuffer(q, " USING INDEX TABLESPACE %s",
6956-
fmtId(indxinfo->tablespace));
6964+
if (strlen(indxinfo->tablespace) != 0)
6965+
appendPQExpBuffer(q, " USING INDEX TABLESPACE %s",
6966+
fmtId(indxinfo->tablespace));
6967+
else if (strlen(dbDefaultTableSpace) != 0)
6968+
appendPQExpBuffer(q, " USING INDEX TABLESPACE %s",
6969+
fmtId(dbDefaultTableSpace));
69576970
}
69586971

69596972
appendPQExpBuffer(q, ";\n");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy