forked from rin-nas/postgresql-patterns-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path{JiraTaskId}_do.sh
More file actions
29 lines (23 loc) · 1.02 KB
/
{JiraTaskId}_do.sh
File metadata and controls
29 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#распараллеливание выполнения SQL по ядрам процессора
#для миграций длительностью < 5 минут этот скрипт не нужен, можно подождать
#cpu_max=`nproc`
cpu_max=$((`nproc` / 2))
#echo "$cpu_max"
name=`basename $0 .sh`
host='host' #modify me!
database='database' #modify me!
user='user' #modify me!
#пароль укажите в файле ~/.pgpass
#exit 0
for ((cpu_num = 1; cpu_num <= cpu_max; cpu_num++))
do
cat ${name}.sql \
| sed "s/cpu_num constant smallint default 1/cpu_num constant smallint default $cpu_num/g" \
| sed "s/cpu_max constant smallint default 1/cpu_max constant smallint default $cpu_max/g" \
| psql postgresql://${user}@${host}:5433/${database}?application_name=${0} \
--echo-all --set="ON_ERROR_STOP=1" \
--log-file=${name}_${cpu_num}.log 2> ${name}_${cpu_num}.stderr.log &
done
jobs -l
#wait #wait for all remaining workers
#echo "All done"