Proposal: manipulating pg_control file from Perl

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Proposal: manipulating pg_control file from Perl
Date: 2025-03-13 20:22:21
Message-ID: CAJ7c6TO-raiYH5S_7LeP=i1_RjjWT7ntjjmJtgQsNiRvdb7L2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Previously it was pointed out [1] that manipulating the pg_control
file from Cluster.pm may be beneficial under certain conditions.

As an example, one can downgrade the catalog version in pg_control,
place input files for pg_upgrade, execute pg_upgrade and check the
results. This would allow writing TAP-tests for pg_upgrade easily, in
some cases at least. Perhaps there are other scenarios.

Unfortunately this can't be done at the moment. One of the reasons is
that the ControlFileData structure stores platform-dependent types
like `int`. The size of the structure and all the offsets within it
are variable. The second reason is that integer representation may be
little- or big-endian depending on the platform. The third reason is
that the alignment of the fields may differ even if we switch to types
of the known size like int32 / int64.

For named reasons, manipulating pg_upgrade from Perl is impractical,
considering the number of environments we support.

I see two possible solutions:

1) Provide a tool written in C that allows changing pg_control, e.g.
`pg_writecontoldata` or maybe a flat like `pg_controldata -w`. The
tool can be executed from Perl, so it shouldn't know about
sizeof(int), alignment and endiness.

2) Change the format of pg_control to platform-independent,
semi-textual perhaps. The reason why it should be semi- is that we
should store the checksum of the file and I think it should have a
fixed offset. For instance:

```
# This is auto-generated file, don't edit!
checksum=AABBCCDD
pg_conrol_version=1800
cat_version=202503131
... etc ...
```

In case (2) we may consider getting rid of the pg_controldata tool.

Thoughts?

[1]: https://www.postgresql.org/message-id/ZzVOTc3ZgPWfEQut%40paquier.xyz

--
Best regards,
Aleksander Alekseev

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2025-03-13 20:34:12 Re: BitmapHeapScan streaming read user and prelim refactoring
Previous Message Jacob Champion 2025-03-13 19:54:46 Re: dblink: Add SCRAM pass-through authentication