automate postgresql upgrade procedure
during the %Debian 12 bookworm upgrade, tor weather suffered a catastrophic failure (#41388 (closed)) due to a flaw in the postgresql upgrade procedure. that procedure has been copy-pasted over and over again, and errors keep creeping in.
let's automate the postgresql upgrade procedure, which would normally keep that kind of problem from occuring again (as we can do error checking better).
part of #41485.