Proposal: new file format for hba/ident/hosts configuration?

Поиск
Список
Период
Сортировка
Искать

Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Вложения:
Hello hackers,

Currently the hba/ident/hosts configuration files follow similar, but
subtly different, whitespace-separated formats. While this works,
there are several problems with it:

1. it is a PostgreSQL-specific format, without commonly available parsers.
2. extensibility is limited, which becomes clearly visible in multiple
discussions/patch proposals. Two recent examples are:
  2.1. the OAuth validators and hba[1]: validators often require extra
fields, and while they can add GUCs, those are global. In a
multi-tenant application, different hba lines might require different
validator configuration. To properly support this use case, validators
have to be able to extend the options in pg_hba.
  2.2. a recent discussion about adding alternative SSL keys, which
also requires an extension of pg_hosts[2], and that's tricky to do in
a readable way.
3. we can include other files in them, or we can load options from
separate files for hba, but we can't go the other direction: keeping
everything (hba, ident, hosts) together in a single file.
4. while they look the same, hba is order-sensitive, ident is
order-independent in semantics (today's parser happens to walk
top-down), and the new pg_hosts is explicitly unordered.

I'd like to improve the above points by introducing a new
configuration format, while also keeping the current format for
backward compatibility. Backward compatibility would be limited to
currently available features, as in the future, we can't guarantee
that we can fit every new feature into the old formats in an
easy-to-understand way. I would even say that we should implement new
functionality only in the new formats.

Is this a good idea in general? What does everyone think about the
current configuration style? Is it good enough, or should we try to
change it?

Moving on to more specific design questions, let's focus on the first point:

Common, non-vendor-specific configuration formats are INI, XML, JSON,
YAML, and TOML.

INI/conf is way too simple, and also not really a single standard, as
there are many different implementations. XML isn't that popular
anymore.

That leaves JSON/YAML/TOML. These all share one new requirement
compared to the current PostgreSQL config infrastructure, valid UTF-8,
but I don't think that could cause any practical problems.

YAML is complex, and has many unintuitive features. While it is quite
common, I don't think we would want to include a full YAML parser in
PostgreSQL, or try to write our own. We could try a limited YAML
format, dropping some complex/unsafe features, but that would be as
unintuitive as the current configuration formats, and could result in
compatibility issues with existing YAML tooling.

My initial choice for prototyping was JSON, and I ended up creating a
few prototypes for pg_hba with it. At first I liked it, but the more I
worked with it, the more I felt the JSON boilerplate hurt readability.
It's still a fine machine format, but I don't think it's a win for
humans editing config files by hand. Its obvious advantage is that we
already have a JSON parser in the code, and we could extend that to
handle the more human-friendly JSONC/JSON5 variants.

During pgconf.dev several people mentioned TOML when I talked about
the idea. Initially I dismissed it for mostly the same reason as
INI/conf, as I thought it was too simple. But when I decided to try
it, I actually liked it more than my JSON tests. It has a precise
specification and many libraries, so it is both easy to parse and
read.

I'd like to focus on this now, on what a specific TOML configuration
could look like. (I am not saying it has to be TOML, it is just the
best option I've found so far, but if you have a better suggestion,
please share!)

I also attached a discussion-starter patchset that implements the
described format for pg_hosts. As PostgreSQL doesn't currently include
a TOML parser, it uses a vendored tomlc17 parser[3], not necessarily
the final approach, but the easiest way to build a PoC that showcases
the concept, since tomlc17 isn't packaged for most of our supported
platforms. I also have similar patches for the other configuration
files, but I'm intentionally including only one of them for
simplicity.

1. pg_ident

Ident contains multiple maps, which map external usernames to internal
usernames, possibly with regexes. Matching works on both fields, as we
are looking for specific pairs. Currently ident parsing is ordered,
but this is an implementation detail, not a functional requirement: we
are only interested in whether a pair is present. If it is matched by
multiple lines, it doesn't matter which line we select, as it's not
user-visible, other than a log entry.

Based on that, I think we can configure it simply in the following way:

[ident]
map1name = {
    "sysuser1" = "ppuser1",
    '/^(.*)@mydomain\.com$' = '\1',
}
map2name = {
    "sysuser1" = "ppuser1",
    "sysuser2" = "ppuser2",
}

This removes the ordering, since TOML tables are unordered, but it is
simple, using the system username as a key and the PostgreSQL username
as the value.

In its current form, it is not extensible. I don't think we have to be
concerned about that too much for ident, but if we ever need to allow
additional values per mapping, we can always optionally allow the
value to be a table like:

        "sysuser1" = { username = "ppuser1", other_param = "value",
foo = "bar" },

I also put everything under the "[ident]" table, which helps with the
"possibly keeping everything in a single file" point.

I also want to point out that in the above example map1name / map2name
are inline tables, and if somebody prefers, this can also be written
in the following way, which has the same meaning:

[ident.map1name]
sysuser1 = "ppuser1"
'/^(.*)@mydomain\.com$' = '\1'

[ident.map2name]
"sysuser1" = "ppuser1"
"sysuser2" = "ppuser2"

2. pg_hosts

Hosts is explicitly unordered. It contains hostnames, and every
hostname has associated fields (certificate, key, ca, passphrase
command, reload), which perfectly fits the "extensibility" version of
ident I sketched above. Compared to ident it is only a single map, so
we can store entries directly under the "[hosts]" table.

We can either write:

[hosts]
"hostname1" = { ca = "...", key = "...", passphrase_command = "..." }
"hostname2" = { ca = "...", key = "...", passphrase_command = "..." }

Or again we can write this as:

[hosts.hostname1]
ca = "..."
key = "..."
passphrase_command = "..."

