Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFo3d-0002ep-8t for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 21:52:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fFo3b-0003Q4-Kr for pgsql-general@arkaria.postgresql.org; Mon, 07 May 2018 21:52:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFo3b-0003Pv-9S for pgsql-general@lists.postgresql.org; Mon, 07 May 2018 21:52:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fFo3U-0000Qk-IC for pgsql-general@lists.postgresql.org; Mon, 07 May 2018 21:52:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w47LqMAr011261; Mon, 7 May 2018 17:52:22 -0400 From: Tom Lane To: "David G. Johnston" cc: David Gauthier , "pgsql-generallists.postgresql.org" Subject: Re: Run external command as part of an sql statement ? In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Mon, 07 May 2018 14:41:39 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <11259.1525729942.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 07 May 2018 17:52:22 -0400 Message-ID: <11260.1525729942@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Mon, May 7, 2018 at 2:35 PM, David Gauthier > wrote: >> I want to be able to run a shell command like this from within a stored >> procedure. Is there a way to do this ? > In core, you can probably use the untrusted​ version of Perl, Python, or > Tcl to accomplish your goal. SQL and pl/pgSQL do not provide that > capability.​ Depending on what you want to do, COPY TO/FROM PROGRAM might be a serviceable option. But, just like the untrusted-PL variants, you need to be superuser. Keep in mind that the program will run as the database server owner (which is the reason for the superuser restriction). regards, tom lane