我研究bcp
并发现-e
直接在错误日志文件中写入任何错误并直接从该日志中获取它们的开关可以显着提高性能。
这是命令中 bcp 的输出:
Starting copy...
1000 rows sent to SQL Server. Total sent: 1000
1000 rows sent to SQL Server. Total sent: 2000
1000 rows sent to SQL Server. Total sent: 3000
1000 rows sent to SQL Server. Total sent: 4000
1000 rows sent to SQL Server. Total sent: 5000
1000 rows sent to SQL Server. Total sent: 6000
1000 rows sent to SQL Server. Total sent: 7000
1000 rows sent to SQL Server. Total sent: 8000
1000 rows sent to SQL Server. Total sent: 9000
1000 rows sent to SQL Server. Total sent: 10000
1000 rows sent to SQL Server. Total sent: 11000
1000 rows sent to SQL Server. Total sent: 12000
SQLState = 22001, NativeError = 0
Error = [Microsoft][ODBC Driver 11 for SQL Server]String data, right truncation
12406 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1351 Average : (9182.8 rows per sec.)
[INFO BCP IN: data2.txt] Import failed for 1 rows out of 12407 rows, Total 0.0%.
Fri Sep 20 01:24:39 CDT 2013
[INFO BCP IN: data2.txt] Total time elapsed 0 days 0 hour 0 minutes 2 seconds
这是错误日志输出:
#@ Row 12407, Column 1: String data, right truncation @#
The Bulk Copy Program (BCP) is a command-line utility
因此,将代码修改为 grep 错误日志文件而不是 bcp in 的整个输出,我们可以获得非常好的性能提升:
bcp Test..Table in datafile.txt -f format_file -m 0 -S server -T -e error_file.txt
error_count=`fgrep -c "right truncation" error_file.txt `
fedorqui、TrueY 和 pgl 感谢您的建议。