Posts

Showing posts with the label postgis

Extract TABLE data from a large postgres SQL dump (with postgis)

What do you do when postgres refuses to import a dump because it contains invalid byte sequences? Solution: feed the sql script to iconv then import it as usual. That's easier said than done especially if your database contains postgis data which must be restored through a custom postgres dump (instructions here ). I recently experienced this issue on a relatively small table in a large-ish database. Since hand editing the SQL dump is cumbersome and hard (it is over 500MB in size) the only and most elegant alternative was to do it with a script. The following is an awk script which will extract the COPY instructions relative to a table from a postgres SQL dump: File: copy_estract.awk ---------------------- BEGIN {start=0} /^COPY "/ { if(index($0,TBL)!=0) { start=1; } } // {if(start==1) print $0;} /\\\./ {start=0;} Usage: awk -f copy_extract.awk -v TBL=TABLENAME pgdump/database_dump.sql One liner: awk -f copy_extract.awk -v TBL=TEST pgdump/d...

Improving TileDrawer rendering speed

I have been playing with TileDrawer recently. After a first rapid successful test on a throw-away EC2 instance I decided to deploy one on a vm for intranet use. The installation process is pretty straightforward, just run the script copied from the TileDrawer page as root. FYI make sure you have installed curl and python-cssutils before launching the script. After the script completed I started browsing the map and noticed that tiles took a looong time to render. A look at top from the server console showed that postgres was hogging the cpu. Memory was fine with no signs of swapping (it is a 1GB instance which I promptly upgraded to 2, running on server class hardware with Xeon CPU). Even after the memory upgrade tile rendering was so slow that the browser would sometime give up and show a white tile. I decided to look into it a little further and started by using the technique I have already described in another article . The database cache looked fine though as mo...