Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ip713-0002j6-KN for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jan 2020 08:48:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ip711-0002Ao-22 for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jan 2020 08:48:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ip710-00028x-O5 for pgsql-bugs@lists.postgresql.org; Wed, 08 Jan 2020 08:48:34 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ip70t-0003VT-2n for pgsql-bugs@lists.postgresql.org; Wed, 08 Jan 2020 08:48:34 +0000 Received: by mail-wr1-x42e.google.com with SMTP id y11so2432017wrt.6 for ; Wed, 08 Jan 2020 00:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dqfImF9/yj7/ktf++PU51csq93/YIqs36tGwtMb0jDs=; b=NzB3YSceDbF2nJzPWPjNogfXQMihHDJzzPhjn3irhjTjjaQ19llN86TZhECwRvrhoo 4RdjxGk74uOUnnaf7HuuhWZ1+yiD21n4GdfzbpbewtQht6KULr/T/NI50gjetQWQL+bS CQJJTUtgngDnv0FVaCfRS2v3srVyFbXjjmTMq8rvbWy60zuNsoDkoW2e48YLf4NHPO7I 0WSjgxouKb5HZmO4Bkfxu+FbPSJAS25CICLhuM/JU55bhIRB3Hc4x7ZQo5VNMrXi7mgg Hhfaew/nnkU0aKNrzyjvcq/dtGeY7wp1QoS9+ZP5yeM4PtL1u1TQOx1hOWm09nc6qC3w tqxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dqfImF9/yj7/ktf++PU51csq93/YIqs36tGwtMb0jDs=; b=l+fqlzKZd5yT2vD5ntZM+IaklT0oKf4oKa/L+NFZcgv9QfDGSDfx2j4+r1RUcNEkSl XEVTkB0T7vcRv/ttXiWDGeKgVssQ6obAje9SvNSawY1E8a5cTWa5z8DhtS9z3hcFhhVL DzL2WWbMKDBI6fVqQ0r3lF/Flca0pPRlXa6tGUHsHNPfHYTzv65/rOLz6CA/1xxgsjZX T+51GPpwTQ6gyQFn1HQnFo1txlxKQfNhV0+wm6iiQ538YR3Df/HDH7S8J7bWHhF+ftc4 o0/5NrHD3wni4TyBidVzcqZXgnSxANKQF8jffibtZFZIgYHVrb5O0nasGfmjyqwHXaVD Ws+w== X-Gm-Message-State: APjAAAWsGp4tWkojeCbjN9OiUXikTdG3wsr5PJDYZ00aop5nvEM4bHM0 2dkpfOMDsUOHbinGZ6rvkDX6JHpezbuiRCGccy8= X-Google-Smtp-Source: APXvYqwLWhLvUtYQySsILRr5RFTKKswSrdl4sFhLcAuyl1HIykBOMfYT3O6NeGy45TYtfHbRYpPTtEpf9FWZJh7w/r8= X-Received: by 2002:adf:f885:: with SMTP id u5mr3202716wrp.359.1578473304865; Wed, 08 Jan 2020 00:48:24 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jobin Augustine Date: Wed, 8 Jan 2020 14:18:12 +0530 Message-ID: Subject: Re: libpq parameter parsing problem To: Oleksandr Shulgin Cc: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000009fbeff059b9cf401" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000009fbeff059b9cf401 Content-Type: text/plain; charset="UTF-8" Thanks Alex and Heikki, Encoding works and it solved the problem. I find the documentation is not very clear about it. Heikki's single line comment was more clear to me than documentation :) A statement like "PostgreSQL URI string need to be encoded with Percent-encoding " would have been much better On Tue, Jan 7, 2020 at 7:54 PM Oleksandr Shulgin < oleksandr.shulgin@zalando.de> wrote: > On Tue, Jan 7, 2020 at 2:17 PM Jobin Augustine wrote: > >> Hello hackers, >> User can pass session-level settings as a parameter in the connection >> string like: >> psql "host=localhost user=postgres options='-c synchronous_commit=off'" >> Which sets the synchronous_commit off for the session. >> >> However, URI spec is not allowing it, >> psql postgresql://postgres@localhost:5432/postgres?options="-c >> synchronous_commit=off" >> psql: error: could not connect to server: extra key/value separator "=" >> in URI query parameter: "options" >> >> psql postgresql://postgres@localhost:5432/postgres?options="-c >> synchronous_commit off" >> psql: error: could not connect to server: FATAL: -c synchronous_commit >> requires a value >> > > Jobin, > > As already pointed out by Heikki, and per documentation: > > > Percent-encoding may be used to include symbols with special meaning in > any of the URI parts, e.g. replace = with %3D. > https://www.postgresql.org/docs/current/libpq-connect.html > > Moreover session just hangs forever: >> psql postgresql://postgres@localhost:5432/postgres?application_name=hello&options='-c >> synchronous_commit=off' >> provided that the connection works without the 'options' parameter >> specification >> > > What you observe here is most likely the result of your shell interpreting > the ampersand sign (&) in the middle of the URI and triggering asynchronous > execution of the command before the sign. Please try escaping the sign or > using appropriate quoting, e.g. extend the single quote to start before the > URI: > > psql 'postgresql://postgres@localhost:5432/postgres?application_name=hello&options=-c > synchronous_commit%3Doff' > Yes, That was too silly. my bad > > Cheers, > -- > Alex > Thanks and Regards, Jobin --0000000000009fbeff059b9cf401 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Alex and Heikki,

Encoding works = and it solved the problem. I find the documentation is not very=C2=A0clear = about it.
Heikki's single line comment was more clear to me than doc= umentation :)
A statement like=C2=A0 "PostgreSQL URI string need to= be encoded with=C2=A0Percent-encoding=C2=A0" would have been much better


On Tue, Jan 7, 2020 at 7:54 PM Oleksandr Shulgin <oleksandr.shulgin@zalando.de= > wrote:
On Tue, Jan 7, 2020 at 2:17 PM Jobin Augustin= e <jobinau@gmail.= com> wrote:
Hello=C2=A0hackers,
User can pass session-level= settings as a parameter in the connection string like:
psql "host= =3Dlocalhost user=3Dpostgres options=3D'-c synchronous_commit=3Doff'= ;"
Which sets the=C2=A0synchronous_commit off for the session.

However, URI spec is not allowing it,
psql postgresql://postgr= es@localhost:5432/postgres?options=3D"-c synchronous_commit=3Doff"= ;
psql: error: could not connect to server: extra key/value separator &q= uot;=3D" in URI query parameter: "options"

psql postg= resql://postgres@localhost:5432/postgres?options=3D"-c synchronous_com= mit off"
psql: error: could not connect to server: FATAL: =C2=A0-c = synchronous_commit requires a value

Jobin,

As already pointed out by Heikki, = and per documentation:

>=C2=A0Percent-encoding may be used to include symbols with special meaning in= any of the=C2=A0URI=C2=A0parts, e.g. replace=C2=A0=3D= =C2=A0with=C2=A0%= 3D.

Moreove= r session just hangs forever:
psql postgresql://postgres@localhost:5432/= postgres?application_name=3Dhello&options=3D'-c synchronous_commit= =3Doff'
provided that the connection works without the 'options&= #39; parameter specification

Wh= at you observe here is most likely the result of your shell interpreting th= e ampersand sign (&) in the middle of the URI and triggering asynchrono= us execution of the command before the sign.=C2=A0 Please try escaping the = sign or using appropriate quoting, e.g. extend the single quote to start be= fore the URI:

psql 'postgresql://postgres@loca= lhost:5432/postgres?application_name=3Dhello&options=3D-c synchronous_c= ommit%3Doff'

Yes,= That was too silly. my bad=C2=A0
<= br>
Cheers,
--
Alex

Thanks and Regards,
Jobin=C2=A0
--0000000000009fbeff059b9cf401--