Logstash cannot connect to my postgresql database, they are both running in docker containers on the same compose network

I am looking for a help, I am struggling with connecting Logstash to my postgres db, they are both running on the same docker compose network and the connection string I passed works from my application which is running in the container on the same network as well,
This is my logstash.conf file:

input {
  jdbc {
    jdbc_connection_string => "jdbc:postgres://sola_db_container:5432/sola_development"
    jdbc_user => "sola"
    jdbc_password => "sola"
    jdbc_driver_library => "/usr/share/logstash/logstash-core/lib/jars/postgresql-42.6.0.jar"
    jdbc_driver_class => "org.postgresql.Driver"
    statement => "SELECT * from users;"
    schedule => "* * * * *"
  }
}

filter {
}

output {
  elasticsearch {
    index => "logstash-%{+YYYY.MM.dd}"
    hosts=> "${ELASTIC_HOSTS}"
    user=> "${ELASTIC_USER}"
    password=> "${ELASTIC_PASSWORD}"
    cacert=> "certs/ca/ca.crt"
  }
}

The error message that I am getting in the terminal is:

[2023-09-23T09:19:32,750][ERROR][logstash.inputs.jdbc     ][main] Unable to connect to database. Tried 1 times {:message=>"Sequel::DatabaseError: driver.new.connect returned nil: probably bad JDBC connection string", :exception=>Sequel::DatabaseConnectionError, :cause=>#<Sequel::DatabaseError: driver.new.connect returned nil: probably bad JDBC connection string>, :backtrace=>["/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/adapters/jdbc.rb:238:in `connect'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/database/connecting.rb:248:in `new_connection'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/connection_pool.rb:161:in `make_new'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/database/connecting.rb:293:in `synchronize'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/database/connecting.rb:302:in `test_connection'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/database/misc.rb:188:in `initialize'", "org/jruby/RubyClass.java:904:in `new'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/database/connecting.rb:57:in `connect'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/sequel-5.71.0/lib/sequel/core.rb:124:in `connect'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/logstash-integration-jdbc-5.4.4/lib/logstash/plugin_mixins/jdbc/jdbc.rb:123:in `block in jdbc_connect'", "org/jruby/RubyKernel.java:1586:in `loop'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/logstash-integration-jdbc-5.4.4/lib/logstash/plugin_mixins/jdbc/jdbc.rb:120:in `jdbc_connect'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/logstash-integration-jdbc-5.4.4/lib/logstash/plugin_mixins/jdbc/jdbc.rb:163:in `open_jdbc_connection'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/logstash-integration-jdbc-5.4.4/lib/logstash/inputs/jdbc.rb:309:in `register'", "/usr/share/logstash/vendor/bundle/jruby/3.1.0/gems/logstash-mixin-ecs_compatibility_support-1.3.0-java/lib/logstash/plugin_mixins/ecs_compatibility_support/target_check.rb:48:in `register'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:237:in `block in register_plugins'", "org/jruby/RubyArray.java:1987:in `each'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:236:in `register_plugins'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:395:in `start_inputs'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:320:in `start_workers'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:194:in `run'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:146:in `block in start'"]}

Am I doing anything wrong? I will appreciate any help!

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