Re: database "cdf_100_1313" does not exist

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "nikhil raj" <nikhilraj474(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>,"Rob Sargent" <robjsargent(at)gmail(dot)com>,"Dan Livingston" <danlivingstone(at)gmail(dot)com>,"Karsten Hilbert" <Karsten(dot)Hilbert(at)gmx(dot)net>,pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: database "cdf_100_1313" does not exist
Date: 2019-09-09 14:45:08
Message-ID: 525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

nikhil raj wrote:

> /usr/lib/postgresql/11/bin/psql -p 5432 -U postgres -d $DBLIST -c "GRANT
> CONNECT ON DATABASE \"$DBLIST\" TO cpupdate"
> ERROR: database " CDF_100_1313" does not exist

That's because you don't use the unaligned format to get the
list of results. You should add -A to psql options.

Or better yet, use a simpler method that does not use
shell variables at all and work with a single psql call:

$ psql -U postgres -d postgres <<EOF

select format('GRANT CONNECT ON DATABASE %I TO cpupdate',
datname) FROM pg_database WHERE <insert conditions here>
\gexec

EOF

That's possible because you don't need to be connected to
a database to grant the right to connect to that database.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2019-09-09 17:15:19 Re: Permissions on postgresql.conf, psql and patroni
Previous Message nikhil raj 2019-09-09 14:38:51 Re: database "cdf_100_1313" does not exist