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

Commitaf704cd

Browse files
author
Thomas G. Lockhart
committed
Implement WAL log location control using "-X" or PGXLOG.
1 parenta19d9d3 commitaf704cd

File tree

6 files changed

+134
-54
lines changed

6 files changed

+134
-54
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.135 2002/08/02 22:36:05 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.136 2002/08/04 06:26:38 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -223,6 +223,7 @@ BootstrapMain(int argc, char *argv[])
223223
intflag;
224224
intxlogop=BS_XLOG_NOP;
225225
char*potential_DataDir=NULL;
226+
char*potential_XLogDir=NULL;
226227

227228
/*
228229
* initialize globals
@@ -250,17 +251,22 @@ BootstrapMain(int argc, char *argv[])
250251
if (!IsUnderPostmaster)
251252
{
252253
InitializeGUCOptions();
253-
potential_DataDir=getenv("PGDATA");/* Null if no PGDATA
254-
* variable */
254+
/* Null if no PGDATA variable */
255+
potential_DataDir=getenv("PGDATA");
256+
/* Null if no PGXLOG variable */
257+
potential_XLogDir=getenv("PGXLOG");
255258
}
256259

257-
while ((flag=getopt(argc,argv,"B:d:D:Fo:px:"))!=-1)
260+
while ((flag=getopt(argc,argv,"B:d:D:X:Fo:px:"))!=-1)
258261
{
259262
switch (flag)
260263
{
261264
case'D':
262265
potential_DataDir=optarg;
263266
break;
267+
case'X':
268+
potential_XLogDir=optarg;
269+
break;
264270
case'd':
265271
{
266272
/* Turn on debugging for the bootstrap process. */
@@ -315,6 +321,7 @@ BootstrapMain(int argc, char *argv[])
315321
proc_exit(1);
316322
}
317323
SetDataDir(potential_DataDir);
324+
SetXLogDir(potential_XLogDir);
318325
}
319326

320327
/* Validate we have been given a reasonable-looking DataDir */

‎src/backend/postmaster/postmaster.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.281 2002/07/13 01:02:14 momjian Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.282 2002/08/04 06:26:38 thomas Exp $
4141
*
4242
* NOTES
4343
*
@@ -347,6 +347,7 @@ PostmasterMain(int argc, char *argv[])
347347
intstatus;
348348
charoriginal_extraoptions[MAXPGPATH];
349349
char*potential_DataDir=NULL;
350+
char*potential_XLogDir=NULL;
350351

351352
*original_extraoptions='\0';
352353

@@ -405,10 +406,11 @@ PostmasterMain(int argc, char *argv[])
405406
InitializeGUCOptions();
406407

407408
potential_DataDir=getenv("PGDATA");/* default value */
409+
potential_XLogDir=getenv("PGXLOG");/* default value */
408410

409411
opterr=1;
410412

411-
while ((opt=getopt(argc,argv,"A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:"))!=-1)
413+
while ((opt=getopt(argc,argv,"A:a:B:b:c:D:X:d:Fh:ik:lm:MN:no:p:Ss-:"))!=-1)
412414
{
413415
switch (opt)
414416
{
@@ -431,6 +433,9 @@ PostmasterMain(int argc, char *argv[])
431433
case'D':
432434
potential_DataDir=optarg;
433435
break;
436+
case'X':
437+
potential_XLogDir=optarg;
438+
break;
434439
case'd':
435440
{
436441
/* Turn on debugging for the postmaster. */
@@ -565,6 +570,7 @@ PostmasterMain(int argc, char *argv[])
565570

566571
checkDataDir(potential_DataDir);/* issues error messages */
567572
SetDataDir(potential_DataDir);
573+
SetXLogDir(potential_XLogDir);
568574

569575
ProcessConfigFile(PGC_POSTMASTER);
570576

‎src/backend/tcop/postgres.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.277 2002/08/0404:31:44 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.278 2002/08/0406:26:33 thomas Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1146,6 +1146,7 @@ PostgresMain(int argc, char *argv[], const char *username)
11461146
StringInfoparser_input;
11471147

11481148
char*potential_DataDir=NULL;
1149+
char*potential_XLogDir=NULL;
11491150

11501151
/*
11511152
* Catch standard options before doing much else. This even works on
@@ -1190,6 +1191,7 @@ PostgresMain(int argc, char *argv[], const char *username)
11901191
{
11911192
InitializeGUCOptions();
11921193
potential_DataDir=getenv("PGDATA");
1194+
potential_XLogDir=getenv("PGXLOG");
11931195
}
11941196

11951197
/* ----------------
@@ -1214,7 +1216,7 @@ PostgresMain(int argc, char *argv[], const char *username)
12141216
ctx=PGC_POSTMASTER;
12151217
gucsource=PGC_S_ARGV;/* initial switches came from command line */
12161218

1217-
while ((flag=getopt(argc,argv,"A:B:c:CD:d:Eef:FiNOPo:p:S:st:v:W:x:-:"))!=-1)
1219+
while ((flag=getopt(argc,argv,"A:B:c:CD:X:d:Eef:FiNOPo:p:S:st:v:W:x:-:"))!=-1)
12181220
switch (flag)
12191221
{
12201222
case'A':
@@ -1246,6 +1248,11 @@ PostgresMain(int argc, char *argv[], const char *username)
12461248
potential_DataDir=optarg;
12471249
break;
12481250

1251+
case'X':/* PGXLOG directory */
1252+
if (secure)
1253+
potential_XLogDir=optarg;
1254+
break;
1255+
12491256
case'd':/* debug level */
12501257
{
12511258
/* Set server debugging level. */
@@ -1537,8 +1544,10 @@ PostgresMain(int argc, char *argv[], const char *username)
15371544
proc_exit(1);
15381545
}
15391546
SetDataDir(potential_DataDir);
1547+
SetXLogDir(potential_XLogDir);
15401548
}
15411549
Assert(DataDir);
1550+
Assert(strlen(XLogDir)>0);
15421551

15431552
/*
15441553
* Set up signal handlers and masks.
@@ -1693,7 +1702,7 @@ PostgresMain(int argc, char *argv[], const char *username)
16931702
if (!IsUnderPostmaster)
16941703
{
16951704
puts("\nPOSTGRES backend interactive interface ");
1696-
puts("$Revision: 1.277 $ $Date: 2002/08/0404:31:44 $\n");
1705+
puts("$Revision: 1.278 $ $Date: 2002/08/0406:26:33 $\n");
16971706
}
16981707

16991708
/*

‎src/bin/initdb/initdb.sh

Lines changed: 86 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
2828
# Portions Copyright (c) 1994, Regents of the University of California
2929
#
30-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.163 2002/07/29 22:14:11 tgl Exp $
30+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.164 2002/08/04 06:26:38 thomas Exp $
3131
#
3232
#-------------------------------------------------------------------------
3333

@@ -252,6 +252,19 @@ do
252252
-D*)
253253
PGDATA=`echo$1| sed's/^-D//'`
254254
;;
255+
# Directory to hold WAL log files.
256+
--pgxlog|-X)
257+
PGXLOG="$2"
258+
defined_pgxlog=yes
259+
shift;;
260+
--pgxlog=*)
261+
PGXLOG=`echo$1| sed's/^--pgxlog=//'`
262+
defined_pgxlog=yes
263+
;;
264+
-X*)
265+
PGXLOG=`echo$1| sed's/^-X//'`
266+
defined_pgxlog=yes
267+
;;
255268
# The directory where the .bki input files are stored. Normally
256269
# they are in PREFIX/share and this option should be unnecessary.
257270
-L)
@@ -341,6 +354,7 @@ if [ "$usage" ]; then
341354
echo
342355
echo"Options:"
343356
echo" [-D, --pgdata] DATADIR Location for this database cluster"
357+
echo" [-X, --pgxlog] XLOGDIR Location for the cluster transaction logs"
344358
echo" -W, --pwprompt Prompt for a password for the new superuser"
345359
if [-n"$MULTIBYTE" ];then
346360
echo" -E, --encoding ENCODING Set default encoding for new databases"
@@ -369,7 +383,7 @@ fi
369383
if ["$MULTIBYTE" ]
370384
then
371385
MULTIBYTEID=`$PGPATH/pg_encoding -b$MULTIBYTE`
372-
if ["$?"-ne 0 ]
386+
if ["$?"-ne 0 ]
373387
then
374388
(
375389
echo"$CMDNAME: pg_encoding failed"
@@ -401,6 +415,11 @@ then
401415
exit 1
402416
fi
403417

418+
if [-z"$PGXLOG" ]
419+
then
420+
PGXLOG="$PGDATA"/pg_xlog
421+
fi
422+
404423

405424
#-------------------------------------------------------------------------
406425
# Find the input files
@@ -418,7 +437,7 @@ then
418437
(
419438
echo
420439
echo"initdb variables:"
421-
forvarin PGDATA datadir PGPATH MULTIBYTE MULTIBYTEID \
440+
forvarin PGDATAPGXLOGdatadir PGPATH MULTIBYTE MULTIBYTEID \
422441
POSTGRES_SUPERUSERNAME POSTGRES_BKI \
423442
POSTGRES_DESCR POSTGRESQL_CONF_SAMPLE \
424443
PG_HBA_SAMPLE PG_IDENT_SAMPLE;do
@@ -503,44 +522,61 @@ then
503522
echo"$CMDNAME: The directory$PGDATA exists but is not empty."
504523
echo"If you want to create a new database system, either remove or empty"
505524
echo"the directory$PGDATA or run initdb with"
506-
echo"an argument other than$PGDATA."
525+
echo"an argument for -D other than$PGDATA."
526+
)1>&2
527+
exit 1
528+
fi
529+
530+
# find out if transaction log directory is empty
531+
pgxlog_contents=`ls -A"$PGXLOG"2>/dev/null`
532+
if [ x"$pgxlog_contents"!= x ]
533+
then
534+
(
535+
echo"$CMDNAME: The directory$PGXLOG exists but is not empty."
536+
echo"If you want to create a new transaction log, either remove or empty"
537+
echo"the directory$PGXLOG or run initdb with"
538+
echo"an argument for -X other than$PGXLOG."
507539
)1>&2
508540
exit 1
541+
fi
542+
543+
if [!-d"$PGDATA" ];then
544+
$ECHO_N"creating directory$PGDATA..."$ECHO_C
545+
mkdir -p"$PGDATA">/dev/null2>&1|| mkdir"$PGDATA"|| exit_nicely
546+
made_new_pgdata=yes
509547
else
510-
if [!-d"$PGDATA" ];then
511-
$ECHO_N"creating directory$PGDATA..."$ECHO_C
512-
mkdir -p"$PGDATA">/dev/null2>&1|| mkdir"$PGDATA"|| exit_nicely
513-
made_new_pgdata=yes
514-
else
515-
$ECHO_N"Fixing permissions on existing directory$PGDATA..."$ECHO_C
516-
chmod go-rwx"$PGDATA"|| exit_nicely
517-
fi
518-
echo"ok"
548+
$ECHO_N"Fixing permissions on existing directory$PGDATA..."$ECHO_C
549+
chmod go-rwx"$PGDATA"|| exit_nicely
550+
fi
551+
echo"ok"
519552

520-
if [!-d"$PGDATA"/base ]
521-
then
522-
$ECHO_N"creating directory$PGDATA/base..."$ECHO_C
523-
mkdir"$PGDATA"/base|| exit_nicely
524-
echo"ok"
525-
fi
526-
if [!-d"$PGDATA"/global ]
527-
then
528-
$ECHO_N"creating directory$PGDATA/global..."$ECHO_C
529-
mkdir"$PGDATA"/global|| exit_nicely
530-
echo"ok"
531-
fi
532-
if [!-d"$PGDATA"/pg_xlog ]
533-
then
534-
$ECHO_N"creating directory$PGDATA/pg_xlog..."$ECHO_C
535-
mkdir"$PGDATA"/pg_xlog|| exit_nicely
536-
echo"ok"
537-
fi
538-
if [!-d"$PGDATA"/pg_clog ]
539-
then
540-
$ECHO_N"creating directory$PGDATA/pg_clog..."$ECHO_C
541-
mkdir"$PGDATA"/pg_clog|| exit_nicely
542-
echo"ok"
543-
fi
553+
if [!-d"$PGXLOG" ];then
554+
$ECHO_N"creating directory$PGXLOG..."$ECHO_C
555+
mkdir -p"$PGXLOG">/dev/null2>&1|| mkdir"$PGXLOG"|| exit_nicely
556+
made_new_pgxlog=yes
557+
else
558+
$ECHO_N"Fixing permissions on existing directory$PGXLOG..."$ECHO_C
559+
chmod go-rwx"$PGXLOG"|| exit_nicely
560+
fi
561+
echo"ok"
562+
563+
if [!-d"$PGDATA"/base ]
564+
then
565+
$ECHO_N"creating directory$PGDATA/base..."$ECHO_C
566+
mkdir"$PGDATA"/base|| exit_nicely
567+
echo"ok"
568+
fi
569+
if [!-d"$PGDATA"/global ]
570+
then
571+
$ECHO_N"creating directory$PGDATA/global..."$ECHO_C
572+
mkdir"$PGDATA"/global|| exit_nicely
573+
echo"ok"
574+
fi
575+
if [!-d"$PGDATA"/pg_clog ]
576+
then
577+
$ECHO_N"creating directory$PGDATA/pg_clog..."$ECHO_C
578+
mkdir"$PGDATA"/pg_clog|| exit_nicely
579+
echo"ok"
544580
fi
545581

546582

@@ -549,7 +585,7 @@ fi
549585
# RUN BKI SCRIPT IN BOOTSTRAP MODE TO CREATE TEMPLATE1
550586

551587
# common backend options
552-
PGSQL_OPT="-F -D$PGDATA"
588+
PGSQL_OPT="-F -D$PGDATA -X$PGXLOG"
553589

554590
if ["$debug"= yes ]
555591
then
@@ -677,7 +713,6 @@ EOF
677713
echo"ok"
678714
fi
679715

680-
681716
$ECHO_N"enabling unlimited row size for system tables..."$ECHO_C
682717

683718
"$PGPATH"/postgres$PGSQL_OPT template1>/dev/null<<EOF
@@ -1058,14 +1093,24 @@ echo "ok"
10581093
#
10591094
# FINISHED
10601095

1096+
postmaster_startup="$PGPATH/postmaster -D$PGDATA"
1097+
if [ x"$defined_pgxlog"!= x ];then
1098+
postmaster_startup="$postmaster_startup -X$PGXLOG"
1099+
fi
1100+
pg_ctl_startup="$PGPATH/pg_ctl -D$PGDATA"
1101+
if [ x"$defined_pgxlog"!= x ];then
1102+
pg_ctl_startup="$pg_ctl_startup -X$PGXLOG"
1103+
fi
1104+
pg_ctl_startup="$pg_ctl_startup -l logfile start"
1105+
10611106
echo
10621107
echo"Success. You can now start the database server using:"
10631108
echo""
1064-
echo"$PGPATH/postmaster -D$PGDATA"
1109+
echo"$postmaster_startup"
10651110
echo"or"
10661111
# (Advertise -l option here, otherwise we have a background
10671112
# process writing to the terminal.)
1068-
echo"$PGPATH/pg_ctl -D$PGDATA -l logfile start"
1113+
echo"$pg_ctl_startup"
10691114
echo
10701115

10711116
exit 0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp