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

Commitbc5334d

Browse files
Allow external recovery_config_directory
If required, recovery.conf can now be located outside of the data directory.Server needs read/write permissions on this directory.
1 parentf7f210b commitbc5334d

File tree

7 files changed

+75
-7
lines changed

7 files changed

+75
-7
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,23 @@ include 'filename'
330330
</listitem>
331331
</varlistentry>
332332

333+
<variablelist>
334+
<varlistentry id="guc-recovery-config-directory" xreflabel="recovery_config_directory">
335+
<term><varname>recovery_config_directory</varname> (<type>string</type>)</term>
336+
<indexterm>
337+
<primary><varname>recovery_config_directory</> configuration parameter</primary>
338+
</indexterm>
339+
<listitem>
340+
<para>
341+
Specifies the directory to use for the recovery.conf file. Note
342+
the server requires read and write permission on this directory
343+
because the file will be renamed to recovery.done at the end of
344+
recovery.
345+
This parameter can only be set at server start.
346+
</para>
347+
</listitem>
348+
</varlistentry>
349+
333350
<varlistentry id="guc-config-file" xreflabel="config_file">
334351
<term><varname>config_file</varname> (<type>string</type>)</term>
335352
<indexterm>

‎src/backend/access/transam/xlog.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
externboolbootstrap_data_checksums;
6464

65+
charrecoveryConfPath[MAXPGPATH];
6566
/* File path names (all relative to $PGDATA) */
6667
#defineRECOVERY_COMMAND_FILE"recovery.conf"
6768
#defineRECOVERY_COMMAND_DONE"recovery.done"
@@ -4163,15 +4164,16 @@ readRecoveryCommandFile(void)
41634164
*head=NULL,
41644165
*tail=NULL;
41654166

4166-
fd=AllocateFile(RECOVERY_COMMAND_FILE,"r");
4167+
snprintf(recoveryConfPath,MAXPGPATH,"%s/%s",RecoveryConfDir,RECOVERY_COMMAND_FILE);
4168+
fd=AllocateFile(recoveryConfPath,"r");
41674169
if (fd==NULL)
41684170
{
41694171
if (errno==ENOENT)
41704172
return;/* not there, so no archive recovery */
41714173
ereport(FATAL,
41724174
(errcode_for_file_access(),
41734175
errmsg("could not open recovery command file \"%s\": %m",
4174-
RECOVERY_COMMAND_FILE)));
4176+
recoveryConfPath)));
41754177
}
41764178

41774179
/*
@@ -4345,15 +4347,15 @@ readRecoveryCommandFile(void)
43454347
if (PrimaryConnInfo==NULL&&recoveryRestoreCommand==NULL)
43464348
ereport(WARNING,
43474349
(errmsg("recovery command file \"%s\" specified neither primary_conninfo nor restore_command",
4348-
RECOVERY_COMMAND_FILE),
4350+
recoveryConfPath),
43494351
errhint("The database server will regularly poll the pg_xlog subdirectory to check for files placed there.")));
43504352
}
43514353
else
43524354
{
43534355
if (recoveryRestoreCommand==NULL)
43544356
ereport(FATAL,
43554357
(errmsg("recovery command file \"%s\" must specify restore_command when standby mode is not enabled",
4356-
RECOVERY_COMMAND_FILE)));
4358+
recoveryConfPath)));
43574359
}
43584360

43594361
/* Enable fetching from archive recovery area */
@@ -4395,6 +4397,7 @@ static void
43954397
exitArchiveRecovery(TimeLineIDendTLI,XLogSegNoendLogSegNo)
43964398
{
43974399
charrecoveryPath[MAXPGPATH];
4400+
charrecoveryDonePath[MAXPGPATH];
43984401
charxlogpath[MAXPGPATH];
43994402

44004403
/*
@@ -4459,12 +4462,13 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
44594462
* Rename the config file out of the way, so that we don't accidentally
44604463
* re-enter archive recovery mode in a subsequent crash.
44614464
*/
4462-
unlink(RECOVERY_COMMAND_DONE);
4463-
if (rename(RECOVERY_COMMAND_FILE,RECOVERY_COMMAND_DONE)!=0)
4465+
snprintf(recoveryDonePath,MAXPGPATH,"%s/%s",RecoveryConfDir,RECOVERY_COMMAND_DONE);
4466+
unlink(recoveryDonePath);
4467+
if (rename(recoveryConfPath,recoveryDonePath)!=0)
44644468
ereport(FATAL,
44654469
(errcode_for_file_access(),
44664470
errmsg("could not rename file \"%s\" to \"%s\": %m",
4467-
RECOVERY_COMMAND_FILE,RECOVERY_COMMAND_DONE)));
4471+
recoveryConfPath,recoveryDonePath)));
44684472

44694473
ereport(LOG,
44704474
(errmsg("archive recovery complete")));

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ intMyPMChildSlot;
4646
* explicitly.
4747
*/
4848
char*DataDir=NULL;
49+
char*RecoveryConfDir=NULL;
4950

5051
charOutputFileName[MAXPGPATH];/* debugging output file */
5152

‎src/backend/utils/init/miscinit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ SetDataDir(const char *dir)
9999
DataDir=new;
100100
}
101101

102+
/*
103+
* Set recovery config directory, but make sure it's an absolute path. Use this,
104+
* never set RecoveryConfDir directly.
105+
*/
106+
void
107+
SetRecoveryConfDir(constchar*dir)
108+
{
109+
char*new;
110+
111+
AssertArg(dir);
112+
113+
/* If presented path is relative, convert to absolute */
114+
new=make_absolute_path(dir);
115+
116+
if (RecoveryConfDir)
117+
free(RecoveryConfDir);
118+
RecoveryConfDir=new;
119+
}
120+
102121
/*
103122
* Change working directory to DataDir. Most of the postmaster and backend
104123
* code assumes that we are in DataDir so it can use relative paths to access

‎src/backend/utils/misc/guc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ inttemp_file_limit = -1;
424424
intnum_temp_buffers=1024;
425425

426426
char*data_directory;
427+
char*recovery_config_directory;
427428
char*ConfigFileName;
428429
char*HbaFileName;
429430
char*IdentFileName;
@@ -2960,6 +2961,17 @@ static struct config_string ConfigureNamesString[] =
29602961
NULL,NULL,NULL
29612962
},
29622963

2964+
{
2965+
{"recovery_config_directory",PGC_POSTMASTER,FILE_LOCATIONS,
2966+
gettext_noop("Sets the server's recovery configuration directory."),
2967+
NULL,
2968+
GUC_SUPERUSER_ONLY
2969+
},
2970+
&recovery_config_directory,
2971+
NULL,
2972+
NULL,NULL,NULL
2973+
},
2974+
29632975
{
29642976
{"config_file",PGC_POSTMASTER,FILE_LOCATIONS,
29652977
gettext_noop("Sets the server's main configuration file."),
@@ -4181,6 +4193,18 @@ SelectConfigFiles(const char *userDoption, const char *progname)
41814193
*/
41824194
SetConfigOption("data_directory",DataDir,PGC_POSTMASTER,PGC_S_OVERRIDE);
41834195

4196+
/*
4197+
* If the recovery_config_directory GUC variable has been set, use that,
4198+
* otherwise use DataDir.
4199+
*
4200+
* Note: SetRecoveryConfDir will copy and absolute-ize its argument,
4201+
* so we don't have to.
4202+
*/
4203+
if (recovery_config_directory)
4204+
SetRecoveryConfDir(recovery_config_directory);
4205+
else
4206+
SetRecoveryConfDir(DataDir);
4207+
41844208
/*
41854209
* If timezone_abbreviations wasn't set in the configuration file, install
41864210
* the default value. We do it this way because we can't safely install a

‎src/include/miscadmin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ extern bool IsBinaryUpgrade;
137137
externboolExitOnAnyError;
138138

139139
externPGDLLIMPORTchar*DataDir;
140+
externPGDLLIMPORTchar*RecoveryConfDir;
140141

141142
externPGDLLIMPORTintNBuffers;
142143
externintMaxBackends;
@@ -301,6 +302,7 @@ extern OidGetCurrentRoleId(void);
301302
externvoidSetCurrentRoleId(Oidroleid,boolis_superuser);
302303

303304
externvoidSetDataDir(constchar*dir);
305+
externvoidSetRecoveryConfDir(constchar*dir);
304306
externvoidChangeToDataDir(void);
305307
externchar*make_absolute_path(constchar*path);
306308

‎src/include/utils/guc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ extern inttemp_file_limit;
220220
externintnum_temp_buffers;
221221

222222
externchar*data_directory;
223+
externchar*recovery_config_directory;
223224
externchar*ConfigFileName;
224225
externchar*HbaFileName;
225226
externchar*IdentFileName;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp