psql coloured prompt misbehaving
I have experience this exact same thing in the past.  It usually happens because you have linked psql against an inferior readline-like library.  If you are using libedit, use libreadline instead.  If you are using libreadline, use a different one.  Details depend on your operating system and method of installation.