{"id":13581727,"url":"https://github.com/wbh1/grafana-sqlite-to-postgres","last_synced_at":"2025-04-10T16:07:01.320Z","repository":{"id":40267645,"uuid":"187105785","full_name":"wbh1/grafana-sqlite-to-postgres","owner":"wbh1","description":"Grafana SQLite to Postgres Database Migrator","archived":false,"fork":false,"pushed_at":"2024-08-22T21:14:56.000Z","size":60,"stargazers_count":100,"open_issues_count":10,"forks_count":26,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T13:51:20.487Z","etag":null,"topics":["grafana","postgres","sqlite"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wbh1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-16T21:48:59.000Z","updated_at":"2024-10-01T07:41:23.000Z","dependencies_parsed_at":"2023-12-15T15:44:40.287Z","dependency_job_id":"bb5a97c2-fbda-4cb6-8834-7cc73834ad70","html_url":"https://github.com/wbh1/grafana-sqlite-to-postgres","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbh1%2Fgrafana-sqlite-to-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbh1%2Fgrafana-sqlite-to-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbh1%2Fgrafana-sqlite-to-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbh1%2Fgrafana-sqlite-to-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wbh1","download_url":"https://codeload.github.com/wbh1/grafana-sqlite-to-postgres/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248250743,"owners_count":21072682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grafana","postgres","sqlite"],"created_at":"2024-08-01T15:02:12.555Z","updated_at":"2025-04-10T16:07:01.300Z","avatar_url":"https://github.com/wbh1.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Grafana SQLite to Postgres Database Migrator\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/wbh1/grafana-sqlite-to-postgres)](https://goreportcard.com/report/github.com/wbh1/grafana-sqlite-to-postgres)\n\n# ⚠️ Unmaintained Warning ⚠️ \nWARNING: This project is currently maintained at a \"best-effort\" level. I no longer have the free time to keep up with changes to Grafana's database schema and handle/test edge cases.\n\nOne day, perhaps this can be rewritten to be more flexible, but it is not now. I'll continue to try to accept PRs as needed. This project started out of necessity and a desire to make a difficult move simpler for others. However, it's not something that I've personally had to use for years, so it's difficult to justify continuing to put in effort to this.\n\nUse the project at your own risk (always back up your database [and test the backup!!]). \n## Background\n[My blog post](https://wbhegedus.me/migrating-grafanas-database-from-sqlite-to-postgres/)\n\nI ran into the issue of Grafana logging users out because the SQLite database was locked and tokens couldn't be looked up. This is discussed in [#10727 on grafana/grafana](https://github.com/grafana/grafana/issues/10727#issuecomment-479378941). The solution is to migrate to a database that isn't the default one of SQLite.\n\n## Prerequisites\nYou **must** already have an existing database in Postgres for Grafana.\n\nRun `CREATE DATABASE grafana` in `psql` to make the database. Then, start up an instance of Grafana pointed to the new database. Grafana will automagically create all the tables that it will need. You can shut Grafana down once those tables are made. We **need** those tables to exist for the migration to work.\n\n## Compatability\nTested on:\n\n| OS             | SQLite Version | Postgres Version | Grafana Version |\n| -------------- | -------------- | ---------------- | --------------- |\n| MacOS          | 3.24.0         | 11.3             | 6.1.0+          |\n| CentOS 7/RHEL7 | 3.7.17         | 11.3             | 6.1.0+          |\n| Fedora 36      | 3.36.0         | 15.0             | 9.2.0           |\n\n## Usage\n```\nusage: Grafana SQLite to Postgres Migrator [\u003cflags\u003e] \u003csqlite-file\u003e \u003cpostgres-connection-string\u003e\n\nA command-line application to migrate Grafana data from SQLite to Postgres.\n\nFlags:\n  --help       Show context-sensitive help (also try --help-long and --help-man).\n  --dump=/tmp  Directory path where the sqlite dump should be stored.\n\nArgs:\n  \u003csqlite-file\u003e                 Path to SQLite file being imported.\n  \u003cpostgres-connection-string\u003e  URL-format database connection string to use in the URL format (postgres://USERNAME:PASSWORD@HOST/DATABASE).\n```\n### Use as Docker image\n1. Build docker image: `docker build -t grafana-sqlite-to-postgres .`\n2. Run migration: `docker run --rm -ti -v \u003cPATH_TO_DB_FILE\u003e:/grafana.db grafana-sqlite-to-postgres /grafana.db \"postgres://\u003cUSERNAME\u003e:\u003cPASSWORD\u003e@\u003cHOST\u003e:5432/\u003cDATABASE_NAME\u003e?sslmode=disable\"`\n\n## Example Command\nThis is the command I used to transfer my Grafana database:\n```\n./grafana-migrate grafana.db \"postgres://postgres:PASSWORDHERE@localhost:5432/grafana?sslmode=disable\"\n```\nNotice the `?sslmode=disable` parameter. The [pq](https://github.com/lib/pq) driver has sslmode turned on by default, so you may need to add a parameter to adjust it. You can see all the support connection string parameters [here](https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters).\n\n## How it works\n1. Dumps SQLite database to /tmp\n2. Sanitize the dump so it can be imported to Postgres\n3. Import the dump to the Grafana database\n\n## Acknowledgments\nInspiration for this program was taken from\n- [haron/grafana-migrator](https://github.com/haron/grafana-migrator)\n- [This blog post](https://0x63.me/migrating-grafana-from-sqlite-to-postgresql/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwbh1%2Fgrafana-sqlite-to-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwbh1%2Fgrafana-sqlite-to-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwbh1%2Fgrafana-sqlite-to-postgres/lists"}