我希望能够使用 pg_ctl 来管理我的 crewdb 数据库。但是,当我使用 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=chh1 而不是 PGUSER=postgres,但当我发出命令 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
我必须以 root 身份打开数据目录,例如:
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,但不确定这样做是否安全,不会危及我的数据。如果您需要更多信息,请告诉我。