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'
我在PHP脚本中构建一个bash命令。 构建的命令如下: p>
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“
code> pre>
当我尝试在shell中运行此命令时, 我收到此错误: p>
psql:FATAL:角色“root”不存在
code> pre>
为什么这样 发生,而我在postgres用户下执行命令? p>
谢谢
欢呼, p>
编辑 strong>
我更改命令 to p>
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
code> pre>
但现在我收到另一个错误,我无法理解其来源 : p>
-bash:意外令牌附近的语法错误`do'
code> pre>
div>
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
try:
sudo -u postgres psql
>
CREATE USER root WITH SUPERUSER;