【问题标题】:postgresql logs dumping in tablepostgresql 日志转储到表中
【发布时间】:2021-08-31 10:26:24
【问题描述】:

我正在将 postgresql .csv 文件转储到表中,但出现以下错误

使用 csv 从“C:\Program Files\PostgreSQL\13\data\log\postgresql-2021-06-15_191640.csv”复制 postgres_log;

ERROR:  extra data after last expected column
CONTEXT:  COPY postgres_log, line 1: "2021-06-15 19:16:40.261 IST,,,5532,,60c8af3f.159c,1,,2021-06-15 19:16:39 IST,,0,LOG,00000,"ending lo..."
SQL state: 22P04

我遵循了以下 postgresql 文档 https://www.postgresql.org/docs/10/runtime-config-logging.html 请建议,如何在表中转储

【问题讨论】:

    标签: postgresql postgresql-13


    【解决方案1】:

    您按照 Postgres 10 的说明进行操作,其中 CSV 日志格式的列比 Postgres 13(您实际运行的版本)少一列。这就是您收到该错误消息的原因。要解决此问题,请根据 PG 13 文档更新您的 postgres_log 表定义:

    https://www.postgresql.org/docs/13/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG

    CREATE TABLE postgres_log
    (
      log_time timestamp(3) with time zone,
      user_name text,
      database_name text,
      process_id integer,
      connection_from text,
      session_id text,
      session_line_num bigint,
      command_tag text,
      session_start_time timestamp with time zone,
      virtual_transaction_id text,
      transaction_id bigint,
      error_severity text,
      sql_state_code text,
      message text,
      detail text,
      hint text,
      internal_query text,
      internal_query_pos integer,
      context text,
      query text,
      query_pos integer,
      location text,
      application_name text,
      backend_type text,
      PRIMARY KEY (session_id, session_line_num)
    );
    

    【讨论】:

    • 谢谢兄弟,它正在工作。我也想自动化这个,这样日志应该直接转储到表中,我不需要做任何事情
    • 自动化它有点棘手,因为日志文件名会因日志轮换而改变。 cybertec-postgresql.com/en/… 对如何实现它有一些想法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多