<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>RE: [postgis-users] How to load postgis enabled database from onemachine to another?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Leonardo Mateo wrote:<BR>
> On 7/2/07, Brent Wood <pcreso@pcreso.com> wrote:<BR>
>><BR>
>> --- Jessica Richard <rjessil@yahoo.com> wrote:<BR>
>><BR>
>> > I need to load a postgis enabled postgres database from on machine to<BR>
>> > another, I got a long list of errors. Some of them are pointing to the<BR>
>> > postgis path on the first machine, while on the second machine, the postgis<BR>
>> > was installed in different location. Thanks.<BR>
>><BR>
>> I've done this in a single step, using the psql client on one host to access<BR>
>> the Postgres server on the other, along the lines of:<BR>
>><BR>
>> pgdump --create db1 | psql -h <host2><BR>
>><BR>
>> Does Postgis work correctly, and are both systems running the same (or at least<BR>
>> a compatible) version?<BR>
><BR>
> This will work if and only if the same postgis version is installed on<BR>
> both machines and postgis is installed in the same location.<BR>
> What I've done on cases like Jessica's is:<BR>
> Case 1<BR>
> 1) pg_dump database > database.source.sql (on source pc)<BR>
> 2) locate liblwgeom.so and find out the path on source pc (/path/to/source/)<BR>
> 3) locate liblwgeom.so and find out the path on target pc (/path/to/target/)<BR>
> 4) sed -e 's/\/path\/to\/source\/\/path\/to\/target/g' > database.dest.sql<BR>
> 5) Load the resultant sql file on the target pc<BR>
><BR>
> This will dump source database and the sed command will replace the<BR>
> path to liblwgeom.so of the source pc with the one in the target pc.<BR>
><BR>
> Case 2 (my preferred after a few tries)<BR>
> 1) pg_dump database > database.source.sql (on source pc)<BR>
> 2) Edit database.source.sql and delete all code related to creation of<BR>
> types and types and everything about postgis (All is in the first<BR>
> part of the file).<BR>
> 3) create the target database<BR>
> 4) createlang -U postgres -d targetdatabase plpgsql<BR>
> 5) locate liblwgeom.sql and spatial_ref_sys.sql (this files are<BR>
> distributed with postgis)<BR>
> 6) run liblwgeom.sql and spatial_ref_sys.sql into the targetdatabase<BR>
> 7) run database.source.sql into the target database<BR>
><BR>
> The second case may look more complicated, but is cleaner and more<BR>
> elegant to my point of view, because it creates a PostGIS enabled<BR>
> database according to the PostGIS installation on that PC. Besides,<BR>
> once you did it once, you can automate the createlang and run of 2<BR>
> PostGIS sql files by scripting.<BR>
> The second method will save you from a few headaches.<BR>
><BR>
> Hope it helps.<BR>
><BR>
><BR>
I've opted for the 2nd method for some time now ... one thing to be careful of is that a dump will include the spatial_ref_sys table from the old instance; if you have customized entries you'll need to make sure they get ported to the new db; if not you should not copy this table over. If you are moving from different enough versions of postGIS the geometry_columns table layout may also change which necessitates some hand crafting for the load.<BR>
<BR>
My $0.02 worth ...<BR>
<BR>
Greg Williamson<BR>
Senior DBA<BR>
GlobeXplorer LLC, a DigitalGlobe company<BR>
<BR>
Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information and must be protected in accordance with those provisions. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.<BR>
<BR>
(My corporate masters made me say this.)<BR>
</FONT>
</P>
</BODY>
</HTML>