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.98.2) (envelope-from ) id 1xH1fF-00000002mWg-2dkC for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2026 16:17:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xH1fE-00000004G9B-2eeI for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2026 16:17:12 +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.98.2) (envelope-from ) id 1xH1fD-00000004G8l-2dDM for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2026 16:17:12 +0000 Received: from fout-b4-smtp.messagingengine.com ([202.12.124.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xH1f9-000000025l6-3UJ1 for pgsql-general@postgresql.org; Wed, 14 Oct 2026 16:17:11 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 40F6E1D00129 for ; Wed, 14 Oct 2026 12:17:04 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Wed, 14 Oct 2026 12:17:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1791994623; x=1792081023; bh=7Wt3O7SlJWX8pG7xbmMb5hh3FhVl2JzASsdqd3oYXMg=; b= HpgfjJNzdruY2XFugAMFY70po23LqT4zYyAonrAsDxMhreusfwyDVIsiBA0DtoG1 x1035yLBUfEnEWzbv7tMlv6s3lKNNFi+K8dX1rDpathqjqlFC5OaJUXdF24BjZcs 1GHwZsezxw3aNWcrxNxpohD1AMmnhG8OPDbYyqYHCnMnLES6YHoEKPA8sCzFbwLY Qr+wxUILU2OVBlO/y+32+9iB+2UZmrLdte4m5caaET05fEp4S0j9bx4f5SJQ7jjE TdzDJgZXY8ylGnWU1sAAF+yY1I4kCv3J/dc3faD+x6jWhwmYAjzdbJtHv/wsfWVA +7wjgcw7Sr7FcDL4xw8S8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1791994623; x= 1792081023; bh=7Wt3O7SlJWX8pG7xbmMb5hh3FhVl2JzASsdqd3oYXMg=; b=Z Jdn8g6uYf5fZ4CpPmAjAwHJDbX40BDA2EjnRaooe2OrrLuSTioYpQN6QBh6kTrOY aYsDEMIp5EcnbrUtfzXLJxxOWc8SMQButHBQ6Q0CjS3vvtJTrxv1picLIM8bOCeu tVa7+cxD2HKYhZzeGEfiuLKeMDSZr5iFny67ncblxTt2EV0yOVuLtzUQTdE469eC ph8vSLxKuIQd+G4IIyGoMjueLQtMhY0z3cZzpqLLJiBLc4T0kk5IeZwz+1rY+qa5 J+IrJogXAowuPw0hBoRbks87e0YX4y0FmpO8OzFsty1ESK+c262ObvXCuNIlwLBw 9vuJ5xyCgNNE2jYZ0iwhQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox; action=sign d=aklaver.com a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1791994623; d=aklaver.com; mf=PGFkcmlhbi5rbGF2ZXJAYWtsYXZlci5jb20+; rt=PHBnc3FsLWdlbmVyYWxAcG9zdGdyZXNxbC5vcmc+; s=fm1:rsa-sha256:SgCPTuP1e+/4J3y7VA+yaLtOfoFFno4Ou+7nMrq85te8cYG oamnqgP7Ch2+OmKau4mAaH2JbrHni4JX45qrGnrf+dxjA4VQlJ8PszCHFTL8jFiw e2i77MJMC0CNVhVnOUMwVMnIUzCoSEY3YC/DsL5K9NDutYrj1UeDsrx2cENV/Z25 nPaV1TdOZn4wx87YzSNVOfAfX+zwt2KDomP1PehIqVrLAqNxT+RE6mSw6sV252Xq 2hZBrf95LfoIbtdiqt6mQkjMnD0WnHAMqrh/Bhi8DqYS91isWHWK5QEIzA4mt3ky mdKjlAGAUMbgSzQEJ12sygDVrYqZj9juYh91K2Q==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06; repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox; action=mi-m=1; hc=14; hn=cc,content-language,content-transfer-encoding,content-type, date,feedback-id,from,in-reply-to,message-id,mime-version, references,subject,to,user-agent; Message-Instance: m=1; h=sha256:mkFXVyI06Jhlc63NKc1PuOpdfNDfZ0x5iyzxCxlvvFw=:5GnOlt1KJO/XXysClrPhUP6gcpi8jhXpnd3dV57lF50=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTECDc1UUcjyExEusa35KRxFIJzt4PsAO3BjAX/rk6ZdxE9E8E0KEXs9QCqC2L+pMw sUzUVxCqi0UQ8XwSTKqinKG9tj9eJK70MxQlOzZAsP+gOmkVbgdDEyCiR8oUP56MkrpkIo 3fOEhUnqAU8LjnoIsZgF+Wb19JKonJuzMY5u6fpgHU3EQgOmEMjGZ7WQdl7bhW4M5a/tEf Qz/ASrwbr0atKYLNSpe3HSLE/UBW5UZAhlNO5owTB3U/WIOinNFZVs2vbPQqE4wgwlRnpK f/JqV6pY1Y61jeuUop6oPCguIn5H2x7gMgXFxJsYRwen71noOxy0XMtMWCcgEJvV9H4QKk sfeRuEF4sWAzygB/LOPkJ9/ZHqL2o9qs1yjwPAtnSqojFpuiMb1FNDJ+0dXwQ7hrPUBtSV QSiK+X+WvlM1ONXChAv/WWxBQFbslNtHvvrHxyPlH2Gu4eZAQ+wj4AH3JiNU/a5UVF+S3z hMQ2syR8b/Zmmskgv0wClSeNrzHuUOUw6lLEPsnuM80mc5eZTi+H85o69gICKrQUIFD5Iv Cp5unMew+c8Hnq/PdpYORE9jP9vCBFFHaVIXyR16MkWBFJTboVx1XHcJBHELzbmteeygbM jqggW1ctkpaT+lRYcD7ZPDWZsUy8B7JdpbqzfQVp+vibhhxA3DGqJ2NafZlw X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Oct 2026 12:17:02 -0400 (EDT) Message-ID: <5ce6f59d-2e18-4206-85ae-b8a7efa41726@aklaver.com> Date: Wed, 14 Oct 2026 09:17:01 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: AW: AW: AW: Why is materialized view creation a "security-restricted operation"? To: =?UTF-8?Q?F=C3=A4rber=2C_Franz-Josef_=28StMUK=29?= , Laurenz Albe , "pgsql-general@postgresql.org" Cc: "Haupt, Matthias (StMUK)" References: <77826d7580a9488ca28eb4bcfe94aa37@stmuk.bayern.de> <2e9d29c1513afb47d652387ea5299076ef24adce.camel@cybertec.at> <4d7467aa0ee958343fca8c6bd6720952b5bc08b1.camel@cybertec.at> <5628a96712e14b9fac594b34b0eb9161@stmuk.bayern.de> <687d09da725449d18e88654dafd9efdd@stmuk.bayern.de> <2fa339b7-ab41-4b33-8d4d-ced91798451b@aklaver.com> <0e86d4ee4a96460a8ce7cef26c587ca2@stmuk.bayern.de> Content-Language: en-US From: Adrian Klaver In-Reply-To: <0e86d4ee4a96460a8ce7cef26c587ca2@stmuk.bayern.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/14/26 7:56 AM, Färber, Franz-Josef (StMUK) wrote: > Yes I read your follow-up post. I understood the table is "global". My remaining question simply was: > > Your function temp_table (as ill-named as it might be), > > Can it run concurrently and will the contents be isolated? I suppose so. I have not tested, though I suspect the DROP TABLE will not play nice with other transactions. I'm going to say that something along the lines of what Laurenz Albe proposed below would work better: https://www.postgresql.org/message-id/4d7467aa0ee958343fca8c6bd6720952b5bc08b1.camel%40cybertec.at "If the security restrictions of materialized views prevent you from using them, why don't you use a normal table instead, TRUNCATE it and INSERT into it?" To that I would add, take a look at Row Level Security: https://www.postgresql.org/docs/current/sql-createpolicy.html If you want a more thought out solution you will need to provide a more detailed explanation of what the data flow is in your process and your expectations of security and throughput. > > > Regards, > Franz-Josef Färber > > -----Ursprüngliche Nachricht----- > Von: Adrian Klaver > Gesendet: Mittwoch, 14. Oktober 2026 16:30 > An: Färber, Franz-Josef (StMUK) ; Laurenz Albe ; pgsql-general@postgresql.org > Cc: Haupt, Matthias (StMUK) > Betreff: Re: AW: AW: Why is materialized view creation a "security-restricted operation"? > > On 10/14/26 6:16 AM, Färber, Franz-Josef (StMUK) wrote: >> Thanks for the suggestion. Could work. >> >> * Then we have a table at global scope. >> * However it won't be seen by other transactions, and is deleted in the same transaction. Sounds safe at first glance? >> * Well, what about two transactions running concurrently, both executing public.temp_table()? Is safe, too, as far as I understand about transactions? Each transaction has its own table, even though on global scope? > > As I indicated in a follow on post, my naming the function temp_table() was a mistake. This actually creates a 'permanent' table that survives a run until dropped on next run. Like I said this was a quick and dirty example. Without more information on what your process flow and security expectations this is about as in depth as I can get. > >> >> Quite a bunch of things to consider, but sounds safe enough for me. Thank you. >> >> >> Regards, >> Franz-Josef Färber >> >> -----Ursprüngliche Nachricht----- >> Von: Adrian Klaver >> Gesendet: Dienstag, 13. Oktober 2026 18:23 >> An: Färber, Franz-Josef (StMUK) ; >> Laurenz Albe ; pgsql-general@postgresql.org >> Cc: Haupt, Matthias (StMUK) >> Betreff: Re: AW: Why is materialized view creation a "security-restricted operation"? >> >> On 10/13/26 4:36 AM, Färber, Franz-Josef (StMUK) wrote: >>>>> [rant about PostgreSQL security restrictions] >>> No no no, not about security restrictions. The rant is about lacking orthogonality. About often NOT being able to combine language features. Doesn't anybody share that view? We COULD do better, I think. >> >> Quick and dirty example. >> >> cat test.csv >> 1,dog,t >> 2,cat,f >> 3,fish,t >> >> CREATE OR REPLACE FUNCTION public.temp_table() >> RETURNS TABLE(id integer, type character varying, active boolean) >> LANGUAGE plpgsql >> AS $function$ >> BEGIN >> DROP TABLE IF EXISTS test_csv; >> CREATE TABLE test_csv(id integer, type varchar, active boolean); >> COPY test_csv FROM '/var/lib/postgresql/18/main/test.csv' WITH CSV; >> RETURN QUERY EXECUTE >> 'SELECT id, type, active FROM test_csv'; END; $function$ >> >> >> select * from temp_table(); >> id | type | active >> ----+------+-------- >> 1 | dog | t >> 2 | cat | f >> 3 | fish | t >> >> >>> >>>> If the security restrictions of materialized views prevent you from using them, why don't you use a normal table instead, TRUNCATE it and INSERT into it? >>> The MAT VIEW is used from "outside". From other views, or from a client that connects to the database. >>> >>> * I can replace it with a view; I didn't do that for performance reasons. >>> * I can replace it with a persistent table, a stored procedure, and custom caching logic. That'll work. But this is what a MAT VIEW is for, I thought. >>> >>> >>> Regards, >>> Franz-Josef Färber >>> >>> -----Ursprüngliche Nachricht----- >>> Von: Laurenz Albe >>> Gesendet: Dienstag, 13. Oktober 2026 13:06 >>> An: Färber, Franz-Josef (StMUK) >>> ; >>> Adrian Klaver ; >>> pgsql-general@postgresql.org >>> Cc: Haupt, Matthias (StMUK) >>> Betreff: Re: Why is materialized view creation a "security-restricted operation"? >>> >>> On Mon, 2026-10-12 at 14:59 +0000, Färber, Franz-Josef (StMUK) wrote: >>> >>>> [rant about PostgreSQL security restrictions] >>>> >>>> Ok, I think some people get the point that I claim SQL / Postgres is >>>> lacking modularity / orthogonality in the way as I tried to define above. >>> >>> I don't. Just because the features you are stacking don't work the way you'd like them to, it's not a shortcoming of orthogonality or modularity. >>> >>>> So let me explain. And perhaps somebody can give good advice. >>>> >>>> * I am running Postgres in a container. >>>> * I am using https://github.com/pramsey/pgsql-http to query REST services using credentials. >>>> * I took it as good advice to pass environment variables into the container, and to pass >>>> passwords as single files, in mounted container directory /run/secrets/ . >>>> * Inside postgres I am trying to load that data, using memoization pattern. For example using >>>> CREATE TEMP TABLE x ...; COPY x ... FROM PROGRAM 'cat /run/secrets/mypassword'. >>>> This part is encapsulated as a function. >>>> >>>> * Now there was one point where I was using a MATERIALIZED VIEW accessing that function. >>>> And well, that failed. >>>> >>>> What I COULD do is replace COPY x ... FROM PROGRAM with a file_fdw >>>> FOREIGN TABLE, but this way it isn't parametrizable. I would have to >>>> create as many foreign tables as I have passwords / environment variables, I think. >>> >>> If the security restrictions of materialized views prevent you from using them, why don't you use a normal table instead, TRUNCATE it and INSERT into it? >>> >>> Yours, >>> Laurenz Albe >> >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com > > > -- > Adrian Klaver > adrian.klaver@aklaver.com -- Adrian Klaver adrian.klaver@aklaver.com