Skip to content

[Bug]: wrong db owner when using monolith import and db name is app #7447

Closed

Description

@smiyc

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: postgres

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    triage
    on Apr 29, 2025
  2. dosubot commented on Apr 29, 2025

    @dosubot

    The behavior you're experiencing is due to the default behavior of CloudNativePG when using .spec.bootstrap.import.monolith with 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.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  3. added
    bug 🐛
    on Apr 29, 2025
  4. smiyc commented on Apr 29, 2025

    @smiyc
    ContributorAuthor

    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.

  5. dosubot commented on Apr 29, 2025

    @dosubot

    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.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  6. removed
    bug 🐛
    on May 5, 2025
  7. self-assigned this
    on May 7, 2025
  8. jsilvela commented on Jun 5, 2025

    @jsilvela
    Contributor

    @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:

    This behavior is specific to the "app" database, intended to be the application database where applications store their data.

    In the monolith model, several databases may exist, all of which will allow applications to store their data.

  9. dosubot commented on Jun 5, 2025

    @dosubot

    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.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  10. added 2 commits that reference this issue on Jul 25, 2025
    1da3a53
    8f69f3a
  11. added a commit that references this issue on Jul 25, 2025
    e35085a
  12. added a commit that references this issue on Jul 25, 2025
    25db589
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions