Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icuCq-0007QQ-Af for pgsql-performance@arkaria.postgresql.org; Thu, 05 Dec 2019 16:42:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icuCo-0001nJ-CF for pgsql-performance@arkaria.postgresql.org; Thu, 05 Dec 2019 16:42:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icuCn-0001nB-Tb for pgsql-performance@lists.postgresql.org; Thu, 05 Dec 2019 16:42:18 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icuCg-0000h0-KM for pgsql-performance@lists.postgresql.org; Thu, 05 Dec 2019 16:42:17 +0000 Received: by mail-wm1-x344.google.com with SMTP id n9so4106635wmd.3 for ; Thu, 05 Dec 2019 08:42:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=hwy6PrqciYK8y88S7jtt1WWlARBxrEX0PhE4WxZ5Ecg=; b=MggQmfkfTuwBNnZ5WuoKSd7i+KQ95wFp7dR/QlRrG5UTOdoAKiWckIfr9HvHiJ9crU JInmpEYbb2Du03MZyh9Ap24dKf+kWe82S5DyGWTNYPyVnQEN2BK4nMY0zviz6ielcawJ BFhTHwehD62sxtRVaCFqepVTA9LHxB7ktT5E+DHNaR22d4T0N/mAD5kVbOK3h8TxDu+9 6iTSpzzmZqe/i6pshb0+stKuzJ+M//ibagufRSSUtPCrDgYZoAl8NK68XpfHg45WUfIx 11O1d33Vx0vI6zWM5VmHTSXij21hfrB10FgwJUAlewWmlCEgJcUnfbgJ2SJGVWVK7NJI E4BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=hwy6PrqciYK8y88S7jtt1WWlARBxrEX0PhE4WxZ5Ecg=; b=q/iSIQUJfoj8rk+RyS++Cvt5UrAWqq8H2I0FKBUAHLWkg4Tlooi0Hlv26zayMw+uQz DSbympvOaRNBeZIqcRzQBsRyMJroOiy+DKYwJ21dd0OY3sIV6MTOHD4nyHneFMlEaYIO A3QrU7uRLiRmYF+eZZAMZTrxHxvP8ydGzbMqEBCpwPlj/nhqMEtiko/PWXHRF8j6/GjA VSssRbKgMvncnZZ1dji9MhtPl/26SWToCfHQ1gI5NjdYIN1jTYnUzgL2gmRucnFemISl TmrSnF7Gxlg/vJsqnDhS6eNBqDIDCJepdmU0dCP3UG5UqgQszs5A4Fn3zPif+EJVlV19 hMoA== X-Gm-Message-State: APjAAAXkVZAI50rnU1WGWUMmbWjIaoaSv9TQqcgnS6pCHvwocubvCb4u 0V3KFyWwmIzmzL0wUH0ZmGvJig== X-Google-Smtp-Source: APXvYqxkNZCLqOFmBHG07ufgC52+QpHX4OywdjyonjljMxpgCiH8gqciAzsuhrz6Crivd9DanqUnwQ== X-Received: by 2002:a7b:c95a:: with SMTP id i26mr6088359wml.67.1575564127631; Thu, 05 Dec 2019 08:42:07 -0800 (PST) Received: from localhost.localdomain (217-149-173-37.nat.highway.telekom.at. [217.149.173.37]) by smtp.gmail.com with ESMTPSA id o7sm349171wmc.41.2019.12.05.08.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2019 08:42:07 -0800 (PST) Message-ID: <65371f0819be9dc954fdece32e9df30d1c5aa39e.camel@cybertec.at> Subject: Re: How to run in parallel in Postgres From: Laurenz Albe To: Lars Aksel Opsahl , "pgsql-performance@lists.postgresql.org" Date: Thu, 05 Dec 2019 17:42:06 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2019-12-05 at 12:10 +0000, Lars Aksel Opsahl wrote: > have a function that prepares data, so the big job can be run it in parallel. > > Today I have solved this by using "Gnu parallel" like this. > psql testdb -c"\! psql -t -q -o /tmp/run_cmd.sql testdb -c\"SELECT find_overlap_gap_make_run_cmd('sl_lop.overlap_gap_input_t1','geom',4258,'sl_lop.overlap_gap_input_t1_res',50);\"; parallel -j 4 > psql testdb -c :::: /tmp/run_cmd.sql" 2>> /tmp/analyze.log; > > The problem here is that I depend on external code which may not be installed. > > Since Postgres now supports parallel I was wondering if it's easy to trigger parallel dynamically created SQL calls. > > If you look at https://github.com/larsop/find-overlap-and-gap/blob/master/src/test/sql/regress/find_overlap_and_gap.sql you see that > find_overlap_gap_make_run_cmd generates as set of 28 sql calls. > > So is it in a simple way possible to use Postgres parallel functionality to call this 28 functions i parallel so I don't have dependent on externally install programs ? > > When this 28 sql calls are done, the find_overlap_gap_make_run_cmd may continue to the next step of work. So the function that triggers parallel calls wait for them complete and then may start on > the next step of work. You cannot run several queries in parallel in a PostgreSQL function. You may want to have a look at PL/Proxy which might be used for things like that. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com