Grafana and PostgreSQL

Hi,

This is my configuration for Grafana:

  services.grafana = {

    enable = true;
    addr = "localhost";
    port = 4000;
    domain = "<DOMAIN>";
    protocol = "http";

    database.type = "postgres";
    database.host = "localhost:5432";
    database.name = "grafana";
    database.user = "grafana";
    database.passwordFile = "/etc/nixos/modules/services/grafana.pass";

    analytics.reporting.enable = false;
    security.adminUser = "sysadmin";
    security.adminPasswordFile = "/etc/nixos/modules/services/grafana.pass";
    
  };

After starting nixos-rebuild switch, I get this error message:

Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=info msg="Executing migration" logger=migrator id="create index UQE_user_email - v2"
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=info msg="Executing migration" logger=migrator id="copy data_source v1 to v2"
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=info msg="Executing migration" logger=migrator id="Drop old table user_v1"
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=info msg="Executing migration" logger=migrator id="Add column help_flags1 to user table"
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=info msg="Executing migration" logger=migrator id="Update user table charset"
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=eror msg="Executing migration failed" logger=migrator id="Update user table charset" error="pq: relation \"UQE_user_login\" already exists"                                                                                                                                                                                                                               
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=eror msg="Exec failed" logger=migrator error="pq: relation \"UQE_user_login\" already exists" sql="ALTER TABLE \"user\" ALTER \"login\" TYPE VARCHAR(190), ALTER \"email\" TYPE VARCHAR(190), ALTER \"name\" TYPE VARCHAR(255), ALTER \"password\" TYPE VARCHAR(255), ALTER \"salt\" TYPE VARCHAR(50), ALTER \"rands\" TYPE VARCHAR(50), ALTER \"company\" TYPE VARCHAR(255), ALTER \"theme\" TYPE VARCHAR(255);"...
Jul 03 10:43:15 HOST 7yc83cxwvgayycrk8wmq1ba5apywkap0-unit-script-grafana-start[5353]: t=2019-07-03T10:43:15+0200 lvl=eror msg="Server shutdown" logger=server reason="Service init failed: Migration failed err: pq: relation \"UQE_user_login\" already exists"                                                                                                                                                                                                                               
Jul 03 10:43:15 HOST systemd[1]: grafana.service: Main process exited, code=exited, status=1/FAILURE
Jul 03 10:43:15 HOST systemd[1]: grafana.service: Failed with result 'exit-code'.

The user “grafana” can log in to postgresql. This works and entries are also created:

psql (11.4)
Type "help" for help.

grafana=# \dt
            List of relations
 Schema |     Name      | Type  |  Owner  
--------+---------------+-------+---------
 public | migration_log | table | grafana
 public | user          | table | grafana
(2 rows)

Any ideas?
Thanks.

1 Like