Re: libpq parameter parsing problem
Jobin Augustine <[email protected]> Wed, 8 Jan 2020 14:18:12 +0530
| Newsgroups | gmane.comp.db.postgresql.bugs |
|---|---|
| Message-ID | <CANaTPsrgsrVK2nb6bPym-fZcQvL7aJErMCXek7LBp-QFDQt-RQ@mail.gmail.com> |
--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 <https://en.wikipedia.org/wiki/Percent-encoding> " would have been much better On Tue, Jan 7, 2020 at 7:54 PM Oleksandr Shulgin < [email protected]> wrote: > 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' > 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 <div dir=3D"ltr"><div>Thanks Alex and Heikki,</div><div><br>Encoding works = and it solved the problem. I find the documentation is not very=C2=A0clear = about it.<br>Heikki's single line comment was more clear to me than doc= umentation :)<br>A statement like=C2=A0 "PostgreSQL URI string need to= be encoded with=C2=A0<a href=3D"https://en.wikipedia.org/wiki/Percent-enco= ding">Percent-encoding</a>=C2=A0" would have been much better</div><di= v><br></div><div><br></div><div class=3D"gmail_quote"><div dir=3D"ltr" clas= s=3D"gmail_attr">On Tue, Jan 7, 2020 at 7:54 PM Oleksandr Shulgin <<a hr= ef=3D"mailto:[email protected]">[email protected]</a>= > wrote:<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 dir=3D"ltr">On Tue, Jan 7, 2020 at 2:17 PM Jobin Augustin= e <<a href=3D"mailto:[email protected]" target=3D"_blank">jobinau@gmail.= com</a>> wrote:<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(2= 04,204,204);padding-left:1ex"><div dir=3D"ltr">Hello=C2=A0<span style=3D"fo= nt-family:arial,sans-serif">hackers</span>,<div>User can pass session-level= settings as a parameter in the connection string like:<br>psql "host= =3Dlocalhost user=3Dpostgres options=3D'-c synchronous_commit=3Doff'= ;"<br>Which sets the=C2=A0synchronous_commit off for the session.</div= ><div><br>However, URI spec is not allowing it,<br>psql postgresql://postgr= es@localhost:5432/postgres?options=3D"-c synchronous_commit=3Doff"= ;<br>psql: error: could not connect to server: extra key/value separator &q= uot;=3D" in URI query parameter: "options"<br><br>psql postg= resql://postgres@localhost:5432/postgres?options=3D"-c synchronous_com= mit off"<br>psql: error: could not connect to server: FATAL: =C2=A0-c = synchronous_commit 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 documentation:</div><div><br></div><div>>=C2=A0<span style=3D"co= lor:rgb(13,10,11);font-family:"Open Sans",sans-serif;font-size:18= px">Percent-encoding may be used to include symbols with special meaning in= any of the=C2=A0</span><acronym style=3D"box-sizing:border-box;color:rgb(1= 3,10,11);font-family:"Open Sans",sans-serif;font-size:18px">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</span><code st= yle=3D"box-sizing:border-box;font-family:monospace,monospace;font-size:18px= ;color:rgb(13,10,11);word-break:break-word;border-radius:0.25rem;margin:0.6= rem 0px;background-color:rgb(248,249,250)">=3D</code><span style=3D"color:r= gb(13,10,11);font-family:"Open Sans",sans-serif;font-size:18px">= =C2=A0with=C2=A0</span><code style=3D"box-sizing:border-box;font-family:mon= ospace,monospace;font-size:18px;color:rgb(13,10,11);word-break:break-word;b= order-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&quo= t;,sans-serif;font-size:18px">.</span></div><div><a href=3D"https://www.pos= tgresql.org/docs/current/libpq-connect.html" target=3D"_blank">https://www.= postgresql.org/docs/current/libpq-connect.html</a></div><div><br></div><blo= ckquote 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>Moreove= r session just hangs forever:<br>psql postgresql://postgres@localhost:5432/= postgres?application_name=3Dhello&options=3D'-c synchronous_commit= =3Doff'<br>provided that the connection works without the 'options&= #39; parameter specification</div></div></blockquote><div><br></div><div>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:</div><div><br></div><div>psql 'postgresql://postgres@loca= lhost:5432/postgres?application_name=3Dhello&options=3D-c synchronous_c= ommit%3Doff'<br></div></div></div></blockquote><div><br></div><div>Yes,= That was too silly. my bad=C2=A0</div><blockquote class=3D"gmail_quote" st= yle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padd= ing-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_quote"><div></div><div><= br></div><div>Cheers,</div><div></div></div>--<br>Alex</div></blockquote><d= iv><br>Thanks and Regards,</div><div>Jobin=C2=A0</div></div></div> --0000000000009fbeff059b9cf401--