Skip to content

Fluentd Inserting NULL Value in PostgreSQL Column Not Mapped in Table Configuration #156

@KanjiVidyasagar

Description

@KanjiVidyasagar

Hi Support Team,

I am currently using Fluentd to insert log data into a PostgreSQL table (metrics_apis_received). However, I have encountered an issue where the insert_time column in the PostgreSQL table is being populated with NULL instead of the expected DEFAULT now() value when data is inserted.

Here is the current setup for the Fluentd configuration and PostgreSQL table:

Fluentd Configuration (Snippet):

<filter metrics_apis_received>
  @type record_transformer
  enable_ruby
  <record>
    log_time_metrics_apis_received ${record["log_time_metrics_apis_received"]}
    company_metrics_apis_received ${record["company_metrics_apis_received"]}
    method_metrics_apis_received ${record["method_metrics_apis_received"]}
    path_metrics_apis_received ${record["path_metrics_apis_received"]}
    source_metrics_apis_received ${record["source_metrics_apis_received"]}
    count_metrics_apis_received ${record["count_metrics_apis_received"]}
  </record>
</filter>

<filter metrics_apis_received>
  @type grep
  <exclude>
    key path_metrics_apis_received
    pattern \/api\/v1\/heartbeat
  </exclude>
</filter>

<match metrics_apis_received>
  @type sql
  adapter postgresql
  host xxxxxxxxxx
  port xxxxxxx
  database xxxxxxxxxxxxxxx
  username xxxxxxxxxxxx
  password xxxxxxxxxxxx
  <table>
    table metrics_apis_received
    column_mapping log_time_metrics_apis_received:log_time, company_metrics_apis_received:company, method_metrics_apis_received:method, path_metrics_apis_received:path, source_metrics_apis_received:source, count_metrics_apis_received:count
  </table>
  <buffer>
    chunk_limit_size 16MB
    flush_mode interval
    flush_interval 2s
  </buffer>
</match>

PostgreSQL Table Schema:


CREATE TABLE IF NOT EXISTS public.metrics_apis_received
(
    log_time timestamp without time zone NOT NULL,
    company text COLLATE pg_catalog."default",
    method text COLLATE pg_catalog."default",
    path text COLLATE pg_catalog."default",
    source text COLLATE pg_catalog."default",
    count integer,
    insert_time timestamp without time zone DEFAULT now()
);

Issue:
The insert_time column is set to NULL on insert, which is not expected, as it has a default value of now() in the PostgreSQL schema.
When inserting data manually into the table, insert_time is correctly populated with the current timestamp (now()).

Expected Behavior:
The insert_time column should automatically use the default now() value when no value is provided during insert, without needing to map it explicitly in the Fluentd configuration.

Can you please assist in resolving this issue, or suggest the best approach to ensure the insert_time column is populated correctly with the default timestamp (now())?

Thank you for your assistance.

Best regards,
Kanji Vidyasagar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions