ha: Only run the psql commands if postgresql is running on this node

Otherwise, we're subject to races where we reach that code before the
node hosting postgresql is fully configured to answer to psql.