[hosts.hostname2]
ca = "..."
key = "..."
passphrase_command = "..."

This format also clearly gives us extensibility. This is currently
limited to SNI support, but "hosts" is a generic name, in case we ever
want to add more properties.

One idea worth considering is a "_defaults" (or similar)
pseudo-hostname. For example, if all hostnames share the same CA, it
saves repeating that everywhere.

3. pg_hba

This is by far the trickiest format of the three, mainly because of
the options list at the end. Fortunately, we can simplify that part
with TOML, since we can treat each line as a table.

The main issue compared to the previous two is that we have to keep
pg_hba ordered, which means we have to use an array for the lines.

We also need some kind of support for defaults, similar to what I
proposed for hosts, or something even more powerful, to somewhat
replicate and improve what the hba configuration can already do with
the @include syntax.

[hba]
    _defaults = { host = "localhost", ssl = "required", transport = "tcp" }
    remote = { host = ["*"] }

[[hba.rules]]
    based_on = "remote" # or alternatively, can be an array to include
multiple: [ "remote", "another" ]
    user = "foo"
    auth_method = "oauth"
    issuer = "..."
    # ...

[[hba.rules]]
# next rule

In the above example I already used the special TOML syntax for arrays
of tables, but of course doing this completely inline is also
possible.

The idea here is that we can specify absolute defaults using the
"_defaults" as before (using _ for consistency with hosts), and also
include other tables to provide more base settings for a specific
rule, using a special based_on property. The value(s) for based_on
reference tables inside hba, e.g. including "foo" means including
"hba.foo".

With based_on, we can also cover part of what the @include syntax does
today: for example, we can define a database array in a separate table
and reference it from a rule. Based on what I've explained so far,
though, this only works within the same file.

What's missing from the above specification is including external
files: TOML has no official support for this, and the generic
suggestion in multiple discussions about it is to "roll your own
extension". This is common for most standard configuration file
formats, which generally leave this part up to the applications.

Adding an include mechanism has the disadvantage that standard parsers
won't be able to use it. But it's an optional feature, and we could
also provide a helper script that generates a "unified" view of an
include hierarchy, which then can be used by standard TOML parsers.

As for the syntax, I think we should simply reuse the existing
include_dir / include_if_exists / include directives, as present in
postgresql.conf, with the additional requirement that we always treat
include directives as global/positional. It's a "preprocessor
directive" similar to #include in C, in that it just concatenates
files together. I think this has many advantages:

1. it keeps the syntax valid TOML, so any TOML library can parse it
(includes found in any table = treat it as global scope, also load
those files, calculate the union)
2. postgresql.conf is already close to TOML. Above I said that it
would be good if we could unify the 3 whitespace-separated
configuration files into one, but with minimal additional effort we
can do more. Since everything for ident/hosts/hba lives in additional
tables, all we have to say is that postgresql.conf only cares about
the global table and ignores everything else, and we can then store
the whole configuration in a single file.

Of course, postgresql.conf allows some syntax that isn't valid TOML,
so it isn't a drop-in subset today, but converting a postgresql.conf
to TOML wouldn't require much work. The main difference is that TOML
doesn't allow unquoted strings, so values like "replica" or "128MB"
need quotes around them.

I want to make clear that postgresql.conf is not in the scope of this
proposal. That's possible future work which I think is important to
mention, but I want to keep the focus on ident/hosts/hba.

I think the second point is especially useful for cloud/container
deployments, or for tests/examples/tutorials. I am not a DBA, so I
don't want to claim that I know all about PostgreSQL configuration,
but my understanding is that most deployments have relatively simple
configuration, where this option would help.

What do you think about this in general? About using TOML? About the
specific TOML format I suggested here?

[1]: https://www.postgresql.org/message-id/CAN4CZFM3b8u5uNNNsY6XCya257u%2BDofms3su9f11iMCxvCacag%40mail.gmail.com
[2]: https://www.postgresql.org/message-id/0cabf744-6d58-4bc4-817a-413c804cf61d%40redhat.com
[3]: https://github.com/cktan/tomlc17

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
"Tristan Partin" <tristan@partin.io>
Дата:
On Tue Jul 7, 2026 at 9:21 PM UTC, Andrew Dunstan wrote:
> On Tue, Jul 7, 2026 at 1:17 PM Tristan Partin  wrote:
>
>> On Tue Jul 7, 2026 at 12:00 PM CDT, Zsolt Parragi wrote:
>> > Hello hackers,
>> >
>> > [...]
>> >
>> > Is this a good idea in general? What does everyone think about the
>> > current configuration style? Is it good enough, or should we try to
>> > change it?
>>
>> I do not like it. I have created some VSCode extensions to help with
>> syntax highlighting, but I would enjoy deprecating those.
>>
>> > Moving on to more specific design questions, let's focus on the first
>> point:
>> >
>> > Common, non-vendor-specific configuration formats are INI, XML, JSON,
>> > YAML, and TOML.
>> >
>> > INI/conf is way too simple, and also not really a single standard, as
>> > there are many different implementations. XML isn't that popular
>> > anymore.
>>
>> Agree.
>>
>> > That leaves JSON/YAML/TOML. These all share one new requirement
>> > compared to the current PostgreSQL config infrastructure, valid UTF-8,
>> > but I don't think that could cause any practical problems.
>>
>> I think you have settled on 3 good options here. All of them support
>> JSON Schema[0], which is super useful in validating files.
>>
>> > YAML is complex, and has many unintuitive features. While it is quite
>> > common, I don't think we would want to include a full YAML parser in
>> > PostgreSQL, or try to write our own. We could try a limited YAML
>> > format, dropping some complex/unsafe features, but that would be as
>> > unintuitive as the current configuration formats, and could result in
>> > compatibility issues with existing YAML tooling.
>>
>> Completely agree.
>>
>> > My initial choice for prototyping was JSON, and I ended up creating a
>> > few prototypes for pg_hba with it. At first I liked it, but the more I
>> > worked with it, the more I felt the JSON boilerplate hurt readability.
>> > It's still a fine machine format, but I don't think it's a win for
>> > humans editing config files by hand. Its obvious advantage is that we
>> > already have a JSON parser in the code, and we could extend that to
>> > handle the more human-friendly JSONC/JSON5 variants.
>>
>> Agree.
>>
>> > During pgconf.dev several people mentioned TOML when I talked about
>> > the idea. Initially I dismissed it for mostly the same reason as
>> > INI/conf, as I thought it was too simple. But when I decided to try
>> > it, I actually liked it more than my JSON tests. It has a precise
>> > specification and many libraries, so it is both easy to parse and
>> > read.
>> >
>> > I'd like to focus on this now, on what a specific TOML configuration
>> > could look like. (I am not saying it has to be TOML, it is just the
>> > best option I've found so far, but if you have a better suggestion,
>> > please share!)
>>
>> I like TOML, and it is quite popular. Another option is KDL:
>> https://kdl.dev/. Not saying that I think it should be used; only
>> mentioning it to give other options.
>>
>> I think the best option other than TOML is JSON5.
>>
>> > [...]
>>
>> [0]: https://json-schema.org/
>>
>>
>>
> Having implemented two (!) JSON parsers for PostgreSQL, as well as recently
> a json schema validator extension [1], I have some skin in this game.
> I am really not a fan of implementing more and more little languages inside
> Postgres. Doing so will incur a non-zero maintenance burden.
>
> [1]  https://github.com/adunstan/json_schema_validate

