【问题标题】:psql - Role root does not existpsql - 角色根不存在
【发布时间】:2015-01-23 07:49:43
【问题描述】:

我在 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 用户下执行命令?

谢谢 干杯,

编辑 我将命令更改为

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'

【问题讨论】:

标签: php bash postgresql


【解决方案1】:

我终于让它工作了,通过保存命令的内容

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

感谢您的帮助

【讨论】:

    【解决方案2】:

    尝试:

    sudo -u postgres psql

    >CREATE USER root WITH SUPERUSER;

    【讨论】:

      猜你喜欢
      • 2015-03-28
      • 2013-02-24
      • 2018-02-18
      • 1970-01-01
      • 2017-03-08
      • 2014-03-15
      • 2013-05-21
      相关资源
      最近更新 更多