dongye9182 2014-11-25 10:43
浏览 255

psql - 角色根目录不存在

I build a bash command in a PHP script. The built command is such as :

su postgres -c "for tbl in `psql -qAt -c \"select tablename from pg_tables where schemaname = 'public';\" demodoo` ;do  psql -c \"alter table $tbl owner to postgres\" demodoo ;done "

When I try to run this command in a shell, I get this error :

 psql: FATAL:  role "root" does not exist

Why is this occuring, whereas i execute the command under postgres user ?

Thanks Cheers,

EDIT I change the command to

sudo -u postgres for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" demodoo` ;do  psql -c "alter table $tbl owner to postgres" demodoo ;done

but now I get another error which I can't understand the origin :

-bash: syntax error near unexpected token `do'
  • 写回答

2条回答 默认 最新

  • dongtang5057 2014-11-25 11:36
    关注

    I finnaly get it working, by saving the content of the command

    for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" demodoo` ;do  psql -c "alter table $tbl owner to postgres" demodoo ;done
    

    in a file myfile.sh, then call the file as follow :

    sudo -u postgres /bin/bash myfile.sh
    

    Thank you for your help

    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面