Metasploit database postgresql connection error

Briefly describe your issue below:
Trying to initialize the metasploit database I get this error, I have been searching for a fix all day and haven’t been able to find one. This is a fresh setup of parrot on virtual box, nothing has been done to it. Also previously when I did a fresh setup of parrot I looked at the port for the postgresql server as some posts said the port would be wrong but it was right. I have no clue what is wrong with metasploit.

What version of Parrot are you running? (include version (e.g. 4.6), edition(e.g. Home//KDE/OVA, etc.), and architecture (currently we only support amd64)
Security 4.9.1 OVA

What method did you use to install Parrot? (Debian Standard / Debian GTK / parrot-experimental)
Virtual box ova

Configured to multiboot with other systems? (yes / no)
Don’t know what that is

If there are any similar issues or solutions, link to them below:
Haven’t found any

If there are any error messages or relevant logs, post them below:

┌─[✗]─[user@parrot]─[~]
└──╼ $sudo service postgresql start
┌─[user@parrot]─[~]
└──╼ $sudo msfdb init
[i] Database already started
psql: error: could not connect to server: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
[+] Creating database user 'msf'
createuser: error: could not connect to database postgres: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
psql: error: could not connect to server: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
[+] Creating databases 'msf'
createdb: error: could not connect to database template1: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
psql: error: could not connect to server: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
[+] Creating databases 'msf_test'
createdb: error: could not connect to database template1: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
[+] Creating configuration file '/usr/share/metasploit-framework/config/database.yml'
[+] Creating initial database schema
rake aborted!
PG::ConnectionBad: 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?
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/connection_handling.rb:87:in `connection'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:941:in `initialize'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:823:in `new'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:823:in `up'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/migration.rb:801:in `migrate'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/tasks/database_tasks.rb:139:in `migrate'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/activerecord-4.2.11.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/share/metasploit-framework/vendor/bundle/ruby/2.7.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
┌─[✗]─[user@parrot]─[~]
└──╼ $

I can confirm this is still an issue but I have figured out how to resolve it. I reinstalled parrot OS today, dual booted alongside windows without issues. Version 4.10.

Steps:

  1. Fresh install of ParrotOS 4.10
  2. Connected to network, ran “sudo parrot-upgrade”, then rebooted.
  3. Noticed postgresql was not running.
  4. /var/log/postgresql/postgresql-12-main.log showed “FATAL: could not load server certificate file “/etc/ssl/certs/ssl-cert-snakeoil.pem”: No such file or directory”
  5. Regenerated the snakeoil cert with “sudo make-ssl-cert generate-default-snakeoil”
  6. Rebuilt the database “sudo msfdb reinit”
  7. Afterwards I was able to confirm the db was connected to metasploit after launching the console with “db_status”.

I hope this helps!
-Rick

2 Likes

Came here to say exactly this.

After not finding alot online about the issue, I used tail to monitor the log file, and then found that it was being stopped in it’s track by a certificate that doesn’t exist.

You can totally do this, and it works just fine after a service restart. Another option is to simply disable SSL in /etc/postgresql/12/main/postgresql.conf if you aren’t bothered about having a certificate for whatever reason (obviously this depends on how comfortable with that you are):

#-SSL-

ssl = off
#ssl_ca_file = ‘’
#ssl_cert_file = ‘/etc/ssl/certs/ssl-cert-snakeoil.pem’
#ssl_crl_file = ‘’
#ssl_key_file = ‘/etc/ssl/private/ssl-cert-snakeoil.key’
#ssl_ciphers = ‘HIGH:MEDIUM:+3DES:!aNULL’ # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = ‘prime256v1’
#ssl_min_protocol_version = ‘TLSv1’
#ssl_max_protocol_version = ‘’
#ssl_dh_params_file = ‘’
#ssl_passphrase_command = ‘’
#ssl_passphrase_command_supports_reload = off

1 Like

Thank you for sharing these fixes; I had tried a few other things before stumbling across this!

thanks that really helped alot

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.