Re: database "cdf_100_1313" does not exist - Mailing list pgsql-general

From Daniel Verite
Subject Re: database "cdf_100_1313" does not exist
Date
Msg-id 525385a5-c69e-47dd-9e33-0640cc6fc165@manitou-mail.org
Whole thread Raw
In response to Re: database "cdf_100_1313" does not exist  (nikhil raj <nikhilraj474@gmail.com>)
List 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



pgsql-general by date:

Previous
From: nikhil raj
Date:
Subject: Re: database "cdf_100_1313" does not exist
Next
From: "Peter J. Holzer"
Date:
Subject: Re: Permissions on postgresql.conf, psql and patroni