Logstash to PostgreSQL as output

Does anyone tried to output data logs to PostgreSQL?

Right now my output is Elasticsearch and I want that every time a data will be output to elasticsearch, it will also output to PostreSQL

Have you looked at the logstash-output-jdbc plugin?

Not yet. Gonna look into it. Thank you @magnusbaeck! :slight_smile:

Hello @magnusbaeck. Did you try to use this plugin? Since I have some questions regarding this plugin. Thank you.

I haven't used it but maybe I or someone else can help out anyway.

I already tried to use the plugin but i got null values in my postgre db.

output {
 elasticsearch {
  hosts => [""]
  index => "awsph_logstash-%{+YYYY.MM.dd}"
 jdbc {
  connection_string => 'jdbc:postgresql://' statement => [ "INSERT INTO logstashdata (index_id, index_name, doc_type) VALUES(?, ?, ?)", "_id", "_index", "_type" ]
 stdout {
  codec => rubydebug

i think the problem maybe is that, I can't get the value of the data like the id, index, and the doc_type.
Is there a way to pre-declare the data and transform to (maybe) variable? so that I can use it in my put statement?
Or if there any workaround with this that you may know.

Thank you!

I tried to use the data inside the "_source" array and it is working. But still the _id, _type, and _index is not working.

Still need help with this. :slight_smile:

But still the _id, _type, and _index is not working.

Correct, because events don't have any such fields (unless you add them yourself).

Thanks for your reply @magnusbaeck!

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