pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Verite <daniel@manitou-mail.org>
To: nikhil raj <nikhilraj474@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: Dan Livingston <danlivingstone@gmail.com>
Cc: Karsten Hilbert <Karsten.Hilbert@gmx.net>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: database "cdf_100_1313" does not exist
Date: Mon, 09 Sep 2019 16:45:08 +0200
Message-ID: <525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org> (raw)
In-Reply-To: <CAG1ps1wFkVhqxd4u90070KjU8_TGUE-3b9BWZ9oE9z4cShqxJA@mail.gmail.com>

	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





view thread (13+ messages)  latest in thread

Message-ID: <525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org>
Permalink:  ../525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org/
Also on:    postgresql.org/message-id/525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: daniel@manitou-mail.org, nikhilraj474@gmail.com, tgl@sss.pgh.pa.us, robjsargent@gmail.com, danlivingstone@gmail.com, Karsten.Hilbert@gmx.net
  Subject: Re: database "cdf_100_1313" does not exist
  In-Reply-To: <525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org>
  References: <CAG1ps1wFkVhqxd4u90070KjU8_TGUE-3b9BWZ9oE9z4cShqxJA@mail.gmail.com> <525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox