Tips: Migrate H2 to Postgres Database

2,857 views
Skip to first unread message

Ning Jiang

unread,
Dec 31, 2013, 6:14:02 AM12/31/13
to repo-d...@googlegroups.com
I've documented the procedure to migrate H2 to Postgres database under gerrit 2.7. Hope it'll be helpful.

Migrate H2 to Postgres Database

1. Create the postgres database and re-init the gerrit to create the
   database schema by:

   cd ~; java -jar gerrit-2.7.war init -d /home/gerrit2/review_site

   NOTE: gerrit may change the project rights in All-Projects.git,
   please back up All-Projects.git and restore it every time you do
   the re-init operation.

   After that, you can switch the database by preparing two sets of
   gerrit.config and secure.config files so that you can connect to
   database offline or start gerrit server by your choice.

   You can connect to the database offline by:

   cd ~/review_site; java -jar bin/gerrit.war gsql

2. List the table schema of both H2 and Postgres and compare them to find
   the differences.

   We need to follow the Postgres database schema to export the tables
   and dump the contents for the next two steps.

3. Switch to H2 and Export all tables into CSV files from H2.

   CALL CSVWRITE('account_diff_preferences',             'SELECT context,
   expand_all_comments,ignore_whitespace,intraline_difference,line_length,
   manual_review,retain_header,show_line_endings, show_tabs,show_whitespace_errors,
   skip_deleted,skip_uncommented,syntax_highlighting,tab_size,id
   FROM account_diff_preferences');

   CALL CSVWRITE('account_external_ids',                 'SELECT account_id,
   email_address,password,external_id
   FROM account_external_ids');

   CALL CSVWRITE('account_group_includes_by_uuid',       'SELECT group_id,include_uuid
   FROM account_group_includes_by_uuid');

   CALL CSVWRITE('account_group_includes_by_uuid_audit', 'SELECT added_by, removed_by,
   removed_on,added_on,group_id,include_uuid
   FROM account_group_includes_by_uuid_audit');

   CALL CSVWRITE('account_group_members',                'SELECT account_id,group_id
   FROM account_group_members');

   CALL CSVWRITE('account_group_members_audit',          'SELECT added_by,removed_by,
   removed_on,account_id,added_on,group_id
   FROM account_group_members_audit');

   CALL CSVWRITE('account_group_names',                  'SELECT group_id,name
   FROM account_group_names');

   CALL CSVWRITE('account_groups',                       'SELECT description,group_type,
   group_uuid,name,owner_group_uuid,visible_to_all,group_id
   FROM account_groups');

   CALL CSVWRITE('account_patch_reviews',                'SELECT account_id,file_name,
   change_id,patch_set_id
   FROM account_patch_reviews');

   CALL CSVWRITE('account_project_watches',              'SELECT notify_abandoned_changes,
   notify_all_comments,notify_new_changes,notify_new_patch_sets,notify_submitted_changes,
   account_id,filter,project_name
   FROM account_project_watches');

   CALL CSVWRITE('account_ssh_keys',                     'SELECT ssh_public_key,valid,
   account_id,seq
   FROM account_ssh_keys');

   CALL CSVWRITE('accounts',                             'SELECT contact_filed_on,
   full_name,comment_visibility_strategy,copy_self_on_email,date_format,download_command,
   download_url,maximum_page_size,relative_date_in_change_table,reverse_patch_set_order,
   show_site_header,show_username_in_review_category,time_format,use_flash_clipboard,
   inactive,preferred_email,registered_on,account_id
   FROM accounts');

   CALL CSVWRITE('change_messages',                      'SELECT author_id,message,
   patchset_change_id,patchset_patch_set_id,written_on,change_id,uuid
   FROM change_messages');

   CALL CSVWRITE('changes',                              'SELECT change_key,created_on,
   current_patch_set_id,dest_branch_name,dest_project_name,last_sha1_merge_tested,
   last_updated_on,mergeable,open,owner_account_id,sort_key,status,subject,topic,
   row_version,change_id
   FROM changes');

   CALL CSVWRITE('patch_comments',                       'SELECT author_id,line_nbr,
   message,parent_uuid,side,status,written_on,file_name,change_id,patch_set_id,uuid
   FROM patch_comments');

   CALL CSVWRITE('patch_set_ancestors',                  'SELECT ancestor_revision,
   change_id,patch_set_id,position
   FROM patch_set_ancestors');

   CALL CSVWRITE('patch_set_approvals',                  'SELECT change_open,
   change_sort_key,granted,value,account_id,category_id,change_id,patch_set_id
   FROM patch_set_approvals');

   CALL CSVWRITE('patch_sets',                           'SELECT created_on,draft,
   revision,uploader_account_id,change_id,patch_set_id
   FROM patch_sets');

   CALL CSVWRITE('schema_version',                       'SELECT version_nbr,singleton
   FROM schema_version');

   CALL CSVWRITE('starred_changes',                      'SELECT account_id,change_id
   FROM starred_changes');

   CALL CSVWRITE('submodule_subscriptions',              'SELECT submodule_branch_name,
   submodule_project_name,submodule_path,super_project_branch_name,
   super_project_project_name
   FROM submodule_subscriptions');

   CALL CSVWRITE('system_config',                        'SELECT admin_group_id,
   admin_group_uuid,anonymous_group_id,batch_users_group_id,batch_users_group_uuid,
   owner_group_id,register_email_private_key,registered_group_id,site_path,
   wild_project_name,singleton
   FROM system_config');

   CALL CSVWRITE('tracking_ids',                         'SELECT change_id,
   tracking_key,tracking_system
   FROM tracking_ids');

4. Start gerrit and Dump the contents of each table for check later into
   directory db_h2. Please make each command one line in real script.
   Note that the ssh port of gerrit is changed to 29419 temporarily to
   make sure no one will operate on it at the same time.

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT context,expand_all_comments,
   ignore_whitespace,intraline_difference,line_length,manual_review,retain_header,
   show_line_endings,show_tabs,show_whitespace_errors,skip_deleted,skip_uncommented,
   syntax_highlighting,tab_size,id
   FROM account_diff_preferences\"             >account_diff_preferences

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT account_id,email_address,
   password,external_id
   FROM account_external_ids\"                 >account_external_ids

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT group_id,include_uuid
   FROM account_group_includes_by_uuid\"       >account_group_includes_by_uuid

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT added_by,removed_by,
   removed_on,added_on,group_id,include_uuid
   FROM account_group_includes_by_uuid_audit\" >account_group_includes_by_uuid_audit

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT account_id,group_id
   FROM account_group_members\"                >account_group_members

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT added_by,removed_by,
   removed_on,account_id,added_on,group_id
   FROM account_group_members_audit\"          >account_group_members_audit

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT group_id,name
   FROM account_group_names\"                  >account_group_names

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT description,group_type,
   group_uuid,name,owner_group_uuid,visible_to_all,group_id
   FROM account_groups\"                       >account_groups

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT account_id,file_name,
   change_id,patch_set_id
   FROM account_patch_reviews\"                >account_patch_reviews

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT notify_abandoned_changes,
   notify_all_comments,notify_new_changes,notify_new_patch_sets,
   notify_submitted_changes,account_id,filter,project_name
   FROM account_project_watches\"              >account_project_watches

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT ssh_public_key,valid,
   account_id,seq
   FROM account_ssh_keys\"                     >account_ssh_keys

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT contact_filed_on,full_name,
   comment_visibility_strategy,copy_self_on_email,date_format,download_command,
   download_url,maximum_page_size,relative_date_in_change_table,
   reverse_patch_set_order,show_site_header,show_username_in_review_category,
   time_format,use_flash_clipboard,inactive,preferred_email,registered_on,account_id
   FROM accounts\"                             >accounts

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT author_id,message,
   patchset_change_id,patchset_patch_set_id,written_on,change_id,uuid
   FROM change_messages\"                      >change_messages

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT change_key,created_on,
   current_patch_set_id,dest_branch_name,dest_project_name,last_sha1_merge_tested,
   last_updated_on,mergeable,open,owner_account_id,sort_key,status,subject,topic,
   row_version,change_id
   FROM changes\"                              >changes

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT author_id,line_nbr,
   message,parent_uuid,side,status,written_on,file_name,change_id,patch_set_id,uuid
   FROM patch_comments\"                       >patch_comments

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT ancestor_revision,
   change_id,patch_set_id,position
   FROM patch_set_ancestors\"                  >patch_set_ancestors

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT change_open,
   change_sort_key,granted,value,account_id,category_id,change_id,patch_set_id
   FROM patch_set_approvals\"                  >patch_set_approvals

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT created_on,draft,
   revision,uploader_account_id,change_id,patch_set_id
   FROM patch_sets\"                           >patch_sets

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT version_nbr,singleton
   FROM schema_version\"                       >schema_version

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT account_id,change_id
   FROM starred_changes\"                      >starred_changes

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT submodule_branch_name,
   submodule_project_name,submodule_path,super_project_branch_name,
   super_project_project_name
   FROM submodule_subscriptions\"              >submodule_subscriptions

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT admin_group_id,
   admin_group_uuid,anonymous_group_id,batch_users_group_id,batch_users_group_uuid,
   owner_group_id,register_email_private_key,registered_group_id,site_path,
   wild_project_name,singleton
   FROM system_config\"                        >system_config

   ssh -p 29419 gerrit.server.com gerrit gsql -c \"SELECT change_id,tracking_key,
   tracking_system
   FROM tracking_ids\"                         >tracking_ids

5. Stop gerrit and connect to H2 database to get sequence number.

   SELECT currval('change_message_id');
   SELECT currval('change_id');
   SELECT currval('account_id');
   SELECT currval('account_group_id');

   You can double check with:

   SELECT nextval('change_message_id');
   SELECT nextval('change_id');
   SELECT nextval('account_id');
   SELECT nextval('account_group_id');

   It should be 'nextval = currval + 1' for each sequence.

6. Stop gerrit, Switch to Postgres and Delete all the contents in Postgres.

   DELETE FROM account_diff_preferences;
   DELETE FROM account_external_ids;
   DELETE FROM account_group_includes_by_uuid;
   DELETE FROM account_group_includes_by_uuid_audit;
   DELETE FROM account_group_members;
   DELETE FROM account_group_members_audit;
   DELETE FROM account_group_names;
   DELETE FROM account_groups;
   DELETE FROM account_patch_reviews;
   DELETE FROM account_project_watches;
   DELETE FROM account_ssh_keys;
   DELETE FROM accounts;
   DELETE FROM change_messages;
   DELETE FROM changes;
   DELETE FROM patch_comments;
   DELETE FROM patch_set_ancestors;
   DELETE FROM patch_set_approvals;
   DELETE FROM patch_sets;
   DELETE FROM schema_version;
   DELETE FROM starred_changes;
   DELETE FROM submodule_subscriptions;
   DELETE FROM system_config;
   DELETE FROM tracking_ids;

7. Change the user gerrit2 to superuser temporarily.

   ALTER USER gerrit2 WITH SUPERUSER;

8. Stay in the Postgres and continue to Import the CSV files to
   Postgres tables.

   COPY account_diff_preferences             FROM '/home/gerrit2/review_site/account_diff_preferences' DELIMITER ',' CSV HEADER;
   COPY account_external_ids                 FROM '/home/gerrit2/review_site/account_external_ids' DELIMITER ',' CSV HEADER;
   COPY account_group_includes_by_uuid       FROM '/home/gerrit2/review_site/account_group_includes_by_uuid' DELIMITER ',' CSV HEADER;
   COPY account_group_includes_by_uuid_audit FROM '/home/gerrit2/review_site/account_group_includes_by_uuid_audit' DELIMITER ',' CSV HEADER;
   COPY account_group_members                FROM '/home/gerrit2/review_site/account_group_members' DELIMITER ',' CSV HEADER;
   COPY account_group_members_audit          FROM '/home/gerrit2/review_site/account_group_members_audit' DELIMITER ',' CSV HEADER;
   COPY account_group_names                  FROM '/home/gerrit2/review_site/account_group_names' DELIMITER ',' CSV HEADER;
   COPY account_groups                       FROM '/home/gerrit2/review_site/account_groups' DELIMITER ',' CSV HEADER;
   COPY account_patch_reviews                FROM '/home/gerrit2/review_site/account_patch_reviews' DELIMITER ',' CSV HEADER;
   COPY account_project_watches              FROM '/home/gerrit2/review_site/account_project_watches' DELIMITER ',' CSV HEADER;
   COPY account_ssh_keys                     FROM '/home/gerrit2/review_site/account_ssh_keys' DELIMITER ',' CSV HEADER;
   COPY accounts                             FROM '/home/gerrit2/review_site/accounts' DELIMITER ',' CSV HEADER;
   COPY change_messages                      FROM '/home/gerrit2/review_site/change_messages' DELIMITER ',' CSV HEADER;
   COPY changes                              FROM '/home/gerrit2/review_site/changes' DELIMITER ',' CSV HEADER;
   COPY patch_comments                       FROM '/home/gerrit2/review_site/patch_comments' DELIMITER ',' CSV HEADER;
   COPY patch_set_ancestors                  FROM '/home/gerrit2/review_site/patch_set_ancestors' DELIMITER ',' CSV HEADER;
   COPY patch_set_approvals                  FROM '/home/gerrit2/review_site/patch_set_approvals' DELIMITER ',' CSV HEADER;
   COPY patch_sets                           FROM '/home/gerrit2/review_site/patch_sets' DELIMITER ',' CSV HEADER;
   COPY schema_version                       FROM '/home/gerrit2/review_site/schema_version' DELIMITER ',' CSV HEADER;
   COPY starred_changes                      FROM '/home/gerrit2/review_site/starred_changes' DELIMITER ',' CSV HEADER;
   COPY submodule_subscriptions              FROM '/home/gerrit2/review_site/submodule_subscriptions' DELIMITER ',' CSV HEADER;
   COPY system_config                        FROM '/home/gerrit2/review_site/system_config' DELIMITER ',' CSV HEADER;
   COPY tracking_ids                         FROM '/home/gerrit2/review_site/tracking_ids' DELIMITER ',' CSV HEADER;

9. Set the sequence number for postgres database.

   SELECT setval('change_message_id', change_message_id_num);
   SELECT setval('change_id', change_id_num);
   SELECT setval('account_id', account_id_num);
   SELECT setval('account_group_id', account_group_id_num);

10.Change the user gerrit2 to non superuser.

   ALTER USER gerrit2 WITH NOSUPERUSER;

11.Start gerrit and execute commands in step 4 in directory db_postgres.
   Compare the table contents in db_h2 and db_postgres to make sure the
   migration is complete.


ruzz mo

unread,
Nov 8, 2015, 10:37:17 AM11/8/15
to Repo and Gerrit Discussion
Thanks! This was very helpful. Based on this, I created a cookbook that I used to update a gerrit instance based on 2.11.4. All seems to be working :)

#Create snapshot, backup, whatever..
#Stop gerrit

sudo apt-get install -y --force-yes postgresql postgresql-contrib
sudo locale-gen en_CA.UTF-8

sudo -u postgres -i
createuser --username=postgres -RDIElPS gerrit
createdb --username=postgres -E UTF-8 -O gerrit reviewdb

psql

ALTER USER gerrit WITH SUPERUSER;


sudo su gerrit

cp /opt/gerrit  # Or wherever your gerrit root is. 

java -jar bin/gerrit.war 'gsql' -d .

CALL CSVWRITE('/opt/gerrit/migrate/account_diff_preferences', 'SELECT ignore_whitespace, tab_size, line_length, syntax_highlighting, show_whitespace_errors, intraline_difference, show_tabs, context, skip_deleted, skip_uncommented, expand_all_comments, retain_header, manual_review, show_line_endings, hide_top_menu, hide_line_numbers, render_entire_file, theme, hide_empty_pane, auto_hide_diff_table_header, id FROM account_diff_preferences');
CALL CSVWRITE('/opt/gerrit/migrate/account_external_ids', 'SELECT  ACCOUNT_ID,EMAIL_ADDRESS,PASSWORD,EXTERNAL_ID FROM account_external_ids');
CALL CSVWRITE('/opt/gerrit/migrate/account_group_by_id', 'SELECT group_id, include_uuid FROM account_group_by_id');
CALL CSVWRITE('/opt/gerrit/migrate/account_group_by_id_aud', ' SELECT  added_by, removed_by, removed_on, group_id, include_uuid, added_on FROM account_group_by_id_aud');
CALL CSVWRITE('/opt/gerrit/migrate/account_group_members', 'SELECT account_id, group_id FROM account_group_members');
CALL CSVWRITE('/opt/gerrit/migrate/account_group_members_audit', 'SELECT added_by, removed_by, removed_on, account_id, group_id, added_on FROM account_group_members_audit');
CALL CSVWRITE('/opt/gerrit/migrate/account_group_names', 'SELECT group_id, name FROM account_group_names');
CALL CSVWRITE('/opt/gerrit/migrate/account_groups', 'SELECT name, description, visible_to_all, group_uuid, owner_group_uuid, group_id FROM account_groups');

CALL CSVWRITE('/opt/gerrit/migrate/account_patch_reviews', 'SELECT account_id, change_id, patch_set_id, file_name FROM account_patch_reviews');
CALL CSVWRITE('/opt/gerrit/migrate/account_project_watches', 'SELECT notify_new_changes, notify_all_comments, notify_submitted_changes, notify_new_patch_sets, notify_abandoned_changes, account_id, project_name, filter FROM account_project_watches');
CALL CSVWRITE('/opt/gerrit/migrate/account_ssh_keys', 'SELECT ssh_public_key, valid, account_id, seq FROM account_ssh_keys');
CALL CSVWRITE('/opt/gerrit/migrate/accounts', 'SELECT registered_on , full_name, preferred_email, contact_filed_on, maximum_page_size, show_site_header, use_flash_clipboard, download_url, download_command, copy_self_on_email, date_format, time_format, relative_date_in_change_table, diff_view, size_bar_in_change_table, legacycid_in_change_table, review_category_strategy, mute_common_path_prefixes, inactive, account_id FROM accounts');

CALL CSVWRITE('/opt/gerrit/migrate/change_messages', 'SELECT author_id, written_on, message, patchset_change_id, patchset_patch_set_id, change_id, uuid FROM change_messages');
CALL CSVWRITE('/opt/gerrit/migrate/changes', 'SELECT change_key, created_on, last_updated_on, owner_account_id, dest_project_name, dest_branch_name, status, current_patch_set_id, subject, topic, original_subject, row_version, change_id FROM changes');
CALL CSVWRITE('/opt/gerrit/migrate/patch_comments', 'SELECT line_nbr, author_id, written_on, status, side, message, parent_uuid, range_start_line, range_start_character, range_end_line, range_end_character, change_id, patch_set_id, file_name, uuid FROM patch_comments');
CALL CSVWRITE('/opt/gerrit/migrate/patch_set_ancestors', 'SELECT ancestor_revision, change_id, patch_set_id, position FROM patch_set_ancestors');
CALL CSVWRITE('/opt/gerrit/migrate/patch_set_approvals', 'SELECT value, granted, change_id, patch_set_id, account_id, category_id FROM patch_set_approvals');
CALL CSVWRITE('/opt/gerrit/migrate/patch_sets', 'SELECT revision, uploader_account_id, created_on, draft, change_id, patch_set_id FROM patch_sets');
CALL CSVWRITE('/opt/gerrit/migrate/schema_version', 'SELECT version_nbr, singleton FROM schema_version');
CALL CSVWRITE('/opt/gerrit/migrate/starred_changes', 'SELECT account_id, change_id FROM starred_changes');
CALL CSVWRITE('/opt/gerrit/migrate/submodule_subscriptions', 'SELECT submodule_project_name, submodule_branch_name, super_project_project_name, super_project_branch_name, submodule_path FROM submodule_subscriptions');
CALL CSVWRITE('/opt/gerrit/migrate/system_config', 'SELECT register_email_private_key, site_path  , admin_group_id, anonymous_group_id, registered_group_id, wild_project_name, batch_users_group_id, owner_group_id, admin_group_uuid, batch_users_group_uuid, singleton FROM system_config');

#Update below commands with the results from here:

SELECT currval('change_message_id');
SELECT currval('change_id');
SELECT currval('account_id');
SELECT currval('account_group_id');

\q


#Backup All-Projects:
cp -aR git/All-Projects.git . 


#Edit etc/gerrit.config:

[database]
        type = POSTGRESQL
        hostname = localhost
        database = reviewdb
        username = gerrit
        password = <mysupersecretimpossibletocrackpassword, eg: 1234>


#Still, as gerrit:
java -jar bin/gerrit.war init --batch -d .


#Restore All-Projects:
rm -rf git/All-Projects.git/
cp -aR All-Projects.git git



java -jar bin/gerrit.war 'gsql' -d .


DELETE FROM account_diff_preferences;
COPY account_diff_preferences FROM '/opt/gerrit/migrate/account_diff_preferences' DELIMITER ',' CSV HEADER;

DELETE FROM account_external_ids;
COPY account_external_ids FROM '/opt/gerrit/migrate/account_external_ids' DELIMITER ',' CSV HEADER;

DELETE FROM account_group_by_id_aud;
COPY account_group_by_id_aud FROM '/opt/gerrit/migrate/account_group_by_id_aud' DELIMITER ',' CSV HEADER;

DELETE FROM account_group_members;
COPY account_group_members FROM '/opt/gerrit/migrate/account_group_members' DELIMITER ',' CSV HEADER;

DELETE FROM account_group_members_audit;
COPY account_group_members_audit FROM '/opt/gerrit/migrate/account_group_members_audit' DELIMITER ',' CSV HEADER;

DELETE FROM account_group_names;
COPY account_group_names FROM '/opt/gerrit/migrate/account_group_names' DELIMITER ',' CSV HEADER;

DELETE FROM account_groups;
COPY account_groups FROM '/opt/gerrit/migrate/account_groups' DELIMITER ',' CSV HEADER;

DELETE FROM account_patch_reviews;
COPY account_patch_reviews FROM '/opt/gerrit/migrate/account_patch_reviews' DELIMITER ',' CSV HEADER;

DELETE FROM account_project_watches;
COPY account_project_watches FROM '/opt/gerrit/migrate/account_project_watches' DELIMITER ',' CSV HEADER;

DELETE FROM account_ssh_keys;
COPY account_ssh_keys FROM '/opt/gerrit/migrate/account_ssh_keys' DELIMITER ',' CSV HEADER;

DELETE FROM accounts;
COPY accounts FROM '/opt/gerrit/migrate/accounts' DELIMITER ',' CSV HEADER;

DELETE FROM change_messages;
COPY change_messages FROM '/opt/gerrit/migrate/change_messages' DELIMITER ',' CSV HEADER;

DELETE FROM changes;
COPY changes FROM '/opt/gerrit/migrate/changes' DELIMITER ',' CSV HEADER;

DELETE FROM patch_comments;
COPY patch_comments FROM '/opt/gerrit/migrate/patch_comments' DELIMITER ',' CSV HEADER;

DELETE FROM patch_set_ancestors;
COPY patch_set_ancestors FROM '/opt/gerrit/migrate/patch_set_ancestors' DELIMITER ',' CSV HEADER;

DELETE FROM patch_set_approvals;
COPY patch_set_approvals FROM '/opt/gerrit/migrate/patch_set_approvals' DELIMITER ',' CSV HEADER;

DELETE FROM patch_sets;
COPY patch_sets FROM '/opt/gerrit/migrate/patch_sets' DELIMITER ',' CSV HEADER;

DELETE FROM schema_version;
COPY schema_version FROM '/opt/gerrit/migrate/schema_version' DELIMITER ',' CSV HEADER;

DELETE FROM starred_changes;
COPY starred_changes FROM '/opt/gerrit/migrate/starred_changes' DELIMITER ',' CSV HEADER;

DELETE FROM submodule_subscriptions;
COPY submodule_subscriptions FROM '/opt/gerrit/migrate/submodule_subscriptions' DELIMITER ',' CSV HEADER;

DELETE FROM system_config;
COPY system_config FROM '/opt/gerrit/migrate/system_config' DELIMITER ',' CSV HEADER;


##Update values. Use the values obtained above:

SELECT setval('change_message_id', change_message_id_num);
SELECT setval('change_id', change_id_num);
SELECT setval('account_id', account_id_num);
SELECT setval('account_group_id', account_group_id_num);


sudo -u postgres psql
ALTER USER gerrit WITH NOSUPERUSER;


#Start gerrit.

yun...@compass.com

unread,
Oct 8, 2016, 9:35:47 AM10/8/16
to Repo and Gerrit Discussion
This was very useful to me in migrating on Gerrit 2.12 as well. There were a few schema changes from 2.11, so here's a modified set of instructions for 2.12:

Liejun Tao

unread,
Jun 18, 2018, 1:49:15 AM6/18/18
to Repo and Gerrit Discussion
Below really helped me migrating a 2.11.10 instance.
A small note, the import part is missing a table.

DELETE FROM account_group_by_id;
COPY account_group_by_id FROM '/tmp/gerrit/migrate/account_group_by_id' DELIMITER ',' CSV HEADER;
Reply all
Reply to author
Forward
0 new messages