Logstash(docker) unable to connect database. Error => Unable to connect to database. Tried 1 times {:message=>Java::OrgPostgresqlUtil::PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections., :exception=>Sequel::DatabaseConnectionError
logstash.conf file:
input{
jdbc {
jdbc_driver_library => '/usr/share/logstash/logstash-core/lib/jars/postgresql-42.5.0.jar'
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql://localhost:2022/testdb"
jdbc_user => "postgres"
jdbc_password => "12345"
statement => "SELECT * FROM users"
schedule => "* * * * *"
}
}
output {
elasticsearch {
hosts => "elasticsearch:9200"
index => "%{indexName}"
}
}
logstash.yml file:
http.host: "0.0.0.0"
path.config: /usr/share/logstash/pipeline
xpack.monitoring.elasticsearch.hosts: ["localhost:9200"]
xpack.monitoring.enabled: true
How can i connect to database?
I fixed this problem as follows =>
1-)My postgreSQL port is "2022" so i changed IPV4 port=127.0.0.1/22 in pg_hba.conf file.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/22 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/22 trust
host replication all ::1/128 trust
host all all all md5
2-) Use computer ip address(ipconfig) instead of localhost=
old= jdbc:postgresql://localhost:2022/testdb
new= jdbc:postgresql://192.168.1.83:2022/testdb