Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php psql-角色根不存在_Php_Bash_Postgresql - Fatal编程技术网

Php psql-角色根不存在

Php psql-角色根不存在,php,bash,postgresql,Php,Bash,Postgresql,我在PHP脚本中构建了一个bash命令。生成的命令如下所示: 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 " 当我尝试在shell中运行此命令时,出现以下错误: psql: FA

我在PHP脚本中构建了一个bash命令。生成的命令如下所示:

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 "
当我尝试在shell中运行此命令时,出现以下错误:

 psql: FATAL:  role "root" does not exist
为什么会发生这种情况,而我在postgres user下执行命令

谢谢 干杯

编辑 我将命令更改为

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
但现在我又犯了另一个错误,我无法理解其根源:

-bash: syntax error near unexpected token `do'

我最终通过保存命令的内容使它工作

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
在文件
myfile.sh
中,然后按如下方式调用该文件:

sudo -u postgres /bin/bash myfile.sh
感谢您的帮助

试试:

sudo-u postgres psql


使用超级用户创建用户根目录

检查此链接:谢谢,我在阅读文章后编辑了我的问题,但我发现一个错误此链接可能会帮助您: