I fear the package locations will differ form version to version, so you can uninstall the most from your OS with
sudo apt-get purge postgresql-9.1
but then you will have to find all remaining files and directory with
sudo updatedb && locate *postgres*9*
and remove them manually with
sudo rm -rf <pattern>
For example, I can tell that for postgres 14.7 you should run these commands
sudo apt-get purge postgresql-14.7
sudo rm /var/log/postgresql/postgresql-14-main.log
sudo rm -rf /run/postgresql/14*
sudo rm -rf /run/systemd/generator/postgresql.service.wants/postgresql@14-main.service
sudo rm -rf /usr/lib/postgresql/14/
sudo rm -rf /usr/share/doc/postgresql-14*
sudo rm -rf /usr/share/doc/postgresql-client-14*
sudo rm -rf /usr/share/lintian/overrides/postgresql-14
sudo rm -rf /usr/share/lintian/overrides/postgresql-client-14
sudo rm -rf /usr/share/postgresql/14/
sudo rm -rf /usr/share/postgresql-common/t/140_pg_config.t
sudo rm -rf /var/lib/dpkg/info/postgresql-14*
sudo rm -rf /var/lib/dpkg/info/postgresql-client-14*
sudo rm -rf /var/lib/postgresql/14/
in the end, check the results with
psql --version