Skip to content

Commit 7294396

Browse files
Add progress reporting of skipped tuples during COPY FROM.
9e2d870 enabled the COPY command to skip malformed data, however there was no visibility into how many tuples were actually skipped during the COPY FROM. This commit adds a new "tuples_skipped" column to pg_stat_progress_copy view to report the number of tuples that were skipped because they contain malformed data. Bump catalog version. Author: Atsushi Torikoshi Reviewed-by: Masahiko Sawada Discussion: https://postgr.es/m/d12fd8c99adcae2744212cb23feff6ed%40oss.nttdata.com
1 parent d282e88 commit 7294396

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

doc/src/sgml/monitoring.sgml

+12
Original file line numberDiff line numberDiff line change
@@ -5780,6 +5780,18 @@ FROM pg_stat_get_backend_idset() AS backendid;
57805780
<command>WHERE</command> clause of the <command>COPY</command> command.
57815781
</para></entry>
57825782
</row>
5783+
5784+
<row>
5785+
<entry role="catalog_table_entry"><para role="column_definition">
5786+
<structfield>tuples_skipped</structfield> <type>bigint</type>
5787+
</para>
5788+
<para>
5789+
Number of tuples skipped because they contain malformed data.
5790+
This counter only advances when a value other than
5791+
<literal>stop</literal> is specified to the <literal>ON_ERROR</literal>
5792+
option.
5793+
</para></entry>
5794+
</row>
57835795
</tbody>
57845796
</tgroup>
57855797
</table>

src/backend/catalog/system_views.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,8 @@ CREATE VIEW pg_stat_progress_copy AS
13181318
S.param1 AS bytes_processed,
13191319
S.param2 AS bytes_total,
13201320
S.param3 AS tuples_processed,
1321-
S.param4 AS tuples_excluded
1321+
S.param4 AS tuples_excluded,
1322+
S.param7 AS tuples_skipped
13221323
FROM pg_stat_get_progress_info('COPY') AS S
13231324
LEFT JOIN pg_database D ON S.datid = D.oid;
13241325

src/backend/commands/copyfrom.c

+5
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ CopyFrom(CopyFromState cstate)
650650
CopyMultiInsertInfo multiInsertInfo = {0}; /* pacify compiler */
651651
int64 processed = 0;
652652
int64 excluded = 0;
653+
int64 skipped = 0;
653654
bool has_before_insert_row_trig;
654655
bool has_instead_insert_row_trig;
655656
bool leafpart_use_multi_insert = false;
@@ -1012,6 +1013,10 @@ CopyFrom(CopyFromState cstate)
10121013
*/
10131014
cstate->escontext->error_occurred = false;
10141015

1016+
/* Report that this tuple was skipped by the ON_ERROR clause */
1017+
pgstat_progress_update_param(PROGRESS_COPY_TUPLES_SKIPPED,
1018+
++skipped);
1019+
10151020
continue;
10161021
}
10171022

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202401241
60+
#define CATALOG_VERSION_NO 202401251
6161

6262
#endif

src/include/commands/progress.h

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
#define PROGRESS_COPY_TUPLES_EXCLUDED 3
143143
#define PROGRESS_COPY_COMMAND 4
144144
#define PROGRESS_COPY_TYPE 5
145+
#define PROGRESS_COPY_TUPLES_SKIPPED 6
145146

146147
/* Commands of COPY (as advertised via PROGRESS_COPY_COMMAND) */
147148
#define PROGRESS_COPY_COMMAND_FROM 1

src/test/regress/expected/rules.out

+2-1
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ pg_stat_progress_copy| SELECT s.pid,
19881988
s.param1 AS bytes_processed,
19891989
s.param2 AS bytes_total,
19901990
s.param3 AS tuples_processed,
1991-
s.param4 AS tuples_excluded
1991+
s.param4 AS tuples_excluded,
1992+
s.param7 AS tuples_skipped
19921993
FROM (pg_stat_get_progress_info('COPY'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20)
19931994
LEFT JOIN pg_database d ON ((s.datid = d.oid)));
19941995
pg_stat_progress_create_index| SELECT s.pid,

0 commit comments

Comments
 (0)