README.pg_standby 7.18 KB
Newer Older
Bruce Momjian's avatar
Bruce Momjian committed
1 2 3 4
pg_standby README		2006/12/08 Simon Riggs

o What is pg_standby?

5 6 7 8 9
  pg_standby allows the creation of a Warm Standby server.
  It is designed to be a production-ready program, as well as a 
  customisable template should you require specific modifications.
  Other configuration is required as well, all of which is 
  described in the main server manual.
Bruce Momjian's avatar
Bruce Momjian committed
10 11 12 13 14 15

  The program is designed to be a wait-for restore_command, 
  required to turn a normal archive recovery into a Warm Standby.
  Within the restore_command of the recovery.conf you could
  configure pg_standby in the following way:

16
    restore_command = 'pg_standby archiveDir %f %p %r'
Bruce Momjian's avatar
Bruce Momjian committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

  which would be sufficient to define that files will be restored
  from archiveDir. 

o features of pg_standby

  - pg_standby is written in C. So it is very portable
    and easy to install.

  - supports copy or link from a directory (only)

  - source easy to modify, with specifically designated
    sections to modify for your own needs, allowing 
    interfaces to be written for additional Backup Archive Restore
    (BAR) systems

  - portable: tested on Linux and Windows 

o How to install pg_standby

 $make
 $make install

o How to use pg_standby?

  pg_standby should be used within the restore_command of the
  recovery.conf file. See the main PostgreSQL manual for details.

  The basic usage should be like this:

47
    restore_command = 'pg_standby archiveDir %f %p %r'
Bruce Momjian's avatar
Bruce Momjian committed
48 49 50

  with the pg_standby command usage as

51
    pg_standby [OPTION]... ARCHIVELOCATION NEXTWALFILE XLOGFILEPATH [RESTARTWALFILE]
Bruce Momjian's avatar
Bruce Momjian committed
52 53 54

  When used within the restore_command the %f and %p macros
  will provide the actual file and path required for the restore/recovery.
55 56 57 58 59 60 61 62 63

  pg_standby assumes that ARCHIVELOCATION is directory accessible by the 
  server-owning user.

  If RESTARTWALFILE is specified, typically by using the %r option, then all files
  prior to this file will be removed from ARCHIVELOCATION. This then minimises
  the number of files that need to be held, whilst at the same time maintaining
  restart capability. This capability additionally assumes that ARCHIVELOCATION
  directory is writable.
Bruce Momjian's avatar
Bruce Momjian committed
64 65 66
  
o options

67
  pg_standby allows the following command line switches
Bruce Momjian's avatar
Bruce Momjian committed
68 69 70 71 72 73 74 75 76

	-c
		use copy/cp command to restore WAL files from archive

	-d
		debug/logging option.

	-k numfiles
		Cleanup files in the archive so that we maintain no more
77 78 79 80
		than this many files in the archive. This parameter will
		be silently ignored if RESTARTWALFILE is specified, since
		that specification method is more accurate in determining
		the correct cut-off point in archive.
Bruce Momjian's avatar
Bruce Momjian committed
81 82 83 84 85 86 87 88 89 90 91

		You should be wary against setting this number too low,
		since this may mean you cannot restart the standby. This
		is because the last restartpoint marked in the WAL files
		may be many files in the past and can vary considerably.
		This should be set to a value exceeding the number of WAL
		files that can be recovered in 2*checkpoint_timeout seconds,
		according to the value in the warm standby postgresql.conf.
		It is wholly unrelated to the setting of checkpoint_segments
		on either primary or standby.

92 93 94
		Setting numfiles to be zero will disable deletion of files
		from ARCHIVELOCATION.

Bruce Momjian's avatar
Bruce Momjian committed
95 96
		If in doubt, use a large value or do not set a value at all.

97 98 99 100
		If you specify neither RESTARTWALFILE nor -k, then -k 0 
		will be assumed, i.e. keep all files in archive.
		Default=0, Min=0

Bruce Momjian's avatar
Bruce Momjian committed
101 102 103 104 105 106 107
	-l 
		use ln command to restore WAL files from archive
		WAL files will remain in archive

		Link is more efficient, but the default is copy to 
		allow you to maintain the WAL archive for recovery
		purposes as well as high-availability.
108 109
		The default setting is not necessarily recommended,
		consult the main database server manual for discussion.
Bruce Momjian's avatar
Bruce Momjian committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

		This option uses the Windows Vista command mklink
		to provide a file-to-file symbolic link. -l will
		not work on versions of Windows prior to Vista.
		Use the -c option instead.
		see http://en.wikipedia.org/wiki/NTFS_symbolic_link

	-r maxretries
		the maximum number of times to retry the restore command if it
		fails. After each failure, we wait for sleeptime * num_retries
		so that the wait time increases progressively, so by default
		we will wait 5 secs, 10 secs then 15 secs before reporting
		the failure back to the database server. This will be
		interpreted as and end of recovery and the Standby will come
		up fully as a result.
125
		Default=3, Min=0
Bruce Momjian's avatar
Bruce Momjian committed
126 127 128 129 130 131

	-s sleeptime
		the number of seconds to sleep between testing to see
		if the file to be restored is available in the archive yet.
		The default setting is not necessarily recommended,
		consult the main database server manual for discussion.
132
		Default=5, Min=1, Max=60
Bruce Momjian's avatar
Bruce Momjian committed
133 134 135 136 137 138 139 140 141 142 143 144

	-t triggerfile
		the presence of the triggerfile will cause recovery to end
		whether or not the next file is available
		It is recommended that you use a structured filename to 
		avoid confusion as to which server is being triggered
		when multiple servers exist on same system.
		e.g. /tmp/pgsql.trigger.5432

	-w maxwaittime
		the maximum number of seconds to wait for the next file,
		after which recovery will end and the Standby will come up.
145
		A setting of zero means wait forever.
Bruce Momjian's avatar
Bruce Momjian committed
146 147
		The default setting is not necessarily recommended,
		consult the main database server manual for discussion.
148
		Default=0, Min=0
Bruce Momjian's avatar
Bruce Momjian committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

	Note: --help is not supported since pg_standby is not intended
		for interactive use, except during dev/test

o examples

	Linux

	archive_command = 'cp %p ../archive/%f'

    	restore_command = 'pg_standby -l -d -k 255 -r 2 -s 2 -w 0 -t /tmp/pgsql.trigger.5442 $PWD/../archive %f %p 2>> standby.log' 

  	which will
	- use a ln command to restore WAL files from archive
	- produce logfile output in standby.log
	- keep the last 255 full WAL files, plus the current one
	- sleep for 2 seconds between checks for next WAL file is full
	- never timeout if file not found
	- stop waiting when a trigger file called /tmp.pgsql.trigger.5442 appears

	Windows
	
	archive_command = 'copy %p ..\\archive\\%f'
	Note that backslashes need to be doubled in the archive_command, but
	*not* in the restore_command, in 8.2, 8.1, 8.0 on Windows.

175
	restore_command = 'pg_standby -c -d -s 5 -w 0 -t C:\pgsql.trigger.5442 ..\archive %f %p 2>> standby.log'
Bruce Momjian's avatar
Bruce Momjian committed
176 177 178 179 180 181 182 183

  	which will
	- use a copy command to restore WAL files from archive
	- produce logfile output in standby.log
	- sleep for 5 seconds between checks for next WAL file is full
	- never timeout if file not found
	- stop waiting when a trigger file called C:\pgsql.trigger.5442 appears

184 185 186 187 188 189 190 191 192 193 194 195 196
o supported versions

	pg_standby is designed to work with PostgreSQL 8.2 and later. It is
	currently compatible across minor changes between the way 8.3 and 8.2
	operate.

	PostgreSQL 8.3 provides the %r command line substitution, designed to
	let pg_standby know the last file it needs to keep. If the last
	parameter is omitted, no error is generated, allowing pg_standby to
	function correctly with PostgreSQL 8.2 also. With PostgreSQL 8.2,
	the -k option must be used if archive cleanup is required. This option
	remains available in 8.3.

Bruce Momjian's avatar
Bruce Momjian committed
197 198 199 200
o reported test success

	SUSE Linux 10.2
	Windows XP Pro
201 202 203 204 205 206

o additional design notes

	The use of a move command seems like it would be a good idea, but
	this would prevent recovery from being restartable. Also, the last WAL
	file is always requested twice from the archive.