Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqipr-00028v-PN for pgsql-general@arkaria.postgresql.org; Thu, 03 Nov 2022 22:37:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oqipp-0001aB-N2 for pgsql-general@arkaria.postgresql.org; Thu, 03 Nov 2022 22:37:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqipo-0001a1-O3 for pgsql-general@lists.postgresql.org; Thu, 03 Nov 2022 22:37:17 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqipj-0002ty-RO for pgsql-general@lists.postgresql.org; Thu, 03 Nov 2022 22:37:16 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 345DB5C005D; Thu, 3 Nov 2022 18:37:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 03 Nov 2022 18:37:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1667515029; x= 1667601429; bh=vAhW2z+CUupQS/6W/oQfEEvGNxnM5TYul6Jfme7ufoA=; b=P mMDUd+oFfbmFQvxobwhMYXfhsR1L2RvLDLg+8nvlRQitg9a/Sy/HAFdApCfdTtPs pDFankIcaD3JB00doPPAVMKdII4rlTHupwILuryPXvd8GWOTuKu/ZbqybjB7IYGR M4IIJ06gk2ZPLeuME0IpUACXHwub8ZbH0D+JkkhUwEGSOMGwt6uGxY33UNYz+K4j esaMyCW5Rr7Jbs1U95oORp0AKP7UVy+Bh/PDzH6ZaFWSJP46pneXkCJox/daS3QU kSwAOzbFkQR1inWllge+o7/Mr/lU5y1yoQN0yle38eAc2Lt7C36ExQlkr2NmZKYf 6fiC+CTngjbHniOevh/Cw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1667515029; x= 1667601429; bh=vAhW2z+CUupQS/6W/oQfEEvGNxnM5TYul6Jfme7ufoA=; b=s 2DNuJqQj0dmT8bUzt4XotRo35kZZPbbEUADlz5X8jfAupSDiNsFVgX2uyg3KN+vs sRxJsxQWdkJ1pXKB8nnqKU5NrM1J+2lmtZhb6R+2cBUqcKAO5coanYJ2Z0IAAZUq /ab2aaPMmELKnSeMgC6mIekDCziGZiae9CX/18HY3JkGrQEn8Lp7p9TiwFOoybHH keZAo8Fym2OKJ5fniyfVTzdc4pam+9WxqilHhb6fetzJ7Um0LGq8597S4Zx4TRo5 gy9oe0uHSLZr76N06AySqYw5uSx/OxyMgY33G3HLrJ+fjf9TMm3Yq4JJxw+hSco/ aiTaraPmjZIhQMatBt57A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvddtucetufdoteggodetrfdotffvucfrrh hofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epkfffgggfuffvvehfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgrnhcu mfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqne cuggftrfgrthhtvghrnheptedtkeevheeltdejteduvdffffeufffhueelueekkeekuedt tedthfehieelhfefnecuffhomhgrihhnpehusghunhhtuhdrtghomhenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Nov 2022 18:37:07 -0400 (EDT) Message-ID: <55260909-8740-1fc0-68a9-4656ac8e755d@aklaver.com> Date: Thu, 3 Nov 2022 15:37:07 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: Putting the O/S user for "local" "peer" authentication in the "postgres" group vs chmod'ing the "pg*.conf" files to be readable by "all" To: Bryn Llewellyn Cc: "David G. Johnston" , pgsql-general list , "Peter J. Holzer" , laurenz.albe@cybertec.at, Karsten Hilbert References: <5EDD4790-7982-4610-8371-9E7F9C7F960B@yugabyte.com> <4B667995-647F-48BB-94CC-22ADE19F0BFB@yugabyte.com> <3A027257-8C6C-444D-91CB-37D53CC0C817@yugabyte.com> <2e36cc43-a759-34f8-8179-72ade14ef72e@aklaver.com> <0FB2CA70-B125-4675-9871-562A6EFDE3DB@yugabyte.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: <0FB2CA70-B125-4675-9871-562A6EFDE3DB@yugabyte.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/3/22 14:49, Bryn Llewellyn wrote: > I should make it clear that my VM has four "ordinary" users. Two are > present on first use when VM creation finishes: the system administrator > (called "parallels") and, of course, "root". The "parallels" user is > enabled for "sudo". Installing PG brings "postgres". (I created mine > before hand, and it was unperturbed by the PG installation. This is my > private laptop. And it suits me to give it a home directory and to > customize its ".bashrc". But that's so that I can look around with the > minimum of fuss.) Finally, there's my "clstr_mgr" O/S user that acts as > the authorization vehicle for my "clstr$mgr" cluster-role. Each of > "postgres" and "clstr_mgr" is in its own singleton group—and in no other > groups. And neither is set up for "sudo".) > > So only "postgres" can edit the files that must be so edited. That is not true: aklaver@arkansas:~$ whoami aklaver aklaver@arkansas:~$ sudo vi /etc/postgresql/14/main/pg_hba.conf [sudo] password for aklaver: which opens pg_hba.conf for editing. > > Apparently, an unwritten rule says that one must never end up so that > "whoami" shows "postgres". I see that I can, then, always do, for > example, this (from "parallels"): > > *sudo -u postgres vi pg_hba.conf* > > And, given that one major theme in our recent mutual, extended, > exchanges is that I want to use "local", "peer" authentication for the > cluster-role "postgres" via the O/S user with the same name, I see that > I can always run all the SQL scripts that I want, using this > authentication, like this: You want to use local peer with OS user postgres, that is not a requirement. You could set up Postgres to log in the db user postgres by any of the other auth means and do the below without sudo(ing) to OS user postgres. > > *sudo -u postgres psql -f my_script.sql* > > With this in mind, I re-wrote my "clean start" script thus: > > *#!/bin/bash > > * > *# do this as ANY user that can do "sudo" (and this includes "root" itself) > > sudo pg_ctlcluster stop 11/main > sudo rm -Rf /var/lib/postgresql/11/main > > sudo -u postgres initdb \ >   -U postgres --encoding UTF8 --locale=C --lc-collate=C > --lc-ctype=en_US.UTF-8 \ >   -A md5 --pwfile=my_password_file \ >   -D /var/lib/postgresql/11/main > > sudo pg_ctlcluster start 11/main > > sudo -u postgres **psql -f my_script.sql** > * > It certainly works. And when it's finished, this: > > *sudo -u postgres psql -c " select name, setting from pg_settings where > category = 'File Locations'; " > * > shows that my files are where they ought to be. Then, further tests show > that "local", "peer" authorization works as intended for my "clstr$mgr" > role and that I can connect from client machines. So all is good. > > Why, though, is "pg_ctlcluster stop/start... " preferred over "systemctl > stop/start postgresql?". Both are quick enough. And I can't see any > difference in effect. Moreover, the latter is what > https://ubuntu.com/server/docs/databases-postgresql >  recommends. It isn't you where using pg_ctl and in the Debian/Ubuntu packaging the better option for that is pg_ctlcluster. I generally use the systemd scripts to start/stop Postgres instances, though when I do pg_lsclusters I tend to fall into using pg_ctlcluster as the cluster info is right there. > > Notice that I'm still using the off-limits "initdb" here. (I wired it up > with a link on "/usr/bin".) Is there any reason to change that and to > try to work out how to use what David (in an email soon after Adrian's) > suggested? Yes and since that is basically coloring outside the lines, then that leads to the below blowing up. > > *sudo pg_dropcluster --stop 11 main > sudo pg_createcluster 11 main > sudo pg_ctlcluster start 11/main- > * > I tried it. But it "did not work". I don't have the energy to describe > the errors that were reported and the nasty outcomes that I got when I > tried to use the new cluster. There's no useful doc for that approach > and I've already established that Internet search gets me nowhere. So > I'm inclined not to use it. Per the saying, "In a ham and eggs breakfast the chicken is involved but the pig is committed", right now you are involved in the Debian/Ubuntu process not committed. Until you commit you will not get the results you want. > > Rather, I want, now, simply to declare victory with the script that I > showed and return to ordinary productive work. > -- Adrian Klaver adrian.klaver@aklaver.com