For PostgreSQL in particular, the Debian / pgdg packages support concurrent installation of multiple versions https://wiki.postgresql.org/wiki/Apt