PostgreSQL 10: pg_ctl 상태가 Ubuntu 18.04에서 작동하지 않습니다.

PostgreSQL 10: pg_ctl 상태가 Ubuntu 18.04에서 작동하지 않습니다.

pg_ctl을 사용하여 크루DB 데이터베이스를 관리하고 싶습니다. 그러나 pg_ctl status를 사용하면 다음 오류가 발생합니다.

chh1@chh1:~$ pg_ctl status
pg_ctl: could not open PID file "/var/lib/postgresql/10/main/postmaster.pid": Permission denied

왜 이런 일이 발생하는지, 어떻게 해결해야 하는지 잘 모르겠습니다. 왜냐하면 다음과 같은 이유 때문입니다.

chh1@chh1:~$ which pg_ctl
/usr/lib/postgresql/10/bin/pg_ctl

chh1@chh1:~$ which initdb
/usr/lib/postgresql/10/bin/initdb

chh1@chh1:~$ whoami
chh1

crewdb=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 chh1      | Superuser                                                  | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}


chh1@chh1:~$ cat .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

PATH=$PATH:/usr/lib/postgresql/10/bin
PGDATA=/var/lib/postgresql/10/main
PGDATABASE=crewdb
PGUSER=postgres

export PATH PGDATA PGDATABASE PGUSER

.profile에서 PGUSER=postgres 대신 PGUSER=chh1을 시도했지만 pg_ctl status 명령을 실행할 때 여전히 동일한 오류 메시지가 나타납니다. 이 문제에 대해 나를 도와줄 수 있는 사람이 있나요? 다음 postgresql 클러스터가 있습니다.

chh1@chh1:~$ ps -ef | grep postgres
postgres  2094     1  0 11:08 ?        00:00:01 /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf
postgres  2114  2094  0 11:08 ?        00:00:00 postgres: 10/main: logger process
postgres  2123  2094  0 11:08 ?        00:00:00 postgres: 10/main: checkpointer process
postgres  2124  2094  0 11:08 ?        00:00:00 postgres: 10/main: writer process
postgres  2125  2094  0 11:08 ?        00:00:00 postgres: 10/main: wal writer process
postgres  2126  2094  0 11:08 ?        00:00:01 postgres: 10/main: autovacuum launcher process
postgres  2127  2094  0 11:08 ?        00:00:01 postgres: 10/main: stats collector process
postgres  2128  2094  0 11:08 ?        00:00:00 postgres: 10/main: bgworker: logical replication launcher
chh1      6401 17468  0 17:47 pts/1    00:00:00 grep --color=auto postgres

다음과 같은 데이터 디렉토리를 열려면 루트여야 한다는 것도 특이한 것 같습니다.

chh1@chh1:~$ cd /var/lib/postgresql/10/main
bash: cd: /var/lib/postgresql/10/main: Permission denied

root@chh1:/var/lib/postgresql/10/main# ls -l
total 100
drwx------ 20 postgres postgres 4096 Jan 13 11:08 ./
drwxr-xr-x  3 postgres postgres 4096 Jul 24 19:12 ../
drwx------  6 postgres postgres 4096 Aug 10 23:04 base/
-rw-------  1 postgres postgres   44 Jan 13 11:08 current_logfiles
drwx------  2 postgres postgres 4096 Jan 13 11:08 global/
drwx------  2 postgres postgres 4096 Jan 13 11:08 log/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_commit_ts/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_dynshmem/
drwx------  4 postgres postgres 4096 Jan 13 11:13 pg_logical/
drwx------  4 postgres postgres 4096 Jul 24 19:12 pg_multixact/
drwx------  2 postgres postgres 4096 Jan 13 11:08 pg_notify/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_replslot/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_serial/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_snapshots/
drwx------  2 postgres postgres 4096 Jan 13 11:08 pg_stat/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_stat_tmp/
drwx------  2 postgres postgres 4096 Jan  3 06:12 pg_subtrans/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_tblspc/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_twophase/
-rw-------  1 postgres postgres    3 Jul 24 19:12 PG_VERSION
drwx------  3 postgres postgres 4096 Jan  3 06:12 pg_wal/
drwx------  2 postgres postgres 4096 Jul 24 19:12 pg_xact/
-rw-------  1 postgres postgres   88 Jul 24 19:12 postgresql.auto.conf
-rw-------  1 postgres postgres  130 Jan 13 11:08 postmaster.opts
-rw-------  1 postgres postgres  108 Jan 13 11:08 postmaster.pid

내 생각은 파일 권한을 /var/lib/postgresql/10/main/chh1:chh1로 변경하는 것이지만 내 데이터를 위험에 빠뜨리지 않고 그렇게 하는 것이 안전한지 확실하지 않습니다. 추가 정보가 필요하면 알려주시기 바랍니다.

관련 정보