Re: libpq parameter parsing problem
Oleksandr Shulgin <[email protected]> Tue, 7 Jan 2020 15:23:41 +0100
| Newsgroups | gmane.comp.db.postgresql.bugs |
|---|---|
| Message-ID | <CACACo5Qf4xBbs=8s4sYxZiQEYzfKM3JY3uCDrtZYu3CpOcP5xA@mail.gmail.com> |
--0000000000006702a3059b8d8727 Content-Type: text/plain; charset="UTF-8" On Tue, Jan 7, 2020 at 2:17 PM Jobin Augustine <[email protected]> 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' Cheers, -- Alex --0000000000006702a3059b8d8727 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr">On Tue, Jan 7, 2020 at 2:17 PM Jobin Augu= stine <<a href=3D"mailto:[email protected]">[email protected]</a>> wr= ote:<br></div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" = style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa= dding-left:1ex"><div dir=3D"ltr">Hello=C2=A0<span style=3D"font-family:aria= l,sans-serif">hackers</span>,<div>User can pass session-level settings as a= parameter in the connection string like:<br>psql "host=3Dlocalhost us= er=3Dpostgres options=3D'-c synchronous_commit=3Doff'"<br>Whic= h sets the=C2=A0synchronous_commit off for the session.</div><div><br>Howev= er, URI spec is not allowing it,<br>psql postgresql://postgres@localhost:54= 32/postgres?options=3D"-c synchronous_commit=3Doff"<br>psql: erro= r: could not connect to server: extra key/value separator "=3D" i= n URI query parameter: "options"<br><br>psql postgresql://postgre= s@localhost:5432/postgres?options=3D"-c synchronous_commit off"<b= r>psql: error: could not connect to server: FATAL: =C2=A0-c synchronous_com= mit requires a value<br></div></div></blockquote><div><br></div><div>Jobin,= </div><div><br></div><div>As already pointed out by Heikki, and per documen= tation:</div><div><br></div><div>>=C2=A0<span style=3D"color:rgb(13,10,1= 1);font-family:"Open Sans",sans-serif;font-size:18px">Percent-enc= oding may be used to include symbols with special meaning in any of the=C2= =A0</span><acronym class=3D"gmail-acronym" style=3D"box-sizing:border-box;c= olor:rgb(13,10,11);font-family:"Open Sans",sans-serif;font-size:1= 8px">URI</acronym><span style=3D"color:rgb(13,10,11);font-family:"Open= Sans",sans-serif;font-size:18px">=C2=A0parts, e.g. replace=C2=A0</spa= n><code class=3D"gmail-literal" style=3D"box-sizing:border-box;font-family:= monospace,monospace;font-size:18px;color:rgb(13,10,11);word-break:break-wor= d;border-radius:0.25rem;margin:0.6rem 0px;background-color:rgb(248,249,250)= ">=3D</code><span style=3D"color:rgb(13,10,11);font-family:"Open Sans&= quot;,sans-serif;font-size:18px">=C2=A0with=C2=A0</span><code class=3D"gmai= l-literal" style=3D"box-sizing:border-box;font-family:monospace,monospace;f= ont-size:18px;color:rgb(13,10,11);word-break:break-word;border-radius:0.25r= em;margin:0.6rem 0px;background-color:rgb(248,249,250)">%3D</code><span sty= le=3D"color:rgb(13,10,11);font-family:"Open Sans",sans-serif;font= -size:18px">.</span></div><div><a href=3D"https://www.postgresql.org/docs/c= urrent/libpq-connect.html">https://www.postgresql.org/docs/current/libpq-co= nnect.html</a></div><div><br></div><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex"><div dir=3D"ltr"><div>Moreover session just hangs forever:<br>ps= ql postgresql://postgres@localhost:5432/postgres?application_name=3Dhello&a= mp;options=3D'-c synchronous_commit=3Doff'<br>provided that the con= nection works without the 'options' parameter specification</div></= div></blockquote><div><br></div><div>What you observe here is most likely t= he result of your shell interpreting the ampersand sign (&) in the midd= le of the URI and triggering asynchronous execution of the command before t= he sign.=C2=A0 Please try escaping the sign or using appropriate quoting, e= .g. extend the single quote to start before the URI:</div><div><br></div><d= iv>psql 'postgresql://postgres@localhost:5432/postgres?application_name= =3Dhello&options=3D-c synchronous_commit%3Doff'<br></div><div><br><= /div><div>Cheers,</div><div></div></div>--<br>Alex</div> --0000000000006702a3059b8d8727--