Migrate up error: Dirty database version

I am trying to setup the chirpstack application server. I have followed all the steps which are provided in the quick start guide. My network server is up and running but my application-server fails with the below error.

Stopped ChirpStack Application Server.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: Started ChirpStack Application Server.
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.350096999Z" level=info msg="starting ChirpStack Application Server" docs="https://www.chirpstack.io/" version=3.17.2
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.353836457Z" level=info msg="storage: setting up storage package"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.354033983Z" level=info msg="storage: setup metrics"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.354196187Z" level=info msg="storage: setting up Redis client"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.354364219Z" level=info msg="storage: connecting to PostgreSQL database"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.360196351Z" level=info msg="storage: applying PostgreSQL data migrations"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.363729949Z" level=fatal msg="setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version."
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Main process exited, code=exited, status=1/FAILURE
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Failed with result 'exit-code'.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Service hold-off time over, scheduling restart.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Scheduled restart job, restart counter is at 5.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: Stopped ChirpStack Application Server.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Start request repeated too quickly.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Failed with result 'exit-code'.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: Failed to start ChirpStack Application Server.

I re-installed Postgres but that too didn’t work.

I am using postgres 10.18 and ubuntu 18

Are you using the same database for the ChirpStack Network Server and ChirpStack Application Server? In that case I recommend to create two new empty databases and retry.

No, I am using different empty databases but still, the error is coming. I then upgraded my OS to ubuntu 20 and after that I was able to run chirpstack application server and visit the interface.

I’ve tried the installation several times on Ubuntu 20.04 Focal Fossa . I ended up with the same error as follow.
level=fatal msg=“setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version.”

It indicates that somehow, it could migrate the database. The Dirty database version indicates that a previous run failed. Please inspect the logs to see what went wrong at that migration run.

I have the same problem using Debian 11 and postgresql-13
migrate up error: Dirty database version 27
Where are the DB migration logs stored? I can see anything under /var/log/chirpstack-application-server/
Is there a way to try running the DB migration alone so I can try to focus on which part of the DB migration it fails on?

starting ChirpStack Application Server" docs="https://www.chirpstack.io/" version=3.17.4
...
storage: applying PostgreSQL data migrations
setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version.

The database does appear to be (partly) migrated:

chirpstack_as=> \dt
                   List of relations
 Schema |         Name         | Type  |     Owner
--------+----------------------+-------+---------------
 public | application          | table | chirpstack_as
 public | application_user     | table | chirpstack_as
 public | device               | table | chirpstack_as
 public | device_activation    | table | chirpstack_as
 public | device_keys          | table | chirpstack_as
 public | device_profile       | table | chirpstack_as
 public | device_queue         | table | chirpstack_as
 public | device_queue_mapping | table | chirpstack_as
 public | downlink_queue       | table | chirpstack_as
 public | gateway              | table | chirpstack_as
 public | gateway_ping         | table | chirpstack_as
 public | gateway_ping_rx      | table | chirpstack_as
 public | integration          | table | chirpstack_as
 public | network_server       | table | chirpstack_as
 public | node                 | table | chirpstack_as
 public | organization         | table | chirpstack_as
 public | organization_user    | table | chirpstack_as
 public | schema_migrations    | table | chirpstack_as
 public | service_profile      | table | chirpstack_as
 public | user                 | table | chirpstack_as
(20 rows)

I had the same error and had installed postgresql-13 on CentOS-8.
So I uninstalled postgresql-13 and installed postgresql-12. Then I additionally installed postgresql-contrib and everything was resolved…
As I understand this error was related to enabling the following:
– enable the extensions
create extension pg_trgm;
create extension hstore;

https://www.chirpstack.io/application-server/install/requirements/

I hope it helped.

I worked out that I had not followed the install instructions (doh). I had forgotten to add the hstore etc extensions to postgres. Once I added that to my ansible I was good. Cheers

1 Like