$ sudo service postgresql start
$ sudo -u postgres createuser –superuser $USER
Enter your desired password when prompted.
We then have to create a database with that $USER login name, this is what Postgres expects as default.
$ sudo -u postgres createdb $USER
Navigate to your home directory and enter the following command to create the .psql_history in order to save your history:
$ touch .psql_history
You can now connect to the Postgres server by typing :
$ psql
When facing an error, go through your terminal and navigate to:
$ ls /etc/apt/sources.list.d
that is
$ cd ..
then when @ sources.list.d :
$ sudo rm -r pgdg.list
When done repeat the first instruction shared in this article
also
https://docs.rapid7.com/metasploit/no-database-connection/