Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc19aaa

Browse files
committed
Give a more user-friendly error message in case where a table is created
in a schema whose default tablespace has been dropped.
1 parent2a63c16 commitdc19aaa

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.134 2004/10/12 21:54:36petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.135 2004/10/16 21:16:36tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -168,6 +168,7 @@ static void StoreCatalogInheritance(Oid relationId, List *supers);
168168
staticintfindAttrByName(constchar*attributeName,List*schema);
169169
staticvoidsetRelhassubclassInRelation(OidrelationId,boolrelhassubclass);
170170
staticboolneeds_toast_table(Relationrel);
171+
staticvoidcheck_tablespace_exists(OidtablespaceId,OidnamespaceId);
171172
staticinttransformColumnNameList(OidrelId,List*colList,
172173
int16*attnums,Oid*atttypids);
173174
staticinttransformFkeyGetPrimaryKey(Relationpkrel,Oid*indexOid,
@@ -337,6 +338,9 @@ DefineRelation(CreateStmt *stmt, char relkind)
337338
{
338339
tablespaceId=get_namespace_tablespace(namespaceId);
339340
/* note no permission check on tablespace in this case */
341+
/* check to see that schema's tablespace still exists */
342+
if (OidIsValid(tablespaceId))
343+
check_tablespace_exists(tablespaceId,namespaceId);
340344
}
341345

342346
/*
@@ -5865,6 +5869,42 @@ needs_toast_table(Relation rel)
58655869
return (tuple_length>TOAST_TUPLE_THRESHOLD);
58665870
}
58675871

5872+
/*
5873+
* Verify that a schema's tablespace still exists
5874+
*
5875+
* We need this because DROP TABLESPACE cannot check whether the target
5876+
* tablespace is the default tablespace for any schemas. (It could check
5877+
* in the current database, but that doesn't seem very helpful.) Subsequent
5878+
* attempts to create tables in that tablespace will fail. This code just
5879+
* exists to ensure that we give a helpful error message.
5880+
*/
5881+
staticvoid
5882+
check_tablespace_exists(OidtablespaceId,OidnamespaceId)
5883+
{
5884+
Relationpg_tablespace;
5885+
ScanKeyDataentry[1];
5886+
HeapScanDescscan;
5887+
HeapTupletuple;
5888+
5889+
/* There's no syscache for pg_tablespace, so must look the hard way */
5890+
pg_tablespace=heap_openr(TableSpaceRelationName,AccessShareLock);
5891+
ScanKeyInit(&entry[0],
5892+
ObjectIdAttributeNumber,
5893+
BTEqualStrategyNumber,F_OIDEQ,
5894+
ObjectIdGetDatum(tablespaceId));
5895+
scan=heap_beginscan(pg_tablespace,SnapshotNow,1,entry);
5896+
tuple=heap_getnext(scan,ForwardScanDirection);
5897+
if (!HeapTupleIsValid(tuple))
5898+
ereport(ERROR,
5899+
(errcode(ERRCODE_UNDEFINED_OBJECT),
5900+
errmsg("tablespace with OID %u does not exist",
5901+
tablespaceId),
5902+
errdetail("The default tablespace for schema \"%s\" has been dropped.",
5903+
get_namespace_name(namespaceId))));
5904+
heap_endscan(scan);
5905+
heap_close(pg_tablespace,AccessShareLock);
5906+
}
5907+
58685908

58695909
/*
58705910
* This code supports

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp