Thread: pgsql: Fix pg_dumpall with database names containing =

pgsql: Fix pg_dumpall with database names containing =

From
Heikki Linnakangas
Date:
Fix pg_dumpall with database names containing =

If a database name contained a '=' character, pg_dumpall failed. The problem
was in the way pg_dumpall passes the database name to pg_dump on the
command line. If it contained a '=' character, pg_dump would interpret it
as a libpq connection string instead of a plain database name.

To fix, pass the database name to pg_dump as a connection string,
"dbname=foo", with the database name escaped if necessary.

Back-patch to all supported branches.

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/957bafb2091136161cb7f1a8a56439310c6bd1b2

Modified Files
--------------
src/bin/pg_dump/pg_dumpall.c |   34 +++++++++++++++++++++++++++++++++-
1 files changed, 33 insertions(+), 1 deletions(-)


Re: pgsql: Fix pg_dumpall with database names containing =

From
Thom Brown
Date:
On 20 February 2013 15:14, Heikki Linnakangas <heikki.linnakangas@iki.fi> wrote:
> Fix pg_dumpall with database names containing =
>
> If a database name contained a '=' character, pg_dumpall failed. The problem
> was in the way pg_dumpall passes the database name to pg_dump on the
> command line. If it contained a '=' character, pg_dump would interpret it
> as a libpq connection string instead of a plain database name.
>
> To fix, pass the database name to pg_dump as a connection string,
> "dbname=foo", with the database name escaped if necessary.
>
> Back-patch to all supported branches.

I also notice that if you create a database with an "=" in, you can't
connect to it using psql.

thom@swift ~/Development/postgresql $ psql "8=8"
psql: invalid connection option "8"
thom@swift ~/Development/postgresql $ psql -d "8=8"
psql: invalid connection option "8"
thom@swift ~/Development/postgresql $ psql --dbname="8=8"
psql: invalid connection option "8"
thom@swift ~/Development/postgresql $ psql -d '8=8'
psql: invalid connection option "8"
thom@swift ~/Development/postgresql $ psql postgres
Expanded display is used automatically.
psql (9.3devel)
Type "help" for help.

postgres=# \c "8=8"
invalid connection option "8"
Previous connection kept
postgres=# \c 8=8
invalid connection option "8"
Previous connection kept

--
Thom


Re: pgsql: Fix pg_dumpall with database names containing =

From
Heikki Linnakangas
Date:
On 26.02.2013 18:03, Thom Brown wrote:
> On 20 February 2013 15:14, Heikki Linnakangas<heikki.linnakangas@iki.fi>  wrote:
>> Fix pg_dumpall with database names containing =
>>
>> If a database name contained a '=' character, pg_dumpall failed. The problem
>> was in the way pg_dumpall passes the database name to pg_dump on the
>> command line. If it contained a '=' character, pg_dump would interpret it
>> as a libpq connection string instead of a plain database name.
>>
>> To fix, pass the database name to pg_dump as a connection string,
>> "dbname=foo", with the database name escaped if necessary.
>>
>> Back-patch to all supported branches.
>
> I also notice that if you create a database with an "=" in, you can't
> connect to it using psql.

Specifying it as a connection string works:

psql dbname='8=8'

That's the same trick I applied to pg_dumpall's pg_dump invocations.

- Heikki


Re: pgsql: Fix pg_dumpall with database names containing =

From
Thom Brown
Date:
On 26 February 2013 16:29, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
> On 26.02.2013 18:03, Thom Brown wrote:
>>
>> On 20 February 2013 15:14, Heikki Linnakangas<heikki.linnakangas@iki.fi>
>> wrote:
>>>
>>> Fix pg_dumpall with database names containing =
>>>
>>> If a database name contained a '=' character, pg_dumpall failed. The
>>> problem
>>> was in the way pg_dumpall passes the database name to pg_dump on the
>>> command line. If it contained a '=' character, pg_dump would interpret it
>>> as a libpq connection string instead of a plain database name.
>>>
>>> To fix, pass the database name to pg_dump as a connection string,
>>> "dbname=foo", with the database name escaped if necessary.
>>>
>>> Back-patch to all supported branches.
>>
>>
>> I also notice that if you create a database with an "=" in, you can't
>> connect to it using psql.
>
>
> Specifying it as a connection string works:
>
> psql dbname='8=8'
>
> That's the same trick I applied to pg_dumpall's pg_dump invocations.

Yes, but while this is true, it still seems like some kind of parsing
oversight.  Once I'm in that database, I can't switch user from within
psql:

8=8=# \c - moo
invalid connection option "8"
Previous connection kept

--
Thom