fix bugs with pg lib close method