Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
7d1f2f8a
Commit
7d1f2f8a
authored
Nov 07, 1997
by
Thomas G. Lockhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support alternate database locations.
parent
d98f2f99
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
260 additions
and
241 deletions
+260
-241
src/backend/parser/dbcommands.c
src/backend/parser/dbcommands.c
+99
-23
src/backend/storage/file/fd.c
src/backend/storage/file/fd.c
+16
-12
src/backend/storage/smgr/md.c
src/backend/storage/smgr/md.c
+10
-1
src/backend/tcop/utility.c
src/backend/tcop/utility.c
+2
-2
src/backend/utils/init/postinit.c
src/backend/utils/init/postinit.c
+123
-199
src/include/miscadmin.h
src/include/miscadmin.h
+6
-1
src/include/nodes/parsenodes.h
src/include/nodes/parsenodes.h
+2
-1
src/include/parser/dbcommands.h
src/include/parser/dbcommands.h
+2
-2
No files found.
src/backend/parser/dbcommands.c
View file @
7d1f2f8a
...
...
@@ -7,13 +7,14 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/dbcommands.c,v 1.
9 1997/09/08 21:46:07 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/dbcommands.c,v 1.
10 1997/11/07 06:37:55 thomas
Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/stat.h>
#include "postgres.h"
#include "miscadmin.h"
/* for DataDir */
...
...
@@ -36,41 +37,58 @@
/* non-export function prototypes */
static
void
check_permissions
(
char
*
command
,
char
*
dbname
,
check_permissions
(
char
*
command
,
char
*
db
path
,
char
*
db
name
,
Oid
*
dbIdP
,
Oid
*
userIdP
);
static
HeapTuple
get_pg_dbtup
(
char
*
command
,
char
*
dbname
,
Relation
dbrel
);
static
void
stop_vacuum
(
char
*
dbname
);
static
void
stop_vacuum
(
char
*
db
path
,
char
*
db
name
);
void
createdb
(
char
*
dbname
)
createdb
(
char
*
dbname
,
char
*
dbpath
)
{
Oid
db_id
,
user_id
;
char
buf
[
512
];
char
*
lp
,
loc
[
512
];
/*
* If this call returns, the database does not exist and we're allowed
* to create databases.
*/
check_permissions
(
"createdb"
,
dbname
,
&
db_id
,
&
user_id
);
check_permissions
(
"createdb"
,
db
path
,
db
name
,
&
db_id
,
&
user_id
);
/* close virtual file descriptors so we can do system() calls */
closeAllVfds
();
sprintf
(
buf
,
"mkdir %s%cbase%c%s"
,
DataDir
,
SEP_CHAR
,
SEP_CHAR
,
dbname
);
system
(
buf
);
sprintf
(
buf
,
"%s %s%cbase%ctemplate1%c* %s%cbase%c%s"
,
COPY_CMD
,
DataDir
,
SEP_CHAR
,
SEP_CHAR
,
SEP_CHAR
,
DataDir
,
SEP_CHAR
,
SEP_CHAR
,
dbname
);
/* Now create directory for this new database */
if
((
dbpath
!=
NULL
)
&&
(
strcmp
(
dbpath
,
dbname
)
!=
0
))
{
if
(
*
(
dbpath
+
strlen
(
dbpath
)
-
1
)
==
SEP_CHAR
)
*
(
dbpath
+
strlen
(
dbpath
)
-
1
)
=
'\0'
;
sprintf
(
loc
,
"%s%c%s"
,
dbpath
,
SEP_CHAR
,
dbname
);
}
else
{
strcpy
(
loc
,
dbname
);
}
lp
=
ExpandDatabasePath
(
loc
);
if
(
mkdir
(
lp
,
S_IRWXU
)
!=
0
)
elog
(
WARN
,
"Unable to create database directory %s"
,
lp
);
sprintf
(
buf
,
"%s %s%cbase%ctemplate1%c* %s"
,
COPY_CMD
,
DataDir
,
SEP_CHAR
,
SEP_CHAR
,
SEP_CHAR
,
lp
);
system
(
buf
);
/* sprintf(buf, "insert into pg_database (datname, datdba, datpath) \
values (\'%s\'::char16, \'%d\'::oid, \'%s\'::text);",
dbname, user_id, dbname);
*/
#if FALSE
sprintf
(
buf
,
"insert into pg_database (datname, datdba, datpath) \
values (
\'
%s
\'
,
\'
%d
\'
,
\'
%s
\'
);"
,
values (
\'
%s
\'
::char16,
\'
%d
\'
::oid,
\'
%s
\'
::text
);"
,
dbname
,
user_id
,
dbname
);
#endif
sprintf
(
buf
,
"insert into pg_database (datname, datdba, datpath)"
" values (
\'
%s
\'
,
\'
%d
\'
,
\'
%s
\'
);"
,
dbname
,
user_id
,
loc
);
pg_eval
(
buf
,
(
char
**
)
NULL
,
(
Oid
*
)
NULL
,
0
);
}
...
...
@@ -80,13 +98,20 @@ destroydb(char *dbname)
{
Oid
user_id
,
db_id
;
char
*
path
;
char
dbpath
[
MAXPGPATH
+
1
];
char
buf
[
512
];
char
loc
[
512
];
text
*
dbtext
;
Relation
dbrel
;
HeapTuple
dbtup
;
/*
* If this call returns, the database exists and we're allowed to
* remove it.
*/
check_permissions
(
"destroydb"
,
dbname
,
&
db_id
,
&
user_id
);
check_permissions
(
"destroydb"
,
db
path
,
db
name
,
&
db_id
,
&
user_id
);
if
(
!
OidIsValid
(
db_id
))
{
...
...
@@ -94,7 +119,36 @@ destroydb(char *dbname)
}
/* stop the vacuum daemon */
stop_vacuum
(
dbname
);
stop_vacuum
(
dbpath
,
dbname
);
#if FALSE
dbrel
=
heap_openr
(
DatabaseRelationName
);
if
(
!
RelationIsValid
(
dbrel
))
elog
(
FATAL
,
"%s: cannot open relation
\"
%-.*s
\"
"
,
"destroydb"
,
DatabaseRelationName
);
dbtup
=
get_pg_dbtup
(
"destroydb"
,
dbname
,
dbrel
);
if
(
!
HeapTupleIsValid
(
dbtup
))
elog
(
NOTICE
,
"destroydb: pg_database entry not found %s"
,
dbname
);
dbtext
=
(
text
*
)
heap_getattr
(
dbtup
,
InvalidBuffer
,
Anum_pg_database_datpath
,
RelationGetTupleDescriptor
(
dbrel
),
(
char
*
)
NULL
);
memcpy
(
loc
,
VARDATA
(
dbtext
),
(
VARSIZE
(
dbtext
)
-
VARHDRSZ
));
*
(
loc
+
(
VARSIZE
(
dbtext
)
-
VARHDRSZ
))
=
'\0'
;
#if FALSE
if
(
*
loc
!=
SEP_CHAR
)
{
sprintf
(
buf
,
"%s/base/%s"
,
DataDir
,
loc
);
strcpy
(
loc
,
buf
);
}
#endif
heap_close
(
dbrel
);
#endif
/*
* remove the pg_database tuple FIRST, this may fail due to
...
...
@@ -108,7 +162,9 @@ destroydb(char *dbname)
* remove the data directory. If the DELETE above failed, this will
* not be reached
*/
sprintf
(
buf
,
"rm -r %s/base/%s"
,
DataDir
,
dbname
);
path
=
ExpandDatabasePath
(
dbpath
);
sprintf
(
buf
,
"rm -r %s"
,
path
);
system
(
buf
);
/* drop pages for this database that are in the shared buffer cache */
...
...
@@ -160,6 +216,7 @@ get_pg_dbtup(char *command, char *dbname, Relation dbrel)
static
void
check_permissions
(
char
*
command
,
char
*
dbpath
,
char
*
dbname
,
Oid
*
dbIdP
,
Oid
*
userIdP
)
...
...
@@ -172,6 +229,8 @@ check_permissions(char *command,
bool
dbfound
;
bool
use_super
;
char
*
userName
;
text
*
dbtext
;
char
path
[
MAXPGPATH
+
1
];
userName
=
GetPgUserName
();
utup
=
SearchSysCacheTuple
(
USENAME
,
PointerGetDatum
(
userName
),
...
...
@@ -228,6 +287,13 @@ check_permissions(char *command,
RelationGetTupleDescriptor
(
dbrel
),
(
char
*
)
NULL
);
*
dbIdP
=
dbtup
->
t_oid
;
dbtext
=
(
text
*
)
heap_getattr
(
dbtup
,
InvalidBuffer
,
Anum_pg_database_datpath
,
RelationGetTupleDescriptor
(
dbrel
),
(
char
*
)
NULL
);
strncpy
(
path
,
VARDATA
(
dbtext
),
(
VARSIZE
(
dbtext
)
-
VARHDRSZ
));
*
(
path
+
VARSIZE
(
dbtext
)
-
VARHDRSZ
)
=
'\0'
;
}
else
{
...
...
@@ -259,21 +325,31 @@ check_permissions(char *command,
elog
(
WARN
,
"%s: database %s is not owned by you."
,
command
,
dbname
);
}
}
if
(
dbfound
&&
!
strcmp
(
command
,
"destroydb"
))
strcpy
(
dbpath
,
path
);
}
/* check_permissions() */
/*
* stop_vacuum() -- stop the vacuum daemon on the database, if one is
* running.
* stop_vacuum() -- stop the vacuum daemon on the database, if one is running.
*/
static
void
stop_vacuum
(
char
*
dbname
)
stop_vacuum
(
char
*
db
path
,
char
*
db
name
)
{
char
filename
[
256
];
FILE
*
fp
;
int
pid
;
sprintf
(
filename
,
"%s%cbase%c%s%c%s.vacuum"
,
DataDir
,
SEP_CHAR
,
SEP_CHAR
,
if
(
strchr
(
dbpath
,
SEP_CHAR
)
!=
0
)
{
sprintf
(
filename
,
"%s%cbase%c%s%c%s.vacuum"
,
DataDir
,
SEP_CHAR
,
SEP_CHAR
,
dbname
,
SEP_CHAR
,
dbname
);
}
else
{
sprintf
(
filename
,
"%s%c%s.vacuum"
,
dbpath
,
SEP_CHAR
,
dbname
);
}
if
((
fp
=
AllocateFile
(
filename
,
"r"
))
!=
NULL
)
{
fscanf
(
fp
,
"%d"
,
&
pid
);
...
...
src/backend/storage/file/fd.c
View file @
7d1f2f8a
...
...
@@ -6,7 +6,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Id: fd.c,v 1.2
6 1997/09/18 20:21:24 momjian
Exp $
* $Id: fd.c,v 1.2
7 1997/11/07 06:38:15 thomas
Exp $
*
* NOTES:
*
...
...
@@ -125,8 +125,6 @@ static Size SizeVfdCache = 0;
*/
static
int
nfile
=
0
;
static
char
Sep_char
=
'/'
;
/*
* Private Routines
*
...
...
@@ -458,23 +456,25 @@ FreeVfd(File file)
VfdCache
[
0
].
nextFree
=
file
;
}
/* filepath()
* Open specified file name.
* Fill in absolute path fields if necessary.
*
* Modify to use GetDatabasePath() rather than hardcoded paths.
* - thomas 1997-11-02
*/
static
char
*
filepath
(
char
*
filename
)
{
char
*
buf
;
char
basename
[
16
];
int
len
;
if
(
*
filename
!=
Sep_char
)
/* Not an absolute path name? Then fill in with database path... */
if
(
*
filename
!=
SEP_CHAR
)
{
/* Either /base/ or \base\ */
sprintf
(
basename
,
"%cbase%c"
,
Sep_char
,
Sep_char
);
len
=
strlen
(
DataDir
)
+
strlen
(
basename
)
+
strlen
(
GetDatabaseName
())
+
strlen
(
filename
)
+
2
;
len
=
strlen
(
GetDatabasePath
())
+
strlen
(
filename
)
+
2
;
buf
=
(
char
*
)
palloc
(
len
);
sprintf
(
buf
,
"%s%s%s%c%s"
,
DataDir
,
basename
,
GetDatabaseName
(),
Sep_char
,
filename
);
sprintf
(
buf
,
"%s%c%s"
,
GetDatabasePath
(),
SEP_CHAR
,
filename
);
}
else
{
...
...
@@ -482,6 +482,10 @@ filepath(char *filename)
strcpy
(
buf
,
filename
);
}
#ifdef FILEDEBUG
printf
(
"filepath: path is %s
\n
"
,
buf
);
#endif
return
(
buf
);
}
...
...
src/backend/storage/smgr/md.c
View file @
7d1f2f8a
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.2
3 1997/10/25 01:10:04 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.2
4 1997/11/07 06:38:19 thomas
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -480,6 +480,7 @@ mdblindwrt(char *dbstr,
nchars
=
0
;
/* construct the path to the file and open it */
/* system table? then put in system area... */
if
(
dbid
==
(
Oid
)
0
)
{
path
=
(
char
*
)
palloc
(
strlen
(
DataDir
)
+
sizeof
(
NameData
)
+
2
+
nchars
);
...
...
@@ -488,8 +489,10 @@ mdblindwrt(char *dbstr,
else
sprintf
(
path
,
"%s/%s.%d"
,
DataDir
,
relstr
,
segno
);
}
/* user table? then put in user database area... */
else
{
#if FALSE
path
=
(
char
*
)
palloc
(
strlen
(
DataDir
)
+
strlen
(
"/base/"
)
+
2
*
sizeof
(
NameData
)
+
2
+
nchars
);
if
(
segno
==
0
)
sprintf
(
path
,
"%s/base/%s/%s"
,
DataDir
,
...
...
@@ -497,6 +500,12 @@ mdblindwrt(char *dbstr,
else
sprintf
(
path
,
"%s/base/%s/%s.%d"
,
DataDir
,
dbstr
,
relstr
,
segno
);
#endif
path
=
(
char
*
)
palloc
(
strlen
(
GetDatabasePath
())
+
2
*
sizeof
(
NameData
)
+
2
+
nchars
);
if
(
segno
==
0
)
sprintf
(
path
,
"%s%c%s"
,
GetDatabasePath
(),
SEP_CHAR
,
relstr
);
else
sprintf
(
path
,
"%s%c%s.%d"
,
GetDatabasePath
(),
SEP_CHAR
,
relstr
,
segno
);
}
if
((
fd
=
open
(
path
,
O_RDWR
,
0600
))
<
0
)
...
...
src/backend/tcop/utility.c
View file @
7d1f2f8a
...
...
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.2
7 1997/10/28 14:57:24 vadim
Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.2
8 1997/11/07 06:38:51 thomas
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -569,7 +569,7 @@ ProcessUtility(Node * parsetree,
commandTag
=
"CREATEDB"
;
CHECK_IF_ABORTED
();
createdb
(
stmt
->
dbname
);
createdb
(
stmt
->
dbname
,
stmt
->
dbpath
);
}
break
;
...
...
src/backend/utils/init/postinit.c
View file @
7d1f2f8a
This diff is collapsed.
Click to expand it.
src/include/miscadmin.h
View file @
7d1f2f8a
...
...
@@ -11,7 +11,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: miscadmin.h,v 1.1
6 1997/09/18 14:42:22 vadim
Exp $
* $Id: miscadmin.h,v 1.1
7 1997/11/07 06:38:29 thomas
Exp $
*
* NOTES
* some of the information in this file will be moved to
...
...
@@ -107,6 +107,11 @@ extern Oid LastOidProcessed; /* for query rewrite */
* POSTGRES directory path definitions. *
*****************************************************************************/
/* in utils/misc/database.c */
extern
void
GetRawDatabaseInfo
(
char
*
name
,
Oid
*
owner
,
Oid
*
db_id
,
char
*
path
);
extern
int
GetDatabaseInfo
(
char
*
name
,
Oid
*
owner
,
char
*
path
);
extern
char
*
ExpandDatabasePath
(
char
*
path
);
/* now in utils/init/miscinit.c */
extern
char
*
GetDatabasePath
(
void
);
extern
char
*
GetDatabaseName
(
void
);
...
...
src/include/nodes/parsenodes.h
View file @
7d1f2f8a
...
...
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: parsenodes.h,v 1.
29 1997/10/28 15:10:39 vadim
Exp $
* $Id: parsenodes.h,v 1.
30 1997/11/07 06:38:38 thomas
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -473,6 +473,7 @@ typedef struct CreatedbStmt
{
NodeTag
type
;
char
*
dbname
;
/* database to create */
char
*
dbpath
;
/* location of database */
}
CreatedbStmt
;
/* ----------------------
...
...
src/include/parser/dbcommands.h
View file @
7d1f2f8a
...
...
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: dbcommands.h,v 1.
4 1997/09/08 02:38:05 momjian
Exp $
* $Id: dbcommands.h,v 1.
5 1997/11/07 06:38:09 thomas
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -20,7 +20,7 @@
#define SIGKILLDAEMON1 SIGINT
#define SIGKILLDAEMON2 SIGTERM
extern
void
createdb
(
char
*
dbname
);
extern
void
createdb
(
char
*
dbname
,
char
*
dbpath
);
extern
void
destroydb
(
char
*
dbname
);
#endif
/* DBCOMMANDS_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment