From: Paul Förster <paul.foerster@gmail.com>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: HOST variable in psql
Date: Mon, 27 Apr 2020 10:03:52 +0200
Message-ID: <91ADA44B-9EFA-4784-A45F-8323B3F552B3@gmail.com> (raw)
Hi,
the use of :HOST in psql containing the socket directory for local connections is pretty useless for us, so we set it to the hostname in a global psqlrc file:
\set HOST `hostname -s`
This works great when invoking psql on the command line. But if I perform a \c to connect to a different database in the database cluster, then :HOST gets reset to the socket directory. On the one hand, this makes sense, on the other, the global psqlrc file does not seem to be executed again, thus leaving :HOST in an unuable state for us:
postgres=# \echo :HOST
mypghost
postgres=# create database test;
CREATE DATABASE
postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# \echo :HOST
/tmp
The documentations (https://www.postgresql.org/docs/12/app-psql.html) says:
"HOST
The database server host you are currently connected to. This is set every time you connect to a database (including program start-up), but can be changed or unset."
"Files
psqlrc and ~/.psqlrc
Unless it is passed an -X option, psql attempts to read and execute commands from the system-wide startup file (psqlrc) and then the user's personal startup file (~/.psqlrc), after connecting to the database but before accepting normal commands."
Makes sense so far, except the last part "after connecting to the database but before accepting normal commands." This applies only to the first psql startup but not a subsequent \c. If I do a \c, then that is connecting to a database and that means, the psqlrc *should* be executed again, which it isn't.
Bug or feature? If feature, is there any remedy to this behavior?
Thanks in advance,
Paul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: paul.foerster@gmail.com
Subject: Re: HOST variable in psql
In-Reply-To: <91ADA44B-9EFA-4784-A45F-8323B3F552B3@gmail.com>
References: <91ADA44B-9EFA-4784-A45F-8323B3F552B3@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox