Repository navigation
Description
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
- I have read the troubleshooting guide and I think this is a new bug.
Contact Details
Version
1.26 (latest patch)
What version of Kubernetes are you using?
1.33
What is your Kubernetes environment?
Self-managed: kind (evaluation)
How did you install the operator?
YAML manifest
What happened?
Investigating #7447 , the issue opened by @smiyc , I agree with his assessment that it is a bug,
and moreover I find the mis-behavior bigger than just that bug.
In this description I discuss the problem, compare with microservice approach, and propose the fix.
Section headings to hopefully aid navigation.
monolith import may take in N source databases and create N + 1, or alter the "app" database owner
To recap from #7447 , when using monolith import, a (database, owner) of ("app", "xxx") results in an imported database of ("app", "app"), whereas a (database, owner) of ("foo", "xxx") is imported, as expected, as ("foo", "xxx").
Now, in the second case, the monolith import doesn't create only ("foo", "xxx"), but adds the default ("app", "app") too.
Doing a kubectl get -o yaml of the running cluster reveals:
spec:
<snipped>
bootstrap:
initdb:
database: app
import:
databases:
- foo
roles:
- xxx
source:
externalCluster: cluster-other
type: monolith
owner: appIn the documentation for the monolith import (https://cloudnative-pg.io/documentation/current/database_import/#the-monolith-type), the expectation is that N .initdb.import.databases will result in N databases in the created cluster.
This example shows this is not the case.
The cause is the defaulting webhook, which will create the default (database, user) if there are no initdb.database and initdb.owner specified.
comparison with microservice
The defaulting webhook behavior makes sense for the microservice approach.
There, a single DB from the source cluster is chosen to be imported, and in the target cluster will result in ("app", "app") by default, unless the user specifies a (database, owner).
For monolith this does not make sense. Firstly, monolith is more useful for N databases to import rather than just one.
And in addition, the monolith approach seems tailor made for copying from the source cluster as faithfully as possible.
proposal
The right fix, in my view, is that the defaulting webhook should not pre-populate the database/owner, if there is a monolith import specified.
Alternatives considered:
Force the user of monolith imports to specify explicitly which of the imported databases is "default" via the initdb.database and initdb.owner.
Also, the documentation needs some updating. And ... we don't have a sample file for monolith import, which shows that it's been taken less seriously than microservice.
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example-new-monolith
spec:
instances: 1
storage:
size: 1Gi
bootstrap:
initdb:
import:
type: monolith
databases:
- foo
roles:
- xxx
source:
externalCluster: cluster-example
externalClusters:
- name: cluster-example
connectionParameters:
host: cluster-example-rw
dbname: postgresRelevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dosubot commentedon Jun 5, 2025
Hi @jsilvela! I'm Dosu and I’m helping the cloudnative-pg team.
You are correct—there are no existing issues or discussions about this bug. The current implementation of the defaulting webhook sets the default database and owner to "app" if they are not specified, regardless of whether a monolith import is being used. This leads to the unintended creation of an extra default database when using monolith imports, which is not the expected behavior according to the documentation and typical use case for monolith imports (source).
Your proposal to change the defaulting webhook so it does not pre-populate the database/owner fields when a monolith import is specified is reasonable and aligns with the documented intent of the monolith import process (source). The documentation also does not mention any defaulting behavior for these fields in the context of monolith imports, which supports your suggestion for both a code and documentation update.
Let me know if you want more details on the relevant code paths or want to discuss possible workarounds until this is addressed.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
armru commentedon Jun 11, 2025
Hello Jaime, thanks for the Issue and PR!
I agree that the monolith approach should do a
carboncopy of the database.I would love to hear the other mantainers opinion on this, I'm also adding this issue to the 1.27 milestone so we are sure to have this discussion.
fix(import): do not create default user and database in monolith mode (…
fix(import): do not create default user and database in monolith mode (…
fix(import): do not create default user and database in monolith mode (…
fix(import): do not create default user and database in monolith mode (…