# Unable to connect to Postgresql installed in local from logstash docker

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-postgresql-installed-in-local-from-logstash-docker/209549>\
**Category:** Logstash\
**Tags:** docker\
**Created:** [November 26, 2019, 4:10pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-postgresql-installed-in-local-from-logstash-docker/209549 "2019-11-26T16:10:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pilo/32/46015_2.png) [@pilo](https://discuss.elastic.co/u/pilo)\
**Post date:** [November 26, 2019, 4:10pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-postgresql-installed-in-local-from-logstash-docker/209549/1 "2019-11-26T16:10:09Z")

</div>

HI everyone,  
I am a beginner in logstash. I'm running Logstash version 7.4.1 on docker.  
I want to create a pipeline as simple as possible to load my database in Postgresql installed in local but i find an error with logstash.

**my logstash config file**

```auto
input {
 jdbc {
         # Postgres jdbc connection string to our database, mydb
         jdbc_connection_string => "jdbc:postgresql://127.0.0.1:5432/logstashtest"
         # The user we wish to execute our statement as
          jdbc_user => "xxx"
          # The path to our downloaded jdbc driver
          jdbc_driver_library => "/home/tnvan/postgresql-42.2.8.jar"
          # The name of the driver class for Postgresql
         jdbc_driver_class => "org.postgresql.Driver"
          jdbc_password => "xxx"
          # our query
          statement => "SELECT * from contacts"                                                                                                                                                           
     }
 }
  
 output {
   stdout { codec => json_lines }
 }

```

The error log:

```auto
[2019-11-26T15:47:53,810][ERROR][logstash.inputs.jdbc] Unable to connect to database. Tried 1 times {:error_message=>"Java::OrgPostgresqlUtil::PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."}
[2019-11-26T15:47:53,814][ERROR][logstash.javapipeline] A plugin had an unrecoverable error. Will restart this plugin.
  Pipeline_id:main
  Plugin: <LogStash::Inputs::Jdbc jdbc_user=>"foo", jdbc_password=><password>, statement=>"SELECT * from contacts", jdbc_driver_library=>"/home/tnvan/postgresql-42.2.8.jar", jdbc_connection_string=>"jdbc:postgresql://127.0.0.1:5432/logstashtest", id=>"6c4aa1be1b9785f024f95401393707ac2c98b6f976b3f003aa849149ca667a74", jdbc_driver_class=>"org.postgresql.Driver", enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_67a76df9-f51f-4cea-8a3b-efc83eef8029", enable_metric=>true, charset=>"UTF-8">, jdbc_paging_enabled=>false, jdbc_page_size=>100000, jdbc_validate_connection=>false, jdbc_validation_timeout=>3600, jdbc_pool_timeout=>5, sql_log_level=>"info", connection_retry_attempts=>1, connection_retry_attempts_wait_time=>0.5, plugin_timezone=>"utc", last_run_metadata_path=>"/usr/share/logstash/.logstash_jdbc_last_run", use_column_value=>false, tracking_column_type=>"numeric", clean_run=>false, record_last_run=>true, lowercase_column_names=>true, use_prepared_statements=>false>
  Error: Java::OrgPostgresqlUtil::PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  Exception: Sequel::DatabaseConnectionError
  Stack: org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(org/postgresql/core/v3/ConnectionFactoryImpl.java:280)

```

I do some google and have changed the config files of postgresql:  
**postgresql.conf**  
`listen_addresses = '*'`  
**pg\_hba.conf**  
`host all all 172.17.0.0/32 trust`  
`host all all 10.0.2.15/32 trust`  
but still the same error.

More information:

```auto
ip addr show 

4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:19:49:0b:27 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:19ff:fe49:b27/64 scope link 
       valid_lft forever preferred_lft forever

```

Thank you all.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 24, 2019, 4:10pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-postgresql-installed-in-local-from-logstash-docker/209549/2 "2019-12-24T16:10:12Z")

</div>

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