HGDB允许在root用户执行psql命令连接使用数据库

首先在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 ~]# 
建议:不建议使用此类配置,如因特殊情况需要使用此方式,请慎重!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值