Bug 55370 - Не подключается к БД через pgbouncer
Summary: Не подключается к БД через pgbouncer
Status: CLOSED NOTABUG
Alias: None
Product: Sisyphus
Classification: Development
Component: pgbouncer (show other bugs)
Version: unstable
Hardware: x86_64 Linux
: P5 normal
Assignee: Alexei Takaseev
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-27 17:33 MSK by Aleksandr Sysoev
Modified: 2025-10-24 13:43 MSK (History)
5 users (show)

See Also:


Attachments
verbose (3.32 KB, text/plain)
2025-07-28 10:36 MSK, Alexander Makeenkov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksandr Sysoev 2025-07-27 17:33:22 MSK
p11-server-11.0-x86-64 обновленный до актуального состояния Sisyphus

# rpm -qa | grep ares
c-ares-1.34.5-alt1.x86_64
libcares-1.34.5-alt1.x86_64

# rpm -qa | grep pgbouncer
pgbouncer-1.24.1-alt1.x86_64
============================
Шаги воспроизведения:
Задать версию postgresql, выбрав автоматически самую последнюю в репозитории:
# PG_VER=$(apt-cache search postgresql-server | cut -d' ' -f1 | grep [0-9]$ | sort -u | tail -1) && echo $PG_VER

Установить пакеты:
# apt-get install ${PG_VER}-server ${PG_VER}-contrib pgbouncer -y

Запустить сервис:
# /etc/init.d/postgresql initdb && systemctl enable --now postgresql && sleep 5; systemctl status postgresql

Настроить конфигурационный файл:
# CONFIG=$(rpm -ql pgbouncer | grep pgbouncer.ini) && echo $CONFIG && cp $CONFIG ${CONFIG}.bak && sed -i -e 's/\[databases\]/\[databases\]\n* = host=localhost port=5432/' \
-e 's/;; logfile/logfile/' \
-e "/listen_addr/s/localhost/$(hostname -i)/" \
-e '/auth_type/s/trust/md5/' \
-e 's/;admin_users.*/admin_users = postgres/' \
-e 's/;max_client_conn.*/max_client_conn = 500/' \
$CONFIG && \
diff -u --color ${CONFIG}.bak $CONFIG

Добавить пользователя postgres и его пароль в список пользователей для pgbouncer:
# PASSWD_HASH=$(psql -U postgres -c "SELECT passwd FROM pg_shadow WHERE usename = 'postgres';" --csv | grep -v passwd) && echo $PASSWD_HASH
# echo "\"postgres\" \"$PASSWD_HASH\"" > /etc/pgbouncer/users.txt && cat /etc/pgbouncer/users.txt

Запустить сервис:
# systemctl enable --now pgbouncer && sleep 5; systemctl status pgbouncer

Проверить, что подключение к базе стало доступно на порту 6432:
# psql -U postgres -p 6432

Ожидаемый результат: подключение к БД выполняется успешно

Реальный результат: psql: ошибка: подключиться к серверу через сокет "/tmp/.s.PGSQL.6432" не удалось: FATAL: client_login_timeout (server down)
============================
Вывод journalctl:
июл 27 17:01:16 server-11-0-x86-64-minimal-20250727.localdomain pgbouncer[2207]: S-0x55cbe33eb890: postgres/postgres@[::1]:5432 closing because: connect failed (age=0s)
июл 27 17:01:19 server-11-0-x86-64-minimal-20250727.localdomain pgbouncer[2207]: stats: 0 xacts/s, 0 queries/s, 0 client parses/s, 0 server parses/s, 0 binds/s, in 0 B/s, out 0 B/s, xact 0 us, query 0 us, wait 0 us
июл 27 17:01:31 server-11-0-x86-64-minimal-20250727.localdomain pgbouncer[2207]: S-0x55cbe33eb890: postgres/postgres@[::1]:5432 closing because: connect failed (age=0s)
июл 27 17:01:47 server-11-0-x86-64-minimal-20250727.localdomain pgbouncer[2207]: S-0x55cbe33eb890: postgres/postgres@[::1]:5432 closing because: connect failed (age=0s)
июл 27 17:02:01 server-11-0-x86-64-minimal-20250727.localdomain pgbouncer[2207]: C-0x55cbe33e2ef0: postgres/postgres@unix(2509):6432 closing because: client_login_timeout (server down) (age=60s)
июл 27 17:02:01 server-11-0-x86-64-minimal-20250727.localdomain pgbouncer[2207]: C-0x55cbe33e2ef0: postgres/postgres@unix(2509):6432 pooler error: client_login_timeout (server down)
============================
Логи:
2025-07-27 17:01:16.421 MSK [2207] LOG S-0x55cbe33eb890: postgres/postgres@[::1]:5432 closing because: connect failed (age=0s)
2025-07-27 17:01:19.088 MSK [2207] LOG stats: 0 xacts/s, 0 queries/s, 0 client parses/s, 0 server parses/s, 0 binds/s, in 0 B/s, out 0 B/s, xact 0 us, query 0 us, wait 0 us
2025-07-27 17:01:31.754 MSK [2207] LOG S-0x55cbe33eb890: postgres/postgres@[::1]:5432 closing because: connect failed (age=0s)
2025-07-27 17:01:47.087 MSK [2207] LOG S-0x55cbe33eb890: postgres/postgres@[::1]:5432 closing because: connect failed (age=0s)
2025-07-27 17:02:01.420 MSK [2207] LOG C-0x55cbe33e2ef0: postgres/postgres@unix(2509):6432 closing because: client_login_timeout (server down) (age=60s)
2025-07-27 17:02:01.420 MSK [2207] WARNING C-0x55cbe33e2ef0: postgres/postgres@unix(2509):6432 pooler error: client_login_timeout (server down)
============================
Доп: аналогично в p11 с заданием 389776 подключение не работает. 

Доп2: в p11 с версией c-arec 1.34.4-alt1 работает корректно. Версия pgbouncer в p11 такая-же (1.24.1-alt1).
Comment 1 Alexander Makeenkov 2025-07-28 10:36:41 MSK
Created attachment 19200 [details]
verbose

verbose лог

У меня подключение заработало после отключения IPv6.
Comment 2 Anton Farygin 2025-07-28 11:37:45 MSK
может быть у вас просто некорректно настроен стенд для работы с ipv6 а pgbouncer пытается его использовать ?
Comment 3 Alexander Makeenkov 2025-07-28 11:39:38 MSK
С c-arec версии 1.34.4-alt1 такой проблемы нету. В р11 ломается сразу после обновления до задания 389776 и перезапуска сервиса pgbouncer.
Comment 4 Repository Robot 2025-08-02 13:21:59 MSK
c-ares-1.34.5-alt2 -> sisyphus:

Mon Jul 28 2025 Anton Farygin <rider@altlinux.com> 1.34.5-alt2
- applied upstream commit 2a35a061 to resolve IPv6 address
  resolution issues (closes: #55370)
Comment 5 Anton Farygin 2025-08-02 13:23:20 MSK
переоткройте если не поможет и повесьте тикет в апстрим c-ares, пожалуйста
Comment 6 Aleksandr Sysoev 2025-08-05 10:05:46 MSK
К сожалению, не помогло. 
 
В апстрим уже завёл:
https://github.com/c-ares/c-ares/issues/1011
Comment 7 Aleksandr Sysoev 2025-10-24 12:48:06 MSK
По-прежнему для корректной работы, необходимо, либо отключить ipv6 в системе, либо в настройках pgbouncer настроить явно работу с ipv4:

[databases]
* = host=127.0.0.1 port=5432 (вместо * = host=localhost port=5432 

Либо, если наоборот настроить postgresql и pgbouncer на работу с ipv6, то подключение так-же отрабатывает корректно.

Судя по сообщению в апстриме - это ожидаемое поведение:
Prior to 1.34.5, c-ares may not properly return dns entries for 'localhost' for both ipv4 and ipv6 if both were requested and only would return what was in /etc/hosts which actually is in violation of the spec, so that was fixed.