Hello

I have made some deeper investigation:

Steps to reproduce:

```
docker pull ubuntu:18.04 && docker run -it --rm ubuntu:18.04 bash
## or
docker pull ubuntu:20.04 && docker run -it --rm ubuntu:20.04 bash
## or
docker pull ubuntu:22.04 && docker run -it --rm ubuntu:22.04 bash


apt-get update
apt-get install -y vim strace less curl ca-certificates gnupg sudo lsb-release

curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null

sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
apt-get update
apt-get install -y postgresql-12

pg_ctlcluster 12 main start

sudo -u postgres -i
psql
CREATE DATABASE database_name;
CREATE USER my_username WITH PASSWORD 'my_password';
GRANT ALL PRIVILEGES ON DATABASE "database_name" to my_username;
exit

echo '*:*:*:my_username:my_password' > .pgpass
chmod 0600 .pgpass
exit

##
## this does not work for ubuntu 18.04 but for ubuntu 20.04/22.04
##
/usr/bin/sudo -u postgres psql -U my_username -h 127.0.0.1 database_name -c "CREATE TABLE foo (foo char);"

##
## this works for all
##
sudo -u postgres -i
psql -U my_username -h 127.0.0.1 database_name -c "CREATE TABLE foo (foo char);"
```

We have narrowed it down to three packages which have been upgraded on ubuntu 18.04 between working and broken state:
- `libpq5` upgraded from `14.5-1.pgdg18.04+1` to `15.0-1.pgdg18.04+1`
- `postgresql-client-common` and `postgresql-common` from `243.pgdg18.04+1` to `244.pgdg18.04+1`

None other packages have been upgraded (incl. ubuntu repo packages)!

For me it does look like a bug with in psql client package.

regards
Mike

--
Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.
Am 17.10.22, 16:19 schrieb PG Bug reporting form <noreply@postgresql.org>:
The following bug has been logged on the website:

Bug reference: 17647
Logged by: Mike Fröhner
Email address: mikefroehner@gmx.de
PostgreSQL version: 12.12
Operating system: Ubuntu 18.04
Description:

Hello,

today our CI noticed the upgrade of PostgreSQL to 12.12. We have a CI/CD
which tests our Puppet Module against Ubuntu 16./18./20./22.04. We run
different tests (kitchen-ci) including the following:
```
describe command('/usr/bin/sudo -u postgres psql -U myuser1 -h 127.0.0.1
mydb1 -c "CREATE TABLE foo (foo char);"') do
its('exit_status') { should eq 0 }
its('stdout') { should eq "CREATE TABLE\n" }
its('stderr') { should eq '' }
end
```
Therefore we rollout a DB and a user via:
```
postgresql::databases:
'mydb1':
user: myuser1
password: mypassword1
host: 127.0.0.1/32
```
We also rollout a file:
```
'/var/lib/postgresql/.pgpass':
owner: postgres
group: postgres
mode: '0600'
content: '*:*:*:myuser1:mypassword1'
require_class: postgresql
```
This test only fails/times out on Ubuntu 18.04 because it is waiting for a
password input. With all other Ubuntu (16./20./22.04) this test succedds. Is
there anything wrong with my test or is the package for Ubuntu 18.04 broken?