Re: Binding Postgres to port 0 for testing

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Binding Postgres to port 0 for testing
Дата
Msg-id ZCDxDqcuaK0FODCs@paquier.xyz
обсуждение исходный текст
Ответ на Binding Postgres to port 0 for testing  (Markus Pilman <markus@pilman.ch>)
Ответы Re: Binding Postgres to port 0 for testing  (Markus Pilman <markus@pilman.ch>)
Список pgsql-general
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

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Bryn Llewellyn
Дата:
Сообщение: Re: Is the PL/pgSQL refcursor useful in a modern three-tier app?
Следующее
От: Markus Pilman
Дата:
Сообщение: Re: Binding Postgres to port 0 for testing