Обсуждение: Question on warm standby log shipping

Поиск
Список
Период
Сортировка

Question on warm standby log shipping

От
Jens Wilke
Дата:
Hi,

I hacked up some scripts to do warm standby log shipping with
postgresql version 8.2.7. Everything is fine, but I have one remaining
curiosity.

The restore script looks like:

--snipp--
from="$1";
to="$2";
while true; do
  if test -f "$ARCHIVEDIR/$from"; then
    src="$ARCHIVEDIR/$from";
    mv "$src" "$to";
    exit 0;
  fi
  # startup triggered
  if test -f $triggerfile; then
    exit 0;
  fi
  sleep 2;
done
--snipp--

However this way its not working, since when the database starts up
it requests log files again that were already feeded. Here is a log
of an unsuccessful startup:

--snipp--
2008-05-05 17:21:42 CEST LOG:  restored log file "000000010000000B0000001C" from archive
2008-05-05 17:22:42 CEST LOG:  restored log file "000000010000000B0000001D" from archive
2008-05-05 17:23:40 CEST LOG:  restored log file "000000010000000B0000001E" from archive
2008-05-05 17:24:40 CEST LOG:  restored log file "000000010000000B0000001F" from archive
2008-05-05 17:25:04 CEST LOG:  could not open file "pg_xlog/000000010000000B00000020" (log file 11, segment 32): No
suchfile or directory 
2008-05-05 17:25:04 CEST LOG:  redo done at B/1F00CB6C
2008-05-05 17:25:04 CEST PANIC:  could not open file "pg_xlog/000000010000000B0000001F" (log file 11, segment 31): No
suchfile or directory 
2008-05-05 17:25:04 CEST LOG:  startup process (PID 4873) was terminated by signal 6
2008-05-05 17:25:04 CEST LOG:  aborting startup due to startup process failure
2008-05-05 17:30:02 CEST LOG:  could not load root certificate file "root.crt": no SSL error reported
2008-05-05 17:30:02 CEST DETAIL:  Will not verify client certificates.
2008-05-05 17:30:02 CEST LOG:  database system was interrupted while in recovery at log time 2008-05-05 17:22:14 CEST
2008-05-05 17:30:02 CEST HINT:  If this has occurred more than once some data may be corrupted and you may need to
choosean earlier recovery targe 
2008-05-05 17:30:02 CEST LOG:  starting archive recovery
2008-05-05 17:30:02 CEST LOG:  restore_command = "/var/lib/postgresql/8.2-wal-archive/pg-standby/restore.sh %f %p"
2008-05-05 17:30:02 CEST LOG:  could not open file "pg_xlog/000000010000000B0000001D" (log file 11, segment 29): No
suchfile or directory 
2008-05-05 17:30:02 CEST LOG:  invalid primary checkpoint record
2008-05-05 17:30:02 CEST LOG:  could not open file "pg_xlog/000000010000000B0000001A" (log file 11, segment 26): No
suchfile or directory 
2008-05-05 17:30:02 CEST LOG:  invalid secondary checkpoint record
2008-05-05 17:30:02 CEST PANIC:  could not locate a valid checkpoint record
2008-05-05 17:30:02 CEST LOG:  startup process (PID 825) was terminated by signal 6
2008-05-05 17:30:02 CEST LOG:  aborting startup due to startup process failure
--snipp--

A successful startup looks like:

--snipp--
2008-05-13 15:55:47 CEST LOG:  restored log file "000000010000002700000046" from archive
2008-05-13 15:56:47 CEST LOG:  restored log file "000000010000002700000047" from archive
2008-05-13 15:57:47 CEST LOG:  restored log file "000000010000002700000048" from archive
2008-05-13 15:59:21 CEST LOG:  could not open file "pg_xlog/000000010000002700000049" (log file 39, segment 73): No
suchfile or directory 
2008-05-13 15:59:21 CEST LOG:  redo done at 27/48016BC0
2008-05-13 15:59:22 CEST LOG:  restored log file "000000010000002700000048" from archive
2008-05-13 15:59:22 CEST LOG:  selected new timeline ID: 2
2008-05-13 15:59:22 CEST LOG:  archive recovery complete
2008-05-13 15:59:22 CEST LOG:  database system is ready
--snipp--

As we can see logfile ..48 is requested again.

So the question is: Which log files can I safely delete from my archive?

OTOH, is this a bug? I think postgresql should not request something again that was already feeded.

Best,

Jens

--
"Everything superfluous is wrong!"

   // Jens Wilke - headissue GmbH - Munich - Germany
 \//  http://www.headissue.com

Re: Question on warm standby log shipping

От
Alvaro Herrera
Дата:
Jens Wilke wrote:

> The restore script looks like:
>
> --snipp--
> from="$1";
> to="$2";
> while true; do
>   if test -f "$ARCHIVEDIR/$from"; then
>     src="$ARCHIVEDIR/$from";
>     mv "$src" "$to";
>     exit 0;
>   fi
>   # startup triggered
>   if test -f $triggerfile; then
>     exit 0;
>   fi
>   sleep 2;
> done
> --snipp--

You should not remove the segment until it's no longer needed.  To
figure that out you can use %r of restore_command.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support