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 1s9q4Y-005RYk-RT for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2024 17:48:20 +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 1s9q4W-001rvq-Tf for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2024 17:48:17 +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.94.2) (envelope-from ) id 1s9q4W-001rvi-Ay for pgsql-general@lists.postgresql.org; Wed, 22 May 2024 17:48:16 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s9q4T-000Ejv-D5 for pgsql-general@postgresql.org; Wed, 22 May 2024 17:48:15 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-23f9d07829bso2800781fac.3 for ; Wed, 22 May 2024 10:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716400091; x=1717004891; darn=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=dhpHAvGQbwTBKCPi8w4bseGZ4TtFJIFL4wmAsB0Ik/Y=; b=R3bOZh2bO3IS7uaKZ/+GjppVObWpiT+Ip4lywI6WrfGRYmS5nf4FGUc4b/ncsiwGsE /vsU2JjggkWDbd7q69lttAdy5Gj1+kBMW5Sp/Rd6++G3eDz6JQZHdOdAS0R6Zb0bzCj2 eW9cRtE8Y4sP+ocYeJxe0PCB+HDrrwRoa8837iYVX60D+amvb2Np7fXnpplzG8+1EGJD v0fSZ44N4IyDC9nGH3EXs3Wctf7j1U3WWkeUv2j9fvg4wrf+HEvIk3Q6Bu2T9ugR78uj GelJLUY7/BLkUW95HaU05RbeJv6kfduWol2fcQp3O0DztYbKEUNZGse3lN1Izvd+talI q0VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716400091; x=1717004891; 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=dhpHAvGQbwTBKCPi8w4bseGZ4TtFJIFL4wmAsB0Ik/Y=; b=dF5vj/CpVCGpxRRiXK0LPTaETj/wtvvknJuOGMPJe5M4FQoCSoRKwKySN+TfPtiLn6 1AkL+tOTjfwJMEsThfqOYWYWiAN1mQ9hjGJvc5vTUkgOKQZuAsztOPDtMCPiFJNa9fP1 ZJVHgiFxzav5+yh+toz8dGBEZrZEkB6OXphDMi39UfhbtMXDp3xkVVhPGvXOqQuVe7w/ 6B2CwW/HJzp9JgHfvVI08RO7Ik/15nXFAzSDQ32LWH1udYqiWN5ojV+gVr5wgL9XoY8V 5qD2OwF8bl2pclm8KnGNnwk0LG/xbf5okAGvQJIHM666V0tQ89Cega0ApcLaDCe9yGoP oRTA== X-Gm-Message-State: AOJu0Yx3j+hCtzJ/wfGSjypcWGLFH7NZzyYX73rzovglYEytjABKrlvD iNT5/RCKVwZxmoJg0EWLSRyJzCwpbPoYNbWYwdvXE8H6aLR20IRwz2IFWsUuDs+m4UCQ7+VLzYP /OPhtZ9oGC5oNEwi77NTjs8VKw9JE20d6 X-Google-Smtp-Source: AGHT+IFFnQF5G+k/G3whI9PW0VR7rZVkq7oYWG5FsINXpR5FUzMH7bKgWW1QKRePXNhMvnOjLYEH765Qc6nWaXkuC0c= X-Received: by 2002:a05:6870:9691:b0:233:f233:c3ee with SMTP id 586e51a60fabf-24c68e04970mr3020141fac.50.1716400091532; Wed, 22 May 2024 10:48:11 -0700 (PDT) MIME-Version: 1.0 References: <4165841.1716397819@sss.pgh.pa.us> In-Reply-To: <4165841.1716397819@sss.pgh.pa.us> From: Ron Johnson Date: Wed, 22 May 2024 13:47:59 -0400 Message-ID: Subject: Re: search_path and SET ROLE To: Tom Lane Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000bf95e806190e8908" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000bf95e806190e8908 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 22, 2024 at 1:10=E2=80=AFPM Tom Lane wrote: > Ron Johnson writes: > > It seems that the search_path of the role that you SET ROLE to does not > > become the new search_path. > > It does for me: > > regression=3D# create role r1; > CREATE ROLE > regression=3D# create schema r1 authorization r1; > CREATE SCHEMA > regression=3D# select current_schemas(true), current_user; > current_schemas | current_user > ---------------------+-------------- > {pg_catalog,public} | postgres > (1 row) > > regression=3D# set role r1; > SET > regression=3D> select current_schemas(true), current_user; > current_schemas | current_user > ------------------------+-------------- > {pg_catalog,r1,public} | r1 > (1 row) > > regression=3D> show search_path ; > search_path > ----------------- > "$user", public > (1 row) > > The fine manual says that $user tracks the result of > CURRENT_USER, and at least in this example it's doing that. > (I hasten to add that I would not swear there are no > bugs in this area.) > > > Am I missing something, or is that PG's behavior? > > I bet what you missed is granting (at least) USAGE on the > schema to that role. PG will silently ignore unreadable > schemas when computing the effective search path. > There are multiple schemata in (sometimes) multiple databases on (many) multiple servers. As a superuser administrator, I need to be able to see ALL tables in ALL schemas when running "\dt", not just the ones in "$user" and public. And I need it to act consistently across all the systems. (Heck, none of our schemas are named the same as roles.) This would be useful for account maintenance: CREATE ROLE dbagrp SUPERUSER INHERIT NOLOGIN; ALTER ROLE dbagrp SET search_path =3D public, dba, sch1, sch2, sch3, sch4; CREATE USER joe IN GROUP dbagrp INHERIT PASSWORD =3D 'linenoise'; Then, as user joe: SHOW search_path; search_path ----------------- "$user", public (1 row) SET ROLE dbagrp RELOAD SESSION; -- note the new clause SHOW search_path; search_path ----------------------------------- public , dba, sch1, sch2, sch3, sch4 (1 row) When a new DBA comes on board, add him/her to dbagrp, and they automagically have everything that dbagrp has. Now, each dba must individually be given a search_path. If you forget, or forget to add some schemas, etc, mistakes ger made and time is wasted. --000000000000bf95e806190e8908 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, May 22, 2024 at 1:10=E2=80=AFPM T= om Lane <tgl@sss.pgh.pa.us> = wrote:
Ron Johnson <ronljohnsonjr@gmail.com> writes:
> It seems that the search_path of the role that you SET ROLE to does no= t
> become the new search_path.

