Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wtYzf-0003ok-21 for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Aug 2026 23:01:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wtYyd-000EaV-1D for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Aug 2026 23:00:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wtYyd-000EaN-0H for pgsql-hackers@lists.postgresql.org; Mon, 10 Aug 2026 23:00:16 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wtYyX-000000003Sc-28Yi for pgsql-hackers@lists.postgresql.org; Mon, 10 Aug 2026 23:00:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67AN06bk2314093; Mon, 10 Aug 2026 19:00:06 -0400 From: Tom Lane To: "Jonathan Gonzalez V." cc: pgsql-hackers@lists.postgresql.org Subject: Re: Introduce psystem() to replace system() In-reply-to: <87zeyt93ns.fsf@abdiel.eu> References: <87zeyt93ns.fsf@abdiel.eu> Comments: In-reply-to "Jonathan Gonzalez V." message dated "Mon, 10 Aug 2026 21:27:51 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2314091.1786402806.1@sss.pgh.pa.us> Date: Mon, 10 Aug 2026 19:00:06 -0400 Message-ID: <2314092.1786402806@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Jonathan Gonzalez V." writes: > For some time I've been wondering why PostgreSQL needs system() calls, > which use a shell that can lead to many problems, and also why it > requires a shell to run a command. There's a lot to be said for not going through system() if we don't have to, and I think you are right that there are many places where we don't have to, if we're willing to write our own stdio-redirection code (but that might be a bigger can of worms than it seems). That'd improve security and also performance, though I'm not very sure how big the latter win would be. However, I think your apparent ambition to have *zero* use of system() is a bridge too far. In particular: > There's an important topic related to using shell versus not a shell. In > some places like `archive_command` people may use `&&`, but this idea > aims to avoid this kind of behavior since it's not secure. I think breaking the existing definition of archive_command and similar GUCs is a nonstarter. You're going to make many users unhappy and only a tiny minority happier. There might be some way to compromise, along the lines of "if the string contains no shell metacharacters then parse it ourselves and use execv(), else use system()". The devil's in the details there; but if it could work then it'd satisfy people who'd like to not have a shell available and are willing to deal with the ensuing restrictions. But if you think that description covers all or even most of our users, I'm here to tell you you're wrong. As for details ... doesn't this pcommand_count_args thing break instantly on cases like pathnames containing spaces? I think you need a much clearer concept (and, um, some documentation) about the semantics of these functions. I don't think we're really going to move the goalposts far unless we can get away from assumptions like that. regards, tom lane