# Logstash jdbc using tns results in error "Unknown host specified"

**URL:** <https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498>\
**Category:** Logstash\
**Created:** [April 30, 2020, 8:19am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498 "2020-04-30T08:19:32Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [April 30, 2020, 8:19am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/1 "2020-04-30T08:19:32Z")

</div>

Hello,

I try to use jdbc to connect to my oracle server using tns.  
logstash.conf:

> input {  
> jdbc {  
> jdbc\_driver\_library =\> ""  
> jdbc\_driver\_class =\> "Java::oracle.jdbc.driver.OracleDriver"  
> jdbc\_connection\_string =\> "jdbc:oracle:thin:@DONSC01"  
> jdbc\_user =\> "user"  
> jdbc\_password=\> "password"  
> schedule =\> "\* \* \* \* \*"  
> statement =\> "SELECT \* from TBL\_CRE"  
> }  
> }  
> output{  
> stdout{codec =\> rubydebug}  
> }

the error:

> [2020-04-30T10:14:00,726][ERROR][logstash.inputs.jdbc][main] Unable to connect to database. Tried 1 times {:error\_message=\>"Java::JavaSql::SQLRecoverableException: IO Error: Unknown host specified "}

And when i do `tnsping DONSC01` I have a good response therefore I really don't know what the issue can be. I hope you can help me with that 😉

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 30, 2020, 9:36am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/2 "2020-04-30T09:36:40Z")

</div>

Can you please provide the exact configuration?

It seems you're not providing the `jdbc_driver_library` path to the `jar`.

One example (replace `<db_name>` and `<path to>`):

```auto
input {
    jdbc {
        jdbc_connection_string => "jdbc:oracle:thin:@DONSC01:1521/<db_name>"
        jdbc_user => "user"
        jdbc_password => "password"
        jdbc_driver_library => "<path to>/ojdbc8.jar"
        jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
        statement => "SELECT * from TBL_CRE"
        schedule => "* * * * *"
       }
}

```

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [April 30, 2020, 4:36pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/4 "2020-04-30T16:36:10Z")

</div>

Hello,  
Yes sorry about that, the jdbc that i am using is ojdbc7.jar I did put it direcly in logstash as is specified in the doc ([https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html#plugins-inputs-jdbc-jdbc\_driver\_library](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html#plugins-inputs-jdbc-jdbc_driver_library)) .  
By the way I thought I did not need to adda anything after the `jdbc:oracle:thin:@DONSC01` cause it is a tns connection as explainned here: [http://www.orafaq.com/wiki/JDBC#Thin\_driver](http://www.orafaq.com/wiki/JDBC#Thin_driver)

---

<div class="post-metadata">

**Author:** ![Luca\_Belluccini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luca_belluccini/32/33239_2.png) [@Luca\_Belluccini](https://discuss.elastic.co/u/Luca_Belluccini)\
**Post date:** [April 30, 2020, 6:28pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/5 "2020-04-30T18:28:23Z")

</div>

Can you enable the debug logs in Logstash and see if you have more details? Have you tried providing the IP instead?

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [April 30, 2020, 6:38pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/6 "2020-04-30T18:38:34Z")

</div>

Thanks for the reply, unfortunatly I do not have access to the IP for security reason(my company policy . . . ), I only know the tns name of the database. As soon as I can I will enable the debug to try to have more details.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 30, 2020, 6:43pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/7 "2020-04-30T18:43:28Z")

</div>

you need to copy ojdbc8.jar to /usr/share/logstash/logstash-core/lib/jars dir.  
and remove jdbc\_driver\_library.  
you only need jdbc\_driver\_class

```
    #jdbc_driver_library => "/usr/lib/oracle/12.2/client64/lib/ojdbc8.jar"
    jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
```

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [May 5, 2020, 8:03am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/8 "2020-05-05T08:03:40Z")

</div>

I already did put ojdbc8.jar to /usr/share/logstash/logstash-core/lib/jars dir. Removing the jdbc\_driver\_library or leaving it empty doesn't seem to change anything.

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [May 5, 2020, 8:06am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/9 "2020-05-05T08:06:13Z")

</div>

HI , I enabled debug fot jdb input but I don't think thats of any help :

```
> [2020-05-05T10:01:20,882][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_user = "NSC_TOM"
[2020-05-05T10:01:20,883][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@schedule = "* * * * *"
[2020-05-05T10:01:20,886][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_password = <password>
[2020-05-05T10:01:20,887][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@statement = "SELECT * from TBL_CRE"
[2020-05-05T10:01:20,888][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_connection_string = "jdbc:oracle:thin:@DONSC01"
[2020-05-05T10:01:20,889][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@id = "5fdf26f7ea5b4333d4fab5d495f8066ac6acd1f0d95b985d69caaced9e4f914d"
[2020-05-05T10:01:20,890][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_driver_class = "Java::oracle.jdbc.driver.OracleDriver"
[2020-05-05T10:01:20,894][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@enable_metric = true
[2020-05-05T10:01:20,902][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@codec = <LogStash::Codecs::Plain id=>"plain_3681cce0-5030-4a08-93d4-c45d49d2f782", enable_metric=>true, charset=>"UTF-8">
[2020-05-05T10:01:20,904][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@add_field = {}
[2020-05-05T10:01:20,905][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_paging_enabled = false
[2020-05-05T10:01:20,906][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_page_size = 100000
[2020-05-05T10:01:20,907][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_validate_connection = false
[2020-05-05T10:01:20,908][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_validation_timeout = 3600
[2020-05-05T10:01:20,909][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@jdbc_pool_timeout = 5
[2020-05-05T10:01:20,910][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@sequel_opts = {}
[2020-05-05T10:01:20,911][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@sql_log_level = "info"
[2020-05-05T10:01:20,912][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@connection_retry_attempts = 1
[2020-05-05T10:01:20,913][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@connection_retry_attempts_wait_time = 0.5
[2020-05-05T10:01:20,914][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@plugin_timezone = "utc"
[2020-05-05T10:01:20,915][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@parameters = {}
[2020-05-05T10:01:20,916][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@last_run_metadata_path = "/projets/nsc/home/nscusrm1/.logstash_jdbc_last_run"
[2020-05-05T10:01:20,917][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@use_column_value = false
[2020-05-05T10:01:20,918][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@tracking_column_type = "numeric"
[2020-05-05T10:01:20,919][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@clean_run = false
[2020-05-05T10:01:20,920][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@record_last_run = true
[2020-05-05T10:01:20,921][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@lowercase_column_names = true
[2020-05-05T10:01:20,922][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@columns_charset = {}
[2020-05-05T10:01:20,922][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@use_prepared_statements = false
[2020-05-05T10:01:20,923][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@prepared_statement_name = ""
[2020-05-05T10:01:20,924][DEBUG][logstash.inputs.jdbc] config LogStash::Inputs::Jdbc/@prepared_statement_bind_values = []
```

---

<div class="post-metadata">

**Author:** ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)\
**Post date:** [May 5, 2020, 8:47am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/10 "2020-05-05T08:47:03Z")

</div>

are you able to ping DONSC01 from your logstash cli ? have you tried replacing the DONSC01 with the ip address ? unknown host error seems to be name resolution rather than sql error

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [May 5, 2020, 8:50am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/11 "2020-05-05T08:50:43Z")

</div>

I don't know how to ping with logstash cli, I did use tsnping and that worked.

---

<div class="post-metadata">

**Author:** ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)\
**Post date:** [May 5, 2020, 8:54am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/12 "2020-05-05T08:54:53Z")

</div>

afaik, tnsping uses oracle configurationtry replacing DONSC01 with the ip address of DONSC01 and see if that helps

what’s the content of tnsnames.ora for DONSC01?

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [May 5, 2020, 9:49am UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/13 "2020-05-05T09:49:30Z")

</div>

I have limited access to the machine and I do not know the ip of the oracle database. In $ORACLE\_HOME/network/admin there is no TSNnames.ora, only a sqlnet.ora containing:

> ```
> # sqlnet.ora Network Configuration File: /soft/oracle/product/client/12.2/network/admin/sqlnet.ora
> # Generated by Oracle configuration tools.
> 
> NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
> 
> ```

---

<div class="post-metadata">

**Author:** ![ptamba](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@ptamba](https://discuss.elastic.co/u/ptamba)\
**Post date:** [May 5, 2020, 12:58pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/14 "2020-05-05T12:58:41Z")

</div>

if you have access to the shell where logstash is installed, are you able to ping the dbserver using hostname (DONSC01)

---

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [May 5, 2020, 1:13pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/15 "2020-05-05T13:13:24Z")

</div>

When I tnsping inside logstash directory it works(returns : `OK (10 msec)` )

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [May 5, 2020, 8:11pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/16 "2020-05-05T20:11:47Z")

</div>

what is the error message?

are you running this from command line as test?  
/usr/share/logstash/bin/logstash -f

this I dont think has anything to do with ip/name

but you can find out ip by just typing  
host donsc01 or nslookup donsc01

---

<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:** [June 2, 2020, 8:11pm UTC](https://discuss.elastic.co/t/logstash-jdbc-using-tns-results-in-error-unknown-host-specified/230498/17 "2020-06-02T20:11:49Z")

</div>

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