It does for me:

regression=3D# create role r1;
CREATE ROLE
regression=3D# create schema r1 authorization r1;
CREATE SCHEMA
regression=3D# select current_schemas(true), current_user;
=C2=A0 =C2=A0current_schemas=C2=A0 =C2=A0| current_user
---------------------+--------------
=C2=A0{pg_catalog,public} | postgres
(1 row)

regression=3D# set role r1;
SET
regression=3D> select current_schemas(true), current_user;
=C2=A0 =C2=A0 current_schemas=C2=A0 =C2=A0 =C2=A0| current_user
------------------------+--------------
=C2=A0{pg_catalog,r1,public} | r1
(1 row)

regression=3D> show search_path ;
=C2=A0 =C2=A0search_path=C2=A0 =C2=A0
-----------------
=C2=A0"$user", public
(1 row)

The fine manual says that $user tracks the result of
CURRENT_USER, and at least in this example it's doing that.
(I hasten to add that I would not swear there are no
bugs in this area.)

> Am I missing something, or is that PG's behavior?

I bet what you missed is granting (at least) USAGE on the
schema to that role.=C2=A0 PG will silently ignore unreadable
schemas when computing the effective search path.

=
There are multiple schemata in (sometimes) multiple databases on= (many) multiple servers.

As a superuser administr= ator, I need to be able to see ALL tables in ALL schemas when running "= ;\dt", not just the ones in "$user" and public.=C2=A0 And I = need it to act consistently across all the systems.

(Heck, none of our schemas are named the same as roles.)
This would be useful for account maintenance:

CREATE ROLE dbagrp SUPERUSER INHERIT NOLO= GIN;
ALTER ROLE dbagrp SET search= _path =3D public, dba, sch1, sch2, sch3, sch4;
CREATE USER joe IN GROUP dbagrp=C2=A0INHERIT PASSWORD =3D &#= 39;linenoise';

Then, as user joe:
SHOW search_path;
=C2=A0 =C2=A0search_path=C2=A0 =C2=A0
---------------= --
=C2=A0"$user", public
(1 row)

= SET ROLE dbagrp RELOAD SESSION; -- note the new cl= ause
SHOW s= earch_path;
=C2=A0 =C2=A0search_p= ath=C2=A0 =C2=A0
-----------------------------------
public
, dba, sch1, sch2, sch3, sch4<= font face=3D"monospace">
(1 row)

When a new DBA comes on board,= add him/her to dbagrp, and they automagically have everything=C2=A0 that d= bagrp=C2=A0has.
Now, each dba must individually be given a se= arch_path.=C2=A0 If you forget, or forget to add some schemas, etc, mistake= s ger made and time is wasted.

--000000000000bf95e806190e8908--