Generate scripts and import policies for large data volumes

Source: Internet
Author: User
When you test the performance of generating scripts for large data volumes and importing policies, note the following when creating a table with large data volumes: how to generate an unl File (this file is a data file suffixed with unl, in the format of data records separated by table columns, for example: 10001 | 33333 | ), during the performance test of generating scripts with large data volumes and importing policies, if you need to construct a table with large data volumes, you must note the following: how to generate an unl File (this file is suffixed. unl data file, in the format of data records separated by table columns, for example: 10001 | 33333 |). Can the generated unl file be imported to the corresponding database table at one time. For ease of description, assume that the database has a table test (id integer, name integer, primary key (id, name )). If you want to import million records to this table, manual insert is unrealistic. Generally, the database system provides specific commands to import and export data. we can create unl files in the corresponding format in advance, then, call the database import command to quickly import data. Taking the Informix database as an example, the data import command is: load from testdata. unl insert into test; now, the problem is how to generate the unl file of 10 million rows. I learned how to use shell scripts quickly and thought about awk implementation. here we also want to use awk implementation: [plain] #! /Bin/sh awk 'In in {dbfile = sprintf ("testdata. unl "); for (I = 0; I <1000; I ++) {for (j = 0; j <10000; j ++) {printf "100% 05d | 9% 08d | \ n", I, j> dbfile} printf "% d completed. \ n ", I} '/dev/null will generate an unl file with records, so we are eager to use" load from testdata. unl insert into test; "command to import data. an error is returned. Because too much data is imported at one time, the cache of the database system and the space of the log system are insufficient, too many records cannot be recorded at one time (or because the operation time is too long, "Long transaction aborted "). There are two solutions: increase the cache and log system size, and reduce the data volume of a single unl. Obviously, the latter is more reasonable. If you divide 10 million of unl into 100 small portions, each of which contains 10 million pieces, you can process more. The script is slightly modified as follows: [plain] #! /Bin/sh awk 'In in {for (I = 0; I <100; I ++) {dbfile = sprintf ("mytable % 02d. unl ", I); for (j = 0; j <100000; j ++) {printf" 100% 05d | 9% 08d | \ n ", I, j> dbfile} printf "% d completed. \ n ", I} '/dev/null at this time, in the face of 100 files, one hundred operations are required, and a little big. In line with the principle of laziness, we naturally want to use it automatically. As a result, the shell script automatically imported to the test table is also released: [plain] #! /Bin/sh # Generate 100 SQL scripts awk 'In in {dbfile = sprintf ("loadData. SQL "); for (I = 0; I <100; I ++) {printf" load from mytable % 02d. unl insert into test; ", I> dbfile} printf" completed. "} '/dev/null # run the script dbaccess mydatabank loadData. SQL, of course, you can put these shells together if you want to take a deeper step, but pay attention to readability. we recommend that you create a new shell and call these two shells in sequence to facilitate subsequent maintenance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.