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 1pgbeK-0002yj-AY for pgsql-general@arkaria.postgresql.org; Mon, 27 Mar 2023 01:27:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pgbeI-0007vb-U3 for pgsql-general@arkaria.postgresql.org; Mon, 27 Mar 2023 01:27:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgbeI-0007vS-Iu for pgsql-general@lists.postgresql.org; Mon, 27 Mar 2023 01:27:50 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pgbeF-0000pf-Ly for pgsql-general@postgresql.org; Mon, 27 Mar 2023 01:27:49 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id AFD7F5C00BC; Sun, 26 Mar 2023 21:27:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 26 Mar 2023 21:27:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type: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=1679880466; x=1679966866; bh=1n vaMApUt7Sn4AS7AI0WZjtHaQL+1ThsUAs4/utjyoc=; b=LC0x+GSZcd+KbXdIF0 6TjP/DY5NOI0TJOYDqo8GDh7FtO1KaphXWZKSV0Y+71H5L6ZNyY4Ny/UZcmQM++W IiuLS6WWH4CJY83g86w77frsyKTYgK1Q1t2lnhq0N2ZomR0pb6KWPX7RPNwL9yow Fgq+Am/o6ZUtexEDxnIk8jhyCC2Y7A61nF5dMxFWCXqAah2mBnt5ns2hsIaDR6ad C40tiOY5qqwyYYYUcjaXkCFMEmsmpwlVlQpjxu4yl6liH2PXMNzhozn7RezVeRCS bVWuiydvs1pQ1lpwKPhCHLMNLBRwR6pUPaTH30aPSozlmYURvslOkevtdQCvBHOd J1+A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type: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=fm2; t=1679880466; x=1679966866; bh=1nvaMApUt7Sn4 AS7AI0WZjtHaQL+1ThsUAs4/utjyoc=; b=Q2H6L4iALMz/arFNbytopc9ZH0UhK 3icL6s+Zv7a+w6QeSAWrI8Tn4ctrBe0h8ZBG9zIpxLIhKez3VFDKEg2nq7cZpBND b+UNfFk3FH3USmr1DBtagXLPhuSSeUj1DjTkuEvgUQxur8AOXOO1y30fOBt4bvP1 3Cxcqy//IiK0zj5ptret/aU/yo5V6sNMkWed1eAT4R/KQGBV1naSRXxT4N9KwlYq CjBXBfU0aE80RFhi0GwfIjMoNyHN/BME3+/Jdc0u/4uYWq0DT9kSOdgpXaJe55nE R4yBZOvQx3iRebzgNaQISJY08BWg3IMyVqzj0ucrHZ1sdZ5BuN0FRAISQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehuddggeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 26 Mar 2023 21:27:45 -0400 (EDT) Date: Mon, 27 Mar 2023 10:27:42 +0900 From: Michael Paquier To: Markus Pilman Cc: pgsql-general@postgresql.org Subject: Re: Binding Postgres to port 0 for testing Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="KNQuCigOmPfc/Li2" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --KNQuCigOmPfc/Li2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Mar 25, 2023 at 11:01:33AM -0600, Markus Pilman wrote: > Now the problem is that I need to find a TCP port for each running postgres > instance. There's multiple ways to do this, but by far the easiest one I > know is to bind to port 0. So my plan was to start postgres with "-p 0" and > then parse stdout to figure out which port it actually uses. But that > doesn't seem to work: Note that you can find some inspiration about that in the code tree within src/test/perl/PostgreSQL/Test/Cluster.pm, particularly get_free_port(), where we have now accumulated a couple of years of experience in designing something that's rather safe, even if it comes with its own limits. It is in perl so perhaps you could just reuse it rather than reinvent the wheel? Of course, still it should not be complicated to translate that in a different language, but there may be no need to reinvent the wheel. And seeing your first message with the requirements you list, this does what you are looking for: - Create an empty cluster. - Freely create databases, tablespaces, queries, etc. - Wipe out the whole. The test cases around src/test/recovery/t/ could be a good starting point, as well. -- Michael --KNQuCigOmPfc/Li2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmQg8Q4ACgkQnvQgOdby QH1PHg/9FbUK5PArEpQLQWWiyERaX3BKxuM9cZUtsdXrgtZ8ssPfZ6AwGigkSh4K gx3zRX7kQbT1bR+hLi00PQKE3JbR2McB9E7dexTPHxZHnMLu6bDCMVHFwMeCWlFK zTOzByYSXgjRp6Nb8enIExiL0tdLYlbMx4U15I2nt8nasS1yZLpu6z5lEIJD3sxG y3yL+o/S0eSL+upLi4Sm3Yd59eZFw/sLMBVHFsSoNPNUGyQ2nDob38kv4zcNaSGB kSyuLpEEaF51pf61kGc9Mg1BALQ/iSSM4w+DUI1L9GuVJ22zIvfWGSjfp6c2I7Qw oyC/4Jx5UGKXn6X8vEftYqONt7vK4RymOboGL8DcobgqaVPeghnqrU6c+4HGY++N BEL5yrvDVFrzIMdQmVAL9qFQu/9gA+tifo6cmOZmWp3ThLkTbqmaLwfHuPpOGypk 8h0+b7KHmrTJDf68SHzvthSQF2cKyfeyc72W09t48HMlkF/LVJj1H+nh1VbwzolS 5cSQg1bCMdaK6pOy01ELLcK3FFnxzcV7Tes+5ZVh6qE9322BjSo+wc9YxFHTVMLj apBNZ8UHqpzhalVq6djgjdjD49PvIsXWocHlBzUNOC+3bpdCh9E9coL2CqdnsMor iJoHdndvktxjyXW08kLcqfZIwgUvAGMSSP9Whn1CZawX8BgFcqU= =54Zv -----END PGP SIGNATURE----- --KNQuCigOmPfc/Li2--