We can use the COPY
statement to load data into tables from files.
When loading from very large files, starting in YugabyteDB 2.15.0.1, we can check on the status of a load via the PG_STAT_ACTIVITY and PG_STAT_PROGRESS_COPY system tables.
SELECT query, now() - backend_start run_time, yb_status, bytes_processed, tuples_processed, tuples_processed / EXTRACT(EPOCH FROM (now() - backend_start))::INT tuples_per_second FROM pg_stat_activity a JOIN pg_stat_progress_copy b ON b.pid = a.pid AND b.datid = a.datid WHERE query ILIKE 'COPY%';
Example:
sh-4.2# cat load.sql
\COPY xyz_customize FROM 'xyz_customize.csv' WITH (DELIMITER '~', NULL '\N', ROWS_PER_TRANSACTION 10000, DISABLE_FK_CHECK, REPLACE);
sh-4.2# ysqlsh -f load.sql &
[1] 30877
sh-4.2# ysqlsh
ysqlsh (11.2-YB-2.15.1.0-b0)
Type "help" for help.
yugabyte=# \x
Expanded display is on.
yugabyte=# SELECT query, now() - backend_start run_time, yb_status, bytes_processed, tuples_processed, tuples_processed / EXTRACT(EPOCH FROM (now() - backend_start))::INT tuples_per_second FROM pg_stat_activity a JOIN pg_stat_progress_copy b ON b.pid = a.pid AND b.datid = a.datid WHERE query ILIKE 'COPY%';
-[ RECORD 1 ]-----+-----------------------------------------------------------------------------------------------------------------------
query | COPY xyz_customize FROM STDIN WITH (DELIMITER '~', NULL '\N', ROWS_PER_TRANSACTION 10000, DISABLE_FK_CHECK, REPLACE);
run_time | 00:05:58.473891
yb_status | IN PROGRESS
bytes_processed | 1291770000
tuples_processed | 4630000
tuples_per_second | 12932
Have Fun!