You may reduce the number of  XDBC connects by 50%
#1)
Create an SQL function for the update

CREATE FUNCTION done_func(integer,varchar) RETURNS integer
    AS 'update my_postgres_table set status=$2 where id=$1'
    LANGUAGE SQL
    IMMUTABLE
    RETURNS NULL ON NULL INPUT
    RETURN 1 ;

#2)
run your SELECT, adding the function in your WHERE clause which is always TRUE
 

select * from my_postgres_table limit 10000 Where 1 = done_Func(id,'S')	

You should check the exact syntax for PostgreSQL
I just composed it guided by
https://www.postgresql.org/docs/current/sql-createfunction.html 
 

1) you miss a final condition in $SELECT(). It's the 1:
$SELECT(^GlFSL("Debug")>0:Entry^HS.Local.VA.Util.Log(%arr,,"D"),1:QUIT)
2) QUIT doesn't return a value but <UNDEFINED> error if you don't have 
a SET QUIT=""  somwhere before or use $GET()
this may fit

$SELECT(^GlFSL("Debug")>0:Entry^HS.Local.VA.Util.Log(%arr,,"D"),1:$GET(QUIT))

Command QUIT is just appropriate with $CASE(...)
https://docs.intersystems.com/iris20252/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fselect#RCOS_fselect_select_and_case

Well, you have to do it yourself.
Suggestion: Keep a list of the indices processed and skip all followers
For the list you need a small Stored Procedure that you add to
your SQL SELECT in the WHERE clause.

CREATE PROCEDURE SQLUSER.DUPL(value VARCHAR, id INTEGER)
RETURNS INTEGER
LANGUAGE OBJECTSCRIPT
{
 set used=$d(^||dupl(value))
 set ^||dupl(value,id)=$i(^||dupl(value))  
 quit used
}

And in the SELECT

SELECT id, sickindex, . . . . . 
FROM your.data 
WHERE DUPL(sickindex,id) < 1

As a side effect, you create a list of affected indices.
I used a PPG to avoid the need to clear it before use.
If you are interested in the duplicate, you need to change the global name
and add some cleanup before use  

 

1.  Use $$DIR^TRACE(dir)  you haven't set a suitable directory
2.  Use $$ON^TRACE(5352)  ; the job you want to trace ==> open file
3:  USE $$OFF ^TRACE(5352) to stop trace ==> close file
4.Now ^TRACE should show the file

I traced my own studio session:

START:1810291850,0,%SYS.BINDSRV,2,1
STACK: [ 0] D - SuperServer+112^%SYS.SERVER +1
STACK: [ 1] D - SuperConnect+34^%SYS.DBSRV +1
STACK: [ 2] D - Dispatch+14^%SYS.BINDSRV +1
DO:1812736542,0,%SYS.BINDSRV,39
ARG:[ 0] INT: 0
ARG:[ 1] INT: 1
ARG:[ 2] INT: 1
DO:1812736624,0,%SYS.BINDSRV,625
ARG:[ 0] INT: 0
ARG:[ 1] INT: 0
DO:1812736631,0,%SYS.BINDSRV,258
ARG:[ 0] INT: 0
ARG:[ 1] INT: 0
QUIT:1812736638,291
DO:1812736642,0,%SYS.BINDSRV,627

Not sure for Caché 2017 
BUT
Cache for UNIX (Red Hat Enterprise Linux for x86-64) 2018.1.5 (Build 659U) Mon Mar 22 2021 07:12:43 EDT
Has ^TRACE in %SYS
with enough $v(..) and $ZU(..) to look promising 

 W $ZU(5)
%SYS
%SYS>D ^TRACE
 
TRACE utility for Cache. You can signal a process to write a record of all
procedure, function, or subroutine calls to a file. Then use this utility to 
interpret and display the trace. The trace file is named: CacheTrace_'pid'.txt 

Use $$DIR^TRACE(dir) to set the directory where the file(s) should be written
(process must have create/write access to the directory). $$DIR^TRACE() returns
the current directory for trace files. 

Use $$ON^TRACE(pid) to start the trace and $$OFF^TRACE(pid) to end the 
recording. Then just run ^TRACE to see the results. 

Process ID for trace file: 

In your screenshot, I see 

$('<div>') simpledialog2(

But W3Schools says:
https://www.w3schools.com/Jquery/jquery_syntax.asp

Basic syntax is: $(selector).action()
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)

I didn't write JavaScript for decades, and I'm not an expert.
BUT: I fail to detect the point after the closing bracket
It was just my Studio that marked it as an error.

