From: Michael Paquier <michael@paquier.xyz>
To: Markus Pilman <markus@pilman.ch>
Cc: pgsql-general@postgresql.org
Subject: Re: Binding Postgres to port 0 for testing
Date: Mon, 27 Mar 2023 10:27:42 +0900
Message-ID: <ZCDxDqcuaK0FODCs@paquier.xyz> (raw)
In-Reply-To: <CALavoowMtHgaX_pVhtkVuynYcjM8k7cF4DxxLzcp7ih7JEoRAw@mail.gmail.com>
References: <CALavoowMtHgaX_pVhtkVuynYcjM8k7cF4DxxLzcp7ih7JEoRAw@mail.gmail.com>
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
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: michael@paquier.xyz, markus@pilman.ch
Subject: Re: Binding Postgres to port 0 for testing
In-Reply-To: <ZCDxDqcuaK0FODCs@paquier.xyz>
References: <CALavoowMtHgaX_pVhtkVuynYcjM8k7cF4DxxLzcp7ih7JEoRAw@mail.gmail.com> <ZCDxDqcuaK0FODCs@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox