Downgrading from 7 to 6. Database migration issues

Hi, so we’ve had a little bit of a problem during a Grafana upgrade that resulted in 7.X being installed instead of 6.7.4.
We had to downgrade and were getting ready to restore the PG database from a backup but everything seemed to work fine so we ended up not restoring the DB.

That is until we needed to add a new datasource via provisioning and things didn’t go very well.

Service init failed: Datasource provisioning error: pq: duplicate key value violates unique constraint \"UQE_data_source_org_id_uid\"

We tried deleting a few constraints
dashboard_pkey1
dashboard_provisioning_pkey1
data_source_pkey1
api_key_pkey1
login_attempt_pkey1

and dropping the following index:
UQE_data_source_org_id_uid

Things started working again in 6.7.4
However after testing to re-upgrade Grafana, we noticed these were not getting re-created.

Any advice on what should be done to ensure our DB is in a stable state when we upgrade to 7.X?
Of course the original backup does not have the latest user data, since this has been running for 3 weeks and losing that much user data is not an option.

We’re thinking we might have to create another DB, let Grafana create its tables, and then re-import our data inside that database.

I’ll just close this by saying we ended up creating a fresh DB for Grafana 6.X, stopped grafana, purged all tables that had conflicts (except the migration log table, you want to keep it from grafana 6) and inserting all data from 7.X inside that fresh database.

If anyone is interested in the details, I can post more info about what columns needed to be dropped, what tables had to be purged, but we were able to restore Grafana completely this way.

1 Like

Hi Marcant. I am planning in migrating grafana from 6.7 to 7 and since I have seen people reporting some errors in the process, i want to know how to downgrade the db gracefully in case of a disaster. Please share me the details. Regards!