4-0-stable: Terminate the backend ourselves on PG 9.2+

This should make it harder to accidentally break this test.

(Backport of #14035, to save @tenderlove dealing with the conflicts)