Greenplum Oracle 兼容性之 - LOG ERRORS INTO

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
简介:

标签

PostgreSQL , Oracle , Greenplum , LOG ERRORS INTO


背景

Oracle支持DML的log errors,是一个很赞的功能。

https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_errlog.htm#CEGEJAAJ

https://oracle-base.com/articles/10g/dml-error-logging-10gr2

支持insert,update,delete,merge的错误日志记录,可以跳过错误的行

INSERT INTO dest  
SELECT *  
FROM   source  
LOG ERRORS INTO err$_dest ('INSERT') REJECT LIMIT UNLIMITED;  
  
99998 rows created.  
  
SQL>  
COLUMN ora_err_mesg$ FORMAT A70  
SELECT ora_err_number$, ora_err_mesg$  
FROM   err$_dest  
WHERE  ora_err_tag$ = 'INSERT';  
  
ORA_ERR_NUMBER$ ORA_ERR_MESG$  
--------------- ---------------------------------------------------------  
           1400 ORA-01400: cannot insert NULL into ("TEST"."DEST"."CODE")  
           1400 ORA-01400: cannot insert NULL into ("TEST"."DEST"."CODE")  
  
2 rows selected.  
  
SQL>  
UPDATE dest  
SET    code = DECODE(id, 9, NULL, 10, NULL, code)  
WHERE  id BETWEEN 1 AND 10  
LOG ERRORS INTO err$_dest ('UPDATE') REJECT LIMIT UNLIMITED;  
  
8 rows updated.  
  
SQL>  
COLUMN ora_err_mesg$ FORMAT A70  
SELECT ora_err_number$, ora_err_mesg$  
FROM   err$_dest  
WHERE  ora_err_tag$ = 'UPDATE';  
  
ORA_ERR_NUMBER$ ORA_ERR_MESG$  
--------------- ---------------------------------------------------------  
           1400 ORA-01400: cannot insert NULL into ("TEST"."DEST"."CODE")  
           1400 ORA-01400: cannot insert NULL into ("TEST"."DEST"."CODE")  
  
2 rows selected.  
  
SQL>  
MERGE INTO dest a  
    USING source b  
    ON (a.id = b.id)  
  WHEN MATCHED THEN  
    UPDATE SET a.code        = b.code,  
               a.description = b.description  
  WHEN NOT MATCHED THEN  
    INSERT (id, code, description)  
    VALUES (b.id, b.code, b.description)  
  LOG ERRORS INTO err$_dest ('MERGE') REJECT LIMIT UNLIMITED;  
  
99998 rows merged.  
  
SQL>  
COLUMN ora_err_mesg$ FORMAT A70  
SELECT ora_err_number$, ora_err_mesg$  
FROM   err$_dest  
WHERE  ora_err_tag$ = 'MERGE';  
  
ORA_ERR_NUMBER$ ORA_ERR_MESG$  
--------------- ---------------------------------------------------------  
           1400 ORA-01400: cannot insert NULL into ("TEST"."DEST"."CODE")  
           1400 ORA-01400: cannot insert NULL into ("TEST"."DEST"."CODE")  
  
2 rows selected.  
  
SQL>  
DELETE FROM dest  
LOG ERRORS INTO err$_dest ('DELETE') REJECT LIMIT UNLIMITED;  
  
99996 rows deleted.  
  
SQL>  
COLUMN ora_err_mesg$ FORMAT A69  
SELECT ora_err_number$, ora_err_mesg$  
FROM   err$_dest  
WHERE  ora_err_tag$ = 'DELETE';  
  
ORA_ERR_NUMBER$ ORA_ERR_MESG$  
--------------- ---------------------------------------------------------------------  
           2292 ORA-02292: integrity constraint (TEST.DEST_CHILD_DEST_FK) violated -  
                child record found  
  
           2292 ORA-02292: integrity constraint (TEST.DEST_CHILD_DEST_FK) violated -  
                child record found  
  
  
2 rows selected.  
  
SQL>  

Greenplum copy兼容log errors

Greenplum可以通过COPY支持log errors。暂时未支持insert, merge, update, delete的error log.

