1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* catalog.c
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2001-11-17 00:30:35 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.44 2001/11/16 23:30:35 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-01-10 21:19:49 +01:00
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "postgres.h"
|
1996-11-04 00:27:08 +01:00
|
|
|
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "access/transam.h"
|
|
|
|
#include "catalog/catalog.h"
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "catalog/catname.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "catalog/pg_type.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "miscadmin.h"
|
2000-11-16 23:30:52 +01:00
|
|
|
#include "utils/lsyscache.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-10-16 16:52:28 +02:00
|
|
|
/*
|
|
|
|
* relpath - construct path to a relation's file
|
|
|
|
*
|
|
|
|
* Result is a palloc'd string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
relpath(RelFileNode rnode)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
if (rnode.tblNode == (Oid) 0) /* "global tablespace" */
|
2000-10-16 16:52:28 +02:00
|
|
|
{
|
|
|
|
/* Shared system relations live in {datadir}/global */
|
|
|
|
path = (char *) palloc(strlen(DataDir) + 8 + sizeof(NameData) + 1);
|
2001-05-30 16:15:27 +02:00
|
|
|
sprintf(path, "%s/global/%u", DataDir, rnode.relNode);
|
2000-10-16 16:52:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = (char *) palloc(strlen(DataDir) + 6 + 2 * sizeof(NameData) + 3);
|
2001-05-30 16:15:27 +02:00
|
|
|
sprintf(path, "%s/base/%u/%u", DataDir, rnode.tblNode, rnode.relNode);
|
2000-10-16 16:52:28 +02:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GetDatabasePath - construct path to a database dir
|
|
|
|
*
|
|
|
|
* Result is a palloc'd string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
GetDatabasePath(Oid tblNode)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
if (tblNode == (Oid) 0) /* "global tablespace" */
|
2000-10-16 16:52:28 +02:00
|
|
|
{
|
|
|
|
/* Shared system relations live in {datadir}/global */
|
|
|
|
path = (char *) palloc(strlen(DataDir) + 8);
|
2001-05-30 16:15:27 +02:00
|
|
|
sprintf(path, "%s/global", DataDir);
|
2000-10-16 16:52:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = (char *) palloc(strlen(DataDir) + 6 + sizeof(NameData) + 1);
|
2001-05-30 16:15:27 +02:00
|
|
|
sprintf(path, "%s/base/%u", DataDir, tblNode);
|
2000-10-16 16:52:28 +02:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2000-04-09 06:43:20 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* IsSystemRelationName
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff name is the name of a system catalog relation.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-11-17 00:30:35 +01:00
|
|
|
* NB: TOAST relations are considered system relations by this test.
|
|
|
|
* This is appropriate in many places but not all. Where it's not,
|
|
|
|
* also check IsToastRelationName.
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* We now make a new requirement where system catalog relns must begin
|
|
|
|
* with pg_ while user relns are forbidden to do so. Make the test
|
|
|
|
* trivial and instantaneous.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* XXX this is way bogus. -- pma
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
bool
|
2000-01-16 21:05:00 +01:00
|
|
|
IsSystemRelationName(const char *relname)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2001-11-17 00:30:35 +01:00
|
|
|
/* ugly coding for speed */
|
|
|
|
return (relname[0] == 'p' &&
|
|
|
|
relname[1] == 'g' &&
|
|
|
|
relname[2] == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IsToastRelationName
|
|
|
|
* True iff name is the name of a TOAST support relation (or index).
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
IsToastRelationName(const char *relname)
|
|
|
|
{
|
|
|
|
return strncmp(relname, "pg_toast_", 9) == 0;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* IsSharedSystemRelationName
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff name is the name of a shared system catalog relation.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
bool
|
2000-01-16 21:05:00 +01:00
|
|
|
IsSharedSystemRelationName(const char *relname)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int i;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Quick out: if it's not a system relation, it can't be a shared
|
|
|
|
* system relation.
|
|
|
|
*/
|
|
|
|
if (!IsSystemRelationName(relname))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (SharedSystemRelationNames[i] != NULL)
|
|
|
|
{
|
|
|
|
if (strcmp(SharedSystemRelationNames[i], relname) == 0)
|
|
|
|
return TRUE;
|
|
|
|
i++;
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* newoid - returns a unique identifier across all catalogs.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Object Id allocation is now done by GetNewObjectID in
|
2001-08-10 20:57:42 +02:00
|
|
|
* access/transam/varsup.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-08-10 20:57:42 +02:00
|
|
|
* This code probably needs to change to generate OIDs separately
|
|
|
|
* for each table.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
Oid
|
2000-12-28 00:59:14 +01:00
|
|
|
newoid(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2001-08-10 20:57:42 +02:00
|
|
|
return GetNewObjectId();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|