Yes, thanks for stating that. Do you view the file format as a problem 
at all? In Zsolt's proposal, he vendored tomlc17. Do you have 
a suggestion for an alternative approach? Is depending on tomlc17 and 
not vendoring an option? Would that assuage your maintenance concerns at 
all? Do we have requirements for when Postgres can take on another 
dependency? Daniel Gustaffson brought the file format up in his 
"Serverside SNI in PostgreSQL 19"[0] talk at PGConf.dev.

One thing that hasn't been mentioned is that higher level configuration 
languages can "compile" to JSON. For instance, HCL[1] (HashiCorp 
Configuration Language) and Pkl[2] have that ability. If we settled on 
JSON, then users could use these types of languages for higher level 
writing of configs.

Additionally, I would add that maintaining our own custom format comes 
with its own challenges and warts as well. See /no_sni/, which I learned 
about at Daniel's talk.

[0]: https://2026.pgconf.dev/session/757
[1]: https://github.com/hashicorp/hcl#information-model-and-syntax
[2]: https://pkl-lang.org/

-- 
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Tue, Jul 7, 2026 at 2:21 PM Andrew Dunstan  wrote:
> I am really not a fan of implementing more and more little languages inside Postgres. Doing so will incur a non-zero maintenance burden.

Sure, but the status quo has its own self-compounding maintenance
burden, in which we'll either need to keep implementing little
languages (as with pg_hosts.conf) or else finally decide to refactor.

On Tue, Jul 7, 2026 at 10:00 AM Zsolt Parragi  wrote:
> What do you think about this in general? About using TOML? About the
> specific TOML format I suggested here?

FWIW, I was recently looking at TOML for libpqrc [1]. Of the
non-custom options you've presented, I prefer its feature set, so I
think it's at least an interesting alternative to explore. I was
especially interested in the pyproject.toml conventions, where
different parts of the ecosystem all coexist in the same configuration
space -- that might be important for letting libpq and other drivers
move in parallel.

I'd be most interested in a mockup of the "final state" you have in
mind. That'd help highlight any need for homegrown syntax. (While
postgresql.conf may be declared out-of-scope, it's hard to imagine
we'd take steps towards an alternate format without some idea of what
the central server config is going to look like in the end.)

Thanks for working on this!

--Jacob

[1] https://postgr.es/m/CAOYmi%2BmhiTPmNxy9JDKh%2BpahDxz2OoxAf%3D-jq%2BG%2BYUkHHqAGUA%40mail.gmail.com


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
I'm noticing a distinct lack of focus on what would be the benefits
to *end users* of Postgres.  I can't see proceeding with a project
like this unless there are strong benefits that would entice people
to convert their configuration files of their own accord [*].
And really I don't think any of the benefits enumerated at the top of
the thread are going to sell very many users on doing that.  It's
not their problem if we're having issues shoehorning new features
into the existing format.

			regards, tom lane

[*] If we try to force it, even by such weak means as not implementing
new features in the old format, we will have mobs of villagers with
pitchforks on our doorsteps.


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Tue, Jul 7, 2026 at 2:58 PM Tom Lane  wrote:
> It's
> not their problem if we're having issues shoehorning new features
> into the existing format.

(It is, though. Users like new features, and I have yet to meet a user
who's happy that we don't implement reasonable improvements because of
choices made pre-21st-century. The config format has gotten in the way
of recent development, and it's starting to force a bunch of
unpleasant compromises.)

--Jacob


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Вложения:
On Tue, Jul 7, 2026 at 6:17 PM Tristan Partin  wrote:
> I think the best option other than TOML is JSON5.

I agree, my first prototype before TOML was JSON5.

On Tue, Jul 7, 2026 at 10:21 PM Andrew Dunstan  wrote:
> Having implemented two (!) JSON parsers for PostgreSQL, as well as recently a json schema validator extension [1], I have some skin in this game.
> I am really not a fan of implementing more and more little languages inside Postgres. Doing so will incur a non-zero maintenance burden.

Mainly for this reason, because if we add JSON5 support to the parser
that's already in postgres, we don't have to worry about adding
another library.

I focused on TOML in my email because I think that's still a better
configuration format than JSON5. However, we could use JSON or another
format, as long as it's a well-defined, common format, it will be a
big improvement.

My initial implementation used JSON/JSON5, and I also still have that
patchset locally, which used a similar JSON structure. I only started
prototyping with TOML after the initial feedback I got during
pgconfdev that most people would prefer using that.

On Tue, Jul 7, 2026 at 10:48 PM Jacob Champion
 wrote:
> I'd be most interested in a mockup of the "final state" you have in
> mind. That'd help highlight any need for homegrown syntax. (While
> postgresql.conf may be declared out-of-scope, it's hard to imagine
> we'd take steps towards an alternate format without some idea of what
> the central server config is going to look like in the end.)

I intentionally left my initial email somewhat vague about the
details, and I didn't include the entire patchset implementing
everything for the same reason: to keep the focus on generic questions
like:

* do we agree on working towards another configuration format?
* if yes, what requirements do we have for it?
* what exact issues do we want to solve, and what to leave as non-goals?

I also understand your point, so I attached a few examples now,
assuming a full implementation, including the toml support for
postgresql.conf:

1. A very simple single file production configuration
2. A development docker image where the container has a built in
configuration and users can specify an override configuration
3. A multi-tenant setup with the traditional hba/hosts/ident split
4. The same multi-tenant setup, but here the split is per tenant
instead: one file for global configuration, and another 2 for the 2
tenants

I want to note that for these examples:

* We can replicate the same or similar structure easily in json/toml/others
* For now this format is mostly based on my preferences with some
feedback from others. I plan to talk about it to many more people and
ask for feedback, so please treat this as a conversation starter, not
a concrete suggestion
* I am unsure about using the array syntax for hba rules, but so far I
like it better than the alternative ideas I tried

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
On Tue, Jul 7, 2026 at 10:58 PM Tom Lane  wrote:

> I'm noticing a distinct lack of focus on what would be the benefits
> to *end users* of Postgres.

The biggest benefit is that postgres would support a common
configuration format that users don't have to learn. Most software
today uses either toml, json or yaml for complex configuration.
Existing installations / users is one thing, new installation / new
users is another. Instead of somebody having to learn 4 slightly
different configuration file formats specific to postgres, we could
document the format with a single sentence: "It's ", and everyone
would know what that means.

I also mentioned tooling, and Tristan also mentioned transformation
and json schema: there are many existing libraries and tools dealing
with these formats, no matter which one we choose. Editors,
validators, syntax highlighting, converters, ... If we choose toml,
people can still use json and convert it, and the same would be true
in the other direction.

And there's also readability: the issues with implementing the two
examples I mentioned aren't the only problem (one was even implemented
and committed), the main issue is the user experience.

In pg_hba, we already have a way too long "options" column at the end,
where we store most of the details about external auth providers. If
an editor doesn't add line breaks, a significant part of the
configuration is invisible without scrolling right. If it adds them,
that breaks the look of the tabulated format. If we use the @include
syntax, we move them into a separate file and again we can't see
everything in a clear way on a single screen.

The pg_hosts example is similar, I thought about 5 different ways we
could add it to pg_hosts that would technically work, so just
implementing it isn't an issue. The problem is that from a
usability/readability viewpoint I would only give maybe a 6/10 to the
best one, or even less.


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Вложения:


On Wed, Jul 8, 2026 at 11:33 AM Zsolt Parragi <zsolt.parragi@percona.com> wrote:
On Tue, Jul 7, 2026 at 6:17 PM Tristan Partin <tristan@partin.io> wrote:
> I think the best option other than TOML is JSON5.

I agree, my first prototype before TOML was JSON5.

On Tue, Jul 7, 2026 at 10:21 PM Andrew Dunstan <andrew@dunslane.net> wrote:
> Having implemented two (!) JSON parsers for PostgreSQL, as well as recently a json schema validator extension [1], I have some skin in this game.
> I am really not a fan of implementing more and more little languages inside Postgres. Doing so will incur a non-zero maintenance burden.

Mainly for this reason, because if we add JSON5 support to the parser
that's already in postgres, we don't have to worry about adding
another library.

I focused on TOML in my email because I think that's still a better
configuration format than JSON5. However, we could use JSON or another
format, as long as it's a well-defined, common format, it will be a
big improvement.



Just for kicks I asked my new best friend (<weg>) to allow for json5 on the RD parser. The actual parser changes are minimal.  Most of the changes are in the lexer. I didn't implement it for the incremental parser, and I skipped the new numeric formats.

cheers

andrew

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
> Just for kicks I asked my new best friend () to allow for json5 on the RD parser. The actual parser changes are minimal. Most of the changes are in the lexer. I didn't implement it for the incremental parser, and I skipped the new numeric formats.

I also have a patchset for that, which also includes a JSON5 SQL type.
I plan to start another thread about that, as it could be useful
independent to the configuration file changes.


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Greg Sabino Mullane <htamfids@gmail.com>
Дата:
On Wed, Jul 8, 2026 at 11:42 AM Zsolt Parragi <zsolt.parragi@percona.com> wrote:
In pg_hba, we already have a way too long "options" column at the end,
where we store most of the details about external auth providers. If
an editor doesn't add line breaks, a significant part of the
configuration is invisible without scrolling right.

But we support backslashes, so there is no need to squash everything onto a single line, e.g.

host  all  all  127.0.0.1/32  ldap \
  ldapserver=localhost \
  ldapbinddn="CN=admin,DC=testy,DC=com" \
  ldapbindpasswd="mysecretpass" \
  ldapbasedn="OU=Users,DC=testy,DC=com" \
  ldapsearchfilter="(&(uid=$username)(memberOf=CN=pg_admins,OU=Groups,DC=testy,DC=com))"


All in all, I am super wary of this whole idea. Not that pg_hba is pretty, or intuitive, but I second the motion to see what a converted one would look like. Can the proponents of format X show what our standard default pg_hba.conf would look like in the new format?

--
Cheers,
Greg

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Matthias van de Meent <boekewurm+postgres@gmail.com>
Дата:
On Tue, 7 Jul 2026 at 19:00, Zsolt Parragi  wrote:
>
> What do you think about this in general? About using TOML? About the
> specific TOML format I suggested here?

Insofar my vote counts, TOML gets a -1 from me.

The argument is twofold: We don't have any TOML support, and I'm an
anti-fan of TOML.

While it is conceptually simple to read and write key-value and nested
object data, the implementation of its nested table notation and its
array-of-tables feature makes the whole configuration language more
complicated and confusing than the "obvious" and "minimal" implied by
its name, to the point of being practically unsuitable for what it's
being used for. Allow me to explain.

The common method for defining objects is as follows:

    ...
    [path.to.the.table]
    key = value

Which one would understand is approximately equivalent to (json)

    { "path": { "to": { "the": { "table": { "key": "value" } } } } }

There's an issue though: This interpretation depends on the previous
definitions.

E.g.

    [[path.to.the]]
    ...

    [path.to.the.table]
    key = value

will be interpreted as

    { "path": { "to": { "the": [{ "table": { "key": "value" } }] } } }

So you can't rely on a consecutive snippet of the document to be
safely and correctly evaluated as a (sub)document of the whole, like
what you can in recursively defined formats like JSON or YAML
documents(*). This -to me- makes the format extremely annoying to work
with and unsuitable for anything related to configuration files, where
copying snippets is one of the most used and important methods of
inputting data.

The only recursively parsed component in TOML is the inline table (and
inline arrays) feature, which seems to map almost directly to JSON.
However, it can't be used as the top level definition (you can't have
an inline table or inline array as top-level object), and the other
structure-related parts of the language require the whole parsed
document as context to make sure the current table key name isn't
conflicting with one that was defined earlier in the document. I don't
believe that's a suitable property for configuration languages.


Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)


(*): Yes, there are some features in the YAML language that break this
rule, such as references and inclusions. I'm willfully ignoring those,
as I'm of the opinion that a YAML without those is a better YAML.


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Isaac Morland <isaac.morland@gmail.com>
Дата:
On Tue, 7 Jul 2026 at 17:48, Jacob Champion <jacob.champion@enterprisedb.com> wrote:
On Tue, Jul 7, 2026 at 2:21 PM Andrew Dunstan <andrew@dunslane.net> wrote:
> I am really not a fan of implementing more and more little languages inside Postgres. Doing so will incur a non-zero maintenance burden.

Sure, but the status quo has its own self-compounding maintenance
burden, in which we'll either need to keep implementing little
languages (as with pg_hosts.conf) or else finally decide to refactor

I've had a few thoughts about this. I tend to lean towards JSON, in part because we already have it within Postgres. But the following applies to whatever syntax is adopted.

Rather than having specific config files for different topics, which makes sense if each is pretty close to just being essentially a database table with rows and columns rather than a nested structure, could we have a single config file that does everything?

Have a way to import other files, so if people want to break out their HBA definitions, for example, they could. So one could at one extreme have everything in one file, and at the other extreme the existing separate files could be broken out and each of those then broken up into many files concerning different parts of the configuration.

To deal with compatibility with the existing config files, have specialized include directives that mean things like "import legacy X data from file F", by contrast with the normal include directives which would expect the files to be in the new format.

Then all that is needed to keep using the existing files is to have a skeleton new-format file that essentially says "import legacy HBA from pg_hba.conf", "import legacy user name mappings from pg_ident.conf" and "import legacy GUC from postgresql.conf".

Freeze the parsing of old-style files; new features and changes go only in the new format. This should eliminate (well, almost eliminate) the maintenance burden associated with having two file formats.

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:


Freeze the parsing of old-style files; new features and changes go only in the new format. This should eliminate (well, almost eliminate) the maintenance burden associated with having two file formats.

That's the scenario Tom warned against upthread.

cheers

andrew 

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Thu, Jul 9, 2026 at 2:19 PM Andrew Dunstan  wrote:
>> Freeze the parsing of old-style files; new features and changes go only in the new format. This should eliminate (well, almost eliminate) the maintenance burden associated with having two file formats.
>
> That's the scenario Tom warned against upthread.

But if, hypothetically, a new format were indeed a big improvement for
people, it's probably what we should do.

--Jacob


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Jul 8, 2026 at 8:33 AM Zsolt Parragi  wrote:
> I focused on TOML in my email because I think that's still a better
> configuration format than JSON5.

(I agree)

> * do we agree on working towards another configuration format?
> * if yes, what requirements do we have for it?
> * what exact issues do we want to solve, and what to leave as non-goals?

Adding small pieces to this pile: I'm primarily motivated by authn/z,
and I'd like to be able to more intuitively attach parameters to
certain connection contexts. This is something that neither a flat
configuration, nor separated tabular configurations, have really
helped us with.

"Connections using SCRAM authentication should time out in X seconds
instead of the default." Or "this group of users should use the
following list of GUCs." The sample I used in [1] a long time ago was

    Everyone has to use LDAP auth
    With this server
    And these TLS settings

    Except admins
        who additionally need client certificates
        with this CA root

    And Jacob
        who isn't allowed in anymore

