Select to view content in your preferred language

ArcSDESQLExecute to delete sde.sde_versions table orphaned records

643
16
06-03-2024 07:23 AM
Labels (3)
vijaybadugu
Occasional Contributor II

I have already created few read-only offline maps for just read only purpose. When we create a offline maps, it does create replications in geodatabase. when users download the offline maps from devices, it does create a replica and few orphaned records got inserted in sde.sde_versions  table. the records are not being deleted even though we unregistered the replicas and deleted offline maps from the devices. in order to compress the database, we should delete orphaned records and unregister the replicas. I have already written a python job to automate this process.  I am able to unregister the replicas successfully without any issue, the problem is with deleting records from sde_versions table,

sde_conn = arcpy.ArcSDESQLExecute(gdb_conn)
sql_query = "DELETE FROM sde.sde_versions WHERE name LIKE 'SYNC_%'"
sde_conn.execute(sql_query)

even though the statement executed successfully, the records are still exists in the table. Please suggest on this to proceed further. 

0 Kudos
16 Replies
MarceloMarques
Esri Regular Contributor

@vijaybadugu - you cannot delete records from the sde.sde_versions table directly because you will corrupt your geodatabase, a traditional version in the geodatabase is not just a record in the sde.sde_versions table, there are many other tables in the sde repository and the data that reference the version, to delete versions use the GP Tool Delete Version.

You can call the GP Tools from an arcpy python script.

1. GP Tool Unregister Replica.
Unregister Replica (Data Management)—ArcGIS Pro | Documentation

2. GP Tool Delete Version.

Delete Version (Data Management)—ArcGIS Pro | Documentation

3. After the versions are deleted, run the GP Tool Compress.

Compress (Data Management)—ArcGIS Pro | Documentation

I hope this helps.

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
0 Kudos
vijaybadugu
Occasional Contributor II

I tried delete version tool to remove the orphaned versions . It did not delete the orphaned records . It deletes only visible versions not hidden ones . I have no clue on this . I have been deleting records from sde_versions as suggested by esri technical team using delete sql statement using sql server .  now , I decided to automate the process

0 Kudos
MarceloMarques
Esri Regular Contributor

It surprises me that Esri Technical Support suggested to delete records directly in the sde.sde_versions table, because is well known that any attempt to make changes directly in the arcsde repository tables can corrupt the geodatabase, I believe Esri Support should have diagnosed your workflow differently and perhaps logged a bug or asked for enhancement request if a solution could not be found using arcpy python scripts and GP tools.

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
0 Kudos
vijaybadugu
Occasional Contributor II

Ok. I am able to unregister the replicas and I could not delete hidden records with delete version tool. Could you please suggest any other solution 

0 Kudos
MarceloMarques
Esri Regular Contributor

This sounds like a bug to me, as I never encountered issues, I was always able to unregister the replicas and delete the versions that were associated with the replicas. You might check if all users and services are disconnected prior to attempt to do these tasks.

On the other hand, if the issue still persists then you will need to work with Esri Support and they will need a copy of your enterprise geodatabase to diagnose the problem, and try to reproduce the issue, then Esri Support can try to find a workaround and/or log a new bug and/or request an enhancement request.

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
0 Kudos
vijaybadugu
Occasional Contributor II

I will try again using your suggestion before going to the support team. How to delete hidden SYNC versions associated with replica? 

0 Kudos
MarceloMarques
Esri Regular Contributor

I connect with the sde user and I am able to see all the versions, then I am able to unregister the replicas, and then delete the versions that were associated with the replicas.

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
0 Kudos
vijaybadugu
Occasional Contributor II

When i see in SQL Server sde_versions table , 

vijaybadugu_0-1717432114270.png

 

at the same time, I logged in as a SA user, 

I could not see any versions 

vijaybadugu_1-1717432165417.png

 

 

 

0 Kudos
MarceloMarques
Esri Regular Contributor

If you logged as SA user, then this is the SQL Server Instance System Administrator, the SQL Server Geodatabase is not designed to work with the SA user.

You must use ArcGIS to connect to the SQL Server Geodatabase using the SDE user, the owner of the ArcSDE Repository, which will be able to see all the versions and delete any versions, if you connect with the data owner user, then you will still see all versions but the data owner user will be able to delete only the versions that the data owner user created.

You will not be able to delete a version if there are other users connected that might be using that version, hence make sure you disconnect all users and stop all ArcGIS Server services, then you can perform the unregister replica, and delete the versions associated with the replica, but you need to connect with the SDE user.

| Marcelo Marques | Principal Product Engineer | Esri |
| Cloud & Database Administrator | OCP - Oracle Certified Professional |
I work with Enterprise Geodatabases since 1997.
“ I do not fear computers. I fear the lack of them." Isaac Isimov
0 Kudos