Psql - The root role does not exist

I am creating a bash command in a PHP script. The built-in command is as follows:

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 the shell, I get this error:

  psql: FATAL: role "root" does not exist 

Why is this happening when I execute a command as postgres user?

Thanks Cheers,

EDIT I am changing the team 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 that cannot understand the origin:

 -bash: syntax error near unexpected token `do' 
+5
source share
2 answers

to try:

sudo -u postgres psql

> CREATE USER root WITH SUPERUSER;

+8
source

I want it to work, saving the contents 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 myfile.sh , then call the file as follows:

 sudo -u postgres /bin/bash myfile.sh 

thanks for the help

0
source

Source: https://habr.com/ru/post/1207658/


All Articles