PostgreSqlSegmentStore: make robust to concurrency

See 8b3f640ed967fef3b09726b5791fcf9aa2637b6c for explanation.