<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410164#M70321</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422974"&gt;@EdX1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Is your feature class registered as versioned?&amp;nbsp; If it is, has your geodatabase been compressed recently?&amp;nbsp; The compress will clear the A&amp;amp;D (delta) tables, which will improve performance of the feature class.&amp;nbsp; You will want to make sure there are no locks on the feature class when performing the compress.&amp;nbsp; For example, make sure all services are stopped, and all users are disconnected.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Apr 2024 12:03:39 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-04-16T12:03:39Z</dc:date>
    <item>
      <title>How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410019#M70318</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am running a script via the ArcPro python terminal, with the layers I am using in my script open in the project. sTabName is a string which contains the name of the table I have opened in ArcPro.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a table which has 200k records, I wish to update and insert &amp;lt;20 items within this table.&lt;BR /&gt;I need to firstly use an &lt;EM&gt;UpdateCursor&lt;/EM&gt; to update a few rows, then a &lt;EM&gt;InsertCursor&lt;/EM&gt; to insert some rows to replace those I updated.&lt;BR /&gt;&lt;BR /&gt;My code currently:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt; # Create a table view to use within the edit session
            arcpy.SelectLayerByAttribute_management(sTabName, "NEW_SELECTION", where_clause=sOldWhere) 
            TableViewCount = int(arcpy.GetCount_management(sTabName).getOutput(0))
            print(f"sTabName with sql querey: {sOldWhere}, applied. TableViewCount contains: {TableViewCount} rows")

            # Start editing session
            edit = None  # Initialize edit variable
            edit = arcpy.da.Editor(SDE_Workspace_Path)
            edit.startEditing(False, True) 
            edit.startOperation()

            # Retire the old assessments
            print("Retiring old assessment(s)...")
            count = 0
            with arcpy.da.UpdateCursor(sTabName, ("RecordStatus", "Retired")) as oRows:
                for oRow in oRows:
                    oRow[0] = "Retired"
                    sretired = "Title retired &amp;amp; replaced by {0}".format(",".join(aNewSIDs))
                    if len(sretired) &amp;gt; 250:
                        oRow[1] = 'Title retired &amp;amp; replaced by Multiple parcels'
                    else:
                        oRow[1] = sretired
                    oRows.updateRow(oRow)
                count += 1
                print(f"retiring item {count} of {TableViewCount}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;The Problem&lt;/U&gt;:&lt;BR /&gt;This seems to take a very long time to open up the UpdateCursor, &amp;gt;1-2 minutes, and the search cursor which comes after it (not included in code sample).&amp;nbsp;&lt;BR /&gt;How can I improve efficiency given that I am only updating the specific items from&amp;nbsp;&lt;EM&gt;where_clause=sOldWhere?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;I have tried using&lt;/U&gt;:&lt;BR /&gt;&lt;EM&gt;arcpy.MakeTableView_management(sTable_path, "TableView", where_clause=sOldWhere&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;)&lt;BR /&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;SPAN&gt;instead of what is at Line 2, which does seem to run faster, but this creates a tableview item which I then have to remove (to clean up) which adds more processing time once again.&lt;BR /&gt;&lt;BR /&gt;I wish to reduce the processing time of this script as much as possible as it is manually run multiple times over a day to complete a task.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 Apr 2024 00:55:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410019#M70318</guid>
      <dc:creator>EdX1</dc:creator>
      <dc:date>2024-04-16T00:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410164#M70321</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422974"&gt;@EdX1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Is your feature class registered as versioned?&amp;nbsp; If it is, has your geodatabase been compressed recently?&amp;nbsp; The compress will clear the A&amp;amp;D (delta) tables, which will improve performance of the feature class.&amp;nbsp; You will want to make sure there are no locks on the feature class when performing the compress.&amp;nbsp; For example, make sure all services are stopped, and all users are disconnected.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 12:03:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410164#M70321</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-04-16T12:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410235#M70327</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422974"&gt;@EdX1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Have you tried saving the script to a toolbox? I write my scripts with ArcGIS notebooks and I've noticed that when I run them in Notebooks they take 4x longer to complete, I haven't tried the python window, but from my understanding it shouldn't bog down the scripts unless there is something weird going on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway I have a feature class that has 3,000 plus records which searches through all of them and updates all of them and when I run it from a tool box it takes ~30 minutes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would first try saving your code to a tool box and run it from there then try adapting my code below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;MP.clearSelection() #Clears any selected features&lt;/P&gt;&lt;P&gt;arcpy.SetProgressorLabel("Updating attribute information") #Changes tool progress label&lt;BR /&gt;arcpy.SetProgressorPosition(1) #Resets progressor to beginning&lt;/P&gt;&lt;P&gt;arcpy.management.SelectLayerByAttribute(sTabName, where_clause = sOldWhere) #Select features for count&lt;BR /&gt;count = arcpy.management.GetCount(sTabName) #Get count of selected features&lt;/P&gt;&lt;P&gt;print("What you want" + str(count))&lt;/P&gt;&lt;P&gt;if int(str(count)) &amp;gt; 0:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; i = 0&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; while i &amp;lt; int(str(count)):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&amp;nbsp;int((i/int(str(count))*100) &amp;gt; 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.SetProgressorPosition(int((i/int(str(count))*100)) #updates tool progress label&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; now = datetime.datetime.now() #gets time process started&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sTabName.definitionQuery = "Your SQL selection here" #Make it so the search cursor will only have to search the 20 records&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Add your edit line here&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; upcursor = arcpy.da.UpdateCursor(sTabName, ["RecordStatus", "Retired"])&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for row in upcursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row[0] = "Retired"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sretired = "Title retired &amp;amp; replaced by {0}". format(",".join(aNewSIDs))&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if len(sretired)&amp;gt;250:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row[1] = "Title retired &amp;amp; replaced by multiple parcels"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row[1] = sretired&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;upcursor.updaterow(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; edit.stopEditing(True) #saves edits and closes edit session&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end = datetime.datetime.now() #gets time code ended&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elapsed = end - now&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; print("Updating: " + str(count) + " records from " + str(sTabName.name) + ". Elapse time: " + str(elapsed)) #or something similar&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;print(What ever you want)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I slightly adapted that for you, but when I run the code above I get about .5 seconds per record. Hope it works for you!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 14:43:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410235#M70327</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-04-17T14:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410243#M70328</link>
      <description>&lt;P&gt;That is definitely what I would do first. You could also try to &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/rebuild-indexes.htm" target="_self"&gt;rebuild the indexes&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Also add the layer to a map and running some gp tool on it. If it's also slow there, you could try &lt;A href="https://support.esri.com/en-us/knowledge-base/how-to-delete-geoprocessing-history-from-a-geodatabase--000027149" target="_self"&gt;deleting geoprocessing history from the metadata&lt;/A&gt;. Or you could copy the features into a new feature class for testing and run your script on the new feature class to see if the performance is any different.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 14:21:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410243#M70328</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-04-16T14:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410352#M70333</link>
      <description>&lt;P&gt;have you tried putting the where clause in the cursors themselves?&amp;nbsp; Might help limit what is being loaded.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 16:05:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410352#M70333</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-04-16T16:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410688#M70346</link>
      <description>&lt;P&gt;Good suggestion! Also allows me to remove the first 4 lines, and does seem to speed it up a small amount.&amp;nbsp;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 22:48:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410688#M70346</guid>
      <dc:creator>EdX1</dc:creator>
      <dc:date>2024-04-16T22:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410712#M70347</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;&amp;nbsp;Thanks for the suggestion! After some investigation it looks like that db is compressed daily, via a script which runs overnight &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I wasn't aware of this process or what the compressing process was so I still learned something! Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 01:53:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410712#M70347</guid>
      <dc:creator>EdX1</dc:creator>
      <dc:date>2024-04-17T01:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410713#M70348</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;Would you recommend rebuilding the indexes on a regular basis? Is there any possible repercussions with deleting geoprocessing history from the metadata? This table I am editing contains critical data.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 01:52:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410713#M70348</guid>
      <dc:creator>EdX1</dc:creator>
      <dc:date>2024-04-17T01:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410841#M70356</link>
      <description>&lt;P&gt;I would verify the feature classes' A&amp;amp;D tables are cleared after the compress.&amp;nbsp; If there is a lock on the feature class, the compress will skip over the feature class.&amp;nbsp; If your database is SQL Server you can find the correct A&amp;amp;D table with the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;query the sde.sde_table_registry table to get the registration_id.&amp;nbsp; Ex:&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="sql"&gt;select registration_id from dbo.SDE_table_registry where table_name = 'Airports'&lt;/LI-CODE&gt;&lt;P&gt;This will return the registration_id:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1713355838210.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/101198iC802EF8CEB55767D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1713355838210.png" alt="JakeSkinner_0-1713355838210.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will indicate which A&amp;amp;D tables to query.&amp;nbsp; Ex:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_1-1713355908614.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/101199i12B0FBEE8D3E7A18/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_1-1713355908614.png" alt="JakeSkinner_1-1713355908614.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 12:11:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410841#M70356</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-04-17T12:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410992#M70361</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422974"&gt;@EdX1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;Would you recommend rebuilding the indexes on a regular basis? Is there any possible repercussions with deleting geoprocessing history from the metadata? This table I am editing contains critical data.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, you should compress, update statistics, and rebuild indexes on a regular basis.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/manage-oracle/enterprise-geodatabase-maintenance.htm" target="_blank" rel="noopener"&gt;Enterprise geodatabase maintenance tasks—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The only down side to removing geoprocessing history is that you have to have a process to do it and you won't have a history of geoprocessing operations run on the data. If neither of those things are trouble for you or your organization, then go for it.&lt;/P&gt;&lt;P&gt;For me, I try to include the option to not record the gp history in metadata when I run scripts.&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;arcpy.SetLogMetadata(False)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/setlogmetadata.htm" target="_blank" rel="noopener"&gt;SetLogMetadata—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 15:28:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1410992#M70361</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-04-17T15:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1411038#M70362</link>
      <description>&lt;P&gt;Have not tested this with 3.x, but with 2.7, if I commented out any print statements, my scripts will run in a fraction of the time.&lt;/P&gt;&lt;P&gt;So, in most all my scripts, I set a debugPrint variable at the top, then I have replaced the print statements with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;debugPrint = True
.
.
.
if debugPrint:print('What ever you want')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, normally, debugPrint = False so that the script runs much faster, but If I'm having issues, I toggle it to True so I can get the printouts.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 16:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1411038#M70362</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-04-17T16:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1411310#M70366</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I would verify the feature classes' A&amp;amp;D tables are cleared after the compress.&amp;nbsp; If there is a lock on the feature class, the compress will skip over the feature class.&amp;nbsp; If your database is SQL Server you can find the correct A&amp;amp;D table with the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;query the sde.sde_table_registry table to get the registration_id.&amp;nbsp; Ex:&lt;/LI&gt;&lt;/UL&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm glad you posted a follow up to this! It looks like it isn't being compressed as the a/d tables contain:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="EdX1_0-1713395451628.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/101302i64F9A66834B6742A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="EdX1_0-1713395451628.png" alt="EdX1_0-1713395451628.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Which is possibly several years worth of changes!!!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you! In the script that automates the compress it looked like it disconnected users and ran the compress but maybe it doesn't do this table, even though this table is in the same SDE its pointed to do a compress on.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'd better do some deeper investigation...&lt;BR /&gt;Here is the code which should be doing the compress, sdeWorkspace variable contains a .sde connection with a massive amount of data, along with the table which the original question was about.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def compress():
    #block new connections to the database.
    triLogger.info("Stopping new user connections")
    triLogger.info("Workspace:  {0}".format(sdeWorkspace)) 
    arcpy.AcceptConnections(sdeWorkspace, False)
    sleep(120) # ____ 03/28/2023 wait until connections fail. https://support.esri.com/en/technical-article/000018531

    try:
        #  Disconnect users for a full compress
        triLogger.info("Disconnecting users")
        arcpy.DisconnectUser(sdeWorkspace, "ALL")

        # Run the compress tool.
        triLogger.info("Compressing (this may take a while)")
        arcpy.Compress_management(sdeWorkspace)
    except arcgisscripting.ExecuteError:
        triLogger.error(arcpy.GetMessages())
    except:
        triLogger.error("Unexpected error:" + sys.exc_info()[0])
    finally:
        # Allow the database to begin accepting connections again - this is critical so try twice!!!
        triLogger.info("Allowing user connections")
        try:
            arcpy.AcceptConnections(sdeWorkspace, True)
        except arcgisscripting.ExecuteError:
            triLogger.error(arcpy.GetMessages())
            sleep(600) # 10 minutes
            arcpy.AcceptConnections(sdeWorkspace, True)
        except:
            triLogger.error("Unexpected error:", sys.exc_info()[0])
            sleep(600) # 10 minutes
            arcpy.AcceptConnections(sdeWorkspace, True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This script runs every day and it looks like sometimes it only takes 1 minute or so to run the compress, which is conflicting with the comment "(this may take a while)". It obviously isn't compressing the table i'm interested in!&lt;BR /&gt;&lt;BR /&gt;&lt;U&gt;My question:&lt;BR /&gt;&lt;/U&gt;Given the code above, should all items within the sdeWorkspace be getting compressed?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 23:58:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1411310#M70366</guid>
      <dc:creator>EdX1</dc:creator>
      <dc:date>2024-04-17T23:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1411312#M70367</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Have not tested this with 3.x, but with 2.7, if I commented out any print statements, my scripts will run in a fraction of the time.&lt;/P&gt;&lt;P&gt;So, in most all my scripts, I set a debugPrint variable at the top, then I have replaced the print statements with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;debugPrint = True
.
.
.
if debugPrint:print('What ever you want')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, normally, debugPrint = False so that the script runs much faster, but If I'm having issues, I toggle it to True so I can get the printouts.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Thanks! This is a very elegant way to add debug messages rather than commenting them out like I do at the moment!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 23:47:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1411312#M70367</guid>
      <dc:creator>EdX1</dc:creator>
      <dc:date>2024-04-17T23:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1412566#M70403</link>
      <description>&lt;P&gt;Try this, change line 33 to the common field and line 9 &amp;amp; 12.&lt;/P&gt;&lt;P&gt;I haven't tested it yet.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
import os
from openpyxl import load_workbook

# Set the workspace (folder or geodatabase) where the Excel file is stored
arcpy.env.workspace = "C:/Temp"

# Path to the Excel file
excel_file = "C:/Temp/file.xlsx"

# Path to the feature class
feature_class = r"feature class"

# Load the Excel workbook
workbook = load_workbook(excel_file)

# Get the list of worksheet names
worksheet_names = workbook.sheetnames

# Loop through each worksheet
for worksheet_name in worksheet_names:
    # Create a unique name for the table view by replacing problematic characters
    table_view_name = f"View_{worksheet_name.replace('$', '_')}"

    # Create a full path to the Excel worksheet
    worksheet_path = os.path.join(excel_file, f"${worksheet_name}")

    # Create a table view from the Excel sheet
    arcpy.MakeTableView_management(in_table=worksheet_path, out_view=table_view_name)
    print(f"Table view created for {worksheet_name}")

    # Define the join field name, common between the feature class and the Excel sheet
    join_field = "Field" # change field

    # Add a join between the feature class and the table view
    arcpy.AddJoin_management(in_layer_or_view=feature_class, in_field=join_field, 
                             join_table=table_view_name, join_field=join_field, 
                             join_type="KEEP_COMMON")

    # Optionally, you can export the joined data to a new feature class
    output_feature_class = f"Joined_{worksheet_name.replace('$', '_')}"
    arcpy.CopyFeatures_management(in_features=feature_class, out_feature_class=output_feature_class)
    print(f"Joined feature class created: {output_feature_class}")

    # Remove the join to clean up before the next iteration
    #arcpy.RemoveJoin_management(feature_class)

    # Delete the table view to avoid locks and clean up
    #arcpy.Delete_management(table_view_name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 23:01:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1412566#M70403</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-04-19T23:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to improve arcpy.da.UpdateCursor / InsertCursor performance?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1415972#M70481</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/422974"&gt;@EdX1&lt;/a&gt;&amp;nbsp;, take a look at the following &lt;A href="https://community.esri.com/t5/arcgis-enterprise-documents/compress-geodatabase/ta-p/1415967" target="_self"&gt;document&lt;/A&gt;.&amp;nbsp; It contains a script that will compress your geodatabase and output a DeltaCounts.csv file showing the before and after counts of the A &amp;amp; D tables.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 17:19:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-improve-arcpy-da-updatecursor-insertcursor/m-p/1415972#M70481</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-04-26T17:19:30Z</dc:date>
    </item>
  </channel>
</rss>

