Skip to content

Improve recommended systemd unit file - #983

Merged
eulerto merged 1 commit into
pgbouncer:masterfrom
eulerto:systemd-network-target
Nov 30, 2023
Merged

eulerto merged 1 commit into
pgbouncer:masterfrom
eulerto:systemd-network-target

Conversation

@eulerto

@eulerto eulerto commented Nov 13, 2023

Copy link
Copy Markdown
Member

Replace network.target with network-online.target. Postgres already did it [1]. Issue #980 suggests that if you are using DNS and, for some reason, the PgBouncer starts before the network finishes the initialization, it is unable to resolve names; the solution is to restart the service if it occurs (which is a unfortunate workaround).

According to man 7 systemd.special [2]:

Note the distinction between this unit and network.target. This unit is an active unit (i.e. pulled in by the consumer rather than the provider of this functionality) and pulls in a service which possibly adds substantial delays to further execution. In contrast, network.target is a passive unit (i.e. pulled in by the provider of the functionality, rather than the consumer) that usually does not delay execution much.

It could delay the service start up to $timeout (default is 90 seconds). Hence, PgBouncer won't accept connections until the network is ready and it is time to start the service. It seems a good tradeoff to wait until the network is ready then to fail a setup that uses DNS. (If you don't use DNS and cannot afford waiting the network to be ready and wants to accept client connections ASAP, then edit the systemd unit file and revert this change.)

Fixes #980

[1] postgres/postgres@2d27e13b35
[2] https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

Replace network.target with network-online.target. Postgres already did
it [1]. Issue pgbouncer#980 suggests that if you are using DNS and, for some
reason, the PgBouncer starts before the network finishes the
initialization, it is unable to resolve names; the solution is to
restart the service if it occurs (which is a unfortunate workaround).

According to man 7 systemd.special [2]:

Note the distinction between this unit and network.target. This unit is
an active unit (i.e.  pulled in by the consumer rather than the provider
of this functionality) and pulls in a service which possibly adds
substantial delays to further execution. In contrast, network.target is
a passive unit (i.e. pulled in by the provider of the functionality,
rather than the consumer) that usually does not delay execution much.

It could delay the service start up to $timeout (default is 90 seconds).
Hence, PgBouncer won't accept connections until the network is ready and
it is time to start the service. It seems a good tradeoff to wait until
the network is ready then to fail a setup that uses DNS. (If you don't
use DNS and cannot afford waiting the network to be ready and wants to
accept client connections ASAP, then edit the systemd unit file and
revert this change.)

Fixes pgbouncer#980

[1] postgres/postgres@2d27e13b35
[2] https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
@emelsimsek

emelsimsek commented Nov 21, 2023 •

Copy link
Copy Markdown
Contributor

Fixes #987

In #987,

PgBouncer cannot bind to an ip address before networking starts.

  2023-11-20 13:49:32.518 EET [1369] DEBUG add_listen: 10.10.0.14:6432
  2023-11-20 13:49:32.525 EET [1369] WARNING cannot listen on 10.10.0.14:6432: bind(): Cannot assign requested address

So even when PgBouncer does not use DNS, this fix is needed most of the times.

@eulerto
eulerto merged commit 6c7730e into pgbouncer:master Nov 30, 2023
@eulerto
eulerto deleted the systemd-network-target branch July 22, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pgbouncer can't resolve DB server name after system reboot.

2 participants