Re: How to make PostreSQL utilities honor home directories?

Поиск
Список
Период
Сортировка
От Peter J. Holzer
Тема Re: How to make PostreSQL utilities honor home directories?
Дата
Msg-id 20220902002307.qrxhyeexronkdgsr@hjp.at
обсуждение исходный текст
Ответ на Re: How to make PostreSQL utilities honor home directories?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: How to make PostreSQL utilities honor home directories?  (Jeffrey Walton <noloader@gmail.com>)
Re: How to make PostreSQL utilities honor home directories?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On 2022-09-01 18:16:14 -0400, Tom Lane wrote:
> Jeffrey Walton <noloader@gmail.com> writes:
> > We are having a heck of a time getting PostreSQL utilities to honor
> > home directories. For example, when I execute this script:
>
> >     sudo -H -u postgres PGPASSWORD=${password} \
> >         psql -h "${hostname}" -U "${username}" -d "${database}" \
> >         --command="..."
>
> > It produces failures:
>
> >     could not change directory to "/home/jwalton/godojo": Permission denied
>
> 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.
>
> 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 =psql
lrwxrwxrwx 1 root root 37 Aug 11 11:25 /bin/psql -> ../share/postgresql-common/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 "(∅)".
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.04+1))
Type "help" for help.

postgres=#

However, when I start a shell, I see that the directory has been
changed:

postgres=# \!
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")     = 0
chdir("/home/hjp/tmp/t")                = 0
chdir("/usr/lib/postgresql/13/bin")     = 0
chdir("/home/hjp/tmp/t")                = 0

(this is without sudo, because I can't strace that)

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Peter
Дата:
Сообщение: Re: How to make PostreSQL utilities honor home directories?
Следующее
От: Jeffrey Walton
Дата:
Сообщение: Re: How to make PostreSQL utilities honor home directories?