created with NPI

In short: 

  • Index ZipIDX On (City,State)  sorts by 2 levels City and State and holds a pointer to the  referred record
  • Index ZipIDX On ZipCode [ Data = (City,State) ] sorts just by ZipCode and holds a pointer to the  referred record but also a copy of City and State This is faster if all you want is to map ZIP to City, State and have no need to access what else is in your record

I did this to verify my approach looping over a simulated table of 100 mio rows

  • SQL procedure TEST1 uses an external Class Method based on anna.INC
  • SQL procedure TEST2 uses an internal Class Method based on anna.INC

The difference is evident:

[SQL]SAMPLES>>select A.HUGE_fill(100000000)
18.     select A.HUGE_fill(100000000)
 
| Expression_1 |
| -- |
| ^A.HUGED=100000000 |
 
1 Rows(s) Affected
statement prepare time(s)/globals/cmds/disk: 0.0008s/5/828/0ms
          execute time(s)/globals/cmds/disk: 18.8332s/100,000,002/200,000,445/0ms
                                query class: %sqlcq.SAMPLES.cls3
---------------------------------------------------------------------------
[SQL]SAMPLES>>select list(A.HUGE_TEST1(ID)) from A.HUGE
19.     select list(A.HUGE_TEST1(ID)) from A.HUGE
 
| Aggregate_1 |
| -- |
|  |
 
1 Rows(s) Affected
statement prepare time(s)/globals/cmds/disk: 0.0005s/4/141/0ms
          execute time(s)/globals/cmds/disk: 101.5573s/100,000,001/700,000,424/0ms
                                query class: %sqlcq.SAMPLES.cls2
---------------------------------------------------------------------------
[SQL]SAMPLES>>select list(A.HUGE_TEST2(ID)) from A.HUGE
20.     select list(A.HUGE_TEST2(ID)) from A.HUGE
 
| Aggregate_1 |
| -- |
|  |
 
1 Rows(s) Affected
statement prepare time(s)/globals/cmds/disk: 0.0005s/4/141/0ms
          execute time(s)/globals/cmds/disk: 72.1640s/100,000,001/700,000,424/0ms
                                query class: %sqlcq.SAMPLES.cls1
---------------------------------------------------------------------------
[SQL]SAMPLES>>

Rough calculation: including the code in the class saves ~30% of execution time

my class code

Include anna
Class A.HUGE Extends (%Persistent, %Populate)
{
Property calc As %Integer [ Calculated, SqlComputeCode = { set {*}={%%ID}}, SqlComputed ];
ClassMethod fill(size) As %String [ SqlProc ]
{
	for i=1:1:size set ^A.HUGED(i)=""
	set ^A.HUGED=i
	quit $ZR_"="_@$ZR
}
ClassMethod test1(val) As %String [ SqlProc ]
{
	quit ##class(A.PERSON).Anna(val)
}
ClassMethod test2(val) As %String [ SqlProc ]
{
	quit $$anna(val)
}

The simplified anna,INC just returns NullString to concentrate on code switching

anna(name) 
 quit ""

Loading compiled obj code from cache to partition should not have any remarkable impact.
But you are right by principle ! It's some kind of overhead and not for free.

If you place the affected code into a .INC routine you may share that piece
rather easy over multiple instances.
Though mostly not used in that way any Include may also contain executable code.
For a :MAC routine it's  nothing impressive.
For Class code it's a bit tricky but works as well

example ANNA.INC

anna(name) ;
 write !,"Hello ",name,!
 quit ">>>"_name_"<<<"

example Anna.CLS
 

/// demo for Anna
Include ANNA
Class A.Anna {
ClassMethod demo(name As %String) As %String
{
	quit $$anna(name)
}
}

It works:

SAMPLES>write "===",##class(A.Anna).demo("robert")
===
Hello robert
>>>robert<<<
SAMPLES>

So multiple loading is reduced.

You have of course also the option to compose a Custom Command in %ZLANG***.MAC
I just have no experience of how this impacts partition loading.
 

#1) in %SYS find the sessions by this Stored Procedure:

#2 Next based on the SessionId I can open the Object
 

%SYS>set sess=##class(%CSP.Session).%OpenId("kTkyVXwgxw")
%SYS>set pid=sess.ProcessId
%SYS>if $l(pid) set tSC=$$DeleteSession^%SYS.cspServer(pid)

The last row was found in  
Class %CSP.UI.Portal.CSPSessions
ClassMethod EndSession

Attention. Not every CSP Session has also a pid !