工作中遇到这样的问题,服务器上需要从root切换至postgreSQL安装用户去启动postgreSQL服务。
切换用户和启动postgreSQL命令如下:
# 切换至pgsql用户 su postgres # 启动 pg_ctl start -bash: pg_ctl: command not found
提示pg_ctl命令不存在,但是可以肯定的是之前安装postgreSQL时就是这么启动的,怎么这次不行了呢。
后来了解到原来是su命令的问题,有没有横杠"-"是有区别的。
su - postgres
有横杠login shell:用户切换,更改工作目录,加载所有用户环境配置。
无横杠interactive shell:用户切换,但是工作目录不会切换到该用户所在工作目录,也不会加载该用户设置的环境变量。
"When Bash starts executes the commands in a variety of different scripts.
(1) When started as an interactive login shell: Bash reads and executes
the /etc/profile (if it exists). After reading that file, it looks for
~/.bash_profile, ~/.bash_login, and ~/.profile in that order, and reads
and executes the first one (that exists and is readable). When a login
shell
exits: Bash reads and executes ~/.bash_logout (if it exists)。
(2) When started as an interactive shell (but not a login shell): Bash reads and executes ~/.bashrc (if it exists)."