use better replica detection method

Fixes #1182
Merge pull request #1183 from miketheman/miketheman/pg_recovery

use better replica detection method