Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sdvE9-002FUf-Ll for pgsql-pkg-debian@arkaria.postgresql.org; Tue, 13 Aug 2024 17:22:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sdvE8-005Ffq-AU for pgsql-pkg-debian@arkaria.postgresql.org; Tue, 13 Aug 2024 17:22:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sdvE7-005Ffi-Uh for pgsql-pkg-debian@lists.postgresql.org; Tue, 13 Aug 2024 17:22:32 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sdvE5-004gTG-Is for pgsql-pkg-debian@postgresql.org; Tue, 13 Aug 2024 17:22:31 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a7aa212c1c9so681440266b.2 for ; Tue, 13 Aug 2024 10:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kartgis-com-pl.20230601.gappssmtp.com; s=20230601; t=1723569748; x=1724174548; darn=postgresql.org; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6KkVtXiXchNeFkmgDA5bUD9wAVff4tdlfKwDFNewwU8=; b=3c44PV9HFjuoWTiegkznGnbqwcwyYO59HTtOdu7PM2itXGlQ2AL6W3av3MwSF2Ad08 hFtrwI/KRs49NsM3SNMyd1S0wI8jatr1SdMQTD6hLVbzs46GplOCJcyfj0aPsycWzgOS ibYT4o/yozTWwTEO89o6U1HiM55oHS7LS7bKRp50+voSlVgU2lw+QXhMPnKd/A6K9cB7 x5kw4gcgxj/3ePEu/ORW315zAOqN/z/ff/rrp5oBdQ6qiHuHAR0oVmwZkSQpj/t3IfwJ taPZQE2gIJxAEdiZBmer5kVhBV6LQO7izApQdrCbRZK2lqcNz5looV5jcEmLZyuzY9P4 uPzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723569748; x=1724174548; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6KkVtXiXchNeFkmgDA5bUD9wAVff4tdlfKwDFNewwU8=; b=FFdDqCwpiulA0XeTht8GUa4ivTaAWClP538IIxnmjs3nIV8dGCpYVcn0M4oCnjBYjX 7HDYiU7Ni2n70h1NsxMQqeyMbrcITFelytqZfs7Ap1GWmB7lNKQq/HIlpxYh7k3qJHX/ w6dlIhPlntRJ/vyuCN/JhdX8xb5KxI/gNJFe3SVeWBpgxALcksA61BStahZDS+qXZ/Pk OcIKECKt76Y1H1p50jryUSSI6tSruuVbqfgJIu0cbmd76BlhcoytH725KY99xW2/W3hI h+YtXftmCXqdnaTVmbFUkXtPjnwemwaS6dyVduv6STizoqz7j2isEPRwu/nj27HqY2jo AgfA== X-Gm-Message-State: AOJu0YxQfXdAcAwG+tQ/RkLGOJkXg4L7fopYbe7egRNZVetB06PVv7Yz z2FddUWLiBLIrj+cASMc3aYjs1w7yxqD6x4NcaT5NOu7TQ+d4ZwULkz/Wrx2MOcKFRBQx2/+OHF BiCIF7hd7+0YFWGykR0IFYNbqM5gg38F+sai++Cn8AB5BD93zMw== X-Google-Smtp-Source: AGHT+IGugGuhpfPoRodgu4fT4EseZuHH+nJE9GcTvNFbSYOI2nIaJpx+yI5/u+Gn0Vji5NmRxzgWOQHX43wZCHSYlKo= X-Received: by 2002:a17:907:3f96:b0:a6f:b98e:9aa4 with SMTP id a640c23a62f3a-a83670e55fbmr2512866b.61.1723569748167; Tue, 13 Aug 2024 10:22:28 -0700 (PDT) MIME-Version: 1.0 From: Krzysztof Tomaszewski Date: Tue, 13 Aug 2024 19:22:17 +0200 Message-ID: Subject: Systemd may start PostgreSQL cluster before time is properly setup on the host machine To: pgsql-pkg-debian@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi All, I previously published following analysis on redmine.postgresql.org as an issue #8009 about 2 months ago. As this system seems to be dormant I took liberty to re-post it here. Hope it is OK. PostgreSQL systemd unit postgresql@.service provided by postgresql-common package is not setup to start after time-set.target nor time-sync.target. In case of SysV init script provided by the same package, there is proper dependency on $time in LSB stanza. Without one of those, cluster may start before time is properly setup (in crude or precise way respectively). According to systemd documentatnion (systemd.special(7) and systemd-sysv-generator(8)) when systemd generates unit for SysV init script, it transform dependency on $time to dependency on time-sync.target so that time-sync.target seems more appropriate than time-set.target at least from consistency standpoint. For example, when machine clock is setup in UTC (as it usually should) and local time is different, PostgreSQL during start may interpret time without timezone applied as one with it. As esoteric and contrived as it sounds, I recently stumbled upon a case in production environment, where `pg_postmaster_start_time()` was returning time in the future, with shift consistent with timezone shift in that environment. Investigation of which case led me to above mentioned findings. As a side note, SysV init script is also configured to be started after $local_fs and $remote_fs. Systemd provides analogical targets ($local-fs.target and $remote-fs.target respectively) but postgresql@.service do not use them (again, systemd-sysv-generator support $remote_fs but interestingly ignores $local_fs in documentation and code of sysv-generator.c for some unknown to me reason). This probably also should be kept consistent among starting mechanisms, i.e. it should be added to unit file or dropped from init script stanza. Another thing of some potential interest may be how RPM packages provided by PostgreSQL project, handle similar unit file. Unit file from RPM package also lacks dependency on any time related target but has additional dependency on syslog.target which may not (do not?) exists at all. As syslog providers do not add dependency on time related targets (only network related), this will not position PostgreSQL start after time is properly setup even in implicit (transitive) way. There are some other differences between unit files provided directly by PostgreSQL project for Debian and RPM based distros, that lead to different behavior among them but are unrelated to this issue (as they mostly relate to how they handle timeouts, with infinity for start and stop in RPM based systems and 1h limit for stopping Postgres cluster in Debian). Regards, Krzysztof Tomaszewski --=20 ktomaszewski@kartgis.com.pl *KartGIS sp. z o.o.* | www.kartgis.com.pl Aleje Jerozolimskie 81 02-001 Warszawa NIP 9512276974, REGON 141747787 Fax 22-213-96-40 Zarejestrowana w S=C4=85dzie Rejonowym dla m.st. Warszawy w Warszawie, XII Wydzia=C5=82 Gospodarczy Krajowego Rejestru S=C4=85dowego pod numerem KRS: 0000517511 Warto=C5=9B=C4=87 Kapita=C5=82u Zak=C5=82adowego: 611 300,00 PLN