Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
#!/usr/bin/env php
<?php
$dbmaster = new PDO('pgsql:host=localhost;port=5432;dbname=postgres;','screened','screened');
$master = $dbmaster->query('SELECT pg_current_xlog_location()')->fetchColumn();
$dbslave = new PDO('pgsql:host=192.168.1.2;port=5432;dbname=postgres;','screened','screened');
$slave = $dbslave->query('SELECT pg_last_xlog_replay_location()')->fetchColumn();
//echo $master." ".$slave;
if($slave) {
echo ((text_to_lsn($master) - text_to_lsn($slave))/1000)."\n";
} else {
echo "0\n";
}
function text_to_lsn($text) {
list($logid, $xrecoff) = explode('/', $text);
$lsn = hexdec($logid) * 16 * 1024 * 1024 * 255 + hexdec($xrecoff);
return $lsn;
}
Watchdog для репликации в PostgreSQL 9