Thread: psql --no-connect option
Currently, psql exits if a database connection is not established when psql is launched. Sometimes it may be useful to launch psql without connecting to the database. For example, a user may choose to start psql and then pipe commands via stdin, one of which may eventually perform the \connect command. Or the user may be interested in performing operations that psql can perform, like setting variables etc., before optionally initiating a connection. The attached patch introduces the --no-connect option, which allows psql to continue operation in absence of connection options. This patch is nowhere close to finished, but I'm posting it here to gauge interest in the feature. For example, this patch results in an undesirable output (0.0 server version), as seen below. $ psql --no-connect psql (17devel, server 0.0.0) WARNING: psql major version 17, server major version 0.0. Some psql features might not work. Type "help" for help. !?> The patch needs many improvements, like not expecting to inherit connection options from a previous connection, etc., but mostly in identifying the conflicting options; an example of this is included in the patch where psql throws an error if --no-connect and --list are specified together. $ psql --no-connect --list psql: error: --no-connect cannot be specified with --list Best regards, Gurjeet http://Gurje.et
Attachment
On Thu Aug 24, 2023 at 2:55 PM CDT, Gurjeet Singh wrote: > Currently, psql exits if a database connection is not established when > psql is launched. > > Sometimes it may be useful to launch psql without connecting to the > database. For example, a user may choose to start psql and then pipe > commands via stdin, one of which may eventually perform the \connect > command. Or the user may be interested in performing operations that > psql can perform, like setting variables etc., before optionally > initiating a connection. Speaking for myself, but you do bring up a fairly interesting usecase. Is this a feature you have found yourself wanting in the past? -- Tristan Partin Neon (https://neon.tech)
Hi, On Thu, Aug 24, 2023 at 12:55:30PM -0700, Gurjeet Singh wrote: > Currently, psql exits if a database connection is not established when > psql is launched. > > Sometimes it may be useful to launch psql without connecting to the > database. For example, a user may choose to start psql and then pipe > commands via stdin, one of which may eventually perform the \connect > command. Or the user may be interested in performing operations that > psql can perform, like setting variables etc., before optionally > initiating a connection. > > The attached patch introduces the --no-connect option, which allows > psql to continue operation in absence of connection options. FTR this has been discussed in the past, see at least [1]. I was interested in this feature, suggesting the exact same "--no-connect" name, so still +1 for this patch (note that I haven't read it). [1]: https://www.postgresql.org/message-id/flat/CAFe70G7iATwCMrymVwSVz7NajxCw3552TzFFHvkJqL_3L6gDTA%40mail.gmail.com
pá 25. 8. 2023 v 6:21 odesílatel Julien Rouhaud <rjuju123@gmail.com> napsal:
Hi,
On Thu, Aug 24, 2023 at 12:55:30PM -0700, Gurjeet Singh wrote:
> Currently, psql exits if a database connection is not established when
> psql is launched.
>
> Sometimes it may be useful to launch psql without connecting to the
> database. For example, a user may choose to start psql and then pipe
> commands via stdin, one of which may eventually perform the \connect
> command. Or the user may be interested in performing operations that
> psql can perform, like setting variables etc., before optionally
> initiating a connection.
>
> The attached patch introduces the --no-connect option, which allows
> psql to continue operation in absence of connection options.
FTR this has been discussed in the past, see at least [1].
I was interested in this feature, suggesting the exact same "--no-connect"
name, so still +1 for this patch (note that I haven't read it).
[1]: https://www.postgresql.org/message-id/flat/CAFe70G7iATwCMrymVwSVz7NajxCw3552TzFFHvkJqL_3L6gDTA%40mail.gmail.com
+1
Pavel