Postgresql scripts/functions to determine the furthest ahead replica/slave