Postgres isn't recreating an ensured database

Hey folks, hitting a strange issue. I have the following Postgres config:

  services.postgresql = {
    ensureDatabases = [ "dev" ];
    ensureUsers = [
      {
        name = "dev";
        ensureDBOwnership = true;
      }
    ];
  };

I set up a Gitea instance pointing at that database and everything was fine. Then I hosed my authentication method config and locked myself out, so I figured I’d drop the database, kill the container, run a nixos-rebuild switch, bring up the container, and try configuring the Gitea instance again from scratch. Only, running nixos-rebuild switch with the above configuration doesn’t seem to recreate the dev database.

My assumption was that I could just drop the database and rebuild my config if I needed to reconfigure Gitea from scratch, but that doesn’t seem to be true, at least in part. What am I missing?

Thanks a bunch.

Sorry, figured this out. Seems like the recreate happens on restart of postgres, not when rebuilding the config. systemctl restart postgres brought the empty database back as expected.

2 Likes