Skip to content

Initialization script when PGData is not empty #1229

Description

@tomera-cyera

I know that when the PGData directory is not empty the container skips the initialization and therefore won't run the initialization script in /docker-entrypoint-initdb.d

I would like to use a way to give the container scripts that will run on startup no matter what (for example to create a role postgres if one does not exist already)

Activity

  1. tianon commented on Apr 18, 2024

    @tianon
    Member

    If you want a solution that does something with a started database (like our existing initdb scripts do), see #173, #821, #191, #929 for some other issues that have some good thoughts / suggestions (one of which this is probably a duplicate of).

  2. tomera-cyera commented on Apr 25, 2024

    @tomera-cyera
    Author

    Hi @tianon! Thanks for your response.
    I managed to run an init script on my db but it fails with role "postgres" does not exist (it was probably deleted).
    I don't know what roles the db has and I want to use the init script to verify the postgres role exists (and if not to create one).

  3. LaurentGoderre commented on Apr 25, 2024

    @LaurentGoderre
    Member

    You can run

    docker exec -u postgres -it postgres psql    
    psql (16.2 (Debian 16.2-1.pgdg120+2))
    Type "help" for help.
    
    postgres=# \du
                                 List of roles
     Role name |                         Attributes                         
    -----------+------------------------------------------------------------
     postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS
    
  4. tomera-cyera commented on Apr 25, 2024

    @tomera-cyera
    Author

    Hi @LaurentGoderre unfortunately your solution would not work in my case because there is no role postgres so I'm unable to execute any command with -u postgres, that's why I would like to init the db with a postgres role creation

  5. LaurentGoderre commented on Apr 25, 2024

    @LaurentGoderre
    Member

    @tomera-cyera I believe postgres in this case refers to the OS user which is postgres not the db role.

  6. tomera-cyera commented on Apr 25, 2024

    @tomera-cyera
    Author

    No, I refer to the postgres db role in case I initialize the container with data-dir that does not have the role postgres I want to make sure the postgres role will be created if not exist
    @LaurentGoderre

  7. LaurentGoderre commented on Apr 25, 2024

    @LaurentGoderre
    Member

    OOh you mean at initialization?

  8. tomera-cyera commented on Apr 30, 2024

    @tomera-cyera
    Author

    @LaurentGoderre, yes. you see I need to initialize the db to have a postgres role even when the datadir already exists (a.k.a the db already initialized)

  9. yuvall-cyera commented on Aug 19, 2024

    @yuvall-cyera

    @tianon @LaurentGoderre what do you think?

  10. tianon commented on Aug 19, 2024

    @tianon
    Member

    @yuvall-cyera can you please be more specific about what it is you're looking for feedback on? IMO the thread above is pretty clear (if you need one-time initialization, the image has that as-is, and if you need more than that, see the references in #1229 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions