Job control refers to the ability to selectively stop (suspend) the execution of processes and continue (resume) their execution at a later point. A user typically employs this facility via an interactive interface supplied jointly by the operating system kernel’s terminal driver and bash.
big tables to restore from s3. Q:How can we restore them in parallel? $ psql > select count(1) from foo_s3archive; count ----------- 1000000000 (1 row) > select count(1) from bar_s3archive; count ----------- 2000000000 (1 row)
big tables to restore from s3. Q:How can we restore them in parallel? A:By running two copies of psql. $ psql > select count(1) from foo_s3archive; count ----------- 1000000000 (1 row) > select count(1) from bar_s3archive; count ----------- 2000000000 (1 row)
recover_foo.psql; create table foo_tmp like foo; insert into foo_tmp ( select * from foo_external ) ; insert into foo ( select * from foo_tmp ); drop table foo_tmp;
tables avoids corruption if the extenal connecion has issues. $ cat recover_foo.psql; create table foo_tmp like foo; insert into foo_tmp ( select * from foo_external ) ; insert into foo ( select * from foo_tmp ) ; drop table foo_tmp;
#1 is still running. Job #2 is ready to be started in the background. $ psql > \i recover_bar ^Z [2]+ Stopped psql $ jobs [1]- Running psql & [2]+ Stopped psql
#1 is still running. Job #2 is ready to be started in the background. $ psql > \i recover_bar ^Z [2]+ Stopped psql $ jobs [1]- Running psql & [2]+ Stopped psql $ bg [2]+ psql &
to foreground psql. The ‘%’ prefix tells bash to work on a job number. Hit Enter for a prompt. $ tail -f ... INSERT 0 1000000000 $ jobs [1]- Running psql & [2]+ Running psql & $ fg %1 psql >
like most programs, will exit gracefully on a TERM. Use “pkill -TERM psql” to locate the job and stop it that way. $ pgrep -a psql; 54741 psql $ kill -TERM 54741; # or just $ pkill -TERM psql;
is job #1. “%ps” is a job running ”psql”. “%?somescript” searches the entire commandl line. $ psql … ^Z # these both work $ %1 $ %ps # psql somescript & $ %?somescript;