Offline Geodatabase Deltas with SQL
Posted: July 1, 2019 Filed under: ArcGIS Collector, ArcGIS Runtime, DBMS, DBMS Administration, Offline Geodatabase, SQL, Sqlite 1 Comment
Whether you’re editing features in an ArcGIS Collector application or a custom ArcGIS Runtime application, in offline situations, a SQLite geodatabase is created on the device to manage changes to the feature classes. There are a few ways to access an offline geodatabase in ArcGIS Desktop/Pro but I wanted to provide an example of using SQL to view the feature changes.
Direct Connections with SDE SDK
Posted: April 26, 2017 Filed under: Programming, SDE Client, SDE Install, SDE SDK | Tags: ArcSDE, C API, Java, Oracle, Sql Server Leave a commentIf you’re still maintaining applications written in the Java or C ArcSDE API you may already know you’re getting close to the end of the code base’s life cycle. The ArcSDE API has been deprecated since 10.2.2 and is set to be officially retired in 2019. If you’re considering a major overhaul of existing SDE applications, I have outlined a few options in this GeoNet.esri.com post.
Despite its impending retirement, I still get asked how to create direct connections to geodatabases instead of the older (and also deprecated) 3-tier ArcSDE service. I will outline how to do just that with the added bonus of not having to have ArcSDE installed at all.
Convert XY Coordinates into geometry in a Postgres Spatial Table
Posted: January 2, 2017 Filed under: DBMS, PostGIS, Programming, SDE Client | Tags: AddGeometryColumn, PostGIS, PostgreSQL, Spatial, SQL, ST_GeomFromText Leave a comment
In keeping with my New Year’s resolution to post more in 2017, here is a follow up to my last post calculating XY coordinates into geometry. This time however, the scenario involves an existing non-spatial table containing separate X and Y coordinate columns. Since I focused on SQL Server last time, I’ll switch over to Postgres to give you an idea of the differences and similarities between the two.
Calculate Coordinates Into Geometry and Vice Versa
Posted: December 31, 2016 Filed under: DBMS, Programming, SDE Client, SQL Server Spatial | Tags: Conversion, Coordinates, DBMS Trigger, PostgreSQL, Spatial, Sql Server 1 Comment
I wanted to be sure and sneak in a post before 2016 ended in California. I also wanted to put into writing that I resolve to post at least 6 times in 2017. Let’s get on with the post…
I get the following question often:
“How do I automatically convert my XY or Lat/Long coordinates into a point geometry?”
Sometimes that question is followed by:
“How do I populate XY or Lat/Long columns with values from a newly added point geometry?”
ArcSDE and GitHub
Posted: December 16, 2015 Filed under: DBMS Administration, Misc., Programming, SDE Administration | Tags: ArcSDE, geodatabase, geodatabase administration, spatial data enterprise Leave a commentHi Everyone,
Just a quick note to let you guys know about an exciting and growing repository of Esri specific scripts and samples on GitHub. The Esri Developer Support git is designed to provide:
[p]roof of concept developer code and samples to help be successful with all ArcGIS developer products (Python, NET, JavaScript, Android…). The repository is designed to be an exchange for sharing coding conventions and wisdom to developers at all skill levels”.
Enjoy!
Setting up an SDE Intercept trace. Updated
Posted: September 22, 2015 Filed under: SDE Administration, SDE Client | Tags: ArcSDE, ArcSDE errors, geodatabase, geodatabase administration, SDE, SDE logging 4 CommentsBack in 2013 I wrote a couple pieces on how to set up the SDE Intercept trace through the environment variables directly and with a batch file. There are no major changes here with the exception of the quantity of traces generated at ArcGIS 10.3 and later. You should now only see 1 trace per ArcGIS/SDE session.
Aside from that, I wanted to streamline the instructions for the manual environment variable set up, combine the batch file instructions and show how to capture a single event all in one post. Here you go…
PostgreSQL Geodatabase Query Performance
Posted: December 18, 2014 Filed under: DBMS Administration | Tags: administration, data management tools, geodata, geodatabase, PostgreSQL Leave a commentI came across a couple things that might be helpful when troubleshooting PostgreSQL geodatabase performance issues. The topics below focus on troubleshooting SQL queries. To get SQL queries from ArcGIS with a PostgreSQL geodatabase, use the instructions found below to set up a trace. Try to isolate the operation by running only the tools or functions needed to cause the behavior in question. This prevents the trace file from filling up with unnecessary information.
To enable PostgreSQL traces to capture ArcGIS/ArcSDE behavior, make a backup of your postgresql.conf file and alter the following parameters:
log_min_duration_statement = 25
log_duration = on
log_line_prefix = '%t [%p]: [%l-1] '
log_statement = 'all'
;stats_start_collector = on #8.3 and earlier
Getting Started:
A good way to approach a slow query is to get an explain plan. This allows one to get a good idea of what the Postgres query optimizer thinks should happen. This can be compared to what was observed. Like Oracle and SQL Server, it is possible to get the query estimation without running the query. Append EXPLAIN ANALYZE to your query get that information:
ortega=# \x Expanded display is on. ortega=# EXPLAIN ANALYZE SELECT objectid, parcelid, bearing, distance FROM mtfabric_lines;
Results in…
QUERY PLAN ---------------------------------------------------------------------------------------------- Seq Scan on mtfabric_lines (cost=0.00..746992.69 rows=12311469 width=1371) (actual time=0.007..1369.557 rows=12311469 loops=1) Total runtime: 1728.851 ms (2 rows)
Keep in mind these are estimations and many factors go into these results. Having said that, we see a SELECT statement on a very large table (12 million rows) results in a seq scan (full table scan). No indexes are used to filter the results. This is interesting because I know there is a primary key index on the objectid column and a non-unique index on parcelid among others in that table. If this had been a query captured in a trace from ArcGIS, I would definitely investigate indexes further.
Bigger Picture:
To get a bigger picture of index usage vs seq scans use the query below. This allows one to view table access by index or full scan with an average of rows returned.
SELECT relname, seq_scan, seq_tup_read, idx_scan, idx_tup_fetch, (seq_tup_read / seq_scan) as avg_results FROM pg_stat_user_tables WHERE seq_scan > 0 ORDER BY seq_tup_read DESC; relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | avg_results ------------------------+----------+--------------+----------+---------------+---------- mtfabric_parcels | 1105 | 928038431 | 600019 | 342328080 | 839853 sde_logfile_data | 49461 | 196097584 | 124536 | 13823200 | 3964 mtfabric_points | 667 | 157639544 | 99108 | 23464095 | 236341 mtfabric_lines | 619 | 135436559 | 1970843 | 1195065528 | 218798 sde_state_lineages | 5656437 | 25287996 | 2526745 | 2685002 | 4 mtfabric_jobobjects | 420 | 14624687 | 117776 | 159958 | 34820 sde_table_registry | 203217 | 13996463 | 948 | 946 | 68 bloomfieldy_lines | 324 | 5966692 | 154259 | 569389 | 18415 sde_spatial_references | 1075 | 5823066 | 14505 | 14505 | 5416 d74 | 248 | 4412565 | 107772 | 117718 | 17792
In the table above, for mtfabric_parcels a seq scan occurred 1,105 times while a scan using an index occurred 600,019 times. This is good considering the average quantity of rows returned is 839,853. This is seen in the avg_results column.
relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | avg_results ------------------------+----------+--------------+----------+---------------+---------- mtfabric_parcels | 1105 | 928038431 | 600019 | 342328080 | 839853
The other side of this coin are the stats from the sde_state_lineages table. This table sees a lot of action in a versioned environment. Reading the state_lineages stats row from left to right looks horribly inefficient until we get to avg_results. While it’s true that the state_lineages table is accessed by a full scan 3 million more times than by an index, the average quantity of rows returned is 4. Literally just 4. Whatever the SQL query used to get those 4 results, the stats show a sequential scan was chosen as the most efficient route and that choice was most likely right each time.
relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | avg_results ------------------------+----------+--------------+----------+---------------+---------- sde_state_lineages | 5656437 | 25287996 | 2526745 | 2685002 | 4
Digging Further:
While the next query requires a bit of initial setup, the results returned can provide a wealth of performance information. Please follow the steps below to set up the pg_stat_statements extension and run the query to list longest running queries in a database.
- Enable the pg_stat_statements extension in your PostgreSQL database (repeat for every database you want this available):
CREATE EXTENSION pg_stat_statements;
- Make a backup of your postgresql.conf file. Open up the original postgresql.conf file, uncomment the shared_preload_libraries entry and add the value ‘pg_stat_statements’.
shared_preload_libraries = 'pg_stat_statements'
- Restart the PostgreSQL service.
- Run the following query:
SELECT * FROM pg_stat_statements ORDER BY total_time DESC;
As you can see from the table above, all queries in the database are captured. This can be a great piece of information or too much information. Either way, that information is readily available in PostgreSQL.
SDEINTERCEPT – The easy way
Posted: March 18, 2014 Filed under: Uncategorized 1 CommentI wanted to share this quick and easy method to set up an SDE Intercept trace. Create a batch file! Running this batch file will set the SDEINTERCEPT variables for the ArcMap/Catalog session it launches. Once you close ArcGIS, the logging stops. Thanks to my colleague Biraja for this one.
1. Open notepad and paste this in:
set SDEINTERCEPTLOC=C:\temp2\client_Intercept
set SDEINTERCEPT=cwrTf
@echo off
start /d "C:\Program Files (x86)\ArcGIS\Desktop10.2\bin\" Arcmap.exe
Make sure you have the path to your temp folder (to contain the trace) and the path to ArcMap are correct.
2. Save the file with the .bat extension.
start_arcsdeint.bat
3. Run the batch file.
In this example, the SDEINTERCEPT and SDEINTERCEPTLOC environment variables are set for the current sesssion and ArcMap is launched. Make a connection to an SDE geodatabase and the client_intercept files should appear in the SDEINTERCEPTLOC you specified.
Enjoy
Resources for Rebuilding Indexes and Updating Statistics in an SDE Geodatabase
Posted: June 22, 2013 Filed under: DBMS, DBMS Administration, SDE Administration 5 CommentsHi Everyone. If you’re reading you probably know that tuning your RDBMS is an important aspect of maintaining your enterprise geodatabase. Two tasks found in all Esri supported RDBMS’ are updating DBMS statistics and rebuilding indexes. If you are loading data in bulk or running query intensive DML operations with SQL these tasks will need to be done often. Fortunately for us, these are relatively straightforward to accomplish.
The scripts found here provide the SQL to both update statistics and rebuild indexes. Oracle databases should be set to automatically update stats. The Sql Server script is still applicable for geodatabases in Sql Server 2008, 2008R2 and 2012 even though it says Sql Server 2000/2005.
Also, if you are using ArcGIS 10.1 there are some new geoprocessing tools that can do this.
ArcGIS 10.1 – ArcToolBox:
Data Management Tools>Geodatabase Administration>Analyze Datasets
Updates database statistics of base tables, delta tables, and archive tables, along with the statistics on those tables’ indexes. This tool is used in enterprise geodatabases to help get optimal performance from the RDBMS’s query optimizer. Stale statistics can lead to poor geodatabase performance.
Data Management Tools>Geodatabase Administration>Rebuild Indexes:
Updates indexes of datasets and system tables stored in an enterprise geodatabase. This tool is used in enterprise geodatabases to rebuild existing attribute or spatial indexes. Out-of-date indexes can lead to poor geodatabase performance.
No matter which one you choose, these resources can be run as automated tasks as SQL or the ArcToolBox tools can be exported to Python and automated as well. Either way, do it.
Stop the SDE intercept.
Posted: February 14, 2013 Filed under: Uncategorized 1 CommentTo stop the trace just remove the environment variable. Click here for more information.

