Repository: kubernetes
Issue: port-forward closed on specific postgres command
Labels: kind/bug,sig/apps,sig/cli,lifecycle/frozen,needs-triage

### What happened?

I've created a postgres cluster by the readme via helm and a simple manifest (see https://github.com/zalando).

I do `port-forward acid-minimal-cluster-0 8098:5432` and then `psql -h localhost -p 8098 -U postgres'. I paste the password from the kubernetes secret created by the operator.

While being connected via psql, I call `\c foo', the connection will then be closed with:

```
E0812 19:41:10.188388 2778901 portforward.go:406] an error occurred forwarding 8098 -> 5432: error forwarding port 5432 to pod 3902fddf18f9819a2114c71be1e745f7610b8695a8a3fa1c838525af3f1576e4, uid : port forward into network namespace "/var/run/netns/eeb57a40-33aa-4feb-a081-b3609a272a89": read tcp [::1]:42206->[::1]:5432: read: connection reset by peer
```

BUT, if I call the psql with a direct selection of a database, like so: `psql -h localhost -p 8098 -U postgres -d foo', I can do all sorts of calls, like select, create an so on.

### What did you expect to happen?

I'd expect no disconnection, no matter what command I run during a session with psql.

### How can we reproduce it (as minimally and precisely as possible)?

```console
git clone https://github.com/zalando/postgres-operator.git
helm repo add postgres-operator-charts https://opensource.zalando.com/postgres-operator/charts/postgres-operator
helm install postgres-operator postgres-operator-charts/postgres-operator

#From within the git repo, above
kubectl create -f minimal-postgres-manifest.yaml

port-forward acid-minimal-cluster-0 8098:5432
#Install posgresql-client, e.g. sudo apt install postgresql-client
psql -h localhost -p 8098 -U postgres
#paste Password from kubernetes secret and then, while in qsql run
 \c foo
```

### Anything else we need to know?

Using `PGSSLMODE=disable psql -h localhost -p 8098 -U postgres` works so far, as there will be no connection drop, but uploads of larger files will hang.

Using the solution with a scat from here https://stackoverflow.com/questions/70762591/kubectl-port-forwarding-to-remote-postgres-port helped, but then data transfers are terribly slow!


### Kubernetes version

<details>

```console
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.3", GitCommit:"aef86a93758dc3cb2c658dd9657ab4ad4afc21cb", GitTreeState:"clean", BuildDate:"2022-07-13T14:30:46Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.3", GitCommit:"aef86a93758dc3cb2c658dd9657ab4ad4afc21cb", GitTreeState:"clean", BuildDate:"2022-07-13T14:23:26Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"}

```

</details>


### Cloud provider

<details>
On premise
</details>


### OS version

<details>

```console
PRETTY_NAME="Debian GNU/Linux bookworm/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
# paste output here
```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>
crio 1.24.2
</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>
```console
Calico:
Client Version:    v3.23.3
Git commit:        3a3559be1
Cluster Version:   v3.23.3
Cluster Type:      typha,kdd,k8s,operator,bgp,kubeadm
```

PROMETHEUS_VERSION='14.12.0'
ROOK_VERSION='v1.9.3'
DASHBOARD_VERSION='5.4.1'
METRICS_VERSION='3.8.2'
METALLB_VERSION='0.12.1'
INGRESS_VERSION='4.1.1'

</details>