Metasploit-framework: Failed to connect to the database: could not connect to server: Connection refused

Created on 8 Jan 2018  ·  23Comments  ·  Source: rapid7/metasploit-framework

Hi all,

I need some help here with this metasploit db issue on a kali box.
When I start metasploit, here are the error messages that comes up..

root@localhost:/home# msfconsole
[-] Failed to connect to the database: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

and
msf > db_status
[*] postgresql selected, no connection

I realise this might be a common issue but all the steps to resolve it after almost 2 days of googling has not yielded results..
Other commands I have run and their output below

root@localhost:/# service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2018-01-08 02:23:44 GMT; 10h ago
Process: 6344 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 6344 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/postgresql.service

Jan 08 02:23:44 localhost.localdomain systemd[1]: Starting PostgreSQL RDBMS...
Jan 08 02:23:44 localhost.localdomain systemd[1]: Started PostgreSQL RDBMS.
Jan 08 13:22:53 localhost.localdomain systemd[1]: Started PostgreSQL RDBMS.
Jan 08 13:23:00 localhost.localdomain systemd[1]: Started PostgreSQL RDBMS.

This command gives a blank output
root@localhost:/# ss -lntp | grep post

Here, it seems the postgresql is not listening
root@localhost:/# ps -aux | grep post
root 6402 0.0 0.3 6224 3496 pts/0 S 12:39 0:00 su postgres
postgres 6403 0.0 0.3 5704 3576 pts/0 S 12:39 0:00 bash
root 6868 0.0 0.0 4756 864 pts/0 S+ 13:24 0:00 grep post

You might also want to check the last ~1k lines of ~/.msf4/logs/framework.log for relevant stack traces

TCP/IP connections on port 5432?

[01/08/2018 13:20:46] [i(0)] core: Trying to continue despite failed database creation: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

[01/08/2018 13:20:46] [e(0)] core: DB.connect threw an exception: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

System stuff

Metasploit version

Framework: 4.16.31-dev-
Console : 4.16.31-dev

OS

What OS are you running Metasploit on? Kali Linux

Can someone please help me resolve this and identify what I am not doing correctly ?

Most helpful comment

The error is :-

msfconsole
[-] Failed to connect to the database: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting

TCP/IP connections on port 5432?

FULLY WORKING SOLUTION

Type the following commands

1.root@kali:~# cd /usr/share/metasploit-framework/config/

2.root@kali:/usr/share/metasploit-framework/config# ls
application.rb database.yml database.yml.vagrant
boot.rb database.yml.example environment.rb
cucumber.yml database.yml.travis environments

3.root@kali:/usr/share/metasploit-framework/config# cat database.yml
development:
adapter: postgresql
database: msf
username: msf
password: 2OjgyhT0tacdnxrYIKC8BgDel7tbY=
host: localhost
port: 5432
pool: 5
timeout: 5

production:
adapter: postgresql
database: msf
username: msf
password: 2O/UYGBP3jgyjgYuIT0tacdnxrYIKC8BgDel7tbY=
host: localhost
port: 5432
pool: 5
timeout: 5

test:
adapter: postgresql
database: msf_test
username: msf
password: 2O/UYGBP3nAhfhffhhyfh0tacdnxrYIKC8BgDel7tbY=
host: localhost
port: 5432
pool: 5

timeout: 5

NOW CHANGE THE PORT NUMBER FROM 5432 TO 5433 ,THIS IS THE MAIN STEP SO DON'T MISS IT

4.root@kali:/usr/share/metasploit-framework/config# nano database.yml

5.root@kali:/usr/share/metasploit-framework/config# cp database.yml /root/.msf4/

6.root@kali:/usr/share/metasploit-framework/config# cd ~/.msf4/

7.root@kali:~/.msf4# ls
database.yml history local logos logs loot modules plugins

8.root@kali:~# /etc/init.d/postgresql start

9.root@kali:~# msfconsole


CONGO YOUR DONE

All 23 comments

Hi @busterb,

Thanks for the link but when I run ss-ant I see port 5432 is not listening. How do I resolve this ?

root@localhost:/# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:57436 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:55345 [::]:*

same problem bro

The error is :-

msfconsole
[-] Failed to connect to the database: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting

