首先在root用户.bash_profile中加入环境变量信息:
[root@ldap ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export HG_HOME=/hgdb/4.0
export PGUSER=highgo
export PGPORT=5866
export PGDATA=$HG_HOME/data
export PATH=$HG_HOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$HG_HOME/lib:$LD_LIBRARY_PATH
此时,即可通过root执行psql命令:
[root@ldap ~]# psql --c '\i a.sql'
current_user
--------------
highgo
(1 row)
[root@ldap ~]# psql --c '\! df -h'
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 46G 4.2G 42G 10% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 497M 88K 497M 1% /dev/shm
tmpfs 497M 7.0M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 497M 157M 341M 32% /boot
tmpfs 100M 0 100M 0% /run/user/0
tmpfs 100M 16K 100M 1% /run/user/42
此种配置下,不能在root下使用pg_ctl命令:
[root@ldap ~]# pg_ctl stop
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@ldap ~]# pg_ctl start
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@ldap ~]# pg_ctl reload
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
危险之处:可以按如下方法执行(可通过psql执行部分类似rm的操作)
[root@sourcedb ~]# date
Thu Aug 31 12:02:39 CST 2017
[root@sourcedb ~]# psql --c '\! rm -rf /'
rm: it is dangerous to operate recursively on `/'
rm: use --no-preserve-root to override this failsafe
[root@sourcedb ~]# psql --c '\! rm -rf /home'
[root@sourcedb ~]# psql --c '\! rm -rf /opt'
[root@sourcedb ~]# cd /
[root@sourcedb /]# ls
bin dev hg4.0 hgdata hgdb2 hvr lib64 media mnt orada root selinux sys u01 var
boot etc hgbackup hgdb highgo lib lost+found misc net proc sbin srv tmp usr
[root@sourcedb /]# psql --c '\! rm -rf /dev'
rm: cannot remove `/dev/pts/0': Operation not permitted
rm: cannot remove `/dev/pts/ptmx': Operation not permitted
rm: cannot remove `/dev/shm': Device or resource busy
[root@sourcedb /]# psql --c '\! rm -rf /boot'
rm: cannot remove `/boot': Device or resource busy
[root@sourcedb ~]# psql --c '\! rm -rf / --no-preserve-root'
如上之后后,系统中大量文件被删除,将会导致系统无法启动及数据丢失的危险。
[root@sourcedb ~]# psql
-bash: /hgdb/3.1.4/bin/psql: No such file or directory
[root@sourcedb ~]# su - highgo
-bash: /bin/su: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
[root@sourcedb ~]# df -h
-bash: /bin/df: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
[root@sourcedb ~]#
建议:不建议使用此类配置,如因特殊情况需要使用此方式,请慎重!!!
[root@ldap ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export HG_HOME=/hgdb/4.0
export PGUSER=highgo
export PGPORT=5866
export PGDATA=$HG_HOME/data
export PATH=$HG_HOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$HG_HOME/lib:$LD_LIBRARY_PATH
此时,即可通过root执行psql命令:
[root@ldap ~]# psql --c '\i a.sql'
current_user
--------------
highgo
(1 row)
[root@ldap ~]# psql --c '\! df -h'
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 46G 4.2G 42G 10% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 497M 88K 497M 1% /dev/shm
tmpfs 497M 7.0M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 497M 157M 341M 32% /boot
tmpfs 100M 0 100M 0% /run/user/0
tmpfs 100M 16K 100M 1% /run/user/42
此种配置下,不能在root下使用pg_ctl命令:
[root@ldap ~]# pg_ctl stop
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@ldap ~]# pg_ctl start
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
[root@ldap ~]# pg_ctl reload
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
危险之处:可以按如下方法执行(可通过psql执行部分类似rm的操作)
[root@sourcedb ~]# date
Thu Aug 31 12:02:39 CST 2017
[root@sourcedb ~]# psql --c '\! rm -rf /'
rm: it is dangerous to operate recursively on `/'
rm: use --no-preserve-root to override this failsafe
[root@sourcedb ~]# psql --c '\! rm -rf /home'
[root@sourcedb ~]# psql --c '\! rm -rf /opt'
[root@sourcedb ~]# cd /
[root@sourcedb /]# ls
bin dev hg4.0 hgdata hgdb2 hvr lib64 media mnt orada root selinux sys u01 var
boot etc hgbackup hgdb highgo lib lost+found misc net proc sbin srv tmp usr
[root@sourcedb /]# psql --c '\! rm -rf /dev'
rm: cannot remove `/dev/pts/0': Operation not permitted
rm: cannot remove `/dev/pts/ptmx': Operation not permitted
rm: cannot remove `/dev/shm': Device or resource busy
[root@sourcedb /]# psql --c '\! rm -rf /boot'
rm: cannot remove `/boot': Device or resource busy
[root@sourcedb ~]# psql --c '\! rm -rf / --no-preserve-root'
如上之后后,系统中大量文件被删除,将会导致系统无法启动及数据丢失的危险。
[root@sourcedb ~]# psql
-bash: /hgdb/3.1.4/bin/psql: No such file or directory
[root@sourcedb ~]# su - highgo
-bash: /bin/su: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
[root@sourcedb ~]# df -h
-bash: /bin/df: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
[root@sourcedb ~]#
建议:不建议使用此类配置,如因特殊情况需要使用此方式,请慎重!!!