{"id":3482,"date":"2025-08-04T12:05:00","date_gmt":"2025-08-04T12:05:00","guid":{"rendered":"https:\/\/kedar.nitty-witty.com\/blog\/?p=3482"},"modified":"2025-08-04T12:17:00","modified_gmt":"2025-08-04T12:17:00","slug":"how-to-migrate-pmm-grafana-users","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/how-to-migrate-pmm-grafana-users","title":{"rendered":"How to migrate PMM (Grafana) users"},"content":{"rendered":"\n<p>You&#8217;ve got a shiny new Percona Monitoring &amp; Management instance standing by and want to move existing users over. This blog is a quick work around for migrating PMM users to another PMM (Grafana) instance &#8220;manually&#8221;.<\/p>\n\n\n\n<p>Note: <em>This blog is only about user migration trick. A tool for exporting performance metrics and QAN data is <a href=\"https:\/\/docs.percona.com\/percona-monitoring-and-management\/3\/troubleshoot\/pmm_dump.html\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">pmm_dump<\/a>. If you&#8217;re looking for a complete migration from PMM 2.x to 3.x, you have a guide <a href=\"https:\/\/docs.percona.com\/percona-monitoring-and-management\/3\/troubleshoot\/pmm_dump.html\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">here<\/a>.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PMM User Migration<\/h2>\n\n\n\n<p>The requirement here was to migrate only PMM users to a new environment but not the data or queries.<\/p>\n\n\n\n<p>All PMM users are actually Grafana users under the hood, stored in a Postgres DB (by default). So it is possible to get those credentials and move them to the new instance without doing much is what I think!<\/p>\n\n\n\n<p>Verify what&#8217;s the Grafana&#8217;s backend database<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Inside PMM container\n&#91;root@1167d2c03dc2 ~] # grep type  \/etc\/grafana\/grafana.ini\n# You can configure the database connection by specifying type, host, name, user and password\ntype = postgres\n&#91;root@1167d2c03dc2 ~] #<\/code><\/pre>\n\n\n\n<p>Connect to database and review users<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>psql -h localhost -p 5432 -U grafana -d grafana\n\nSELECT\n  ou.id AS org_user_id,\n  ou.org_id,\n  ou.role,\n  u.id AS user_id,\n  u.login,\n  u.email,\n  u.name,\n  u.is_admin,\n  u.salt,\n  u.password\nFROM\n  org_user ou\nJOIN\n  \"user\" u ON ou.user_id = u.id\nORDER BY ou.id;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>grafana=> SELECT ou.id AS org_user_id, ou.org_id, ou.role, u.id AS user_id, u.login, u.email, u.name, u.is_admin,u.salt, u.password FROM org_user ou JOIN \"user\" u ON ou.user_id = u.id ORDER BY ou.id;\n org_user_id | org_id |  role  | user_id | login |      email      | name  | is_admin |    salt    |                                               p\nassword\n-------------+--------+--------+---------+-------+-----------------+-------+----------+------------+------------------------------------------------\n------------------------------------------------------\n           1 |      1 | Admin  |       1 | <strong>admin | admin@localhost <\/strong>|       | t        | k4XvdKrvBv | <strong>ba4af563a729c06fc95b1c921a598b6de2<\/strong>\n           2 |      1 | Viewer |       2 | <strong>kedar | kedar<\/strong>           | kedar | f        | k4XvdKrvBv | 5b1c921a598b6de2c55d906e900db04c82f<\/code><\/pre>\n\n\n\n<p>One may think that we can copy username and password hash but it is not that simple. We also need to add a pinch of NaCl AKA Salt. <\/p>\n\n\n\n<p>In password authentication, &#8220;salt&#8221; is a unique random string of characters added to a password before it&#8217;s hashed to provide additional security. Thus we have to make sure to copy the &#8220;salt&#8221; values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Magic happens here<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>grafana=>  \\x auto\nExpanded display is used automatically.\ngrafana=> SELECT\n  'INSERT INTO \"user\" (id, version, email, name, login, password, salt, email_verified, theme, created, updated, is_admin, is_disabled, last_seen_at, org_id) VALUES (' ||\n  u.id || ', ' || u.version || ', ''' || REPLACE(u.email, '''', '''''') || ''', ''' || REPLACE(u.name, '''', '''''') || ''', ''' || REPLACE(u.login, '''', '''''') || ''', ''' || u.password || ''', ''' || u.salt || ''', ' || u.email_verified || ', ''' || u.theme || ''', ''' || u.created || ''', ''' || u.updated || ''', ' || u.is_admin || ', ' || u.is_disabled || ', ''' || u.last_seen_at || ''', ' || u.org_id || ');' AS insert_user_command,\n  CASE\n    WHEN ou.user_id IS NOT NULL THEN\n      'INSERT INTO org_user (id, org_id, user_id, role, created, updated) VALUES (' ||\n      ou.id || ', ' || ou.org_id || ', ' || ou.user_id || ', ''' || ou.role || ''', ''' || ou.created || ''', ''' || ou.updated || ''');'\n    ELSE\n      '-- User ' || u.login || ' has no org_user entry to migrate.'\n  END AS insert_org_user_command\nFROM \"user\" u\nLEFT JOIN org_user ou ON u.id = ou.user_id\nORDER BY u.id, ou.org_id;\n-&#91; RECORD 1 ]-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\ninsert_user_command     | INSERT INTO \"user\" (id, version, email, name, login, password, salt, email_verified, theme, created, updated, is_admin, is_disabled, last_seen_at, org_id) VALUES (1, 0, 'admin@localhost', '', 'admin', '65c0a138b91f2793ec9b545352355a7b658dkedar.nitty-witty.com0a03b736918ba4af563a729c06fc9d906e900db04c82f', 'k4XvdKrvBv', false, '', '2025-01-01 11:14:30', '2025-07-30 08:16:29', true, false, '2025-07-30 08:38:40', 1);\ninsert_org_user_command | INSERT INTO org_user (id, org_id, user_id, role, created, updated) VALUES (1, 1, 1, 'Admin', '2025-01-01 11:14:30', '2025-01-01 11:14:30');\n-&#91; RECORD 2 ]-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\ninsert_user_command     | INSERT INTO \"user\" (id, version, email, name, login, password, salt, email_verified, theme, created, updated, is_admin, is_disabled, last_seen_at, org_id) VALUES (2, 0, 'kedar', 'kedar', 'kedar', '2e2bc60603c77811b4fe141271bc49aecekedar.nitty-witty.comdb0b11d1f921a0f19c7777dae68ebeb2d2f8bce643911', 'lwcv2cuO70', false, '', '2025-07-30 08:18:53', '2025-07-30 08:18:53', false, false, '2025-07-30 08:28:24', 1);\ninsert_org_user_command | INSERT INTO org_user (id, org_id, user_id, role, created, updated) VALUES (2, 1, 2, 'Viewer', '2025-07-30 08:18:53', '2025-07-30 08:18:53');\n-&#91; RECORD 3 ]-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\ninsert_user_command     | INSERT INTO \"user\" (id, version, email, name, login, password, salt, email_verified, theme, created, updated, is_admin, is_disabled, last_seen_at, org_id) VALUES (5, 0, 'aarya', 'aarya', 'aarya', '1a9ecc6b962db8028fe0a8ac1319208a1d29110c1017f2a79908f78a111fb86067c3b051ae3af9dde07a09cd49080c7c5d8b', 'N2nFw762t3', false, '', '2025-07-30 08:30:11', '2025-07-30 08:30:11', false, false, '2015-06-30 08:30:11', 1);\ninsert_org_user_command | INSERT INTO org_user (id, org_id, user_id, role, created, updated) VALUES (5, 1, 5, 'Viewer', '2025-07-30 08:30:11', '2025-07-30 08:30:11');\n-&#91; RECORD 4 ]-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\ninsert_user_command     | INSERT INTO \"user\" (id, version, email, name, login, password, salt, email_verified, theme, created, updated, is_admin, is_disabled, last_seen_at, org_id) VALUES (6, 0, 'rudra', 'rudra', 'rudra', '99752b5c4ca5b20a049d193551d566105f5ekedar.nitty-witty.com2491ff058f1e8b808d8bd9a555687655118c0081ba7', 'nLOfMsnE4m', false, '', '2025-07-30 08:30:29', '2025-07-30 08:30:29', false, false, '2015-06-30 08:30:29', 1);\ninsert_org_user_command | INSERT INTO org_user (id, org_id, user_id, role, created, updated) VALUES (6, 1, 6, 'Viewer', '2025-07-30 08:30:29', '2025-07-30 08:30:29');<\/code><\/pre>\n\n\n\n<p>I believe you&#8217;ve understood the next step! Connect to the target PMM, execute these insert statements and you&#8217;re done.<\/p>\n\n\n\n<p>Hope someone somewhere finds this post helpful.<\/p>\n","protected":false},"excerpt":{"rendered":"You&#8217;ve got a shiny new Percona Monitoring &amp; Management instance standing by and want to move existing users over. This blog is a quick work around for migrating PMM users&hellip;\n","protected":false},"author":1,"featured_media":3483,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,1089],"tags":[1109,1112,427,1108,1111,1110],"class_list":{"0":"post-3482","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-mysql","8":"category-percona-monitoring-and-management","9":"tag-grafana-user-migration","10":"tag-grafana-users","11":"tag-mysql","12":"tag-pmm-migration","13":"tag-pmm-user-migration","14":"tag-user-migration"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=3482"}],"version-history":[{"count":2,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3482\/revisions"}],"predecessor-version":[{"id":3485,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3482\/revisions\/3485"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media\/3483"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=3482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=3482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=3482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}