Changes between Version 9 and Version 10 of HowToMoveFromMySQLToPostgres


Ignore:
Timestamp:
Jul 13, 2009, 12:28:28 AM (15 years ago)
Author:
heikki
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowToMoveFromMySQLToPostgres

    v9 v10  
    102102Many thanks to Thijs Brentjens who gave this excellent tip, I've found a relatively straightforward way of doing it using the tool [http://www.gdal.org/ogr2ogr.html ogr2ogr] which is part of the [http://www.gdal.org/index.html GDAL] tool suite. The ogr2ogr build I found on their web site does not include drivers for MySQL and Postgress though. Downloading the tool suite [http://fwtools.maptools.org/ FWTools], which includes GDAL, solved this.
    103103
     104Using ogr2ogr, you can simply replicate a MySQL database into a Postgres database. The end result needs some massaging, but not much.
     105
     106Assuming you already created a Postgres database 'geonetwork' and a Postgres user 'postgressusername', you issue a command like
     107
     108{{{
     109   ogr2ogr -overwrite -update -f "PostgreSQL" PG:"host=localhost user=postgressusername dbname=geonetwork password=postgressuserpassword" MYSQL:"geonetworkdbname,host=localhost,user=mysqlusername,password=mysqluserpassword,port=3306"
     110}}}
     111
     112This creates the table structure in Postgres and copies the data into it.
     113
     114There are only 2 little tweaks necessary to make things work :
     115
     116 * each table in Postgres gets a column {{{wkb_geometry}}} that was not there in your original, MySQL table
     117 * Primary key column {{{id}}} gets called {{{ogc_fid}}} in Postgres
     118
     119The {{{wkb_geometry}}} columns can be fixed using this sql (thanks Thijs Brentjens) :
     120
     121{{{
     122-- In pgsql:
     123-- create the SQL commands:
     124
     125select 'ALTER TABLE ' || table_name || ' drop column wkb_geometry;' from information_schema.tables where table_schema='public';
     126
     127-- save the results to file and/or execute it directly:
     128ALTER TABLE isolanguages drop column wkb_geometry;
     129ALTER TABLE categories drop column wkb_geometry;
     130ALTER TABLE categoriesdes drop column wkb_geometry;
     131ALTER TABLE groups drop column wkb_geometry;
     132ALTER TABLE groupsdes drop column wkb_geometry;
     133ALTER TABLE languages drop column wkb_geometry;
     134ALTER TABLE isolanguagesdes drop column wkb_geometry;
     135ALTER TABLE monitoringrequests drop column wkb_geometry;
     136ALTER TABLE monitoringservices drop column wkb_geometry;
     137ALTER TABLE metadata drop column wkb_geometry;
     138ALTER TABLE metadatacateg drop column wkb_geometry;
     139ALTER TABLE metadatarating drop column wkb_geometry;
     140ALTER TABLE operationallowed drop column wkb_geometry;
     141ALTER TABLE monitoringlog drop column wkb_geometry;
     142ALTER TABLE monitoringstatsgroups drop column wkb_geometry;
     143ALTER TABLE operations drop column wkb_geometry;
     144ALTER TABLE operationsdes drop column wkb_geometry;
     145ALTER TABLE regions drop column wkb_geometry;
     146ALTER TABLE usergroups drop column wkb_geometry;
     147ALTER TABLE regionsdes drop column wkb_geometry;
     148ALTER TABLE relations drop column wkb_geometry;
     149ALTER TABLE settings drop column wkb_geometry;
     150ALTER TABLE users drop column wkb_geometry;
     151ALTER TABLE sources drop column wkb_geometry;
     152}}}
     153
     154
     155
     156
     157
    104158=== Links to related information ===
    105159