Repository navigation
Closed
Labels
triagePending triage
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
No response
Version
1.26.0-rc2
What version of Kubernetes are you using?
1.29
What is your Kubernetes environment?
Other
How did you install the operator?
YAML manifest
What happened?
when using .spec.bootstrap.import.monolith and the db name to be imported is "app" the initial db owner is replaced by the "app" user.
source cluster:
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+---------+-------+--------+-----------+-----------------------
app | xxx | UTF8 | libc | C | C | | |
import monolith cluster:
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------
app | app | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
when the to be imported db is <> app, the correct owner is used
Cluster resource
source cluster:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 1
postgresql:
pg_hba:
- host all all all trust
storage:
size: 1Gi
bootstrap:
initdb:
database: app
owner: xxx
import.monolith cluster
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example-monolith
spec:
instances: 1
storage:
size: 1Gi
bootstrap:
initdb:
encoding: UTF8
dataChecksums: true
localeCType: en_US.UTF-8
localeCollate: en_US.UTF-8
import:
type: monolith
databases:
- app
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
Reacted by dosubot
Metadata
Metadata
Assignees
Labels
triagePending triage
Activity
dosubot commentedon Apr 29, 2025
The behavior you're experiencing is due to the default behavior of CloudNativePG when using
.spec.bootstrap.import.monolithwith the database name "app". The operator defaults the user that owns the database to the database name itself. Therefore, when the database name is "app", the owner is set to "app" by default. This is documented behavior: "The user that owns the database defaults to the database name instead" [1][2].If you need to override this behavior, you might need to explore configuration options or custom scripts to set the desired owner after the import process. Unfortunately, I couldn't find specific documentation on overriding this default behavior directly within the import process.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
smiyc commentedon Apr 29, 2025
if the to be imported db is not named "app" the correct db owner from the source cluster is used.
why should the db name make any difference in the way the monolith import works.
dosubot commentedon Apr 29, 2025
The database name "app" affects the owner assignment during the monolith import process because CloudNativePG has a default behavior where, if no database name is supplied, the operator creates the "app" database by convention and assigns the database owner to the database name itself. This is done using a defaulting webhook, which sets the user that owns the database to the name "app" [1][2]. This behavior is specific to the "app" database, intended to be the application database where applications store their data. Other database names do not have this default behavior, which is why they retain the correct owner from the source cluster.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
jsilvela commentedon Jun 5, 2025
@dosu this issue is the tip of the iceberg of a wider problem with monolith import, explained in #7731
Firstly, the issue as reported by @smiyc is about how the feature should work, not how it does work.
Secondly, your analysis makes unwarranted deductions:
In the monolith model, several databases may exist, all of which will allow applications to store their data.
dosubot commentedon Jun 5, 2025
You're right—my earlier analysis was off. The monolith import is designed to preserve the owner of each imported database, regardless of its name, as confirmed by both the code and the test suite. There is no intended special-case behavior for a database named "app" in the monolith import model; several databases can exist and all should retain their original owners from the source cluster, not default to the database name or "app" user. The fact that "app" gets its owner replaced is not expected or documented behavior for monolith import, and points to a bug or an unintended interaction in the implementation, not a feature or convention.
I couldn't find public details for issue #7731, so if there are broader architectural or design concerns, I don't have visibility into them. If you can share more about the wider problem or the specifics of #7731, I can help dig deeper into the code or documentation.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
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 (…