TCP/IP connections on port 5432?

FULLY WORKING SOLUTION

Type the following commands

1.root@kali:~# cd /usr/share/metasploit-framework/config/

2.root@kali:/usr/share/metasploit-framework/config# ls
application.rb database.yml database.yml.vagrant
boot.rb database.yml.example environment.rb
cucumber.yml database.yml.travis environments

3.root@kali:/usr/share/metasploit-framework/config# cat database.yml
development:
adapter: postgresql
database: msf
username: msf
password: 2OjgyhT0tacdnxrYIKC8BgDel7tbY=
host: localhost
port: 5432
pool: 5
timeout: 5

production:
adapter: postgresql
database: msf
username: msf
password: 2O/UYGBP3jgyjgYuIT0tacdnxrYIKC8BgDel7tbY=
host: localhost
port: 5432
pool: 5
timeout: 5

test:
adapter: postgresql
database: msf_test
username: msf
password: 2O/UYGBP3nAhfhffhhyfh0tacdnxrYIKC8BgDel7tbY=
host: localhost
port: 5432
pool: 5

timeout: 5

NOW CHANGE THE PORT NUMBER FROM 5432 TO 5433 ,THIS IS THE MAIN STEP SO DON'T MISS IT

4.root@kali:/usr/share/metasploit-framework/config# nano database.yml

5.root@kali:/usr/share/metasploit-framework/config# cp database.yml /root/.msf4/

6.root@kali:/usr/share/metasploit-framework/config# cd ~/.msf4/

7.root@kali:~/.msf4# ls
database.yml history local logos logs loot modules plugins

8.root@kali:~# /etc/init.d/postgresql start

9.root@kali:~# msfconsole


CONGO YOUR DONE

Problem still remain doesnt work if i change the port to 5433
It is still throwning same error

Don't change the port.

Copy database.yaml /root/.msf4
Restart the postgre

yes!! i did but still having error

On Fri, Jul 20, 2018 at 9:05 AM, Myo Soe notifications@github.com wrote:

Don't change the port.

Copy database.yaml /root/.msf4
Restart the postgre


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/rapid7/metasploit-framework/issues/9386#issuecomment-406477437,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AcyNENMgzWnrpBKsPgwRHgd__Uje-zndks5uIUxsgaJpZM4RWYEz
.

solution from nilay worked for me thanks a lot

i need help on the same issue. the database connection problem
and if i may ask is it important to connect to the database

@thereavercode the database is useful for storing things like credentials, identified hosts, identified network services, etc. It's not strictly a requirement.

Rather than use a .yml configuration file, you can also connect to the database manually, provided you know the username, password, and database name:

msf > db_connect msf:[email protected]:5432/msf

BRO TRUST ME
just wait for few more minutes the metasploit automatically starts and you can start using msfconsole
proof
screenshot 166

Thanks... Post helped a lot...

Im trying to see if my wife is cheating on me but i dont understand this that well. Ive installed phonesploit but unabe to connect her ip

Unless your target has consented, this would be a violation of law. Another violation of law is posting an unrelated question for guidance to a closed issue on GitHub.

Im trying to see if my wife is cheating on me but i dont understand this that well. Ive installed phonesploit but unabe to connect her ip

https://www.reddit.com/r/relationships/

service postgresql start

Thanks alot
Problem solved

Perfect Solution

  1. Start PostGreSQL: # systemctl _restart_ postgresql
  2. Make sure it is working properly: # systemctl _status_ postgresql
  3. Now you should be listening on ports 5432 & 5433: # ss -ant
  4. Reinitialize DB Settings (user, config files, msfdb): # msfdb _reinit_
  5. Finally, launch MSF: # msfconsole

I've done everything listed in here, nothing worked.

I have tried everything here and followed numerous videos, but can't seem to resolve this. Any other suggestions?

Below are some pics of results from after following steps:

image

image

Put the Postgresql service to start with the boot:
sudo update-rc.d postgresql enable

And start the postgresql service:
service postgresql start or /etc/init.d/postgresql start.

@nilay121
I solved the problem exactly by following the guide, it's perfect !!
;)

But I am using windows 10 to use metasploit (I also got same problem....) , what should I do

Was this page helpful?
0 / 5 - 0 ratings