mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
Move TablespaceCreateDbspace() call into smgrcreate(), which is where it
probably should have been to begin with; this is to cover cases like needing to recreate the per-db directory during WAL replay. Also, fix heap_create to force pg_class.reltablespace to be zero instead of the database's default tablespace; this makes the world safe for CREATE DATABASE to handle all tables in the default tablespace alike, as per previous discussion. And force pg_class.reltablespace to zero when creating a relation without physical storage (eg, a view); this avoids possibly having dangling references in this column after a subsequent DROP TABLESPACE.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.271 2004/06/18 06:13:19 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.272 2004/07/11 19:52:48 tgl Exp $
|
||||
*
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
@@ -43,7 +43,6 @@
|
||||
#include "catalog/pg_statistic.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/tablecmds.h"
|
||||
#include "commands/tablespace.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
@@ -195,10 +194,6 @@ SystemAttributeByName(const char *attname, bool relhasoids)
|
||||
* and is mostly zeroes at return.
|
||||
*
|
||||
* Remove the system relation specific code to elsewhere eventually.
|
||||
*
|
||||
* If storage_create is TRUE then heap_storage_create is called here,
|
||||
* else caller must call heap_storage_create later (or not at all,
|
||||
* if the relation doesn't need physical storage).
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
Relation
|
||||
@@ -207,7 +202,7 @@ heap_create(const char *relname,
|
||||
Oid reltablespace,
|
||||
TupleDesc tupDesc,
|
||||
bool shared_relation,
|
||||
bool storage_create,
|
||||
bool create_storage,
|
||||
bool allow_system_table_mods)
|
||||
{
|
||||
Oid relid;
|
||||
@@ -268,6 +263,25 @@ heap_create(const char *relname,
|
||||
else
|
||||
relid = newoid();
|
||||
|
||||
/*
|
||||
* Never allow a pg_class entry to explicitly specify the database's
|
||||
* default tablespace in reltablespace; force it to zero instead.
|
||||
* This ensures that if the database is cloned with a different
|
||||
* default tablespace, the pg_class entry will still match where
|
||||
* CREATE DATABASE will put the physically copied relation.
|
||||
*
|
||||
* Yes, this is a bit of a hack.
|
||||
*/
|
||||
if (reltablespace == MyDatabaseTableSpace)
|
||||
reltablespace = InvalidOid;
|
||||
|
||||
/*
|
||||
* Also, force reltablespace to zero if the relation has no physical
|
||||
* storage. This is mainly just for cleanliness' sake.
|
||||
*/
|
||||
if (!create_storage)
|
||||
reltablespace = InvalidOid;
|
||||
|
||||
/*
|
||||
* build the relcache entry.
|
||||
*/
|
||||
@@ -280,33 +294,18 @@ heap_create(const char *relname,
|
||||
nailme);
|
||||
|
||||
/*
|
||||
* have the storage manager create the relation's disk file, if
|
||||
* wanted.
|
||||
* have the storage manager create the relation's disk file, if needed.
|
||||
*/
|
||||
if (storage_create)
|
||||
heap_storage_create(rel);
|
||||
if (create_storage)
|
||||
{
|
||||
Assert(rel->rd_smgr == NULL);
|
||||
rel->rd_smgr = smgropen(rel->rd_node);
|
||||
smgrcreate(rel->rd_smgr, rel->rd_istemp, false);
|
||||
}
|
||||
|
||||
return rel;
|
||||
}
|
||||
|
||||
void
|
||||
heap_storage_create(Relation rel)
|
||||
{
|
||||
/*
|
||||
* We may be using the target table space for the first time in this
|
||||
* database, so create a per-database subdirectory if needed.
|
||||
*
|
||||
* XXX it might be better to do this right in smgrcreate...
|
||||
*/
|
||||
TablespaceCreateDbspace(rel->rd_node.spcNode, rel->rd_node.dbNode);
|
||||
/*
|
||||
* Now we can make the file.
|
||||
*/
|
||||
Assert(rel->rd_smgr == NULL);
|
||||
rel->rd_smgr = smgropen(rel->rd_node);
|
||||
smgrcreate(rel->rd_smgr, rel->rd_istemp, false);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* heap_create_with_catalog - Create a cataloged relation
|
||||
*
|
||||
|
Reference in New Issue
Block a user