Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql - Role root does not exist

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'
like image 609
renard Avatar asked Nov 25 '14 10:11

renard


1 Answers

try:

sudo -u postgres psql

> CREATE USER root WITH SUPERUSER;

like image 137
Dmitriy Kosolobov Avatar answered Oct 11 '22 10:10

Dmitriy Kosolobov