# About logstash jdbc input

**URL:** https://discuss.elastic.co/t/about-logstash-jdbc-input/159697
**Category:** Logstash
**Created:** [December 6, 2018, 9:30am UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697 "2018-12-06T09:30:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![supermario](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@supermario](https://discuss.elastic.co/u/supermario)
#### Post date: [December 6, 2018, 9:30am UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697/1 "2018-12-06T09:30:09Z")

</div>

I have a mysql database . A big table have 2000 billion rows records.  
I create a config file and use jdbc input, content:

input {  
jdbc {  
jdbc\_driver\_library =\> "/usr/share/logstash/jars/mysql-connector-java-5.1.47.jar"  
jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
jdbc\_connection\_string =\> "jdbc:mysql://_._._._:3306/mydatabase"  
jdbc\_user =\> "root"  
jdbc\_password =\> "pawwrod"  
use\_column\_value =\> true  
tracking\_column=\> "ID"  
tracking\_column\_type=\> "numeric"  
jdbc\_paging\_enabled =\> true  
statement =\> "SELECT \* from mytable where ID \>:sql\_last\_value "  
}  
}

I know ,not set schedule , then the statement is run exactly once.it only init my data.

My question is when this job is finish. I modify config,set schedule '0 0 \*/1 \* \*'(one day execute one times ). Whether Last\_value from the last execution.

My goal is to initialize the data.Then perform the task regularly.

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [December 6, 2018, 11:50am UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697/2 "2018-12-06T11:50:13Z")

</div>

You probably want to set `last_run_metadata_path` to a file you are in control of, this file will hold the ID last used as `sql_last_value`.

2000 billion rows is a lot to process - it will take many hours and things can go wrong.

It may be better to run, say, 10 logstash instances with each one loading a smaller subset of the IDs.

Each LS instance will still write the sql\_last\_value to the file, so if say on LS 2 that is doing `where ID >= 1000000 AND ID < 2000000` something goes wrong after doing ID of 1234567 then you can change the statement to `where ID > 1234567 AND ID < 2000000` and so on.

When those 10 are done then change the values in each statement to the next set.

---

<div class="post-metadata">

### Author: ![supermario](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@supermario](https://discuss.elastic.co/u/supermario)
#### Post date: [December 6, 2018, 1:09pm UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697/3 "2018-12-06T13:09:21Z")

</div>

thanks your reply, `sql_last_value` parameter in the form of a metadata file stored in the configured `last\_run\_metadata\_path(quote logstash documention). so,i can set last\_run\_metadata\_path to max id,when the init job finish?

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [December 6, 2018, 6:08pm UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697/4 "2018-12-06T18:08:12Z")

</div>

Yes.

---

<div class="post-metadata">

### Author: ![supermario](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@supermario](https://discuss.elastic.co/u/supermario)
#### Post date: [December 7, 2018, 1:04am UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697/5 "2018-12-07T01:04:24Z")

</div>

thanks

---

<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: [January 4, 2019, 1:04am UTC](https://discuss.elastic.co/t/about-logstash-jdbc-input/159697/6 "2019-01-04T01:04:25Z")

</div>

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