COPY table [(column [, ...])] FROM {'file' | STDIN}  
  [ [WITH]  
    [OIDS]  
    [HEADER]  
    [DELIMITER [ AS ] 'delimiter']  
    [NULL [ AS ] 'null string']  
    [ESCAPE [ AS ] 'escape' | 'OFF']  
    [NEWLINE [ AS ] 'LF' | 'CR' | 'CRLF']  
    [CSV [QUOTE [ AS ] 'quote']  
    [FORCE NOT NULL column [, ...]]  
    [FILL MISSING FIELDS]  
    [[LOG ERRORS [INTO error_table] [KEEP]  
    SEGMENT REJECT LIMIT count [ROWS | PERCENT] ]  
  
  
COPY {table [(column [, ...])] | (query)} TO {'file' | STDOUT}  
  [ [WITH]  
    [OIDS]  
    [HEADER]  
    [DELIMITER [ AS ] 'delimiter']  
    [NULL [ AS ] 'null string']  
    [ESCAPE [ AS ] 'escape' | 'OFF']  
    [CSV [QUOTE [ AS ] 'quote']  
    [FORCE QUOTE column [, ...]] ]  
    [IGNORE EXTERNAL PARTITIONS ]  
LOG ERRORS [INTO error_table] [KEEP]  
This is an optional clause that can precede a SEGMENT REJECT LIMIT clause to log  
information about rows with formatting errors. The INTO error_table clause specifies an  
error table where rows with formatting errors will be logged when running in single row error  
isolation mode.  
If the INTO error_table clause is not specified, the error log information is stored internally  
(not in an error table). Error log information that is stored internally is accessed with the  
Greenplum Database built-in SQL function gp_read_error_log().  
If the error_table specified already exists, it is used. If it does not exist, it is created. If  
error_table exists and does not have a random distribution (the DISTRIBUTED RANDOMLY  
clause was not specified when creating the table), an error is returned.  
If the command generates the error table and no errors are produced, the default is to drop  
the error table after the operation completes unless KEEP is specified. If the table is created  
and the error limit is exceeded, the entire transaction is rolled back and no error data is  
saved. If you want the error table to persist in this case, create the error table prior to running  
the COPY.  
See Notes for information about the error log information and built-in functions for viewing  
and managing error log information.  
Note: The optional INTO error_table clause is deprecated and will not be  
supported in a future release. Only internal error logs will be supported.  
When you specify LOG ERRORS INTO error_table, Greenplum Database creates the table error_table  
that contains errors that occur while reading the external table. The table is defined as follows:  
CREATE TABLE error_table_name ( cmdtime timestamptz, relname text,  
filename text, linenum int, bytenum int, errmsg text,  
rawdata text, rawbytes bytea ) DISTRIBUTED RANDOMLY;  
You can view the information in the table with SQL commands.  
For error log data that is stored internally when the INTO error_table is not specified:  
- Use the built-in SQL function gp_read_error_log('table_name'). It requires SELECT privilege on  
table_name. This example displays the error log information for data loaded into table ext_expenses  
with a COPY command:  
SELECT * from gp_read_error_log('ext_expenses');  
The error log contains the same columns as the error table.  
The function returns FALSE if table_name does not exist.  
- If error log data exists for the specified table, the new error log data is appended to existing error log  
data. The error log information is not replicated to mirror segments.  
- Use the built-in SQL function gp_truncate_error_log('table_name') to delete the error log data  
for table_name. It requires the table owner privilege This example deletes the error log information  
captured when moving data into the table ext_expenses:  
SELECT gp_truncate_error_log('ext_expenses');  
The function returns FALSE if table_name does not exist.  
Specify the * wildcard character to delete error log information for existing tables in the current  
database. Specify the string *.* to delete all database error log information, including error log  
information that was not deleted due to previous database issues. If * is specified, database owner  
privilege is required. If *.* is specified, operating system super-user privilege is required.  
When a Greenplum Database user who is not a superuser runs a COPY command, the command can be  
controlled by a resource queue. The resource queue must be configured with the ACTIVE_STATEMENTS  
parameter that specifies a maximum limit on the number of queries that can be executed by roles assigned  
to that queue. Greenplum Database does not apply a cost value or memory value to a COPY command,  
resource queues with only cost or memory limits do not affect the running of COPY commands.  
A non-superuser can runs can run these types of COPY commands:  
- COPY FROM command where the source is stdin  
- COPY TO command where the destination is stdout  
For information about resource queues, see "Workload Management with Resource Queues" in the  
Greenplum Database Administrator Guide.  

参考

https://greenplum.org/docs/570/ref_guide/sql_commands/COPY.html

《PostgreSQL 11 preview - MERGE 语法支持与CTE内支持,兼容SQL:2016 , 兼容 Oracle》

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
6月前
|
Oracle 关系型数据库 MySQL
实时计算 Flink版操作报错之使用oracle-cdc的,遇到错误:ORA-01292: no log file has been specified for the current LogMiner session,该如何处理
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
|
3月前
|
SQL Oracle 关系型数据库
"揭秘!一键解锁Oracle日志清理魔法,让海量归档日志无处遁形,守护数据库健康,告别磁盘空间告急噩梦!"
【8月更文挑战第9天】随着Oracle数据库在企业应用中的普及,归档日志管理对保持数据库健康至关重要。归档日志记录所有更改,对数据恢复极为重要,但也可能迅速占用大量磁盘空间影响性能。利用Oracle提供的RMAN工具,可通过编写Shell脚本来自动清理归档日志。脚本包括设置环境变量、连接数据库、检查和删除指定时间前的日志,并记录执行情况。通过Cron作业定时运行脚本,可有效管理日志文件,确保数据库稳定运行。
87 7
|
3月前
|
SQL 监控 Oracle
Oracle数据误删不用怕,跟我来学日志挖掘
Oracle数据误删不用怕,跟我来学日志挖掘
36 0
|
4月前
|
存储 SQL Oracle
关系型数据库Oracle归档日志备份
【7月更文挑战第19天】
64 5
|
6月前
|
SQL Oracle 关系型数据库
实时计算 Flink版产品使用合集之从Oracle数据库同步数据时,checkpoint恢复后无法捕获到任务暂停期间的变更日志,如何处理
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStreamAPI、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
4月前
|
Oracle 关系型数据库 MySQL
实时计算 Flink版产品使用问题之在online模式下增量抓取Oracle数据时,在archive_log切换时,出现数据丢失的情况,是什么原因
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
5月前
|
SQL Oracle 关系型数据库
探索 Linux 命令 `db_archive`:Oracle 数据库归档日志的工具
探索 Linux 中的 `db_archive`,实际与 Oracle 数据库归档日志管理相关。在 Oracle 中,归档日志用于恢复,当在线重做日志满时自动归档。管理员可使用 SQL*Plus 查看归档模式,通过 `RMAN` 进行备份和恢复操作。管理归档日志需谨慎,避免数据丢失。了解归档管理对 Oracle 管理员至关重要,确保故障时能快速恢复数据库。
|
5月前
|
SQL DataWorks Oracle
DataWorks产品使用合集之datax解析oracle增量log日志该如何操作
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
54 0
|
6月前
|
Oracle 关系型数据库 数据库
实时计算 Flink版产品使用合集之采集Oracle数据库时,归档日志大小暴增的原因是什么
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStreamAPI、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
21天前
|
XML JSON Java
Logback 与 log4j2 性能对比:谁才是日志框架的性能王者?
【10月更文挑战第5天】在Java开发中,日志框架是不可或缺的工具,它们帮助我们记录系统运行时的信息、警告和错误,对于开发人员来说至关重要。在众多日志框架中,Logback和log4j2以其卓越的性能和丰富的功能脱颖而出,成为开发者们的首选。本文将深入探讨Logback与log4j2在性能方面的对比,通过详细的分析和实例,帮助大家理解两者之间的性能差异,以便在实际项目中做出更明智的选择。
135 3

热门文章

最新文章

  • 1
    非阻塞 I/O:异步编程提升 Python 应用速度
    7
  • 2
    2024 Mysql基础与进阶操作系列之MySQL触发器详解(20)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    4
  • 3
    2024 RedisAnd Mysql基础与进阶操作系列(16-1)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    4
  • 4
    2024Mysql And Redis基础与进阶操作系列(13)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    6
  • 5
    2024Mysql And Redis基础与进阶操作系列(10)作者——LJS[你个IKUN还学不会嘛?你是真爱粉嘛?真是的 ~;以后别侮辱我家鸽鸽]
    5
  • 6
    2024 RedisAnd Mysql基础与进阶操作系列(15)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    4
  • 7
    2024Mysql And Redis基础与进阶操作系列(9)作者——LJS[含MySQL存储过程之局部、系统变量、参数传递、流程控制-判断/case具体详步骤;注意点及常见报错问题所对应的解决方法]
    8
  • 8
    2024 Mysql基础与进阶操作系列之MySQL触发器详解(21)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    6
  • 9
    2024 RedisAnd Mysql基础与进阶操作系列(19)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    6
  • 10
    2024 RedisAnd Mysql基础与进阶操作系列(18)作者——LJS[你个小黑子这都还学不会嘛?你是真爱粉嘛?真是的 ~;以后请别侮辱我家鸽鸽]
    5
  • 推荐镜像

    更多