# Last run reflect in db is possible or not?

**URL:** <https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895>\
**Category:** Logstash\
**Created:** [July 6, 2018, 10:58am UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895 "2018-07-06T10:58:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokul\_15](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Gokul\_15](https://discuss.elastic.co/u/Gokul_15)\
**Post date:** [July 6, 2018, 10:58am UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/1 "2018-07-06T10:58:43Z")

</div>

i have created config file in that i have coded such that for every 2mins my db is called ,it works perfectly...  
and i have have column name "date(TImestamp) in db : eg:2018-07-06 11:11:19.754371",  
i have to overwrite r update the value of timestamp with new timestamp..  
any suggestion??  
my code is:  
input {  
jdbc {  
jdbc\_connection\_string =\> "jdbc:postgresql://localhost:5432/postgres"  
jdbc\_user =\> "postgres"  
jdbc\_password =\>"xxx"  
jdbc\_driver\_library =\> "C:\logstash-6.3.0\postgresql-42.2.2.jar"  
jdbc\_driver\_class =\> "org.postgresql.Driver"  
last\_run\_metadata\_path =\> 'C:\xx\xx.logstash\_jdbc\_last\_run'  
record\_last\_run =\> true  
jdbc\_paging\_enabled =\> "true"  
jdbc\_page\_size =\> "50000"  
schedule =\>'\*/2 \* \* \* \*'

```
	 statement => "SELECT * from contacts where date > :sql_last_value"   
	  }

```

}  
output{  
stdout{ }  
}

---

<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:** [July 6, 2018, 11:37am UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/2 "2018-07-06T11:37:01Z")

</div>

You want to update the timestamp column in the database each time Logstash has run? There's no trivial support for that, unless you perhaps can call a stored procedure that performs the update but also returns the result set of a select query.

---

<div class="post-metadata">

**Author:** ![Gokul\_15](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Gokul\_15](https://discuss.elastic.co/u/Gokul_15)\
**Post date:** [July 6, 2018, 11:47am UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/3 "2018-07-06T11:47:16Z")

</div>

is it possible to save records in file rather than procedure??if so?? how?? shall v use template??

---

<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:** [July 6, 2018, 12:44pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/4 "2018-07-06T12:44:48Z")

</div>

Save which records? The timestamp? Did you read everything that's said about the `sql_last_value` query parameter in the jdbc input documentation?

---

<div class="post-metadata">

**Author:** ![Gokul\_15](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Gokul\_15](https://discuss.elastic.co/u/Gokul_15)\
**Post date:** [July 6, 2018, 12:47pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/5 "2018-07-06T12:47:52Z")

</div>

output{  
file{  
path=\>"C:\logstash-6.3.0\map.log"  
}  
} i have done like this,but data is not posted on the specific map.log file

---

<div class="post-metadata">

**Author:** ![Gokul\_15](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Gokul\_15](https://discuss.elastic.co/u/Gokul_15)\
**Post date:** [July 6, 2018, 12:48pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/6 "2018-07-06T12:48:58Z")

</div>

output{  
file{  
path=\>"C:\logstash-6.3.0\map.log"  
}  
} i have done like this,but data is not posted on the specific map.log file

---

<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:** [July 6, 2018, 12:51pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/7 "2018-07-06T12:51:41Z")

</div>

If you replace the file output with a `stdout { codec => rubydebug }` output, are you getting anything in the Logstash log?

---

<div class="post-metadata">

**Author:** ![Gokul\_15](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Gokul\_15](https://discuss.elastic.co/u/Gokul_15)\
**Post date:** [July 6, 2018, 12:52pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/8 "2018-07-06T12:52:52Z")

</div>

yes..for every 2 mins it call db  
[2018-07-06T18:18:00,359][INFO][logstash.inputs.jdbc] (0.001542s) SELECT count(_) AS "count" FROM (SELECT \* from contacts where date \> '2018-07-06 18:16:00.080000+0530') AS "t1" LIMIT 1  
[2018-07-06T18:20:00,313][INFO][logstash.inputs.jdbc] (0.000884s) SELECT CAST(current\_setting('server\_version\_num') AS integer) AS v  
[2018-07-06T18:20:00,319][INFO][logstash.inputs.jdbc] (0.001579s) SELECT count(_) AS "count" FROM (SELECT \* from contacts where date \> '2018-07-06 18:18:00.353000+0530') AS "t1" LIMIT 1  
[2018-07-06T18:22:00,270][INFO][logstash.inputs.jdbc] (0.000853s) SELECT CAST(current\_setting('server\_version\_num') AS integer) AS v

---

<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:** [July 6, 2018, 1:09pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/9 "2018-07-06T13:09:19Z")

</div>

Sure, but is that query producing any events in Logstash? If not then nothing will end up in the output file, obviously.

---

<div class="post-metadata">

**Author:** ![Gokul\_15](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Gokul\_15](https://discuss.elastic.co/u/Gokul_15)\
**Post date:** [July 6, 2018, 1:20pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/11 "2018-07-06T13:20:18Z")

</div>

only generation these 🙂  
[2018-07-06T18:20:00,319][INFO][logstash.inputs.jdbc] (0.001579s) SELECT count() AS "count" FROM (SELECT \* from contacts where date \> '2018-07-06 18:18:00.353000+0530') AS "t1" LIMIT 1  
[2018-07-06T18:22:00,270][INFO][logstash.inputs.jdbc] (0.000853s) SELECT CAST(current\_setting('server\_version\_num') AS integer) AS v

---

<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:** [July 6, 2018, 1:27pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/12 "2018-07-06T13:27:12Z")

</div>

_Should_ that query return anything, then? What if you run it from a query console of the database server?

---

<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:** [August 3, 2018, 1:27pm UTC](https://discuss.elastic.co/t/last-run-reflect-in-db-is-possible-or-not/138895/13 "2018-08-03T13:27:13Z")

</div>

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