# Do not update sql\_last\_value when an Elastic error is encountered

**URL:** <https://discuss.elastic.co/t/do-not-update-sql-last-value-when-an-elastic-error-is-encountered/263788>\
**Category:** Logstash\
**Created:** [February 9, 2021, 5:40pm UTC](https://discuss.elastic.co/t/do-not-update-sql-last-value-when-an-elastic-error-is-encountered/263788 "2021-02-09T17:40:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSmith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ksmith/32/83666_2.png) [@KSmith](https://discuss.elastic.co/u/KSmith)\
**Post date:** [February 9, 2021, 5:40pm UTC](https://discuss.elastic.co/t/do-not-update-sql-last-value-when-an-elastic-error-is-encountered/263788/1 "2021-02-09T17:40:47Z")

</div>

```
input {
    jdbc {
        jdbc_driver_library => "/usr/share/logstash/drivers/jdbc/${PG_DRIVER}"
        jdbc_driver_class => "org.postgresql.Driver"
        jdbc_connection_string => "jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}?user=${DATABASE_USER}"
        jdbc_user => "${DATABASE_USER}"
        jdbc_password => "${DATABASE_PASSWORD}"
        schedule => "* * * * *"
        statement_filepath => "/usr/share/logstash/inputs/query.sql"
        clean_run => true
        last_run_metadata_path => "/usr/share/logstash/.logstash_jdbc_last_run"
    }
}

```

My logstash.cgf file uses the above input to query a postgres database and send the results to Elastic. The query itself uses the sql\_last\_value to only ingest new data. However, if logstash loses the connection to elastic the sql\_last\_value continues to update resulting in lost data when the elastic connection is reestablished.

Is there anyway to keep sql\_last\_value from updating when an elastic error is encountered?

Thank you in advance,  
K Smith

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 9, 2021, 5:46pm UTC](https://discuss.elastic.co/t/do-not-update-sql-last-value-when-an-elastic-error-is-encountered/263788/2 "2021-02-09T17:46:26Z")

</div>

> [@KSmith](#):
>
> Is there anyway to keep sql\_last\_value from updating when an elastic error is encountered?

No. The input updates sql\_last\_value when the query is complete, it has no way to know what happens at the other end of the pipeline.

---

<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:** [March 9, 2021, 5:47pm UTC](https://discuss.elastic.co/t/do-not-update-sql-last-value-when-an-elastic-error-is-encountered/263788/3 "2021-03-09T17:47:05Z")

</div>

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