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.94.2) (envelope-from ) id 1siGoo-001SHz-1B for pgsql-general@arkaria.postgresql.org; Sun, 25 Aug 2024 17:14:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1siGol-00HDNu-2H for pgsql-general@arkaria.postgresql.org; Sun, 25 Aug 2024 17:14:19 +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.94.2) (envelope-from ) id 1siGok-00HDNl-L9 for pgsql-general@lists.postgresql.org; Sun, 25 Aug 2024 17:14:19 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1siGoi-001OGg-Pa for pgsql-general@lists.postgresql.org; Sun, 25 Aug 2024 17:14:17 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5a10835487fso5415898a12.1 for ; Sun, 25 Aug 2024 10:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724606055; x=1725210855; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kkxAVxZ88itjt3T0D0v9eLixW8IqgpJdbu9TS6ZyCX0=; b=JoM+lBS2NUeSxW4Y6sMpVGqExa2Y5DJYT1yQ2oxNWIE8qyqg6xjxGTZCqJ+myIOVr9 a33BrAQSDtoiDU8HjEFCVSncYKxUX2s9KifW3xrv8jp8v1/vPXUCYCDLWQVAKqENdWv3 2pejoej9numWOLuD4yV5WWCNZisbz8o64I9sd14ed8uHku5YuIm+wqvAWRgF/TIfSsN4 cI0m+MoaBHdIJs3dEw0/O380DG76grDkrZjMe+HDstHzkDnz5y3EMfYzI6QMJTlgMlVs HbAVpUBob5f73tuzZeWHrAQ512fyd8xSdcoW/uem8CfS6kwzRVm1/TpD3+rAO77xHZrb ivMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724606055; x=1725210855; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kkxAVxZ88itjt3T0D0v9eLixW8IqgpJdbu9TS6ZyCX0=; b=ob0HphOOcXMdPWkFZFBV6euvXtw9dwdgRPkukGV1p2XYqSUd14FzYsjiQ9HKoXp9kv n0Z0eWozZ18uIYjTIUjvrYje7onDfdqIIS6krP2rquf6Wv8CCupUqqxchqY37xWUfDpv XahGJBw2o2CCULDies8/YVfcjhPOqepz3mShSpXEfsCt6EbtkDS9WUb7BJpXIYk9oAJq LBVNEAbNkasXRCpFExoGZazi/wR6aOQ3buK5OKRYtAqeoSDmiyh/ormJFMxHYG7TIjm+ 09f/DZr648V3MDgKh1z9rUoCTeNzIrZ+AtuLpGYOVCrXWgsO2REGLPWe/r4F8udJW3P3 FIrw== X-Forwarded-Encrypted: i=1; AJvYcCWZto1WsZjeuTiVK6krNd4Ykq0XyMCno+mpkLOKjypvLFUVBO1maY3nVWz2kmxuy22j4cpK2OsMagA8iIIB@lists.postgresql.org X-Gm-Message-State: AOJu0Ywh5WFWhPsoS6IsaVpVHNgHY+gOD/K/Xtu3G54xXI21KgRLcclK gya4x33f+ZZhMucZ5A2sQPfbtdbjeosMgmyMblzkfeduvPuk5CdZ4Rnc5+AhLapa3aAIm7lq290 EW6y2eMUt3EOhnGng32eDn0WArok= X-Google-Smtp-Source: AGHT+IG1jm79WpohJbnPGDrlqZg/pRtP0S/g0JH08GMuBgpkDaBSyV5OTEzcptZGjEewEfP52yCY1mui78K7UpsMihE= X-Received: by 2002:a17:907:3f18:b0:a86:7c6e:2bb9 with SMTP id a640c23a62f3a-a86a51632damr548994066b.2.1724606054552; Sun, 25 Aug 2024 10:14:14 -0700 (PDT) MIME-Version: 1.0 References: <73bc7752-442c-4c67-a263-46017f1948cc@vondra.me> <4fb5ab14-80c6-4ca8-b451-df3cbcacd92f@aklaver.com> In-Reply-To: <4fb5ab14-80c6-4ca8-b451-df3cbcacd92f@aklaver.com> From: Marcelo Zabani Date: Sun, 25 Aug 2024 14:14:03 -0300 Message-ID: Subject: Re: ERROR: could not open relation with OID XXXX To: Adrian Klaver Cc: Tomas Vondra , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000004262ce06208523b6" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000004262ce06208523b6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you all for your comments. > I would think that the queries in that case would be running as a superuser in order to do the migrations. Users of codd can choose the role that applies their migrations. Codd even supports individual migrations running with ad-hoc users (so that a migration can use the _postgres_ user to create the application's database, for example) and users are free to add statements like `SET ROLE` inside their migrations, too. So it's sadly not possible AFAICT to force superuser onto them. But I think I have plenty of things to try to avoid this problem, from retrying like Tomas suggested to materialized CTEs that filter out temporary relations before functions like pg_get_indexdef are called. I will give these things a shot. Regards. On Sun, Aug 25, 2024 at 1:13=E2=80=AFPM Adrian Klaver wrote: > On 8/25/24 08:36, Marcelo Zabani wrote: > > > we do some special stuff for catalogs > > > > That is good to know, thanks! > > > > > I believe you could actually lock the pg_class rows for update. Just > > add FOR UPDATE at the end of the query. > > > > Thanks, but I tried that and got "ERROR: permission denied for table > > pg_class", even if I try it only for tables the user owns. > > > > As I understand it this issue came up in: > > https://github.com/mzabani/codd > > I would think that the queries in that case would be running as a > superuser in order to do the migrations. > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > --0000000000004262ce06208523b6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you all for your comments.

=
> I would think that the queries in that case would be running as a=
superuser in order to do the migrations.

Users of = codd can choose the role that applies their migrations. Codd even supports = individual migrations running with ad-hoc users (so that a migration can us= e the _postgres_ user to create the application's database, for example= ) and users are free to add statements like `SET ROLE` inside their migrati= ons, too. So it's sadly not possible AFAICT to force superuser onto the= m.

But I think I have plenty of things to try to a= void this problem, from retrying like Tomas suggested to materialized CTEs = that filter out temporary relations before functions like pg_get_indexdef a= re called.

I will give these things a shot.

Regards.

On Sun, Aug 25, 2024 at 1:13=E2=80= =AFPM Adrian Klaver <adrian= .klaver@aklaver.com> wrote:
On 8/25/24 08:36, Marcelo Zabani wrote:
>=C2=A0 > we do some special stuff for catalogs
>
> That is good to know, thanks!
>
>=C2=A0 > I believe you could actually lock the pg_class rows for upd= ate. Just
> add FOR UPDATE at the end of the query.
>
> Thanks, but I tried that and got "ERROR: =C2=A0permission denied = for table
> pg_class", even if I try it only for tables the user owns.
>

As I understand it this issue came up in:

https://github.com/mzabani/codd

I would think that the queries in that case would be running as a
superuser in order to do the migrations.

--
Adrian Klaver
adrian.klave= r@aklaver.com

--0000000000004262ce06208523b6--