EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Logstash Tutorial Logstash JDBC
Secondary Sidebar
Logstash Tutorial
  • Basic
    • What is Logstash?
    • Kibana Logstash
    • Logstash Alternatives
    • Logstash if field exists
    • Logstash Test Config
    • Logstash Date Filter
    • Logstash Version
    • Logstash Filter
    • Logstash Pipeline
    • Logstash Port
    • Logstash Filter JSON
    • Logstash JDBC
    • Logstash Timestamp
    • Logstash Multiline
    • Logstash split
    • Logstash Codec
    • Logstash HTTP input
    • Logstash Filebeat
    • Logstash if
    • Logstash File Input
    • Logstash mutate
    • Logstash Syslog
    • Logstash AWS
    • Logstash.yml
    • Logstash Install Plugin
    • Logstash Geoip
    • Logstash add field
    • Logstash Multiple Pipelines
    • Logstash TCP input
    • Logstash Multiple Outputs
    • Logstash Stdout
    • Logstash Pipeline Configuration
    • Logstash Monitoring
    • LogstashEncoder
    • Logstash CSV
    • Logstash Cluster
    • Logstash Debug

Logstash JDBC

Logstash JDBC

Introduction to Logstash JDBC

Logstash JDBC is an interface that contains various plugins for input and output integration with java database connectivity from Logstash. In this article, we will try to throw a little light on Logstash JDBC by studying the subtopics. how to use Logstash JDBC plugin, Logstash input JDBC and a conclusion about the same.

What is Logstash JDBC?

Logstash JDBC input plugin is the mechanism of accepting all the input from and of the database being used in the JDBC interface and then transferring the same to the Logstash. This process of taking in all the data as input is called ingestion. There is also the provision of scheduling the periodic ingestion of the data according to our requirement with the help of cron syntax. Another functionality available is that we can execute the query once which will then be proceeded with the data loading into the platform of Logstash.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

A corresponding event is created from each and every individual row that is presented in the result set. While for the columns that are present in the result set, corresponding fields of the event are created.

How to use Logstash JDBC?

The parameter named sql_last_value persists the value inside the metadata file. This file is located in the configured path whose value is present in last_run_metadata_path. When the execution of the query has been completed the file of metadata will be updated and the value that is currently stored in the variable sql_last_value is stored in the file.

Again, when the pipeline starts next time, the value is to be fetched from the file itself. When the value of variable clean_run is set to true then the value that is fetched from the file will be ignored and the default value of 1 Jan 1970 whichever is set will be assigned to the state sql_last_value or the value is set to 0 when the value of use_column_value is set to true which means like none of the queries has been executed ever in the system.

When we have large data set in the result, we can make use of the fetch_size parameter which is used for the specification of a number of rows to be prefetched from cursor to cache of the client before going for getting extra data from the result set. In the JDBC input Logstash plugin, we can make use of the same functionality by using JDBC_fetch_size which is the option available in configurations. As there is no specification of the default value of the plugin, Internally, it is set the default size of the specific driver for this purpose.

Let us consider a small example to understand how we can make the use of input plugin. Here, we will be retrieving the data from the MySQL database. The configuration of Logstash for this example will be as shown below –

input {
JDBC {
JDBC_driver_library => "mysql-connector-java-8.0.21-bin.jar"
JDBC_driver_class => "com.mysql.JDBC.Driver"
JDBC_connection_string => "JDBC:mysql://localhost:3306/educbaDatabase"
JDBC_user => "educbaUser"
parameters => { "liked_subject" => "Computer Science" }
schedule => "* * * * *"
statement => "SELECT * from students where fav_subject = :liked_subject"
}
}

In the above example, our user is educbaUser and we are accessing a MySQL database named educbaDatabase. What we are doing here is get all the input rows from the table of students which contain their most liked subject like computer science.

Logstash JDBC Plugin

Logstash JDBC plugin is available for input as well as output. Note that when talking about input JDBC plugins it does not come along with the libraries of JDBC driver into a single package. What we need to do to get this is to make use of the configuration namedJDBC_driver_library option which should be taken and the value of the required library needs to be passed to the plugin option explicitly.

We can schedule the inputs that are received using the input JDBC plugin in a periodic manner which is a feature provided by refers schedular where the periodic scheduling as per the requirements is done as per the syntax mentioned in it. The syntax of refus along with its specifications looks quite similar to that of cron along with certain extensions. Let us consider a sample example, when we write the schedule as 0 * * * *, it will result in the execution of the event for each and every hour at 0th minute for each and every day.

Logstash input JDBC

Logstash input JDBC plugin as discussed above is used for the ingestion of data that is present in any of the databases you are using with the JDBC interface and then transfer the same to the Logstash platform. We can configure the SQL statement by passing it as a string value in the option of statement. Alternatively, we can also configure it by reading the statement_filepath parameter value from the file. When the sql statement is substantially long and complex at that time we can make use of the file option. Note that at a single time the input plugin of Logstash JDBC can accept one option only either from file or from the configuration parameter “statement”.
There are various predefined input configuration options available in the input plugin which can be useful. The below table mentions some of them –

Configuration option Data type Optional or required
Clean_run Boolean Optonal
JDBC_default_timezone String Optional
JDBC_connection_string String Required
JDBC_driver_class String Required
JDBC_user String Required
Use_column_value Boolean Optional
Tracking_column_type String value which can be either timestamp or numeric Optional
Tracking_column String Optional
Target Reference of the field Optional
Use_prepared_statements Boolean Optional
Sequel_opts Hash value Optional
Schedule String Optional
Statement String Optional
Sql_log_level String which can have one of the value from debug, warn, fatal, error, or info. Optional

For a complete reference of the input configurations and their usage and purpose along with implementation, visit this link.

Conclusion

Logstash JDBC is when you are using the data from a database which uses JDBC and then transferring it to and from Logstash. The input plugin helps us ingest the data from the result set of the database which I used by JDBC and then passing it to the Logstash.

Recommended Articles

This is a guide to Logstash JDBC. Here we discuss the Introduction, What is Logstash JDBC, How to use Logstash JDBC, examples with code implementation. You may also have a look at the following articles to learn more –

  1. JDBC hive
  2. JDBC connector
  3. JDBC Types
  4. JDBC Batch Insert
Popular Course in this category
Kibana Training (1 Course, 3 Project)
  1 Online Courses |  3 Hands-on Project |  14+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more