hel10word
hel10word

Reputation: 11

A single linux shell script executes multiple commands, and the commands are written into multiple shell scripts and executed in sequence. Total time

I am a linux beginner , I am trying to import and export data using shell script. The data about 60,000,000 rows. When I execute the import and export commands separately from the command line, I find that perform very well. But I merged commands into a single shell script and the performance slowed down, I tried many times and I don't know why.

The following is the information of my test environment

Export_from_POSTGRES_lineitem.sh

psql postgres://postgres:[email protected]/sf10 -c  "\copy lineitem to './Export_from_POSTGRES_lineitem.csv' with DELIMITER '|';" 2>&1

Load_to_MYSQL_lineitem.sh

mysql -h 127.0.0.1 -P 3306 -uroot -prdpuser --database test_db -e "load data local infile './Export_from_POSTGRES_lineitem.csv' into table lineitem fields terminated by '|';" 2>&1

What I'm doing is exporting a table on a postgres database on another machine to a local csv file and then importing the csv file into my local mysql database. Before executing the export script, I will manually delete the existing local csv file. The csv file exported each time is about 8.6GB. Before importing to mysql, I will use ** TRUNCATE ** to clear the original data in the table. I make sure it's a clean environment before each test.

When I execute the Export script alone, it takes about 4 minutes.

When I execute the Load script alone, it takes about 5 minutes 30 seconds.

I have tested it many times, and the time is only within 20 seconds.

enter image description here

But when I merged the two scripts and executed them, I found that the time consuming increased.

I don't know what caused this, I hope I have described the problem I encountered in detail, and I hope to get your suggestions. If other information is needed, I will give it in time.

Upvotes: 1

Views: 95

Answers (0)

Related Questions