zalando / zalando/postgres-operator

Configurable database name regexp

Open
#667 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement felix-wishlist
Dominant language
Go
Stars
5.2k
Forks
1.1k
Avg merge
2d 16h
Merged PRs (30d)
3

Description

databaseNameRegexp = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
postgres-operator/pkg/cluster/cluster.go
Is there some kind of reason why this regex looks as it is?

The pattern seems to follow this from the documentation (not to the dot):

SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). Note that dollar signs are not allowed in identifiers according to the letter of the SQL standard, so their use might render applications less portable. The SQL standard will not define a key word that contains digits or starts or ends with an underscore, so identifiers of this form are safe against possible conflict with future extensions of the standard.

But as long as the name is quoted in SQL statement, we should be able to put whatever we like with the exception of \0.
I have this issue that I have to migrate postgres to k8s, but all our databases are named in the following fashion: [a-z]+-[a-z]+.

I'm not very familiar with the operator's code, but if quoted identifiers are used everywhere, then I don't see any reason why the regex shouldn't be expanded.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in postgres-operator/pkg/cluster/cluster.go at databaseNameRegexp and trace every place the validation is used. Verify how database names are quoted in the operator and compare that behavior with PostgreSQL identifier rules. Done means the supported naming behavior is clearly defined and validated without breaking existing database-name handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.