# Logstash jdbc - unnable to connect to database - plugin restart

**URL:** <https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959>\
**Category:** Logstash\
**Created:** [April 13, 2021, 1:17am UTC](https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959 "2021-04-13T01:17:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![g34ncarlo](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@g34ncarlo](https://discuss.elastic.co/u/g34ncarlo)\
**Post date:** [April 13, 2021, 1:17am UTC](https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959/1 "2021-04-13T01:17:41Z")

</div>

We're running Logstash with jdbc plugin as a Kubernetes cron job. Due to some network problem, eventually it cannot connect to database:

```auto
[ERROR][logstash.inputs.jdbc] Unable to connect to database. Tried 1 times {:error_message=>"Java::JavaSql::SQLRecoverableException: IO Error: Unknown host specified "}

```

And then, plugin is restarted:

```auto
[ERROR][logstash.pipeline] A plugin had an unrecoverable error. Will restart this plugin.

```

Fail and restart cycle can be repeated several times. When the connection is finally succeeded and the pipeline has terminated, Logstash seems to be stalled and the Kubernetes pod doesn't succeed nor fail.

I can add an option like `connection_retry_attempts => 10`, but that doesn't garantee that, at the end of those attempts, if connection fails, the plugin will be restarted.

It seems to me it would be better to get an error and finish Logstash. Is it possible, in some way, to prevent the plugin from being restarted?

```auto
    jdbc {
       jdbc_connection_string => "..."
       jdbc_user => "..."
       jdbc_password => "..."
       jdbc_validate_connection => true
       jdbc_driver_library => "/opt/ojdbc6.jar"
       jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver"
       last_run_metadata_path => "..."
       tracking_column => "..."
       tracking_column_type => "timestamp"
       statement_filepath => "..."
    }

```

---

<div class="post-metadata">

**Author:** ![g34ncarlo](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@g34ncarlo](https://discuss.elastic.co/u/g34ncarlo)\
**Post date:** [April 14, 2021, 8:24pm UTC](https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959/2 "2021-04-14T20:24:32Z")

</div>

Sorry about the "unnable" in the title. Unfortunately, I am unable to edit and correct it.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [April 14, 2021, 8:30pm UTC](https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959/3 "2021-04-14T20:30:38Z")

</div>

Not sure if this is correct but I would try to add a [schedule](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html#plugins-inputs-jdbc-schedule). That way it will try connect based on that schedule. Once an hour or day, whatever you set it for.

> There is no schedule by default. If no schedule is given, then the statement is run exactly once.

---

<div class="post-metadata">

**Author:** ![g34ncarlo](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@g34ncarlo](https://discuss.elastic.co/u/g34ncarlo)\
**Post date:** [April 14, 2021, 10:26pm UTC](https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959/4 "2021-04-14T22:26:24Z")

</div>

@aaron-nimocks, thank you for the answer. But let me try to explain better.

The original idea was really to run the statement exactly once. The schedule is actually dictated by the Kubernetes cron job. At scheduled time, it creates a Logstash Docker instance, Logstash is started and the pipeline is run only once.

In normal operation, when the pipeline has terminated, the Logstash Docker instance is also finished, succeeded or not (eg, with some error). Once it is finished, the cron job is able to create another instance next scheduled time.

With the problem described (after some "unable to connect"/"plugin restart" cycles) the Logstash Docker instance continues running after pipeline has terminated and, at the next scheduled time, Kubernetes can not create another instance.

---

<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:** [May 12, 2021, 10:27pm UTC](https://discuss.elastic.co/t/logstash-jdbc-unnable-to-connect-to-database-plugin-restart/269959/5 "2021-05-12T22:27:19Z")

</div>

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