Segmentation fault occurs when the standby becomes primary, in SR

Fujii Masao <masao.fujii@gmail.com>

From: Fujii Masao <masao.fujii@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>, Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Date: 2010-01-28T14:40:24Z
Lists: pgsql-hackers

Attachments

Hi,

When I created the trigger file to activate the standby server,
I got the segmentation fault:

  sby [11342]: LOG:  trigger file found: ../trigger
  sby [11343]: FATAL:  terminating walreceiver process due to
administrator command
  sby [11342]: LOG:  redo done at 0/10000E0
  sby [11342]: LOG:  last completed transaction was at log time
2000-01-01 09:21:04.685861+09
  sby [11341]: LOG:  startup process (PID 11342) was terminated by
signal 11: Segmentation fault
  sby [11341]: LOG:  terminating any other active server processes

This happens in the following scenario:

0. The trigger file is found.
1. The variable StandbyMode is reset to FALSE before re-fetching
   the last applied record.
2. That record attempts to be read from the archive.
3. RestoreArchivedFile() goes through the following condition
   expression because the StandbyMode is off.

     if (StandbyMode && recoveryRestoreCommand == NULL)
         goto not_available;

4. RestoreArchivedFile() wrongly constructs the command to be
   executed even though restore_command has not been supplied
   (this is possible in standby mode).
   ---> Segmentation fault!

The attached patch would fix the bug.

Regards,

-- 
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center