We don't handle these (perfectly reasonable IMO) cases very well, or
sometimes at all. I'm primarily used to servers in the web space
(httpd, nginx, caddy, haproxy) when it comes to this configuration
style, which I think I called "contexts with property bags" in that
other thread.

> * I am unsure about using the array syntax for hba rules, but so far I
> like it better than the alternative ideas I tried

FWIW I find that part of it pretty hard to read and understand, though
that should not in any way spike the general concept into the ground.

Thanks!
--Jacob

[1] https://postgr.es/m/0e0c038ab962c3f6dab00934fe5ae1ae115f44c0.camel%40vmware.com


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Вложения:
> I've had a few thoughts about this. I tend to lean towards JSON, in part
> because we already have it within Postgres. But the following applies to
> whatever syntax is adopted.

As most answers seem to prefer json(5), I attached json5 versions of
my previous toml mockups. The structure is the same, I only changed
the representation of the include directives a bit.

> Rather than having specific config files for different topics, which makes
> sense if each is pretty close to just being essentially a database table
> with rows and columns rather than a nested structure, could we have a
> single config file that does everything?

That's part of my proposal, see 01 or 02. But in my initial email
specified this as a long-term goal, I think it is also a valid option
to rework only hba/hosts/ident and leave postgresql.conf and complete
unification as a next step.

We could also do a non-traditional split, that's my 04 example:
instead of postgresql-hba-ident-hosts, we have
postgresql-tenant1-tenant2.

With toml, including an entire file into a specific table is a tricky
and possibly confusing, so in that mockup/prototype, I defined include
as global-only.
There's a special include table, and all files mentioned there are
globally merged together with the main file. But other than this
limitation, includes are recursive.

This can possible be more generic in json if we want to allow it, as
that has a more visible nested structure.
In that prototype, I used the following logic:

* Every json5 file has to be an object at the top level
* { foo: { include: "bar.json5", "x": "y" } } means that we load
bar.json5 and merge it with the "foo" object.

I didn't use this in the mockups, but I think it is more intuitive in
json than in toml.


> Then all that is needed to keep using the existing files is to have a
> skeleton new-format file that essentially says "import legacy HBA from
> pg_hba.conf", "import legacy user name mappings from pg_ident.conf" and
> "import legacy GUC from postgresql.conf".

That is certainly an interesting idea, I like that it would make the
new format more visible, as a new style file would be always there. On
the other hand I worry that it wouldn't be this easy, unless the new
format is a trivial 1-1 mapping of the old files with a different
syntax, like my current mockups. And in that case, it can restrict us
how we can modify the new format while the old option still available.

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
> "Connections using SCRAM authentication should time out in X seconds
> instead of the default." Or "this group of users should use the
> following list of GUCs." The sample I used in [1] a long time ago was
>
>     Everyone has to use LDAP auth
>     With this server
>     And these TLS settings
>
>     Except admins
>         who additionally need client certificates
>         with this CA root
>
>     And Jacob
>         who isn't allowed in anymore

The first 2 options would fit easily into my mockups, as if I parse
that correctly, that is tied to our HBA GUC discussion I linked in
earlier messages.

About the second part of it, and the issue with arrays, I agree that I
could imagine a better way of configuring things than mapping current
pg_hba 1:1 to a different file format. But I also didn't want to
propose changing too many things at once. If we already have HBA
information stored in generic structured file format such as
JSON/TOML, then refactoring/extending it seems easier to me than doing
everything in one step.

If we do everything in one step, it will be a really ambitious big
patch, touching many different parts of postgres.

Another option would be first refactoring the authentication logic
internally, leaving the user interface (configuration) limited to
what's currently available with pg_hba, so that the new configuration
file only has to make the new features available instead of
implementing from scratch. But that seems like doing things backwards
to me.


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:


On Thu, Jul 9, 2026 at 5:43 PM Jacob Champion <jacob.champion@enterprisedb.com> wrote:
On Thu, Jul 9, 2026 at 2:19 PM Andrew Dunstan <andrew@dunslane.net> wrote:
>> Freeze the parsing of old-style files; new features and changes go only in the new format. This should eliminate (well, almost eliminate) the maintenance burden associated with having two file formats.
>
> That's the scenario Tom warned against upthread.

But if, hypothetically, a new format were indeed a big improvement for
people, it's probably what we should do.




I think the bar is going to be fairly high.  And just jumping to a new format is going to create a world of pain for users. We'd need to carry the old format for a while as well, I think, and also provide some conversion tools.

I do agree that sometimes the formats can make expressiveness very clumsy. A recent example is the log_min_messages work. 

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 11 Jul 2026, at 14:43, Andrew Dunstan  wrote:

> just jumping to a new format is going to create a world of pain for users. We'd need to carry the old format for a while as well, I think,

Agreed, I don't think anyone is suggesting we migrate formats in a release.
Making sure that existing configurations continue to work, either as
one-or-the-other or with a new config as additive to the old, until converted
will be very important.

> and also provide some conversion tools.

+1

> I do agree that sometimes the formats can make expressiveness very clumsy.

+1

--
Daniel Gustafsson



Re: Proposal: new file format for hba/ident/hosts configuration?

