# :sql\_last\_value doesn't reiterate with multiple jdbc inputs

**URL:** https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523
**Category:** Logstash
**Created:** [October 20, 2016, 3:10pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523 "2016-10-20T15:10:49Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![wmedlen](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@wmedlen](https://discuss.elastic.co/u/wmedlen)
#### Post date: [October 20, 2016, 3:10pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/1 "2016-10-20T15:10:49Z")

</div>

I hope my title wasn't confusing -

we have 2 jdbc inputs in our logstash config, one that pulls a commentid and one that pulls a messageid from our application.

the messageid does not get added to logstash _unless_ I put the id into logstash.conf directly; after running logstash in debug mode and sending the output to a file, the ouput shows that the messageid used by :sql\_last\_value is equal to the commentid, not the messagid.

What appears to be happening is, like a variable, logstash is using the first value of :sql\_last\_value, instead of 'updating' it on the next sql command/jdbc input.

I should still have this ouput saved, i just havent run logstash in debug mode in a while because it is in our production environment; dev doesn't have enough usable data.

I can include this output if need be, or re-run logstash in debug mode.

I hope this was clear...

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [October 23, 2016, 4:52pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/2 "2016-10-23T16:52:25Z")

</div>

Did you set the `last_run_metadata_path` option to unique values for each input so that Logstash doesn't read/write to the same file for both inputs?

---

<div class="post-metadata">

### Author: ![dzondo](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dzondo](https://discuss.elastic.co/u/dzondo)
#### Post date: [October 24, 2016, 9:37am UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/3 "2016-10-24T09:37:54Z")

</div>

Hi there,

I've encountered the same issue as @wmedlen. I have two jdbc inputs, two distinct tables with their own ID-s and only 1 sql\_last\_value parameter gets stored in the .logstash\_jdbc\_last\_run file. From your comment @magnusbaeck I realize in this case we should have two distinct metadata paths specified by which every statement will use it's own value, so thanks for clarifying. I am pretty sure that most people with multiple jdbc inputs will run into the same problem, since all the solutions on stackoverflow etc. mention adding multiple inputs but none of them mentions how to deal with the sql\_last\_value and the last\_run\_metadata\_path in this case.

The funny thing is that everything's been working fine for quite a a while, apparently because it was always the lower ID from the two tables that was being saved. Only after a recent server restart have the things "turned around" and I realized that something was fishy, since recent records from one table were missing.

Although it (now 🙂) makes total sense and there is an obvious workaround, I would suggest to  
a) either update the docs to include some instructions regarding handling multiple inputs in one file or  
b) change the behaviour of the plugin to keep separate per-input sql\_last\_value parameters.

If you think a) is enough I could go ahead and prepare a PR for the docs part. Let me know what you think.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [October 24, 2016, 10:39am UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/4 "2016-10-24T10:39:10Z")

</div>

Implementing b) requires some care and would probably not be backwards compatible so starting with a) sounds very reasonable.

---

<div class="post-metadata">

### Author: ![wmedlen](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@wmedlen](https://discuss.elastic.co/u/wmedlen)
#### Post date: [October 24, 2016, 3:16pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/5 "2016-10-24T15:16:51Z")

</div>

This is perfect. I simply set two separate directories with each file. By the way, simply setting the path did not work; I had to specify the filename in the logstash.conf to point to the actual file. For example,

> last\_run\_metadata\_path =\> "/path/to/directory"

produced this error:

> :message=\>"Pipeline aborted due to error", :exception=\>#\<Errno::EISDIR: Is a directory

but

> last\_run\_metadata\_path =\> "/path/to/directory/.logstash\_jdbc\_last\_run"

worked like a charm.

I think that @dzondo is correct; while i did read over the documentation (carefully, I thought), adding a bit in there about multiple, separate paths for each jdbc input would be extremely helpful.

Thanks for all of your help guys. These forums have really helped us out a lot. I work on a very small team and have to wear many hats. We use the Elasticstack to keep logs for government mandated security procedures and this has literally saved us tons of time and money. Thanks again.

---

<div class="post-metadata">

### Author: ![dzondo](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dzondo](https://discuss.elastic.co/u/dzondo)
#### Post date: [October 25, 2016, 12:35pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/6 "2016-10-25T12:35:33Z")

</div>

Hi Kyle,

Yes, the "path" in there kind of implies that it is a directory, but as you've found out it actually points to a file. So you don't even need to keep two separate directories, if you don't want to. You can have for example:

> (in query 1): last\_run\_metadata\_path =\> "/path/to/directory/my\_great\_last\_run\_info\_for\_query\_1.txt"  
> (in query 2): last\_run\_metadata\_path =\> "/path/to/directory/my\_great\_last\_run\_info\_for\_query\_2.txt"

Not that it really matters though 🙂

Magnus,

thanks for your feedback. I'll put together a PR for the doc fix in the next day or two.

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [October 25, 2016, 12:49pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/7 "2016-10-25T12:49:58Z")

</div>

> Yes, the "path" in there kind of implies that it is a directory

A "path" describes the location of a resource. Nothing is said about the kind of resource.

---

<div class="post-metadata">

### Author: ![dzondo](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dzondo](https://discuss.elastic.co/u/dzondo)
#### Post date: [October 30, 2016, 10:28pm UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/8 "2016-10-30T22:28:44Z")

</div>

Hi, I've prepared a [PR](https://github.com/logstash-plugins/logstash-input-jdbc/pull/175) for the doc update. Hope it saves somebody troubleshooting time in the future.

---

<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: [July 6, 2017, 4:31am UTC](https://discuss.elastic.co/t/sql-last-value-doesnt-reiterate-with-multiple-jdbc-inputs/63523/9 "2017-07-06T04:31:58Z")

</div>


