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 1xGzzF-00000002lTf-1QV3 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2026 14:29:45 +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 1xGzzE-00000003f9s-1U0L for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2026 14:29:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGzzD-00000003f9g-0umK for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2026 14:29:44 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xGzzA-00000001zYw-2zwR for pgsql-general@postgresql.org; Wed, 14 Oct 2026 14:29:42 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 6E4681D00298 for ; Wed, 14 Oct 2026 10:29:39 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 14 Oct 2026 10:29:39 -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=1791988178; x=1792074578; bh=vK4cC7zdMcAzEtYU1jyNthbdmGdM6k9pXwWHlkOaWAY=; b= jjrgM1pSZVgDmVKYXLB93TCefNuU3I4iel1X1dsDFBU/dO2F5TuoTy+vgYpJs0Qf vfFkSZZousPRZkkg7d5hJx7A5h+x7n++SGa/hRm51IpiX2xR4Qqg0djLP0pHvz1B lmsC+mfzmqgl1VbUsgUrj3MyCl/zmIN1t+AC4p4vJMCELf+5Fi8dosH0wyYTCuP2 8B0I56R29qn3U73z/QSI+VClrqNSbwzcYUkBTTU46xdk+bCMntK2hkx/O6hwEf8n uJZ07p5zE3ggI5unjFAZB6m+5MCutwoTqakbDsjOiYIDcp87OHqFrVvlbZJjVc3g bucI8psvpllYF1g/3w0hZw== 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=1791988178; x= 1792074578; bh=vK4cC7zdMcAzEtYU1jyNthbdmGdM6k9pXwWHlkOaWAY=; b=H m9KguJ32LGcURCaYLUX5WR2NwXEDmVLauN5xLleKCvDXuKRpZUvLKt+v6fk3O/ys r9xHOcnpOAg5ceqJQaLjUWfH0M4WmBY6q1HUxB2JA6lQtrprhVeOQX8enTsNsua1 De+zUOM7NBdDnjnQ9zMHIn/mg/G699NRhyPglbKY09KpXv4U9RHzH/u6C++F7Zvl MA9gxoMjKJ+fqPcZ2IR+m8o/eA9wRYnHRZaovyROJDBhl8QT4ANMr+r6LvUwDCv9 jggUh3QbGEh1zpFqaqN2P9uoevj4Up9ShfX3d8gdQxfQlEBbLqLpHc0oXpEbVM7t QLpaYqqi0kfBgkoeIgq3g== 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=1791988178; d=aklaver.com; mf=PGFkcmlhbi5rbGF2ZXJAYWtsYXZlci5jb20+; rt=PHBnc3FsLWdlbmVyYWxAcG9zdGdyZXNxbC5vcmc+; s=fm1:rsa-sha256:Hcmv1IkpqxytEUVsLGY1pVFhvUbZJp5HXQT36qMabPPjyo4 vf8io0/UKwmSzxLl2Imq4FZZOgodcThEEZ8ZlIdEL6RHjD7YDn/pK4EbyAs3b8OK 3dDf84W/WWptClBv2CipkTXdJH55Nc89gBehnh08JwwWT0KEYWa5NLFVe96i46Tu RdI8MdlC6Hq14Ifo/xASx/5YfgjVzOhcvWHSNyo3Sk35IUg7cJCnaZBtdCTfQapC lkhciZs5izEsXls13uzOLuhou+4HRu+e69rHtsT2YSOxYsPBh42Da/GWq1RP80gB S3AaJYQx9OE5q7301fVchCpHJj0WUEIKupI4B1g==; 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:MlLJun6cEPfdUvn10AVQSB692Ek9cp+0A04voynGroo=:55sEfeJh7ho1F2bH9hfoVEe7BRlXdO3PfeB1zRcZeKA=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGV9HIEICTyHcfFQR4aeiaIugUTDUsROHpawduU/mMqmw/YfFUr8DDeaKMOAQjn9p w9Kj1t6MgFFqOZA4GuXEL/NZgsqP4kv0vUUdlJZ1mzxIQfL+Dalt+D0xfyTCChIcl/6VWZ bSK0w4zqtsk07EGANri8XbfflUetQ6tNYDLOSxNPnKcAZXkboFlhiHv29G16/tnF82dLu2 srdPNprT9DOej9sI8SbxowJL8SlU1sOBNvsRgRYrMOjnFd6QZOxehIdk4tFhTGuItMv8CM cwjXrIW1GCWCB41KJqL2UW/OShBOHr1L955iEGn2UO3oKfDynCyNrkFObhcekaa71p9qrk TyPWFWUMQ72jb3cKy0fhXXO5zQEBGNFhAJe7BKodEhBczoRgqQho2XtsMo2lKEU4Bf3Znx TlSHZJjhKec4OdHOUp/JlilgygMioOx5lbX03HHHckrhH/vhTHdhNP0mnN4ytHWHLwuk7j 4GzFVkJ//Sy5bgM5w+y683vp6ryJf0pUZ7+bOS7VIwo7rft5iTf1Nk8lpeZ+s9bmODrele e0J9nAlUi+inOlAqfZ25xCfPaxVfuath3RDLBohjtRVfGk7ksbvaQUPWjc0qXz5LKHKMDB yW44ElG2FPKJYyhkLt6H1JeJ5MmaObnHKJjDxXv/GzPeCe/0Yg0Vu0u2CLQA X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Oct 2026 10:29:37 -0400 (EDT) Message-ID: <2fa339b7-ab41-4b33-8d4d-ced91798451b@aklaver.com> Date: Wed, 14 Oct 2026 07:29:37 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: 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> Content-Language: en-US From: Adrian Klaver In-Reply-To: <687d09da725449d18e88654dafd9efdd@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 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