От:
"Tristan Partin" <tristan@partin.io>
Дата:
On Thu Jul 9, 2026 at 12:16 PM UTC, Andrew Dunstan wrote:
> On Wed, Jul 8, 2026 at 11:33 AM Zsolt Parragi 
> wrote:
>
>> On Tue, Jul 7, 2026 at 6:17 PM Tristan Partin  wrote:
>> > I think the best option other than TOML is JSON5.
>>
>> I agree, my first prototype before TOML was JSON5.
>>
>> On Tue, Jul 7, 2026 at 10:21 PM Andrew Dunstan 
>> wrote:
>> > Having implemented two (!) JSON parsers for PostgreSQL, as well as
>> recently a json schema validator extension [1], I have some skin in this
>> game.
>> > I am really not a fan of implementing more and more little languages
>> inside Postgres. Doing so will incur a non-zero maintenance burden.
>>
>> Mainly for this reason, because if we add JSON5 support to the parser
>> that's already in postgres, we don't have to worry about adding
>> another library.
>>
>> I focused on TOML in my email because I think that's still a better
>> configuration format than JSON5. However, we could use JSON or another
>> format, as long as it's a well-defined, common format, it will be a
>> big improvement.
>>
>>
>>
> Just for kicks I asked my new best friend () to allow for json5 on the
> RD parser. The actual parser changes are minimal.  Most of the changes are
> in the lexer. I didn't implement it for the incremental parser, and I
> skipped the new numeric formats.

What are your thoughts on first starting with support for JSONC? It has 
no implications other than comments (single-line and multi-line) and 
trailing commas. We could collaborate and commit that, and then 
subsequently work on JSON5 support. It should enable the JSON5 support 
patches to be even smaller than what you posted already.

I am basically done with a JSONC patch that has support for both the 
recursive-descent parser and the incremental parser. I need to polish it 
up a bit before I send it, and it builds on top of some of my other work 
refactoring json_lex()[0].

Do we want to support JSONC/JSON5 in the incremental parser? My 
inclination is yes so the parsers are consistent in what they support.

[0]: https://www.postgresql.org/message-id/DJXSBQVKCQU2.SIQVXEH2P0AM@partin.io

-- 
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
> What are your thoughts on first starting with support for JSONC? It has
> no implications other than comments (single-line and multi-line) and
> trailing commas. We could collaborate and commit that, and then
> subsequently work on JSON5 support. It should enable the JSON5 support
> patches to be even smaller than what you posted already.

I also sent my patchset[1] for JSONC/JSON5. I wanted to organize it
into smaller patches and stress test it before sharing, but I think
it's in a good enough shape now.
My logic was similar: the first patch in the series is the JSONC
support, as that's a feature usable on its own.

> Do we want to support JSONC/JSON5 in the incremental parser? My
> inclination is yes so the parsers are consistent in what they support.

I included it for completeness, but the incremental parser has no real
user other than the tests, and it's complex. A patch without that
would be significantly smaller. Most (nearly all) of the corner case
issues I identified while testing the patch were also in that.

[1]: https://www.postgresql.org/message-id/CAN4CZFP5dvO4sij414YYG%2B4Hghf3M5m2oPiyR_vNgRj3vhQ_0Q%40mail.gmail.com


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
"Tristan Partin" <tristan@partin.io>
Дата:
On Tue Jul 14, 2026 at 11:18 PM UTC, Zsolt Parragi wrote:
>> What are your thoughts on first starting with support for JSONC? It has
>> no implications other than comments (single-line and multi-line) and
>> trailing commas. We could collaborate and commit that, and then
>> subsequently work on JSON5 support. It should enable the JSON5 support
>> patches to be even smaller than what you posted already.
>
> I also sent my patchset[1] for JSONC/JSON5. I wanted to organize it
> into smaller patches and stress test it before sharing, but I think
> it's in a good enough shape now.
> My logic was similar: the first patch in the series is the JSONC
> support, as that's a feature usable on its own.

Awesome. I will review and see how they compare against my changes!

>> Do we want to support JSONC/JSON5 in the incremental parser? My
>> inclination is yes so the parsers are consistent in what they support.
>
> I included it for completeness, but the incremental parser has no real
> user other than the tests, and it's complex. A patch without that
> would be significantly smaller. Most (nearly all) of the corner case
> issues I identified while testing the patch were also in that.

I was able to get a patch for the incremental parser to support comments 
in:

	1 file changed, 272 insertions(+), 41 deletions(-)

A patch to the incremental parser to support trailing commas is even 
smaller:

	1 file changed, 87 insertions(+), 1 deletions(-)

These stats don't include the additional tests.

> [1]: https://www.postgresql.org/message-id/CAN4CZFP5dvO4sij414YYG%2B4Hghf3M5m2oPiyR_vNgRj3vhQ_0Q%40mail.gmail.com

-- 
Tristan Partin
PostgreSQL Contributors Team
AWS (https://aws.amazon.com)


Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Andrew Dunstan <andrew@dunslane.net>
Дата:


On Tue, Jul 14, 2026 at 7:27 PM Tristan Partin <tristan@partin.io> wrote:
On Tue Jul 14, 2026 at 11:18 PM UTC, Zsolt Parragi wrote:
>> What are your thoughts on first starting with support for JSONC? It has
>> no implications other than comments (single-line and multi-line) and
>> trailing commas. We could collaborate and commit that, and then
>> subsequently work on JSON5 support. It should enable the JSON5 support
>> patches to be even smaller than what you posted already.
>
> I also sent my patchset[1] for JSONC/JSON5. I wanted to organize it
> into smaller patches and stress test it before sharing, but I think
> it's in a good enough shape now.
> My logic was similar: the first patch in the series is the JSONC
> support, as that's a feature usable on its own.

Awesome. I will review and see how they compare against my changes!

>> Do we want to support JSONC/JSON5 in the incremental parser? My
>> inclination is yes so the parsers are consistent in what they support.
>
> I included it for completeness, but the incremental parser has no real
> user other than the tests, and it's complex. A patch without that
> would be significantly smaller. Most (nearly all) of the corner case
> issues I identified while testing the patch were also in that.

I was able to get a patch for the incremental parser to support comments
in:

        1 file changed, 272 insertions(+), 41 deletions(-)

A patch to the incremental parser to support trailing commas is even
smaller:

        1 file changed, 87 insertions(+), 1 deletions(-)

These stats don't include the additional tests.

> [1]: https://www.postgresql.org/message-id/CAN4CZFP5dvO4sij414YYG%2B4Hghf3M5m2oPiyR_vNgRj3vhQ_0Q%40mail.gmail.com




I'm inclined not to support the incremental parser. From a pure grammar POV it would be doable - you would just need a new parsing table. But I suspect the added complexity for the lexer would be considerable.  It's already fairly complex, so that bothers me. Also, what's the use case? The point of the incremental parser is to support handling huge documents like backup manifests. But that's not the use case for JSON5. At least for a first go round I would stick with supporting the RD parser only. Then you can ignore things like partial tokens,

It might be worth talking about the data representation of a JSON5 datum. One of my first experiments with claude code was the creation of an extension to support YAML. See <https://github.com/adunstan/pgyaml>. One possibly controversial decision I made was to store the YAML in two formats - original text plus the data as jsonb. That costs you some in storage but makes up for it in allowing you to use the equivalent of jsonb ops, and jsonpath on the data efficiently while being able to get back the original text as well. This could be reasonable for  small documents such as configuration settings, which is the main use case I see for YAML (and JSON5). (It also provides methods you convert the YAML to pure jsonb) 

cheers

andrew

Re: Proposal: new file format for hba/ident/hosts configuration?

От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Вложения:
Hello

I reworked the prototype based on the feedback in this thread, and
attached a new patchset implementing it.
The patches are marked as POC on purpose: they are complete enough to
try out (docs, tests, initdb support), but they are definitely not
ready for proper code review yet.

I'm still mainly looking for feedback on the idea and the format,
before spending more time on a proper implementation.

The main changes since my last emails:

1. It is JSON now, not TOML.

Most answers preferred json(5), mainly because we already have a
parser for it. So this version uses the existing src/common JSON
parser, without any new dependency.

The patchset only accepts strict JSON for now. I sent my JSON5 patches
to a separate thread[1], and if that gets accepted, accepting JSON5
here (comments, trailing commas, unquoted keys, ...) is a parser flag.

The current examples are noisier than they would be with JSON5, and
there is no way to write comments, which is a real limitation for a
configuration file.

The JSON5 patchset is ready for review, so if somebody has time and is
interested in it, please check it out.

2. hba is a tree, not a flat array of rules.

Jacob found the array of rules hard to read, and asked for "contexts
with property bags", like web servers do. So instead of a 1:1 mapping
of pg_hba.conf with _defaults and based_on, an hba node now narrows
the match of its parent, and carries authentication options and
settings that its children inherit (integrating my previous thread
about custom OAuth validator options[2]).

Children are tried before their parent, so the most specific node
wins, and a flat pg_hba.conf is simply a tree of depth one.

Jacob's example from upthread looks like this:

"hba": {"children": [
  {"auth": {"method": "ldap", "ldapserver": "ldap.example.com", "ldaptls": 1},
   "children": [
     {"users": "+admins", "auth": {"clientcert": "verify-full"}},
     {"users": "jacob", "auth": {"method": "reject"}}
   ]}
]}

Greg asked how the default pg_hba.conf would look, that is:

"hba": {"children": [
  {"transport": "local", "auth": {"method": "trust"}},
  {"address": ["127.0.0.1/32", "::1/128"], "auth": {"method": "trust"}},
  {"databases": "replication", "children": [
    {"transport": "local", "auth": {"method": "trust"}},
    {"address": ["127.0.0.1/32", "::1/128"], "auth": {"method": "trust"}}
  ]}
]}

Narrowing is a convention, not enforced: a child can name users or
addresses outside of its parent's. I'm not sure if this is acceptable,
or if this makes the tree misleading.

3. Per-rule and per-host settings.

This is the "this group of users should use the following GUCs" part,
connected to the hba GUC discussion[2]. hba nodes and hosts entries
can have a "settings" object, applied when they match. For this the
patch adds 2 new GUC contexts, PGC_HOSTS and PGC_HBA, between SIGHUP
and SU_BACKEND. Currently only authentication_timeout is moved into
PGC_HBA, so it can differ per authentication method. Everything later
than PGC_HBA (e.g. work_mem, statement_timeout) can be set per rule
already.

4. The "final state", including postgresql.conf.

Jacob asked for a mockup of the whole thing, so this is a "complete"
patchset, and the last patches add a postgresql.json root file: GUCs
at the top level, and "hba", "ident" and "hosts" sections in the same
document, with "include" for splitting it into multiple files. initdb
--config-format=json creates a cluster with it.

I also attached a larger example with all of the above
(example-postgresql.json). With the patchset applied and the paths
adjusted, it works as a complete configuration.

Everything is still completely opt-in in the PoC patch, legacy
configurations continue working the same way.

Things I left out, and know about:

* A conversion tool. Andrew and Daniel both said that we need one. I
considered adding one to this PoC patchset, but decided to leave it
out for now.
* JSON strings are used as bytes, as in postgresql.conf, so non-ASCII
values have the same encoding issues as today.

Main open questions:

* What is the exact scope? The attached patchset is a mostly complete
PoC to show the vision, but as I wrote earlier in this thread, I am
not sure that all this should be done in one step.
* What does everyone think about this format proposal, compared to the
versions I sent earlier?
* Does anybody have different ideas/suggestions?

[1]: https://www.postgresql.org/message-id/CAN4CZFMmapQG7yJZwjxKhZ%3DzjzDrEK2GYCg%3DFo2_47UYCrkUPA%40mail.gmail.com
[2]: https://www.postgresql.org/message-id/CAN4CZFM3b8u5uNNNsY6XCya257u%2BDofms3su9f11iMCxvCacag%40mail.gmail.com
FAQ