> I have two questions/suggestions about replication lag check for
> straming replication in pgpool-II.
>
> 1. In text_to_lsn() there is formula
>
> lsn = xlogid * 16 * 1024 * 1024 * 255 + xrecoff;
>
> 16 * 1024 * 1024 * 255 = 4278190080 = 0xff000000
>
> where this magic numbers come from?
>
> I think multiplier should be
> 0xffffffff - XLogSegSize.
>
> In PostgreeSQL source this constant used in
> src/include/access/xlog_internal.h
>
> #define XLogSegsPerFile (((uint32) 0xffffffff) / XLogSegSize)
>
> But in comment noted, that one segment at the end of each log file is
> wasted
>
> Each xlogid corresponds to (XLogSegsPerFile - 1) * XLogSegSize =
> 0xffffffff - XLogSegSize bytes
>
> 2. On slave better to use
> SELECT pg_last_xlog_replay_location()
> instead
> SELECT pg_last_xlog_receive_location()
>
> if we want to know if slave will return stale data on SELECTs to
> user's databases.
Thanks for the suggestion. I fixed the calculation of LSN and change
pg_last_xlog_receive_location() to pg_last_xlog_replay_location().
See included patches for more details.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese: http://www.sraoss.co.jp
Index: pool_worker_child.c
===================================================================
RCS file: /cvsroot/pgpool/pgpool-II/pool_worker_child.c,v
retrieving revision 1.7
diff -c -r1.7 pool_worker_child.c
*** pool_worker_child.c 23 Feb 2011 06:47:48 -0000 1.7
--- pool_worker_child.c 5 May 2011 02:32:53 -0000
***************
*** 233,239 ****
}
else
{
! query = "SELECT pg_last_xlog_receive_location()";
}
sts = do_query(slots[i]->con, query, &res, PROTO_MAJOR_V3);
--- 233,239 ----
}
else
{
! query = "SELECT pg_last_xlog_replay_location()";
}
sts = do_query(slots[i]->con, query, &res, PROTO_MAJOR_V3);
***************
*** 307,312 ****
--- 307,318 ----
*/
static long text_to_lsn(char *text)
{
+ /*
+ * WAL segment size in bytes. XXX We should fetch this from
+ * PostgreSQL, rather than having fixed value.
+ */
+ #define WALSEGMENTSIZE 16 * 1024 * 1024
+
unsigned int xlogid;
unsigned int xrecoff;
unsigned long long int lsn;
***************
*** 316,322 ****
pool_error("text_to_lsn: wrong log location format: %s", text);
return 0;
}
! lsn = xlogid * 16 * 1024 * 1024 * 255 + xrecoff;
return lsn;
}
--- 322,331 ----
pool_error("text_to_lsn: wrong log location format: %s", text);
return 0;
}
! lsn = xlogid * ((unsigned long long int)0xffffffff - WALSEGMENTSIZE) + xrecoff;
! #ifdef DEBUG
! pool_log("lsn: %X %X %llX", xlogid, xrecoff, lsn);
! #endif
return lsn;
}
_______________________________________________
Pgpool-hackers mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgpool-hackers