# Logstash to PostgreSQL as output

**URL:** <https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500>\
**Category:** Logstash\
**Created:** [July 18, 2017, 6:15am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500 "2017-07-18T06:15:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [July 18, 2017, 6:16am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/1 "2017-07-18T06:16:00Z")

</div>

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

---

<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 20, 2017, 6:43pm UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/2 "2017-07-20T18:43:43Z")

</div>

Have you looked at the [logstash-output-jdbc](https://github.com/theangryangel/logstash-output-jdbc) plugin?

---

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [July 21, 2017, 3:53am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/3 "2017-07-21T03:53:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [July 26, 2017, 9:18am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/4 "2017-07-26T09:18:41Z")

</div>

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

---

<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 26, 2017, 9:50am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/5 "2017-07-26T09:50:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [July 27, 2017, 2:33am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/6 "2017-07-27T02:33:08Z")

</div>

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

```
output {
 elasticsearch {
  hosts => ["192.168.200.254:9200"]
  index => "awsph_logstash-%{+YYYY.MM.dd}"
 }
 jdbc {
  connection_string => 'jdbc:postgresql://192.168.200.2:5432/Sample?user=postgres&password=Welcome123' 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!

---

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [July 27, 2017, 3:04am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/7 "2017-07-27T03:04:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [July 28, 2017, 3:53am UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/8 "2017-07-28T03:53:47Z")

</div>

Still need help with this. 🙂

---

<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:** [August 2, 2017, 6:49pm UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/9 "2017-08-02T18:49:12Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jogoinar10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogoinar10/32/20068_2.png) [@jogoinar10](https://discuss.elastic.co/u/jogoinar10)\
**Post date:** [August 2, 2017, 10:25pm UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/10 "2017-08-02T22:25:34Z")

</div>

Thanks for your reply @magnusbaeck!

---

<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 30, 2017, 10:25pm UTC](https://discuss.elastic.co/t/logstash-to-postgresql-as-output/93500/11 "2017-08-30T22:25:45Z")

</div>

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