<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I use <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>st_union(st_band(rast, '2,3,4') )<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>instead of your ARRAY[ROW… construct.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If polygon comes from a table of geometries (e.g. adminbounds), you would need to add a JOIN (FROM landsat8, adminbounds).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Using WHERE rast && polygon would seem to be a good idea as well.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If your polygon is a big as the entire Landsat image, your query will return several 100 Mb of data, and may close the connection before completion.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>GL<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> postgis-users-bounces@lists.osgeo.org [mailto:postgis-users-bounces@lists.osgeo.org] <b>On Behalf Of </b>Jackie<br><b>Sent:</b> 17 March 2014 17:16<br><b>To:</b> postgis-users@lists.osgeo.org<br><b>Subject:</b> [postgis-users] ST_Union() about 1179 raster-tiles cause ProgreSQL crashes<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222;background:white'>Hi PostGIS users,</span> <o:p></o:p></p><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'>I have a PostGIS database, which stores raster from Landsat 8. Each scene was divided with tile-size 500x500. Then each row in database will keep 1 tile with 11 bands (except band No. 8).<o:p></o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'>I'm trying to ST_Union() about 1179 raster-tiles with 3 bands (2,3,4) and pgAdminIII shows a window said "Connection lost - Try to reconnect database";<o:p></o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'>Here's my query:<o:p></o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Courier New";color:#222222;border:none windowtext 1.0pt;padding:0cm'>SELECT ST_Union(rast, ARRAY[ROW(2,'LAST'),ROW(3,'LAST'),ROW(4,'LAST')]::unionarg[])</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'><o:p></o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Courier New";color:#222222;border:none windowtext 1.0pt;padding:0cm'>FROM landsat8</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'><o:p></o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Courier New";color:#222222;border:none windowtext 1.0pt;padding:0cm'>WHERE ST_Overlaps(polygon, rast_geom_4326)</span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'><o:p></o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'><o:p> </o:p></span></p></div><div><p class=MsoNormal style='background:white;vertical-align:baseline'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222;border:none windowtext 1.0pt;padding:0cm'>I'm using PostGIS 2.1, my raster is retrieved from <a href="http://earthexplorer.usgs.gov/" target="_blank"><span style='color:#6611CC;text-decoration:none'>earthexplorer.usgs.gov</span></a></span><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#222222'><o:p></o:p></span></p></div></div></body></html>