# JDBC does not create .logstash\_jdbc\_last\_run

**URL:** <https://discuss.elastic.co/t/jdbc-does-not-create-logstash-jdbc-last-run/37334>\
**Category:** Logstash\
**Created:** [December 16, 2015, 9:56am UTC](https://discuss.elastic.co/t/jdbc-does-not-create-logstash-jdbc-last-run/37334 "2015-12-16T09:56:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aviv.ratzon](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@aviv.ratzon](https://discuss.elastic.co/u/aviv.ratzon)\
**Post date:** [December 16, 2015, 9:56am UTC](https://discuss.elastic.co/t/jdbc-does-not-create-logstash-jdbc-last-run/37334/1 "2015-12-16T09:56:00Z")

</div>

Everything worked OK, until I made some change I guess.  
I tried everything - different computer, different conf, redownloading the logstash and the plugin. It just won't create the file. I tried specifying another path but it outputs an error of premission denied.  
Running on windows 7 machine.  
my conf:

> input {  
> jdbc {  
> jdbc\_driver\_library =\> "ojdbc7.jar"  
> jdbc\_driver\_class =\> "Java::oracle.jdbc.driver.OracleDriver"  
> jdbc\_connection\_string =\> "\*\*\*\*\*\*\*\*\*\*\*\*_"  
> jdbc\_user =\> "\*\***"  
> jdbc\_password =\> "**"  
> #schedule =\> "_ \* \* \* \*"  
> statement =\> "SELECT \* FROM BUG WHERE to\_date(bg\_vts, 'YYYY-MM-DD HH24:MI:SS') \> :sql\_last\_start"  
> }  
> }  
> filter {  
> date {  
> match =\> ["bg\_vts", "YYYY-MM-dd HH:mm:ss"]  
> }  
> #if %{DATE} in [bg\_closing\_date]  
> ruby {  
> code =\> "event['duration'] = (event['bg\_closing\_date'] - event['bg\_detection\_date'])"  
> }  
> }  
> output {  
> elasticsearch {  
> hosts =\> "127.0.0.1:9201"  
> index =\> "logstash-oracle"  
> # document\_id =\> "%{bg\_bug\_id}"  
> # action =\> update  
> }  
> stdout{}  
> }

The solution is here:

> <https://github.com/logstash-plugins/logstash-input-jdbc/issues/88>
>
> The only shutdown method implemented is "stop". You also need to implement "clos…e". Sometimes "stop" isn't called and only "close" is. If you run logstash from the command line to do an import of data into elasticsearch, and at a future date want to run it again, but using the sql\_last\_start (like a monthly/weekly/daily job or something) then it'll never invoke the "stop" method of the plugin.
> 
> You should add the YAML.dump() command to the "close" method. I think the "stop" method shouldn't ever be used for this purpose, as it's not reliable.
> 
> This is what I did to just get my instance working now.
> 
> I added this to inputs/jdbc.rb below the "stop" method.
> 
> \`\`\`
> def close
> puts "closing"
> # update state file for next run
> if @record\_last\_run
> File.write(@last\_run\_metadata\_path, YAML.dump(@sql\_last\_start))
> end
> 
> close\_jdbc\_connection
> end
> \`\`\`

adding this code to inputs/jdbc.rb below the "stop" method:

> def close  
> puts "closing"
> 
> # update state file for next run
> 
> if @record\_last\_run  
> File.write(@last\_run\_metadata\_path, YAML.dump(@sql\_last\_start))  
> end

> close\_jdbc\_connection  
> end

---

<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, 5:17am UTC](https://discuss.elastic.co/t/jdbc-does-not-create-logstash-jdbc-last-run/37334/2 "2017-07-06T05:17:47Z")

</div>


