# Redirecting postgresql tables to Elasticsearch

**URL:** <https://discuss.elastic.co/t/redirecting-postgresql-tables-to-elasticsearch/345458>\
**Category:** Logstash\
**Created:** [October 20, 2023, 12:28pm UTC](https://discuss.elastic.co/t/redirecting-postgresql-tables-to-elasticsearch/345458 "2023-10-20T12:28:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krzychohoho](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@krzychohoho](https://discuss.elastic.co/u/krzychohoho)\
**Post date:** [October 20, 2023, 12:28pm UTC](https://discuss.elastic.co/t/redirecting-postgresql-tables-to-elasticsearch/345458/1 "2023-10-20T12:28:26Z")

</div>

Hi,  
I am trying to redirect my postgresql tables to elasticsearch using JDBC and Logstash. I was able to do it but i came across a problem of ingesting the same data over and over again. I know i need to use tracking column but i think i have a problem with timestamp format.

This is my conf file:

```auto
input {
    jdbc {
     clean_run => true
        jdbc_driver_library => "/tmp/postgresql-42.6.0.jar"
        jdbc_driver_class => "org.postgresql.Driver"
        jdbc_connection_string => "jdbc:postgresql://postgres:5432/template1"
        jdbc_user => "postgres"
        jdbc_password => " ******"
        statement => "SELECT * FROM public.users WHERE last_update > :sql_last_value AND last_update < CURRENT_TIMESTAMP ORDER BY last_update ASC"
        use_column_value => true
        tracking_column_type => "timestamp"
        tracking_column => "last_update"
        last_run_metadata_path => "/tmp/last.yml"
        #schedule => "* * * * *"
    }
}
filter {
    mutate {
    }
}
output{
    elasticsearch {
        hosts => [" ******""]
        index => "sql_idx"
        user => "elastic"
        password => " ******"
        ssl => true
        ssl_certificate_verification => false
    }
}

```

But the problem is, logstash log still gives me:

```auto
WHERE last_update > '1970-01-01 00:00:00.000000+0000'

```

The out.yml file keeps the correct record:

```auto
2023-10-20 12:10:06.789306000 Z

```

But it seems like :sql\_last\_value does not ingest it correctly. Can anyone help me with this? Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)\
**Post date:** [October 25, 2023, 5:21pm UTC](https://discuss.elastic.co/t/redirecting-postgresql-tables-to-elasticsearch/345458/2 "2023-10-25T17:21:22Z")

</div>

Hi @krzychohoho,

This might not fix your problem, but you probably don't need the "AND clause" with the current timestamp. Try the following please:

```auto
"SELECT * FROM public.users WHERE last_update > :sql_last_value ORDER BY last_update ASC"

```

---

<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:** [November 22, 2023, 5:21pm UTC](https://discuss.elastic.co/t/redirecting-postgresql-tables-to-elasticsearch/345458/3 "2023-11-22T17:21:38Z")

</div>

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