Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3jTZ-0008L5-1C for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2020 16:42:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3jTX-0003dX-RO for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2020 16:42:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3jTW-0003dB-0Z for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2020 16:42:27 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j3jTQ-0007XH-Sm for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2020 16:42:24 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 87D91210AF; Mon, 17 Feb 2020 11:42:19 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 17 Feb 2020 11:42:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=k 7GYGAB2FW9h9nRdig6fO8wHRifT0pvdcirEYPWQtcI=; b=Miwp0b9s/rylHoPBl Iymw744s5OMi3b7+sdpuTrZWsyJ/KdfcMt6/6f7h/Vpe62+6eyPFKuewHWFEmh2V POT3P6SLTZ8LJuJ2ni1t+UGwlSXoEAEArZVksDgeQfwc4RfF0K7K0ty+D99JW5MY 9JhO2ZlRloTS7t850oA0CZsiBCjnXDFbGL2oNYqlvj3BpKVdBIAAFNWOc/MS9ZCj SCSfkA4kaj3NI/D22Dsis1lbefPeFwIZmkoayLvRs6N/Ca1DduUDye1PlmVyXPO2 R6dgsq79Qru7qHW5FltGolZ6iWCiG6rg5lYbk4UwX8QbivthiG0N+bEFeH1hNwH0 Sd2yA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=k7GYGAB2FW9h9nRdig6fO8wHRifT0pvdcirEYPWQt cI=; b=HZvqVeiZ+Sk8+CaUymvvvacvX40xWdriN/Ifq3oc8/+ShxUnihPsC4Ghn VfDHvtUlyIgQr1k/94nDdbCz2DlKc9jj5QBvL0644QhEE8KiYF6FIjIgxXi7vSgS sSPf8f/RB+oPr3GqItdZzMxl9XN5XKn6q2XepXw5HIsiV0yIY4a7BZRt1WSwFD9P yqqYksTV/DeCfI95SbL/O8p9xxw+82+SUoQSqATKcOWVrc69q5ASlVO30Qb9P8un xKFygjsCZgB7v29MA9mqkLK4drdhx+zjvgiXfNlWcigcm29xyiQRIKv14tUBFPAZ wF0X0E7aEmunAdtoLG55k2VkkQENg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrjeeigdelfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucfkphepjedurddvuddv rdduvdelrdduleefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id AD9DD3060BD1; Mon, 17 Feb 2020 11:42:18 -0500 (EST) Subject: Re: Cannot connect to postgresql-11 from another machine after boot To: Jason Swails , "Peter J. Holzer" Cc: pgsql-general@lists.postgresql.org References: <4e04fcba-2921-df12-c1a5-7a3eb5afb1eb@aklaver.com> <20200216135121.GA10553@hjp.at> From: Adrian Klaver Message-ID: Date: Mon, 17 Feb 2020 08:42:17 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/17/20 7:17 AM, Jason Swails wrote: > > > On Sun, Feb 16, 2020 at 8:51 AM Peter J. Holzer > wrote: > > On 2020-02-13 21:03:48 -0800, Adrian Klaver wrote: > > On 2/13/20 9:02 PM, Adrian Klaver wrote: > > > On 2/13/20 7:54 PM, Jason Swails wrote: > > > > The problem is that after my machine boots, I'm unable to > connect to > > > > the server from anywhere except localhost.  Running a simple > > > > "systemctl restart postgresql" fixes the problem and allows me to > > > > connect from anywhere on my LAN.  Here is an example of this > > > > behavior: > [...] > > > > > > > > So the first connection attempt fails.  But when I restart the > > > > service and try again (doing nothing else in between), the > > > > connection attempt succeeds.  My workaround has been to simply > > > > restart the service every time my machine reboots, but I'd really > > > > like to have a more reliable startup. > > > > > > > > Any ideas how to start hunting down the root cause?  I think this > > > > started happening after I moved the data directory to another > drive. > > > > > > I would start by looking in the system log to see what it > records when > > > the service tries to start on reboot. > > > > Hit send to soon. At a guess the Postgres service is starting > before the > > drive is mounted. > > I don't think this has anything to do with the drive. If the drive > wasn't mounted he couldn't connect from localhost either. > > What is probably happening is that postgresql is configured to listen on > localhost and the IP address of the ethernet interface and is starting > before the etherned interface is ready. So it is listening only on > localhost (there should be an error message regarding the other address > in the log). When he restarts postgresql some time later, the interface > is ready. > > It should be possible to solve this by adding the right dependencies > to systemd. > > > I actually think the problem was both of these.  The postgresql.conf > file was on the non-root drive that probably wasn't mounted before > postgresql started up -- I think the "default" listen_addresses when no > conf file is available is just "localhost".  To fix this, I added Without a conf file the server will not start(the ok notwithstanding): sudo /etc/init.d/postgresql12 start Starting PostgreSQL: ok postmaster: could not access the server configuration file "/usr/local/pgsql12/data/postgresql.conf": No such file or directory ps ax | grep postmaster Returns nothing Whereas with conf file: sudo /etc/init.d/postgresql12 start Starting PostgreSQL: ok --2020-02-17 08:35:05.026 PST-0LOG: starting PostgreSQL 12.1 on x86_64-pc-linux-gnu, compiled by gcc (SUSE Linux) 7.4.1 20190905 [gcc-7-branch revision 275407], 64-bit --2020-02-17 08:35:05.026 PST-0LOG: listening on IPv4 address "0.0.0.0", port 5432 --2020-02-17 08:35:05.026 PST-0LOG: listening on IPv6 address "::", port 5432 --2020-02-17 08:35:05.075 PST-0LOG: listening on Unix socket "/tmp/.s.PGSQL.5432" --2020-02-17 08:35:05.131 PST-0LOG: redirecting log output to logging collector process --2020-02-17 08:35:05.131 PST-0HINT: Future log output will appear in directory "pg_log". ps ax | grep postmaster /usr/local/pgsql12/bin/postmaster -D /usr/local/pgsql12/data > "After=home.mount" to the postgresql systemd service.  Once I did that, > I started seeing the error message regarding the other address in the > log, so I suspected exactly what you mentioned here. What is the actual error message? > > I then added "network.target", "networking.service", and > "network-online.target" to the After line of the postgresql.service > systemd file, but it still didn't fix the problem.  I ultimately had to > change listen_addresses from "localhost,192.168.1.3" to "*".  It's > certainly not my favorite approach as the former is stricter and > therefore more secure. But I don't have port forwarding set up for the > postgres port, so my router should serve as a suitable firewall for my > small-scale home database setup. You can also use pg_hba.conf to restrict access: https://www.postgresql.org/docs/11/auth-pg-hba-conf.html > > Thanks, > Jason > > -- > Jason M. Swails -- Adrian Klaver adrian.klaver@aklaver.com