Convert Gerrit Database from pgsql to Mysql

636 views
Skip to first unread message

Partha Subramanian

unread,
Jun 1, 2010, 11:34:29 AM6/1/10
to Repo and Gerrit Discussion
Hi,
I am using Gerrit version 2.1.2.2 with a Postgres database. I need
to switch to mysql database. I searched on the internet for tools that
could convert postgres database to mysql. I couldn't find any.
Can someone please suggest a solucion ?

Thanks
Partha

Shawn Pearce

unread,
Jun 1, 2010, 12:17:38 PM6/1/10
to Partha Subramanian, Repo and Gerrit Discussion

Yikes.

Probably the cleanest solution is to:

- Initialize a new MySQL database for Gerrit using a temporary site.

*MAKE SURE YOU USE THE SAME VERSION OF GERRIT*

Just run the standard installation procedure to setup a
MySQL instance of Gerrit Code Review in a temporary site path.
You'll wind up with a clean database schema in your MySQL server,
and this dummy site directory directory you can clean up later.

- Purge out the system generated rows:

DELETE FROM schema_version;
DELETE FROM system_config;
DELETE FROM projects;
DELETE FROM ref_rights;
DELETE FROM account_groups;
DELETE FROM approval_categories;
DELETE FROM approval_category_values;

- Shutdown your PostgreSQL based Gerrit server.

- Dump each PostgreSQL table as a CSV file.

No clue how to do this easily, check the PostgreSQL documentation.
It may be a bit annoying to dump each table one at a time...

- Load each CSV file into MySQL.

- Reset the sequence counters in MySQL:

INSERT INTO account_group_id VALUES (SELECT MAX(account_group_id) + 1 FROM account_groups));
INSERT INTO account_id VALUES (SELECT MAX(account_id) + 1 FROM accounts));
INSERT INTO change_id VALUES (SELECT MAX(change_id) + 1 FROM changes));
INSERT INTO contributor_agreement_id VALUES (SELECT MAX(contributor_agreement_id) + 1 FROM contributor_agreements));

INSERT INTO change_message_id VALUES (....);

For that last one, you'll have to get the current counter from
PostgreSQL and fill in the ... by hand with the counter value:

SELECT nextval('change_message_id');


- Update your server's gerrit.config and secure.config files to
use the MySQL database parameters.

- Restart your Gerrit server.

- You should now be able to delete that temporary site you created
in the first step.


I've never tried this procedure myself. But in theory it should
work. Just watch out for the CSV dump-load process to make sure
they are using the same escaping rules for data values, same table
column orderings, and that you got every table in the schema.

Partha Subramanian

unread,
Jul 23, 2010, 3:54:31 PM7/23/10
to Repo and Gerrit Discussion
Thanks Shawn for providing a solution to convert from postgres to
mysql.

I tried the procedure and i found that postgres is case sensitive and
MySQL is not. Due to this some rows were rejected by mySQL when i
imported. I was able to work it around by changing the data type. For
example in projects table, i changed the data type of name from
varchar(255) to varchar(255) binary. I was wondering if there is any
other way of accomplishing this in mySQL without changing the schema.

Thanks
Partha

On Jun 1, 11:17 am, Shawn Pearce <s...@google.com> wrote:

Tariq Mehmood

unread,
Aug 24, 2012, 7:15:22 AM8/24/12
to repo-d...@googlegroups.com, Partha Subramanian
Hi, 
Just wondering would it be the same approach moving from H2 ot mySQL?
Reply all
Reply to author
Forward
0 new messages