I need to make two sessions (two files) run concurrently (at the same time). Is there a way to do this using pg_sleep or some other function like "delayExecutionUntil(x_time)"?
To get two transactions at the (almost) exact same time, you could schedule two or more invocations of psql at the same time in a Linux shell with the at
command .
Like:
at '08:00 01.12.2012' -f script.sql
(The required timestamp format may depend on your system locale.)
Where script.sql
contains something like:
psql mydb -p 5432 -c "INSERT INTO tbl (col) VALUES ('foo');
Just with a lot more rows to provoke the collisions you are after ..
You can use table locks (see LOCK
command in the docs) to synchronize the stuff:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.