Thread: How to get connection details from psql -> \e

How to get connection details from psql -> \e

From
hubert depesz lubaczewski
Date:
Hi,
I'm trying to work on some extension to vim when invoked as \e from
psql.

To make it fully work, I need to know connection details that psql was
using while it invoked \e.

Is it possible to do in any way, or if not, any chance it could be added
to wishlist for next versions of Pg?

Best regards,

depesz



Re: How to get connection details from psql -> \e

From
Laurenz Albe
Date:
hubert depesz lubaczewski wrote:
> I'm trying to work on some extension to vim when invoked as \e from
> psql.
> 
> To make it fully work, I need to know connection details that psql was
> using while it invoked \e.
> 
> Is it possible to do in any way, or if not, any chance it could be added
> to wishlist for next versions of Pg?

Do you mean something like \set?

test=> \set
DBNAME = 'test'
ENCODING = 'UTF8'
HOST = '/var/run/postgresql'
PORT = '5432'
SERVER_VERSION_NAME = '10.5'
SERVER_VERSION_NUM = '100005'
VERSION_NAME = '10.5'
VERSION_NUM = '100005'
...

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


Re: How to get connection details from psql -> \e

From
Tom Lane
Date:
hubert depesz lubaczewski <depesz@depesz.com> writes:
> I'm trying to work on some extension to vim when invoked as \e from
> psql.
> To make it fully work, I need to know connection details that psql was
> using while it invoked \e.

Uh, why?

The only likely reason I can guess at is that you want vim to make its
own connection to the database for some purpose like autocompletion.

That's a cute idea, but from a security standpoint it sounds like a
disaster in the making.  There isn't any secure way to pass down e.g.
a password (neither command line nor environment variables can be
trusted not to be visible to other users), and even if there was
I'm not sure people would be really happy with handing out their
database credentials to any random piece of code psql invokes.

> Is it possible to do in any way, or if not, any chance it could be added
> to wishlist for next versions of Pg?

You'd need to make a case for it that's a lot stronger than "I wish"
before anyone would consider this.

            regards, tom lane


Re: How to get connection details from psql -> \e

From
hubert depesz lubaczewski
Date:
On Mon, Aug 13, 2018 at 10:00:56AM -0400, Tom Lane wrote:
> The only likely reason I can guess at is that you want vim to make its
> own connection to the database for some purpose like autocompletion.

That's precisely what I'm looking for.

> That's a cute idea, but from a security standpoint it sounds like a
> disaster in the making.  There isn't any secure way to pass down e.g.
> a password (neither command line nor environment variables can be
> trusted not to be visible to other users), and even if there was
> I'm not sure people would be really happy with handing out their
> database credentials to any random piece of code psql invokes.

I think that passing all-but-password would be good enough.

At the very least for my usecases, as I tend to use pgpass and other
non-interactive authentications.

Best regards,

depesz



Re: How to get connection details from psql -> \e

From
hubert depesz lubaczewski
Date:
On Mon, Aug 13, 2018 at 03:32:21PM +0200, Laurenz Albe wrote:
> hubert depesz lubaczewski wrote:
> > I'm trying to work on some extension to vim when invoked as \e from
> > psql.
> > 
> > To make it fully work, I need to know connection details that psql was
> > using while it invoked \e.
> > 
> > Is it possible to do in any way, or if not, any chance it could be added
> > to wishlist for next versions of Pg?
> 
> Do you mean something like \set?

Something like this, but automatically sent "somehow" to editor when
I run \e.

Best regards,

depesz