Re: Adding a pg_servername() function

2023-08-09 Thread GF
Hi everybody,

On 09.08.23 08:42, Laetitia Avrot wrote:
> I agree that the feature I'm suggesting could be done with a few tricks.
> I meant to simplify the life of the user by providing a simple new
> feature. (Also, I might have trust issues with DNS due to several past
> production disasters.)

Just my contribution on why this function could be useful, since we had a
use case that fits exactly this.
In the past I needed such a pg_servername() function because in a project I
was engaged on they needed to distribute "requests" directed to a in-house
management service running on network servers, and each one had a DB, so we
went with pglogical to be used as a (transactional) messaging middleware.
The requests were targeted to specific hostnames, thus on the replication
downstream we wanted to filter with a before-insert trigger on the hostname.
At that point, we had to do some contortions to get the hostname the DB was
running on, sometimes really nasty like: on linux servers we could go with
a python function; but on windows ones (where there was no python
available) we had to resort to a function that read the OS "hostname"
command into a temporary table via the pg "copy", which is both tricky and
inefficient.

So, from me +1 to Laetitia's proposal.

On Wed, 9 Aug 2023 at 10:26, Peter Eisentraut  wrote:

> (*) But we should think about access control for this.


And +1 also to Peter's note on enforcing the access control. BTW that's
exactly what we needed with plpythonu, and also with "copy from program".

Best,
Giovanni


Re: Adding a pg_servername() function

2023-08-09 Thread GF
On Wed, 9 Aug 2023 at 16:05, Tom Lane  wrote:

> Peter Eisentraut  writes:
> > On 09.08.23 08:42, Laetitia Avrot wrote:
> >> My question is very simple: Do you oppose having this feature in
> Postgres?
>
> > I think this is pretty harmless(*) and can be useful, so it seems
> > reasonable to pursue.
>
> I actually do object to this, because I think the concept of "server
> name" is extremely ill-defined
>

Tom,
But the gethostname() function is well defined, both in Linux and in
Windows.
Maybe the proposed name pg_servername() is unfortunate in that it may
suggest that DNS or something else is involved, but in Laetitia's patch the
call is to gethostname().
Would it be less problematic if the function were called pg_gethostname()?
@Laetitia: why did you propose that name? maybe to avoid clashes with some
extension out there?

Best,
Giovanni