Postgresql pg_standby 需要永远执行故障转移
我有一个可用的 WAL 传送设置,其中有一个应用 WAL 文件的热备用从属服务器。
当我创建 pg_standby 触发器文件时,它会立即检测到这一点,但实际上需要大约 10-15 分钟才能准备好接受连接。大部分时间都花在等待 .history 文件上。
触发器文件是空的,因此应该进行“智能”故障转移。我可以做些什么来使故障转移(更快)更快吗?
日志输出:
WAL file not present yet. Checking for trigger file...
trigger file found: smart failover
LOG: could not open file "pg_xlog/000000010000000000000089" (log file 0, segment 137): No such file or directory
LOG: redo done at 0/88003428
LOG: last completed transaction was at log time 2010-08-10 13:26:20.232799+00
Trigger file : /psql_archive/role.master
Waiting for WAL file : 000000010000000000000088
WAL file path : /psql_archive/000000010000000000000088
Restoring to : pg_xlog/RECOVERYXLOG
Sleep interval : 60 seconds
Max wait interval : 0 forever
Command for restore : cp "/psql_archive/000000010000000000000088" "pg_xlog/RECOVERYXLOG"
Keep archive history : 000000000000000000000000 and later
trigger file found: smart failover
running restore : OK
LOG: restored log file "000000010000000000000088" from archive
Trigger file : /psql_archive/role.master
Waiting for WAL file : 00000002.history
WAL file path : /psql_archive/00000002.history
Restoring to : pg_xlog/RECOVERYHISTORY
Sleep interval : 60 seconds
Max wait interval : 0 forever
Command for restore : cp "/psql_archive/00000002.history" "pg_xlog/RECOVERYHISTORY"
Keep archive history : 000000000000000000000000 and later
running restore :cp: cannot stat `/psql_archive/00000002.history': No such file or directory
cp: cannot stat `/psql_archive/00000002.history': No such file or directory
cp: cannot stat `/psql_archive/00000002.history': No such file or directory
cp: cannot stat `/psql_archive/00000002.history': No such file or directory
not restored
history file not found
LOG: selected new timeline ID: 2
Trigger file : /psql_archive/role.master
Waiting for WAL file : 00000001.history
WAL file path : /psql_archive/00000001.history
Restoring to : pg_xlog/RECOVERYHISTORY
Sleep interval : 60 seconds
Max wait interval : 0 forever
Command for restore : cp "/psql_archive/00000001.history" "pg_xlog/RECOVERYHISTORY"
Keep archive history : 000000000000000000000000 and later
running restore :cp: cannot stat `/psql_archive/00000001.history': No such file or directory
cp: cannot stat `/psql_archive/00000001.history': No such file or directory
cp: cannot stat `/psql_archive/00000001.history': No such file or directory
cp: cannot stat `/psql_archive/00000001.history': No such file or directory
not restored
history file not found
LOG: archive recovery complete
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
谢谢。
-丹尼斯
I have a working WAL shipping setup with a warm standby slave server applying the WAL files.
When I create the pg_standby trigger file, it detects this at once, but it takes about 10-15 minutes to actually be ready for accepting connections. Most of the time is spent waiting for .history files.
The trigger file is empty, so a "smart" failover should be done. Can I do something to make failover (much) faster?
Log output:
WAL file not present yet. Checking for trigger file...
trigger file found: smart failover
LOG: could not open file "pg_xlog/000000010000000000000089" (log file 0, segment 137): No such file or directory
LOG: redo done at 0/88003428
LOG: last completed transaction was at log time 2010-08-10 13:26:20.232799+00
Trigger file : /psql_archive/role.master
Waiting for WAL file : 000000010000000000000088
WAL file path : /psql_archive/000000010000000000000088
Restoring to : pg_xlog/RECOVERYXLOG
Sleep interval : 60 seconds
Max wait interval : 0 forever
Command for restore : cp "/psql_archive/000000010000000000000088" "pg_xlog/RECOVERYXLOG"
Keep archive history : 000000000000000000000000 and later
trigger file found: smart failover
running restore : OK
LOG: restored log file "000000010000000000000088" from archive
Trigger file : /psql_archive/role.master
Waiting for WAL file : 00000002.history
WAL file path : /psql_archive/00000002.history
Restoring to : pg_xlog/RECOVERYHISTORY
Sleep interval : 60 seconds
Max wait interval : 0 forever
Command for restore : cp "/psql_archive/00000002.history" "pg_xlog/RECOVERYHISTORY"
Keep archive history : 000000000000000000000000 and later
running restore :cp: cannot stat `/psql_archive/00000002.history': No such file or directory
cp: cannot stat `/psql_archive/00000002.history': No such file or directory
cp: cannot stat `/psql_archive/00000002.history': No such file or directory
cp: cannot stat `/psql_archive/00000002.history': No such file or directory
not restored
history file not found
LOG: selected new timeline ID: 2
Trigger file : /psql_archive/role.master
Waiting for WAL file : 00000001.history
WAL file path : /psql_archive/00000001.history
Restoring to : pg_xlog/RECOVERYHISTORY
Sleep interval : 60 seconds
Max wait interval : 0 forever
Command for restore : cp "/psql_archive/00000001.history" "pg_xlog/RECOVERYHISTORY"
Keep archive history : 000000000000000000000000 and later
running restore :cp: cannot stat `/psql_archive/00000001.history': No such file or directory
cp: cannot stat `/psql_archive/00000001.history': No such file or directory
cp: cannot stat `/psql_archive/00000001.history': No such file or directory
cp: cannot stat `/psql_archive/00000001.history': No such file or directory
not restored
history file not found
LOG: archive recovery complete
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
Thanks.
-dennis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,如果您不使用快速故障转移,pg_standby 将继续处理剩余的所有日志(理应如此)以最大程度地减少数据丢失。
为了让您的生活更轻松,我会看看 PITRTools。
In short if you don't use fast failover pg_standby will continue to process all logs that are left (as it should) to minimize data loss.
To make your life easier I would look at PITRTools.
根据文档: http://www.postgresql.org/docs/current /static/pgstandby.html
快速故障转移:在快速故障转移中,服务器立即启动。存档中尚未应用的任何 WAL 文件都将被忽略,并且这些文件中的所有事务都将丢失。要触发快速故障转移,请创建一个触发器文件并将“快速”一词写入其中。如果在定义的时间间隔内没有出现新的 WAL 文件,pg_standby 还可以配置为自动执行快速故障转移。
或者查看“表 F-23. pg_standby 选项”,其中描述了 maxwaittime。
干杯
According to the docs: http://www.postgresql.org/docs/current/static/pgstandby.html
Fast Failover: In fast failover, the server is brought up immediately. Any WAL files in the archive that have not yet been applied will be ignored, and all transactions in those files are lost. To trigger a fast failover, create a trigger file and write the word fast into it. pg_standby can also be configured to execute a fast failover automatically if no new WAL file appears within a defined interval.
Or have a look into "Table F-23. pg_standby options" there is a maxwaittime described.
Cheers