<div dir="ltr"><font face="arial, sans-serif">Hi Regina,</font><div><br></div><div>Below is the command that was run by pg_upgrade</div><div><br></div><div><div style="font-size:12px;line-height:18px;white-space:pre"><div style="font-family:Menlo,Monaco,"Courier New",monospace"><font color="#000000">"/usr/pgsql-15/bin/pg_restore" --host /tmp --port 5302 --username postgres --create --exit-on-error --verbose --dbname template1 "/data/pg/13/pg_upgrade_dump_16403.custom"</font></div><div style="font-family:Menlo,Monaco,"Courier New",monospace"><font color="#000000"><br></font></div><div><font color="#000000" face="arial, sans-serif">Thanks,</font></div><div><font color="#000000" face="arial, sans-serif">Nikhil</font></div><div style="font-family:Menlo,Monaco,"Courier New",monospace;color:rgb(0,0,0)"><span style="color:rgb(163,21,21)"><br></span></div></div></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Jun 30, 2025 at 6:27 PM Regina Obe <<a href="mailto:lr@pcorp.us">lr@pcorp.us</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="msg-6962432331751458666"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-6962432331751458666WordSection1"><p class="MsoNormal">Yes ST_Transform refers to spatial_ref_sys too.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">This one is a bit odd though I thought during regular pg_resstore that CREATE EXTENSION postgis is one of the first steps that happens, so this should never happen.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">What commands are you using for pg_restore?<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><div style="border-width:medium medium medium 1.5pt;border-style:none none none solid;border-color:currentcolor currentcolor currentcolor blue;padding:0in 0in 0in 4pt"><div><div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(225,225,225) currentcolor currentcolor;padding:3pt 0in 0in"><p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> Nikhil Shetty <<a href="mailto:nikhil.dba04@gmail.com" target="_blank">nikhil.dba04@gmail.com</a>> <br><b>Sent:</b> Monday, June 30, 2025 6:14 AM<br><b>To:</b> <a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a><br><b>Cc:</b> Jeevan Chalke <<a href="mailto:jeevan.chalke@enterprisedb.com" target="_blank">jeevan.chalke@enterprisedb.com</a>>; <a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br><b>Subject:</b> Re: pg_upgrade fails due to lack of dependencies.<u></u><u></u></span></p></div></div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">Hi All,<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">We also faced a similar issue during pg_upgrade. Table <span style="font-size:9pt;font-family:"Courier New";color:black">spatial_ref_sys </span><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">is not created and when pg_restore creates a table referring to</span><span style="font-size:9pt;font-family:"Courier New";color:black"> spatial_ref_sys</span><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">, it will error out.</span><u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">I am upgrading PostgreSQL 13 and PostGIS 3.1.2 TO PostgreSQL 15 and PostGIS 3.4.2<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:blue">pg_restore:</span><span style="font-size:9pt;font-family:"Courier New";color:black"> creating </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">TABLE</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"table1"</span><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:blue">pg_restore:</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(175,0,219)">while</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">PROCESSING</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:blue">TOC:</span><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:blue">pg_restore:</span><span style="font-size:9pt;font-family:"Courier New";color:black"> from </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">TOC</span><span style="font-size:9pt;font-family:"Courier New";color:black"> entry </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">551</span><span style="font-size:9pt;font-family:"Courier New";color:black">; </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">1259</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">39789310</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">TABLE</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">table1</span><span style="font-size:9pt;font-family:"Courier New";color:black"> db1<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:blue">pg_restore:</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:blue">error:</span><span style="font-size:9pt;font-family:"Courier New";color:black"> could not execute </span><span style="font-size:9pt;font-family:"Courier New";color:blue">query:</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:blue">ERROR:</span><span style="font-size:9pt;font-family:"Courier New";color:black">  relation </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public.spatial_ref_sys"</span><span style="font-size:9pt;font-family:"Courier New";color:black"> does not exist<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">LINE</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">1</span><span style="font-size:9pt;font-family:"Courier New";color:black">: ...</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">LECT</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">proj4text</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">auth_name</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">auth_srid</span><span style="font-size:9pt;font-family:"Courier New";color:black">, srtext </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">FROM</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:blue">public</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">spa</span><span style="font-size:9pt;font-family:"Courier New";color:black">...<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black">                                                             ^<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:blue">QUERY:</span><span style="font-size:9pt;font-family:"Courier New";color:black">  </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">SELECT</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">proj4text</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">auth_name</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">auth_srid</span><span style="font-size:9pt;font-family:"Courier New";color:black">, srtext </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">FROM</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:blue">public</span><span style="font-size:9pt;font-family:"Courier New";color:black">.spatial_ref_sys </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">WHERE</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,16,128)">srid</span><span style="font-size:9pt;font-family:"Courier New";color:black"> = </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">3857</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">LIMIT</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">1</span><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">Command</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:blue">was:</span><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p></div><div><div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">CREATE</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">TABLE</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">table1</span><span style="font-size:9pt;font-family:"Courier New";color:black"> (</span><span style="font-size:9pt;font-family:"Courier New""><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black">    </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"id1"</span><span style="font-size:9pt;font-family:"Courier New";color:black"> numeric </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">NOT</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">NULL</span><span style="font-size:9pt;font-family:"Courier New";color:black">,<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black">    </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"geom"</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public"</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"geometry"</span><span style="font-size:9pt;font-family:"Courier New";color:black">(</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">Geometry</span><span style="font-size:9pt;font-family:"Courier New";color:black">,</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">4326</span><span style="font-size:9pt;font-family:"Courier New";color:black">),<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black">    </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"geom_3857"</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public"</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"geometry"</span><span style="font-size:9pt;font-family:"Courier New";color:black">(</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">Geometry</span><span style="font-size:9pt;font-family:"Courier New";color:black">,</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">3857</span><span style="font-size:9pt;font-family:"Courier New";color:black">) </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">GENERATED</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">ALWAYS</span><span style="font-size:9pt;font-family:"Courier New";color:black"> </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">AS</span><span style="font-size:9pt;font-family:"Courier New";color:black"> (</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public"</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"st_transform"</span><span style="font-size:9pt;font-family:"Courier New";color:black">(</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public"</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"st_intersection"</span><span style="font-size:9pt;font-family:"Courier New";color:black">(</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"geom"</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public"</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"st_transform"</span><span style="font-size:9pt;font-family:"Courier New";color:black">(</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"public"</span><span style="font-size:9pt;font-family:"Courier New";color:black">.</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(163,21,21)">"st_tileenvelope"</span><span style="font-size:9pt;font-family:"Courier New";color:black">(</span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">0</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">0</span><span style="font-size:9pt;font-family:"Courier New";color:black">, </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">0</span><span style="font-size:9pt;font-family:"Courier New";color:black">), </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">4326</span><span style="font-size:9pt;font-family:"Courier New";color:black">)), </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(9,134,88)">3857</span><span style="font-size:9pt;font-family:"Courier New";color:black">)) </span><span style="font-size:9pt;font-family:"Courier New";color:rgb(0,112,193)">STORED</span><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black">);<u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-family:"Times New Roman",serif;color:black">IS st_transform function is referring to </span><span style="font-size:9pt;font-family:"Courier New";color:black">'spatial_ref_sys'?.</span><span style="color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">Thanks,</span><span style="font-size:9pt;color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">Nikhil</span><span style="font-size:9pt;color:black"><u></u><u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p></div><div><p class="MsoNormal" style="line-height:13.5pt"><span style="font-size:9pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p></div></div></div></div></div></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">On Sat, May 17, 2025 at 12:35<span style="font-family:Arial,sans-serif"> </span>AM <<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>> wrote:<u></u><u></u></p></div><blockquote style="border-width:medium medium medium 1pt;border-style:none none none solid;border-color:currentcolor currentcolor currentcolor rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in"><div><div><div><p class="MsoNormal">Okay seems like an issue with pg_upgrade frankly that it doesn’t also load data in an extension it is restoring from the migrated cluster and how the heck it doesn’t even load the structure before any user data seems like real bug.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">As mentioned I think the reason we never see this issue is because most people use 4326 for geography and that I suspect is hard-coded in our system to be never checked against spatial_ref_sys cause it’s the default.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I’ve ticketed issue here - <a href="https://trac.osgeo.org/postgis/ticket/5899" target="_blank">https://trac.osgeo.org/postgis/ticket/5899</a><u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Paul,<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">You think there is some way we could just hard-code longlat srids in PostGIS code (or check proj sqlite db now that we require newer proj anyway) to address, so there is no dependency with spatial_ref_sys when the code is confirming the srid is a longlat projection.<u></u><u></u></p><p class="MsoNormal">I’m assuming that’s why it’s checking spatial_ref_sys in the first place <u></u><u></u></p><p class="MsoNormal">Only if it can’t find it in our list would it then resort to interrogating spatial_ref_sys?<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal">Regina<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><div style="border-width:medium medium medium 1.5pt;border-style:none none none solid;padding:0in 0in 0in 4pt;border-color:currentcolor currentcolor currentcolor blue"><div><div style="border-width:1pt medium medium;border-style:solid none none;padding:3pt 0in 0in;border-color:currentcolor"><p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> Jeevan Chalke <<a href="mailto:jeevan.chalke@enterprisedb.com" target="_blank">jeevan.chalke@enterprisedb.com</a>> <br><b>Sent:</b> Friday, May 16, 2025 6:58 AM<br><b>To:</b> <a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a><br><b>Cc:</b> <a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br><b>Subject:</b> Re: pg_upgrade fails due to lack of dependencies.</span><u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><p class="MsoNormal">Thank you, Regina <u></u><u></u></p><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">You’re right -- this dependency alone doesn't fully resolve the issue.<u></u><u></u></p></div><div><p class="m_-6962432331751458666m2599589297390036943gmail-">We did receive a complaint about missing data in the <code><span style="font-size:10pt">spatial_ref_sys</span></code> table, with the error:<br><code><span style="font-size:10pt">ERROR: Cannot find SRID (4283) in spatial_ref_sys</span></code>.<u></u><u></u></p><p class="m_-6962432331751458666m2599589297390036943gmail-">By tweaking <code><span style="font-size:10pt">pg_dump</span></code>, we managed to dump data for this table <em><span style="font-family:Aptos,sans-serif">before</span></em> any user tables accessed it. However, we later encountered a new issue:<br><code><span style="font-size:10pt">ERROR: relation "public.spatial_ref_sys" does not exist</span></code>.<u></u><u></u></p><p class="m_-6962432331751458666m2599589297390036943gmail-">As a PostgreSQL developer, this new error came as a surprise. The table in question is part of an extension, and that extension does create it. Upon further investigation, I discovered that the issue lies in the sort order used by <code><span style="font-size:10pt">pg_dump</span></code> when dumping extension and user tables, the order isn't always correct. Although <code><span style="font-size:10pt">pg_dump</span></code> and <code><span style="font-size:10pt">pg_restore</span></code> are generally smart enough to account for object dependencies, based on entries in the <code><span style="font-size:10pt">pg_depend</span></code> catalog, this case seems to expose a gap in that logic.<u></u><u></u></p><p class="m_-6962432331751458666m2599589297390036943gmail-">Specifically, since both <code><span style="font-size:10pt">spatial_ref_sys</span></code> and <code><span style="font-size:10pt">geography</span></code> are part of the same extension and have a dependency relationship, this relationship is <em><span style="font-family:Aptos,sans-serif">not</span></em> reflected in the <code><span style="font-size:10pt">pg_depend</span></code> table. If it were, <code><span style="font-size:10pt">pg_dump</span></code> would ensure the table is dumped before the dependent type, avoiding this issue. This is what I’ve suggested as a fix.<u></u><u></u></p><p class="m_-6962432331751458666m2599589297390036943gmail-">We encountered this problem while using the latest server versions for PostgreSQL v11, v13, and v16, along with PostGIS versions 3.2.4 and 3.4.3.<u></u><u></u></p><p class="m_-6962432331751458666m2599589297390036943gmail-">Thanks<u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Thu, May 15, 2025 at 10:03<span style="font-family:Arial,sans-serif"> </span>PM <<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>> wrote:<u></u><u></u></p></div><blockquote style="border-width:medium medium medium 1pt;border-style:none none none solid;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt;border-color:currentcolor currentcolor currentcolor rgb(204,204,204)"><div><div><div><p class="MsoNormal">I think we have a tickets somewhere complaining about issues with pg_upgrade and geography, but they have always involved just data missing in spatial_ref_sys.<u></u><u></u></p><p class="MsoNormal">I found this one - <a href="https://trac.osgeo.org/postgis/ticket/4405" target="_blank">https://trac.osgeo.org/postgis/ticket/4405</a>  but these cases have always been issues with data not present in spatial_ref_sys rather than the table being missing.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">What puzzles me is how this dependency even helps, cause that still wouldn’t guarantee data in the spatial_ref_sys table is loaded and ultimately I would assume it is checking spatial_ref_sys to make sure 4283 is a valid longlat projection and will fail if it can’t find it.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I thought extensions are always created before user tables so should only be an issue with the data in them and why spatial_ref_sys doesn’t even exist when you load the user table makes no sense.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I don’t see how putting  dependency between geography type and spatial_ref_sys would help here and I’ve never seen this particular error before.<u></u><u></u></p><p class="MsoNormal">I suppose it’s possibly most people just use 4326 which geography doesn’t need to verify cause that’s the default srid used for geography when none is specified so is probably hard-coded in our system and that might explain why we’ve never seen this issue.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">That said, can you give us the output of your postgis versions from your PostgreSQL 11 and PostgreSQL 13<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">And also what versions of 11 and 13 you are running.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal">Regina<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><div style="border-width:medium medium medium 1.5pt;border-style:none none none solid;padding:0in 0in 0in 4pt;border-color:currentcolor currentcolor currentcolor blue"><div><div style="border-width:1pt medium medium;border-style:solid none none;padding:3pt 0in 0in;border-color:currentcolor"><p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> Jeevan Chalke <<a href="mailto:jeevan.chalke@enterprisedb.com" target="_blank">jeevan.chalke@enterprisedb.com</a>> <br><b>Sent:</b> Thursday, May 15, 2025 9:42 AM<br><b>To:</b> <a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br><b>Subject:</b> Re: pg_upgrade fails due to lack of dependencies.</span><u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">PostGIS hackers/developers,<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">Does this addition make sense?<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Wed, May 14, 2025 at 11:07<span style="font-family:Arial,sans-serif"> </span>AM Jeevan Chalke <<a href="mailto:jeevan.chalke@enterprisedb.com" target="_blank">jeevan.chalke@enterprisedb.com</a>> wrote:<u></u><u></u></p></div><blockquote style="border-width:medium medium medium 1pt;border-style:none none none solid;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt;border-color:currentcolor currentcolor currentcolor rgb(204,204,204)"><div><div><p class="MsoNormal">Hello,<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal" style="margin-bottom:12pt">While working with one of our customers, we observed that <span style="font-family:"Courier New"">pg_upgrade</span> is failing with PostGIS.<br><br>What is happening is (SQL attached below), the user table <span style="font-family:"Courier New"">"prosch"."MyTab"</span> has a column of type <span style="font-family:"Courier New"">"public"."geography"</span>, which, in turn, references a row in <span style="font-family:"Courier New"">public.spatial_ref_sys</span>. While there is a recorded dependency between <span style="font-family:"Courier New"">"procsch"."MyTab"</span> and <span style="font-family:"Courier New"">"public"."geography"</span>, no such dependency exists between <span style="font-family:"Courier New"">"public"."geography"</span> and <span style="font-family:"Courier New"">public.spatial_ref_sys</span>.<br><br>As a result, while the type <span style="font-family:"Courier New"">"public"."geography"</span> is created before the user table, <span style="font-family:"Courier New"">spatial_ref_sys</span> is not. Due to sorting (in <span style="font-family:"Courier New"">pg_dump</span>), the user table is dumped before <span style="font-family:"Courier New"">spatial_ref_sys</span>, leading to an error during restoration.<br><br>Since PostgreSQL does not maintain dependencies at the row level (and thus not for tables containing such rows), the extension itself should explicitly define this dependency. This would ensure that <span style="font-family:"Courier New"">public.spatial_ref_sys</span> is dumped before the type <span style="font-family:"Courier New"">"public"."geography"</span>, preventing issues during dump and restore.<br><br>If we manually add the dependency in the source database, <span style="font-family:"Courier New"">pg_upgrade</span> will work well. The query to achieve this is:<br><br><span style="font-family:"Courier New"">INSERT INTO pg_depend VALUES (<br>  'pg_catalog.pg_type'::regclass::oid, 'public.geography'::regtype::oid, 0,<br>  'pg_catalog.pg_class'::regclass::oid, 'public.spatial_ref_sys'::regclass::oid, 0,<br>  'n');</span><br><br>Can this be considered a valid request and added to the extension SQL file itself?<br><br>---<br><br>Here is the SQL sequence that yields an error (shared by one of our engineers)<u></u><u></u></p></div><div><p class="MsoNormal"><span style="font-family:"Courier New"">CREATE SCHEMA procsch;<br>CREATE TABLE "procsch"."MyTab" (<br>    "id" bigint,<br>    "loc" "public"."geography"(Point,4283)<br>);<br><br>INSERT INTO procsch.MyTab VALUES (1, ST_GeomFromText('POINT(152.138672 -30.689888)', 4283));<br><br>$ strings /PATH/bin/pg_dump | grep POSTGIS_spatial<br>POSTGIS_spatial_ref_sys<br>$<br><br>/PATH/bin/initdb -D /srv/13/data/pg_data<br>/PATH11/bin/pg_ctl -D /srv/11/data/pg_data -l logfile stop<br>/PATH/bin/pg_upgrade --check --link --old-datadir=/srv/11/data/pg_data --new-datadir=/srv/13/data/pg_data --old-bindir=/PATH11/bin --new-bindir=/PATH/bin --old-port=5432 --new-port=5434<br># for real, no --check:<br>/PATH/bin/pg_upgrade --link --old-datadir=/srv/11/data/pg_data --new-datadir=/srv/13/data/pg_data --old-bindir=/PATH11/bin --new-bindir=/PATH/bin --old-port=5432 --new-port=5434</span><br><br><br>And it did blow up with : <br><br><br><span style="font-family:"Courier New"">[..]<br>pg_restore: creating TABLE "procsch.MyTab"<br>pg_restore: while PROCESSING TOC:<br>pg_restore: from TOC entry 371; 1259 17425 TABLE MyTab u1<br>pg_restore: error: could not execute query: ERROR:  relation "public.spatial_ref_sys" does not exist<br>LINE 21:     "loc" "public"."geography"(Point,4283)<br>                   ^<br>QUERY:  SELECT proj4text, auth_name, auth_srid, srtext FROM public.spatial_ref_sys WHERE srid = 4283 LIMIT 1<br>[..]<br>CREATE TABLE "procsch"."MyTab" (<br>    "id" bigint,<br>    "loc" "public"."geography"(Point,4283)<br>);<br>[..]</span><u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">Thanks<u></u><u></u></p></div><p class="MsoNormal"><span class="m_-6962432331751458666m2599589297390036943m-1792571721072084611gmailsignatureprefix">-- </span><u></u><u></u></p><div><div><div><div><div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"><img border="0" width="200" height="37" style="width: 2.0833in; height: 0.3854in;" id="m_-6962432331751458666_x0000_i1027" src="https://ci3.googleusercontent.com/mail-sig/AIorK4wUmLsFZCrsP0IzlqcrOBS4LG-QdOAM_CPz15Rip0P4elztKb7pS0FF_Tbb_lCOORByN9lcXUTXqe-8"><u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"><b>Jeevan Chalke</b><br><i><span style="font-family:Arial,sans-serif;color:rgb(29,28,29)">Principal Engineer, Engineering Manager</span><br>Product Development</i><br><b><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(255,62,0);background:repeat white"><br><a href="https://www.enterprisedb.com" target="_blank">enterprisedb.com</a></span></b><u></u><u></u></p></div></div></div></div></div></div></div></div></div></blockquote></div><div><p class="MsoNormal"><br clear="all"><u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><p class="MsoNormal"><span class="m_-6962432331751458666m2599589297390036943m-1792571721072084611gmailsignatureprefix">-- </span><u></u><u></u></p><div><div><div><div><div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"><img border="0" width="200" height="37" style="width: 2.0833in; height: 0.3854in;" id="m_-6962432331751458666_x0000_i1026" src="https://ci3.googleusercontent.com/mail-sig/AIorK4wUmLsFZCrsP0IzlqcrOBS4LG-QdOAM_CPz15Rip0P4elztKb7pS0FF_Tbb_lCOORByN9lcXUTXqe-8"><u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"><b>Jeevan Chalke</b><br><i><span style="font-family:Arial,sans-serif;color:rgb(29,28,29)">Principal Engineer, Engineering Manager</span><br>Product Development</i><br><b><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(255,62,0);background:repeat white"><br><a href="https://www.enterprisedb.com" target="_blank">enterprisedb.com</a></span></b><u></u><u></u></p></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div><div><p class="MsoNormal"><br clear="all"><u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><p class="MsoNormal"><span class="m_-6962432331751458666m2599589297390036943gmailsignatureprefix">-- </span><u></u><u></u></p><div><div><div><div><div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"><img border="0" width="200" height="37" style="width: 2.0833in; height: 0.3854in;" id="m_-6962432331751458666_x0000_i1025" src="https://ci3.googleusercontent.com/mail-sig/AIorK4wUmLsFZCrsP0IzlqcrOBS4LG-QdOAM_CPz15Rip0P4elztKb7pS0FF_Tbb_lCOORByN9lcXUTXqe-8"><u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"><b>Jeevan Chalke</b><br><i><span style="font-family:Arial,sans-serif;color:rgb(29,28,29)">Principal Engineer, Engineering Manager</span><br>Product Development</i><br><b><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(255,62,0);background:repeat white"><br><a href="https://www.enterprisedb.com" target="_blank">enterprisedb.com</a></span></b><u></u><u></u></p></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div>