Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTuSu-0000iu-Nx for pgsql-general@arkaria.postgresql.org; Fri, 02 Sep 2022 00:23:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTuSr-00007f-UB for pgsql-general@arkaria.postgresql.org; Fri, 02 Sep 2022 00:23:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTuSr-00007V-DY for pgsql-general@lists.postgresql.org; Fri, 02 Sep 2022 00:23:17 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTuSl-0005Dj-3f for pgsql-general@lists.postgresql.org; Fri, 02 Sep 2022 00:23:16 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 22EE565B2; Fri, 2 Sep 2022 02:23:07 +0200 (CEST) Date: Fri, 2 Sep 2022 02:23:07 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: How to make PostreSQL utilities honor home directories? Message-ID: <20220902002307.qrxhyeexronkdgsr@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <780195.1662070574@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ztcflmnl7ap3zdgx" Content-Disposition: inline In-Reply-To: <780195.1662070574@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ztcflmnl7ap3zdgx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2022-09-01 18:16:14 -0400, Tom Lane wrote: > Jeffrey Walton writes: > > We are having a heck of a time getting PostreSQL utilities to honor > > home directories. For example, when I execute this script: >=20 > > sudo -H -u postgres PGPASSWORD=3D${password} \ > > psql -h "${hostname}" -U "${username}" -d "${database}" \ > > --command=3D"..." >=20 > > It produces failures: >=20 > > could not change directory to "/home/jwalton/godojo": Permission de= nied >=20 > You've left out quite a lot of information here ... like what > connection that directory has to do with anything. Is it your > current directory when you invoke this command? Probably. See below. > If so, a plausible explanation is that psql is trying to chase a > symlink to somewhere, which involves some chdir's so it can resolve > the symlink correctly, and afterwards it has to change back to > where it started --- which would fail if it can't look up that > directory. >=20 > Why it's trying to resolve a symlink isn't apparent though. > Is the "psql" you're invoking a symlink to somewhere? It is on Debian/Ubuntu: % ls -l =3Dpsql lrwxrwxrwx 1 root root 37 Aug 11 11:25 /bin/psql -> ../share/postgresql-com= mon/pg_wrapper* (this is the pgdg package) I do get the same message, but psql seems to start normally: % sudo -u postgres -H psql could not change directory to "/home/hjp/tmp/t": Permission denied Null display is "(=E2=88=85)". Line style is unicode. Border style is 2. Unicode border line style is "double". Timing is on. Expanded display is used automatically. psql (13.8 (Ubuntu 13.8-1.pgdg20.04+1), server 11.17 (Ubuntu 11.17-1.pgdg20= =2E04+1)) Type "help" for help. postgres=3D# However, when I start a shell, I see that the directory has been changed: postgres=3D# \! postgres@trintignant:/usr/lib/postgresql/13/bin$ However, the symlink doesn't seem to be the culprit. If I run % sudo -u postgres -H /usr/lib/postgresql/13/bin/psql (which is not a symlink) I get the same behaviour. So it seems that psql changes to its basedir and then can't change back again. And sure enough, strace shows: chdir("/usr/lib/postgresql/13/bin") =3D 0 chdir("/home/hjp/tmp/t") =3D 0 chdir("/usr/lib/postgresql/13/bin") =3D 0 chdir("/home/hjp/tmp/t") =3D 0 (this is without sudo, because I can't strace that) hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --ztcflmnl7ap3zdgx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmMRTOYACgkQ8g5IURL+ KF2rWw/+PWZHuoWUVXyHBuebBOPP9l1b5K58O1sgnkNDLAPKQhQqj8HhXGw6l5su TI/zJPtXJorY4AywhrRePkqQJnsie9xcORxAIYMaZseGSjFPPIX+0lwBA2fabe0H nwml87Y4UquaYdnVa5GMebwbV4vS5akxPiVXn++kFa5pZV0BFrXIDebjGYW/wwRu YIVSWXNY3CMPFuRY4o3P1Zq7nP9XoO7PEq4zHB3f01KsTyEulIj7cr1E+RZGWLLH jHxVnrhdeTF9IjJHcVw31iNCHx/7erpXv9DQg0BMojCfzCwGNRNd8MIzTfhHX4Nu nn1wv9KEulb6jTSWWRDn9glb4XWe/GkVNWVFk0VZ7wV76ZdiY/KCE6OVeQpd5j4C RYxIFUe5OsOjy3JOigwkw9EwiYm+ZT4tPwx2mX9ZK5cqLcOLMQ1HoqfamlDm9zlJ U4j4EskEwJepSukUTkU/ouiZ8sgN7Ip6OpEnG2iET1neUBr78KPy1VlsQogE8eQc m+vkQgoZkZGLsuXvjR72luFnF+QpXrWONyT34rlpxjKxvf4fWw9DdbXsDfL73Hld /foSsC0QMZxhvFNSl20IHxgUahnBZY46ClbvrebtPj5TnEUOYaHpovxCuCQcG09y 0VnbIb0koTH0E/GmOt0zEoPy/R53c4WT6zOjOqAD91llk9u11L0= =0HWe -----END PGP SIGNATURE----- --ztcflmnl7ap3zdgx--