Question about Restart point and checkpoint_segments

From: Benoit Lobréau <benoit(dot)lobreau(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Question about Restart point and checkpoint_segments
Date: 2016-02-16 17:02:37
Message-ID: CAPE8EZ6gHgOGmzs_WCEr4fM=UpY9UsMoazKzANByz02Ova1=Gw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I am using a hot_standby setup on PostgreSQL 9.1
While I was testing, I found out that only checkpoint_timeout (+ a
checkpoint since the last restart point) could trigger a restart point.

The code (bgwriter.c) seems to confirm this:

/*
* Check progress against WAL segments written and checkpoint_segments.
*
* We compare the current WAL insert location against the location
* computed before calling CreateCheckPoint. The code in XLogInsert that
* actually triggers a checkpoint when checkpoint_segments is exceeded
* compares against RedoRecptr, so this is not completely accurate.
* However, it's good enough for our purposes, we're only calculating an
* estimate anyway.
*/
if (!RecoveryInProgress()) ===> Only in case of primary
{
recptr = GetInsertRecPtr();
elapsed_xlogs =
(((double) (int32) (recptr.xlogid -
ckpt_start_recptr.xlogid)) * XLogSegsPerFile +
((double) recptr.xrecoff - (double)
ckpt_start_recptr.xrecoff) / XLogSegSize) /
CheckPointSegments;

if (progress < elapsed_xlogs) ===> progress in volume
{
ckpt_cached_elapsed = elapsed_xlogs;
return false;
}
}

/*
* Check progress against time elapsed and checkpoint_timeout.
*/
gettimeofday(&now, NULL);
elapsed_time = ((double) ((pg_time_t) now.tv_sec - ckpt_start_time) +

now.tv_usec / 1000000.0) / CheckPointTimeout;

if (progress < elapsed_time) ===> progress in time
{
ckpt_cached_elapsed = elapsed_time;
return false;
}

/* It looks like we're on schedule. */
return true;

I also found a post from Simon Riggs [1]: "checkpoint_segments is ignored
on standby."

The documentation is stating the opposite [2]: "In standby mode, a
restartpoint is also triggered if checkpoint_segments log segments have
been replayed since last restartpoint and at least one checkpoint record
has been replayed."

Since I am not a native english speaker, maybe I misunderstood the
documentation. But to me, it looks wrong.
If it's indeed wrong. Could you explain why checkpoint_segments doesn't
trigger a restart_point in standby mode ?

Thank you
Benoit

[1]
http://www.postgresql.org/message-id/CA+U5nMKdf7odZzYNnoRkkCZmJpGEy=OQbU9Nan_zva_Rtzi2vw@mail.gmail.com
[2] http://www.postgresql.org/docs/9.1/static/wal-configuration.html

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2016-02-16 17:42:47 Re: Doubt in 9.5 release note
Previous Message Oleg Bartunov 2016-02-16 16:54:54 Re: pglogical - logical replication contrib module