Subject: [pgjdbc/pgjdbc] issue #3514: Add PGConnection#getHost, PGConnection#getPort so clients could identify the current host for each connection

From: "vlsi (@vlsi)" <[email-masked]>
Date: Fri, 07 Feb 2025 09:39:08 +0000

**Describe the issue**

See https://github.com/pgjdbc/pgjdbc/pull/3506.

For monitoring and debugging purposes it might be helpful to identify the URL for a given connection.
It might be tempting to expose `#getHost`, `#getPort` or `#getHostPort`, however, there might be cases like a connection over unix domain socket [which have no host and port parts](https://github.com/pgjdbc/r2dbc-postgresql/issues/181#issuecomment-1404648223).

We might expose something like `URI PGConnection#getServerUri()`, however, it looks like there's no canonical way to map domain sockets to URL/URI: https://github.com/whatwg/url/issues/577

So we might be better to expose interface like `interface ConnectionSpec { String toString(); }` with a default implementation that we ship for regular socket connections like `interface InetAddressConnectionSpec implements ConnectionSpec { ..getHost(); getPort(); }`.

---

From: "robert-mirzakhanian (@robert-mirzakhanian)" <[email-masked]>
Date: Mon, 10 Feb 2025 07:43:07 +0000

What do you think about such a structure?
ConnectionSpec
```
public interface ConnectionSpec {
  String getConnectedAddress();
}
```
InetAddressConnectionSpec
```
public interface InetAddressConnectionSpec extends ConnectionSpec {

  String getHost();

  int getPort();

  @Override
  default String getConnectedAddress() {
    return getHost().concat(":").concat(String.valueOf(getPort()));
  }
}
```
and implement InetAddressConnectionSpec from HostSpec
`public class HostSpec implements InetAddressConnectionSpec`

---

From: "robert-mirzakhanian (@robert-mirzakhanian)" <[email-masked]>
Date: Wed, 12 Feb 2025 04:22:56 +0000

@vlsi what do you think about this?

---

From: "robert-mirzakhanian (@robert-mirzakhanian)" <[email-masked]>
Date: Thu, 20 Feb 2025 20:42:00 +0000

@vlsi Привет. Я сделал изменения связанные с добавлением ConnectionSpec. Как будет время, глянь пожалуйста
https://github.com/robert-mirzakhanian/pgjdbc/tree/add-connection-spec

---

From: "robert-mirzakhanian (@robert-mirzakhanian)" <[email-masked]>
Date: Sun, 23 Feb 2025 19:45:41 +0000

Нашел в api у PgConnection [метод](https://github.com/pgjdbc/pgjdbc/blob/ddb71441b26af63df7ced9af35da0542d0500c40/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java#L550) который возращает до QueryExecutor, а у QueryExecutor есть метод чтобы получить HostSpec. 
Думаю issue больше не актуаьно

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Mon, 24 Feb 2025 05:57:15 +0000

@robert-mirzakhanian , `PgConnection` и `QueryExecutor` это **не** public api.
public api это `org.postgresql.PGConnection`

---

From: "robert-mirzakhanian (@robert-mirzakhanian)" <[email-masked]>
Date: Mon, 24 Feb 2025 06:00:57 +0000

> public api это `org.postgresql.PGConnection`

🥲 грустно. 
@vlsi, Подскажи пожалуйста, что надо сделать чтобы ты смог посмотреть изменения связанные с ConnectionSpec? Мне лучше принести PR?

---

From: "robert-mirzakhanian (@robert-mirzakhanian)" <[email-masked]>
Date: Wed, 05 Mar 2025 13:36:39 +0000

@davecramer может быть ты сможешь мне помочь?