There's more...
To connect to a database manually, you can use the db_connect command followed by the credentials, host, and database you want to connect to, using the following syntax:
db_connect <user:pass>@<host:port>/<database>
To test the db_connect command, we can use the values of the username, password, database name, and port number, from the database.yml file:
msf > db_disconnect
msf > db_status
[*] postgresql selected, no connection
msf > db_connect msf:3HcNhAtdH6F9F2iGa4z3wJVoI7UK1Ot+MG1zuKjYzn4=@127.0.0.1/msf
[*] Rebuilding the module cache in the background...
msf > db_status
[*] postgresql connected to msf
We can also use db_connect with the -y option and the path to the database configuration file:
msf > db_disconnect
msf > db_status
[*] postgresql selected, no connection
msf > db_connect -y /usr/share/metasploit-framework/config/database.yml
[*] Rebuilding the module cache in the background...
msf > db_status
[*] postgresql connected to msf
If you want the database to connect every time you launch msfconsole, copy the database configuration file to the .msf4 directory which was created in your home directory by the Metasploit installer.