Skip to content

Initial database not created and init script refuses to run #467

@danielo515

Description

@danielo515

With this basic example, I can't get postgres to contain the expected database I want.

        process-compose."default" = {config, ...}: let
          dbuser = "postgres";
          dbpass = "postgres";
          dbName = "example";
        in {
          imports = [
            inputs.services-flake.processComposeModules.default
          ];
          services.postgres.pg1 = {
            enable = true;
            superuser = dbuser;
            initialScript.before = ''
              CREATE USER ${dbuser} WITH SUPER PASSWORD '${dbpass}';
            '';
            initialDatabases = [
              {
                name = dbName;
                schemas = [];
              }
            ];
          };

First time I run it, process-compose exits immediately, next time I try to start it, the pgint script refuses to run:

+ export PGDATA=./data/pg1                                                                                        ║│
│║+ PGDATA=./data/pg1                                                                                               ║│
│║+ export PGPORT=5432                                                                                              ║│
│║+ PGPORT=5432                                                                                                     ║│
│║+ POSTGRES_RUN_INITIAL_SCRIPT=false                                                                               ║│
│║+ [[ ! -d ./data/pg1 ]]                                                                                           ║│
│║+ echo 'Setting up postgresql.conf'                                                                               ║│
│║Setting up postgresql.conf                                                                                        ║│
│║+ cp /nix/store/1cz3y8b8fbdysx51afappcjga2w3yaaw-postgresql.conf ./data/pg1/postgresql.conf                       ║│
│║+ [[ false = \t\r\u\e ]]                                                                                          ║│
│║+ echo                                                                                                            ║│
│║                                                                                                                  ║│
│║PostgreSQL database directory appears to contain a database; Skipping initialization                              ║│
│║                                                                                                                  ║│
│║+ echo 'PostgreSQL database directory appears to contain a database; Skipping initialization'                     ║│
│║+ echo                                                                                                            ║│
│║+ unset POSTGRES_RUN_INITIAL_SCRIPT                                                                               ║│
│║

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions