psql 启动多个并发 .sql 脚本并限制进程
psql start multiple concurrent .sql scripts and limit processes
背景:
OS Win10
postgresql9.6
post地理信息系统 2.5
故事:
我在 win 文件夹中有 200 个带有 postgres(st_union 函数)查询的 .slq 脚本。
我可以 运行 a "for %%f in (*.sql) do (start cmd /c "psql -U postgres -f "%%f" abn2030")" .bat 并行处理这些文件,我的 8 个内核有一些饲料。
除了 200 个脚本太多了。我正在寻找一种方法来限制 运行ning 'cmd'/'psql' 实例。我想检查 cmd(或 psql)运行ning 的实例并启动下一个(排队等候).sql 脚本仅当 cmd/psql 的实例数未满 15 岁。(如果这有意义;也许还有其他选择)。
我尝试了 powershell 和 python(范围较小),但我不知道继续使用哪个(如果有的话)。
电源外壳:
运行宁直接。脚本执行没有问题。
cmd /c ""C:\PostgreSQL.6\bin\psql.exe" -U postgres -d db -f "D:\Dropbox\scripts_sql\execute_htunion\pwshl\queries1.SQL""
在脚本中:(主要是从另一个 post 偷来的)
function numInstances([string]$process)
{
@(get-process -ea silentlycontinue $process).count
}
$files = Get-ChildItem $scriptDir\*.sql
foreach ($file in $files) {
$running = numInstances("cmd")
if ($running.Count -le 2) {
$script= {& cmd /c psql "-U postgres -f $file db"}
Start-Job $script
write-host "$file"
} else {
$running | Wait-Job
}
Get-Job | Receive-Job
}
输出:psql:致命:角色“postgres -f D:\Dropbox\scripts_sql\execute_htunion\pwshl\queri”不存在
如何在 powershell(或其他语言)的 psql 命令中发送 start .sql?
编辑:
在 .bat 中解决:
"C:\Program Files\Git\bin\sh.exe" --login -i -c "find . -iname '*.sql' -print0 | xargs --null --max-procs=14 -I {} psql.exe -U postgres -d db -f {}"
Git for Windows should have xargs and find,它们是 Linux 发起的命令,串联起来非常适合任务:
find . -name '*.sql' -print0 \
| xargs --null --max-procs=16 -I{} psql.exe -U postgres -d db -f {}
背景: OS Win10 postgresql9.6 post地理信息系统 2.5
故事: 我在 win 文件夹中有 200 个带有 postgres(st_union 函数)查询的 .slq 脚本。 我可以 运行 a "for %%f in (*.sql) do (start cmd /c "psql -U postgres -f "%%f" abn2030")" .bat 并行处理这些文件,我的 8 个内核有一些饲料。 除了 200 个脚本太多了。我正在寻找一种方法来限制 运行ning 'cmd'/'psql' 实例。我想检查 cmd(或 psql)运行ning 的实例并启动下一个(排队等候).sql 脚本仅当 cmd/psql 的实例数未满 15 岁。(如果这有意义;也许还有其他选择)。 我尝试了 powershell 和 python(范围较小),但我不知道继续使用哪个(如果有的话)。
电源外壳: 运行宁直接。脚本执行没有问题。
cmd /c ""C:\PostgreSQL.6\bin\psql.exe" -U postgres -d db -f "D:\Dropbox\scripts_sql\execute_htunion\pwshl\queries1.SQL""
在脚本中:(主要是从另一个 post 偷来的)
function numInstances([string]$process)
{
@(get-process -ea silentlycontinue $process).count
}
$files = Get-ChildItem $scriptDir\*.sql
foreach ($file in $files) {
$running = numInstances("cmd")
if ($running.Count -le 2) {
$script= {& cmd /c psql "-U postgres -f $file db"}
Start-Job $script
write-host "$file"
} else {
$running | Wait-Job
}
Get-Job | Receive-Job
}
输出:psql:致命:角色“postgres -f D:\Dropbox\scripts_sql\execute_htunion\pwshl\queri”不存在
如何在 powershell(或其他语言)的 psql 命令中发送 start .sql?
编辑:
在 .bat 中解决:
"C:\Program Files\Git\bin\sh.exe" --login -i -c "find . -iname '*.sql' -print0 | xargs --null --max-procs=14 -I {} psql.exe -U postgres -d db -f {}"
Git for Windows should have xargs and find,它们是 Linux 发起的命令,串联起来非常适合任务:
find . -name '*.sql' -print0 \
| xargs --null --max-procs=16 -I{} psql.exe -U postgres -d db -f {}