Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote - Mailing list pgsql-hackers

From Mahendra Singh Thalor
Subject Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote
Date
Msg-id CAKYtNAoVKQL5rLD4P4hZXZSnThwO-j4q3Y1vTDHQGjzwC-kUJg@mail.gmail.com
Whole thread Raw
In response to Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote  (Álvaro Herrera <alvherre@alvh.no-ip.org>)
Responses Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote
List pgsql-hackers
On Thu, 27 Mar 2025 at 18:33, Álvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>
> On 2025-Mar-27, Andrew Dunstan wrote:
>
> > I don't think we can backpatch this. It's a behaviour change.
>
> I agree, we can't.
>
> Also, if we're going to enforce this rule, then pg_upgrade --check needs
> to alert users that they have a database name that's no longer valid.
> That needs to be part of this patch as well.  We should also ensure that
> these are the only problem characters, which IMO means it should add a
> test for pg_dumpall that creates a database whose name has all possible
> characters and ensures that it is dumpable.
>
> --
> Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/
> "La virtud es el justo medio entre dos defectos" (Aristóteles)

Thanks Álvaro.

Yes, I also agree with you. "pg_upgrade --check" should alert users regarding database names because pg_upgrade is failing if we have \n\r in dbname(old cluster).

pg_upgrade --check: This is passing but pg_upgrade is failing.
............
Checking for new cluster tablespace directories               ok
*Clusters are compatible*

pg_upgrade
.........................
Creating dump of global objects                               ok
Creating dump of database schemas                            
shell command argument contains a newline or carriage return: "dbname='invalid
db'"


As a part of this patch, we can teach pg_upgrade to alert users regarding database names with invalid characters or we can keep old behavior as upgrade is already failing without this patch also.

I will try to make a separate patch to teach "pg_upgrade --check" to alert users regarding database/user/role with \n\r in the old cluster.

Here, I am attaching an updated patch for review.

This patch has changes for: CREATE DATABASE, CREATE ROLE, CREATE USER and RENAME DATABASE/USER/ROLE and have some tests also. (EXCEPT RENAME test case)

--
Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com
Attachment

pgsql-hackers by date:

Previous
From: Melanie Plageman
Date:
Subject: Re: read stream on amcheck
Next
From: Matheus Alcantara
Date:
Subject: Re: read stream on amcheck