Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g423M-0007RM-JT for pgsql-general@arkaria.postgresql.org; Sun, 23 Sep 2018 10:55:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g423L-0006zt-02 for pgsql-general@arkaria.postgresql.org; Sun, 23 Sep 2018 10:55:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g423K-0006zl-LC for pgsql-general@lists.postgresql.org; Sun, 23 Sep 2018 10:55:50 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g423H-0003mM-NS for pgsql-general@lists.postgresql.org; Sun, 23 Sep 2018 10:55:49 +0000 Received: by mail-wm1-x330.google.com with SMTP id r1-v6so7613944wmh.0 for ; Sun, 23 Sep 2018 03:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HRl1UTrKxy8ZZM4ErikNStQoPQxU2X+WtfF6hGQzjc0=; b=hGRcMX6/2aRWES7XHFFFjlPqZiYSAK321IlKZBhmtuzPGhJA8eQcF95P1KWLrj0PYi mIHTAm1+q/YR/xGSOxhJ8HQEI5LqLPV2i04EKoVyY96FcGDOVlT7Af8JjeMpjAmTGp7Y 1auI0IpEYdy4Tr7v+kcUsIJHf+lVc4bP40XAS6QbihvLMUQdHRE8lRvZLRq5HLXTH+jA nTX2Lgg3NgAacktTFib3cMx3IMtXbDWgUIwhwafw0+xu2Euc7L1g0RYG1EY9FLex6h6T irrmTt9lfdeByn7VWAQdghEUYDqvfoG/S9qi/8hm29vb/M6xe4BNs1Z9w3sXouCg02Pj Fo4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=HRl1UTrKxy8ZZM4ErikNStQoPQxU2X+WtfF6hGQzjc0=; b=ADtOf+/2+veMLl2x2tQwXi4Qhrj/lwJjHqSoBxl7HjQr7fv/6wOkJMCvLT6GVMPvBr SoMiY1a89s2ifog/9kPpl5d3NB4MQsrbeIerQ5z0Bm6oLbUTfMo4PkuAIO4S3P8WRVXm 79A+PJT9Og3QIIhgHjsjK/31rOVys6y0nQPiwj8coDELKU+p426CCihaf16PnLPEhkmW WrcI35bEztKhJPbl5ueBx9yDgEa9pl6ncxkbQUAzEw3lI1pd5I3tqSS5BXD59pbq4W2C vq6ZmaVyfexbdtlkQ7KitoZLZ/FdJBihzT3r0sTWPChzbcrYDt+h2HJ/lgGhhB4G87Ke zPXw== X-Gm-Message-State: APzg51BTRYIRig8V1wQGu6ozqd5fvzaF1MXFaGxO+Ped0clVvOB6C3pi /sCUQ2u5craqF6+UOJj9IUBYf1BhhJA= X-Google-Smtp-Source: ANB0VdapY2UNaIP7DG1lmiAj8U8Mt78sQhfhEhKWDsLQPYraDQKbvOcgWyeJKpnbvv7YmqSKHvHelA== X-Received: by 2002:a1c:a507:: with SMTP id o7-v6mr4018802wme.45.1537700145820; Sun, 23 Sep 2018 03:55:45 -0700 (PDT) Received: from localhost (bzq-109-66-221-219.red.bezeqint.net. [109.66.221.219]) by smtp.gmail.com with ESMTPSA id u4-v6sm21471007wro.47.2018.09.23.03.55.44 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Sep 2018 03:55:45 -0700 (PDT) Date: Sun, 23 Sep 2018 13:55:05 +0300 From: Doron Behar To: pgsql-general@lists.postgresql.org Subject: Re: postgresql systemd service fails to start only on boot but not manually Message-ID: <20180923105505.fmo43ad2asbdeoo4@NUC.doronbehar.com> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <20180922104411.u463kkorvmbombyk@NUC.doronbehar.com> <20180922145817.GA31091@elch.exwg.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180922145817.GA31091@elch.exwg.net> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Sep 22, 2018 at 04:58:18PM +0200, Christoph Moench-Tegeder wrote: > ## Doron Behar (doron.behar@gmail.com): > > > My server fails to start PostgreSQL only on boot, if I restart it > > manually afterwards it doesn't have any problem starting. Here is the > > log extracted from the journal: > > > > ``` > > 2018-09-21 20:46:40.028 CEST [306] LOG: listening on IPv4 address "127.0.0.1", port 5432 > > 2018-09-21 20:46:40.036 CEST [306] LOG: listening on Unix socket "/run/postgresql/.s.PGSQL.5432" > > 2018-09-21 20:46:40.233 CEST [337] LOG: database system was shut down at 2018-09-21 20:46:21 CEST > > 2018-09-21 20:48:10.441 CEST [352] WARNING: worker took too long to start; canceled > > 2018-09-21 20:49:10.469 CEST [352] WARNING: worker took too long to start; canceled > > This would indicate that your machine is overloaded during start - > perhaps there's just too much being started at the same time? > ObRant: that's what happens if people take "system startup duration" > as a benchmark and optimize for that - sure, running one clumsy shell > script after another isn't effective usage of today's systems, > but starting eight dozens programs all at once may have other > side effects. Really, with the hardware taking small ages to find > it's own arse before even loading the boot loader, those few seconds > weren't worth optimizing - and if people reboot their computers so > often that startup time takes a measurable toll on their productive > day, perhaps they should rather spend their time thinking about their > usage pattern than "optimizing" the startup process. > > So, now that I've got that off my chest... your machine propably tries to > do too much at the same time when booting: the worker processes take > longer than 90 seconds to start. Slow CPU or storage maybe? > > > 2018-09-21 20:49:10.478 CEST [306] LOG: database system is ready to accept connections > > 2018-09-21 20:49:10.486 CEST [306] LOG: received fast shutdown request > > And in the mean time, systemd has lost it's patience, declares the > start as failed and terminates the process group. (The default systemd > timeout is 90 seconds, at least in some releases of systemd, so > this fits quite nicely). > > You could try to work around this by increasing TimeoutStartSec > in postgresql's systemd unit (or even globally), which perhaps > only hides the problem until the next service suddenly doesn't > start anymore. > You could move postgresql to the end of the boot order by > adding "After=..." to the Unit section of the systemd service > file, the value behind "After=" being all the other services in > the same target, which should reduce parallelism and improve > PostgreSQL's startup behaviour. > A more advanced variant of that would be to create a new > systemd target, make that start "After" multiuser.target > or even graphical.target (depending on your setup), make sure > it "Requires" the current default systemd target and make > postgresql the only additional service in that target. > (This would be the cleanest solution, but you should get some > grasp of systemd and how your specific distribution uses it > before meddling with the default targets; I don't know every > distribution/version variant of systemd integration, so I > can't give that specific instructions here). > Or you figure out what the heck your machine is running > during startup any why it is that slow, and try to fix that. > > Regards, > Christoph Thanks for your very detailed answer, that helped me a lot. I've increased `TimeoutSec=` to infinity in the systemd service since it was set initially to 120 seconds which apparently wasn't enough for my poor VPS with 2G RAM and 1 CPU core. That worked great, I still feel like I have slow startups but at least PostgreSQL doesn't totally fail to start on boot. I'll try to debug the slow startups on my own, thanks again for everything! Doron.