There are few feelings in this profession worse than the one I had at nine o’clock on a Monday morning, years ago, when a colleague walked into my office with a face the color of paper. The geodatabase/” data-khs-tag=”185″>file geodatabase that held three years of a municipality’s utility inventory, 400,000 features, would not open. The software said the workspace was invalid. Somebody had copied the folder to a USB stick on Friday afternoon while a long editing session was still running in the background, and then had unplugged it before the copy finished. The copy was a mess. The original, we eventually discovered, had been overwritten by an automatic synchronization tool that took a “snapshot” of half-written files. We spent two days piecing it together. We did get nearly everything back, and the only reason we did is that someone, at some point, had made a nightly backup that nobody had thought about since.
I tell this story because it contains almost every lesson of this guide. File-based geospatial databases are wonderfully convenient, and fragile in specific, predictable ways. They break when programs fight over them, when they are copied, synchronized or moved at the wrong moment, when power fails mid-write, and when too many people try to use a tool built for one. Most of the damage is avoidable, and most of it is recoverable if you stay calm and follow the right order of operations.
In this guide I’ll explain how locks work, how to diagnose “locked” and “corrupted” situations, how to recover step by step (for file geodatabases, GeoPackages and SQLite, Shapefiles, PostGIS and rasters), and how to set up your work so it never happens again. It is a deep dive into the seventh item of Top 10 Most Common GIS Errors and How to Fix Them.

First, a Warning: Stop, Copy, Then Think
When something looks wrong with an important dataset, your first instinct will be to try things. Resist it. Every action you take on a damaged file can make it worse. Before anything else:
- Stop writing. Close the applications that use the data. Cancel running jobs.
- Don’t “repair” in place. Don’t run compacting, repair or conversion tools on the only copy.
- Make a full copy of the entire dataset, including every file in the folder, to a safe place, and work on the copy. For a file geodatabase, that means the whole
.gdbfolder. For a GeoPackage, the.gpkgfile and any-waland-shmfiles next to it. - Find your backups, and check their dates. Knowing that you have a good backup changes how bold you can be.
- Write down what happened, the error messages, and what changed recently. The cause is often in the last thing someone did.
Now we can diagnose.
Part One: Locks
What is a lock?
When a program opens a dataset, it announces its intention, so that other programs don’t corrupt each other’s work. That announcement is a lock.
- Shared (read) lock: “I’m reading this. Others may read, but nobody may change the structure while I’m here.”
- Exclusive (write or edit) lock: “I’m editing this. Nobody else may read or write until I’m done.”
- Schema lock: “I’m using the structure of this table (fields, indexes). Nobody may alter that structure.” Operations that change the schema, such as adding a field, deleting a feature class or compacting, need an exclusive schema lock, which they can’t get while anyone else has the data open.
How the lock is recorded depends on the format.
- File geodatabases create small lock files inside the
.gdbfolder while they are in use, with names that include the machine name and a process identifier. When the program closes normally, it removes them. - GeoPackage and other SQLite-based formats rely on SQLite’s own locking, and may create temporary
-wal(write-ahead log) and-shm(shared memory) files while open. - Shapefiles have no formal lock mechanism, though some software creates lock files next to them, and the operating system may also prevent changes to open files.
- Enterprise databases such as PostgreSQL manage locks internally and keep them in system tables.
Typical symptoms
- “Cannot get exclusive schema lock. Either being edited or in use by another application” (a classic ArcGIS message).
- “Database is locked” (SQLite and GeoPackage).
- “Unable to open”, “Failed to open”, or “The file is being used by another process.”
- The dataset opens as read-only, and edits aren’t saved.
- A tool fails halfway and then the dataset is locked.
- You can’t delete, rename, move or overwrite the folder or file.
- A scheduled script fails at night because a user left the dataset open.
- Stale lock files remain after a crash, so the software believes that someone is still using the data.
Who is holding the lock? A systematic search
- Check your own programs first. Is the dataset open in ArcGIS Pro, ArcCatalog, QGIS, a second QGIS window, a Python notebook or a script that is still running? Layers shown in a catalog preview or a thumbnail can also hold a read lock. Close them all, including background Python kernels.
- Look for background processes: geoprocessing tasks that are still running, an ArcGIS Pro process that survived a crash, a QGIS process that remains after the window closed.
- Windows: use Task Manager to look for leftover processes. Resource Monitor (the CPU tab, “Associated Handles”) lets you search for the name of a file or folder, and shows which process has it open.
- macOS and Linux: use
lsofto list the processes that have files open, for examplelsof +D /path/to/data.gdb.
- Check other users and machines if the data is on a shared drive. Another colleague may have it open. Ask, or look at the lock file names, which usually include the machine name.
- Check services: a map service published from the data (for example, by an ArcGIS Server) keeps it open. Stop the service, or use a copy for publishing.
- Check background tools: antivirus, backup and cloud synchronization programs scan or copy files while they are open and can hold locks, or interfere with writes. Exclude your data folders from real-time scanning where policy allows.
- Check permissions. A read-only folder or file looks like a lock. Test by creating a new file in the same location.
- Restart the application, then, if needed, the computer. A reboot clears a surprising number of phantom locks.
Fixing a lock
Normal case: someone is really using the data. Close the program, or ask the person to close it. Then run your operation again.
Stale lock files (after a crash). If you are certain that no program is using the data, on any machine, the lock files may be stale leftovers.
- Make a backup copy of the dataset first.
- With everything closed, delete the lock files (in a file geodatabase, files whose names end in
.lock) from inside the.gdbfolder. - Restart your software, and open the data.
Warning: deleting lock files while someone is using the data can cause the very corruption you want to avoid. Be sure first. On a shared drive, confirm with colleagues.
Schema lock errors during tools: the tool needs exclusive access. Close every other use of the data, including the layers in open maps, which hold shared locks. In ArcGIS Pro, removing the layer from the map, or closing the project, usually frees it.
GeoPackage “database is locked”: another connection, perhaps in QGIS or a Python process, holds a write transaction. Close other connections. If the problem is persistent, check for orphaned -wal and -shm files, and for sync software. See below for the important rule about those files.
PostgreSQL and PostGIS locks: look at the active sessions and locks.
-- Who is connected, and what are they doing?
SELECT pid, usename, state, query_start, left(query, 80) AS query
FROM pg_stat_activity
WHERE datname = current_database() AND state <> 'idle'
ORDER BY query_start;
-- Which lock requests are waiting?
SELECT * FROM pg_locks WHERE NOT granted;
-- Politely cancel a query, or, as a last resort, end a session (use with care)
SELECT pg_cancel_backend(12345);
SELECT pg_terminate_backend(12345);A common culprit is a session that is “idle in transaction”: a client that started a transaction and never finished it, holding locks for hours. Find it, ask its owner, and terminate it only if necessary. See PostGIS: A Practical Introduction.
Enterprise geodatabases: in the Esri world, administrators can see connected users and disconnect them, and block new connections during maintenance. Use the geodatabase administration tools, and plan maintenance windows.
Part Two: Corruption
What is corruption?
Corruption means that the internal structure of the data no longer makes sense: files are incomplete, indexes don’t match the tables, or pieces are missing. The data may still be partly readable.
What causes it?
- Interrupted writes: power loss, a crash, a forced shutdown or a killed process while the data was being written.
- Partial or inconsistent copies: copying a file geodatabase (or any multi-file dataset) while it is open, or copying only some of the files, or interrupting a copy. This was the story at the start.
- Cloud synchronization and backup tools that capture files in the middle of changes, or that sync parts of a dataset at different moments. File databases in synchronized folders are the single most frequent source of mysterious corruption I see.
- Network drives: unreliable connections, latency, or file systems that don’t handle locking properly can corrupt databases that depend on file-level locking. SQLite-based formats are especially vulnerable on network shares.
- Multiple users editing a file-based database at the same time, which these formats weren’t designed for.
- Full disks: a write that runs out of space halfway.
- Hardware problems: failing disks, bad memory, USB sticks unplugged without ejecting.
- Software bugs and version incompatibilities: a newer version of a geodatabase opened in an older program, or an interrupted upgrade.
- Antivirus quarantining a file that looks suspicious.
- Manual meddling: deleting, renaming or moving individual files inside a geodatabase folder.
- Very large or heavily edited datasets that have never been compacted.
Typical symptoms
- The dataset won’t open, or reports the workspace as invalid or unsupported.
- Tables or feature classes are missing from the catalog.
- Tables open but show zero or fewer rows than expected.
- Errors during a tool run: “something unexpected caused the tool to fail”, read or write errors, or “invalid table”.
- Geometry is damaged, features drawn as garbage, or exports that stop partway.
- SQLite errors: “database disk image is malformed”, “file is not a database”, “disk I/O error”.
- Shapefiles that won’t open: missing or truncated component files.
- Rasters with errors reading tiles, or truncated files.
- Unexplained growth in size or very slow access.
Recovery, Format by Format
Always work on a copy. Try the least invasive option first.
File geodatabases (.gdb)
Understand the structure
A file geodatabase is a folder with many files whose names look like a00000001.gdbtable, a00000001.gdbtablx, a00000009.gdbindexes, a00000009.spx and so on. Each table has a data file, an index file and other support files. The first tables hold the system catalog, which lists the contents. If the catalog is damaged, the geodatabase looks empty or invalid, even if the data files are fine.
| File type | Role |
|---|---|
.gdbtable | The data of a table or feature class |
.gdbtablx | The index of the table’s rows |
.gdbindexes | The list of attribute indexes |
.atx | An attribute index |
.spx | A spatial index |
.freelist | Free space tracking |
.lock | A temporary lock file |
gdb | A small file marking the folder as a geodatabase |
Never delete or rename individual files inside a .gdb folder.
Step 1: Check what you have
- Count the files and compare with a healthy backup or an earlier copy, if you have one. Missing
.gdbtablxor.gdbtablefiles are a bad sign. - Try to open it in different software: ArcGIS Pro and QGIS use different readers. QGIS, through the GDAL
OpenFileGDBdriver, can often read data that ArcGIS refuses to open, and the reverse.
# List what GDAL can see inside the geodatabase
ogrinfo -so mydata.gdb
# Show details of one layer
ogrinfo -so -al mydata.gdb MyFeatureClassStep 2: Export everything readable
If GDAL or ArcGIS can read some layers, export them immediately to a safe, different format, such as GeoPackage, one layer at a time:
ogr2ogr -f GPKG rescue.gpkg mydata.gdb MyFeatureClassDon’t try a bulk operation if one corrupted layer is stopping the process. Export layer by layer, and note which ones fail. A script can loop over the layers and log failures. See Python for GIS: Getting Started.
Step 3: Use repair tools (on the copy)
- Compact (in the geodatabase tools of ArcGIS): reorganizes the data, removes wasted space and can resolve some inconsistencies. It needs an exclusive schema lock.
- Recover: recent versions of ArcGIS Pro include a tool for recovering a file geodatabase, designed to salvage data from a damaged one into a new geodatabase. Check what your version offers. Always run it on a copy.
- Copy to a new geodatabase: create a fresh file geodatabase, and copy feature classes and tables into it one by one (with Copy, Feature Class to Feature Class or Table to Table). A new container often escapes the damage that was in the old one.
- Export an XML workspace document of the schema (structure without data), if the schema is readable. It lets you rebuild the structure in a new geodatabase, and then load data into it.
Step 4: Restore from backup
If recovery doesn’t give you what you need, restore the last good backup, and replay edits since then from logs, emails, or exported data.
Step 5: After recovery
Validate geometries and topology, because damaged data can contain subtle errors. See How to Fix Invalid Geometry Errors and Fixing Topology Errors and Overlaps. Compare counts with your records.
GeoPackage and other SQLite-based files
GeoPackage is built on SQLite, a robust database engine. It is very reliable under normal conditions, but it relies on correct file-system behavior, and it can be harmed by network drives, sync tools and killed processes.
The golden rule about -wal and -shm files
In write-ahead logging mode, SQLite writes changes first to a -wal file, and later merges them into the main file. A -shm file coordinates access. If a program stops abnormally, the -wal file may contain committed changes that are not yet in the main .gpkg.
- Never delete a
-walfile by itself, because you may delete recent data. - Always copy the
.gpkg, the-waland the-shmtogether, as a set, when the program isn’t running. - When all programs close normally, SQLite merges the log and removes these files.
Check integrity
With the SQLite command-line tool (or any SQLite library):
sqlite3 data.gpkg "PRAGMA integrity_check;"A healthy file answers ok. Anything else lists the problems.
Recover data
Try these in order, on a copy.
# 1. Let GDAL copy what it can into a fresh GeoPackage
ogr2ogr -f GPKG rescued.gpkg data.gpkg
# 2. Use SQLite's recovery command to rebuild a new database from a damaged one
sqlite3 broken.gpkg ".recover" | sqlite3 recovered.gpkg
# 3. As a last step, check the result
sqlite3 recovered.gpkg "PRAGMA integrity_check;"
ogrinfo -so recovered.gpkgThe .recover command salvages as much content as possible. The recovered database may need cleanup: lost geometry columns, missing spatial indexes or orphaned records. Check the layer list, the feature counts and a sample. You might also need to rebuild the spatial index, which many tools do automatically on opening.
If the file is only “locked”, not corrupted, close the other connections first. See Shapefile vs. GeoJSON vs. GeoPackage: Which Format to Use?
Never keep a GeoPackage in a cloud-synchronized folder while you edit it, and avoid editing it over a network share.
Shapefiles
Shapefiles are simple, and most of their problems come from missing or inconsistent components.
- Missing
.shx(index): GDAL can rebuild it. With the configuration optionSHAPE_RESTORE_SHX=YES, tools that use GDAL, such asogr2ogr, will recreate the index from the.shpfile:
ogr2ogr -f GPKG rescued.gpkg broken.shp --config SHAPE_RESTORE_SHX YES- Missing
.dbf(attributes): you have the shapes but no attributes. Look for the file in backups and in the original delivery. - Truncated
.shpor.dbf: files that were cut short by an interrupted copy or download. GDAL may still read the beginning. Export what you can, and compare the feature count with the original. - Mismatched components: a
.dbffrom one version and a.shpfrom another, with different feature counts. Restore a consistent set. - Unreadable text: that is an encoding problem, not corruption. See Shapefile Limitations and Encoding Problems (Field Names, UTF-8).
- Files over 2 GB: a size limit, not corruption.
PostGIS and other databases
Server databases such as PostgreSQL are far more robust, thanks to transactions and crash recovery, and they restart safely after a power loss. When a problem does occur:
- Restore from a backup, such as a
pg_dumpfile or a physical backup, usingpg_restore. - Check for disk space and hardware issues first.
- Read the server logs.
- Don’t edit system files manually.
- Use point-in-time recovery if it is set up.
- For spatial index problems, rebuild with
REINDEX, and runVACUUM ANALYZE.
See Enterprise GIS & Spatial Databases: PostGIS, Geodatabases, and Server Architecture for the backup strategies that make this reliable.
Rasters and other files
- Truncated or partly downloaded GeoTIFFs often show errors about reading tiles or directories. Download the file again, and compare its size and checksum with the source, if provided.
- Check a raster:
gdalinfo -stats broken.tif # reads the data, and reveals errors
gdalinfo -checksum broken.tif # computes a checksum for each band- Convert a partly readable raster to a fresh file with
gdal_translate, and see how much you can save. - Cloud-optimized files: validate with a COG validator. See Cloud-Native Geospatial (COG, STAC, Zarr).
- QGIS project files (.qgz, .qgs): a damaged project can often be opened by unzipping the
.qgz(it is a compressed archive), and examining the.qgsfile, which is XML. QGIS also keeps a backup of the previous version of a project when you save. See QGIS Crashes and Performance Issues: Fixes.
A Recovery Decision Guide
| Situation | First actions |
|---|---|
| “Cannot get exclusive schema lock” | Close every use of the data (maps, previews, services, other users). Retry. Then check stale lock files |
| “Database is locked” in GeoPackage | Close other connections. Check for a still-running process and sync tools |
| Program crashed, and now the data won’t open | Copy the whole dataset, check for stale locks, try another reader (GDAL) |
| File geodatabase invalid or empty | Copy it. Test with GDAL. Export each readable layer. Try the recovery and compact tools. Restore from backup |
database disk image is malformed | Copy the file with its -wal and -shm. Run the integrity check. Try .recover and ogr2ogr |
Shapefile missing .shx | Rebuild with SHAPE_RESTORE_SHX=YES |
| Dataset damaged after a copy or sync | Retrieve a clean copy from the source or a backup. Don’t trust the partial copy |
| Raster errors reading tiles | Re-download. Test with gdalinfo -stats |
| PostgreSQL session blocks everything | Find the blocking session. Cancel or terminate it carefully |
A Worked Example: The Geodatabase That Wouldn’t Open
Problem: a file geodatabase with the municipality’s utility data reports an invalid workspace. It was copied while an editing session was running, and the copy was interrupted.
- Stop. Nobody touches the original or the copy. Both are preserved.
- Find the good backup. The nightly backup from Sunday is intact. The edits from Monday and Tuesday are missing.
- Make a copy of the damaged folder, and work on that.
- Inspect: compare the file lists. The copy lacks some
.gdbtablxfiles and has several.lockfiles. The folder is clearly incomplete. - Check the original: is it also damaged? The original is intact but was overwritten by the sync tool. A look at the file dates shows that the sync snapshot replaced half of the files.
- Try GDAL on the original:
ogrinforeads 18 of 21 layers. Export these 18 to a GeoPackage right away. Three layers fail. - Compare the exported data with the Sunday backup: feature counts are higher, so the original carries Monday’s and Tuesday’s edits. Keep both.
- Recover the three failing layers from the Sunday backup, and re-apply the missing edits using the edit log and field notes.
- Rebuild a clean geodatabase: create a new file geodatabase, load all layers, recreate domains, relationships and topology from the schema documentation, and validate.
- Verify: compare counts and totals, and run geometry and topology checks. See How to Fix Invalid Geometry Errors.
- Fix the process: exclude the geodatabase folders from cloud synchronization, introduce versioned, timestamped backups, and move to a proper multi-user database for shared editing.
- Document the incident and the recovery.
Total data lost: two hours of edits, recovered from notes. It could have been three years.
Prevention: How to Never Have This Day
1. Back up, properly
- Follow the 3-2-1 rule: three copies of the data, on two different kinds of media, with one off-site.
- Automate backups on a schedule, and keep several versions, not only the latest.
- Back up consistent snapshots, taken when the data is closed, or with tools that handle open files correctly.
- Test restores. A backup that has never been restored is a hope, not a backup.
- Document the recovery procedure, and who is responsible.
2. Respect how file-based formats work
- Never copy a file geodatabase or a GeoPackage while it is in use. Close all programs, then copy the entire folder or file set.
- Move and copy the entire dataset (every file), not selected pieces.
- Use proper tools to copy inside the GIS software, rather than the file explorer, when the data is open.
- Compress folders into a single archive before emailing or uploading.
- Eject drives safely.
3. Keep file databases away from fragile environments
- Don’t store active file geodatabases or GeoPackages in cloud-synchronized folders, such as consumer file-sync services. They will eventually corrupt something.
- Avoid editing across network shares, especially unreliable ones. Work locally, and copy results back.
- Exclude data folders from real-time antivirus scanning and from backup agents that copy open files, where policy allows. Or schedule the backups when the data isn’t in use.
4. Use the right tool for multi-user editing
File-based databases are for one editor at a time. If several people must edit the same data, use a multi-user database: an enterprise geodatabase or PostGIS, with proper versioning, transactions and permissions. See Enterprise GIS & Spatial Databases: PostGIS, Geodatabases, and Server Architecture.
5. Maintain your data
- Compact file geodatabases regularly, after heavy editing.
- Keep an eye on disk space. Don’t let drives fill.
- Update software with the latest patches, and avoid mixing versions.
- Upgrade geodatabases deliberately, with backups, and don’t open newer versions in older software.
- Monitor storage health and replace failing hardware.
- Protect against power loss with a UPS for critical machines.
6. Work habits
- Close programs properly, and don’t kill processes in the middle of operations.
- Save and stop edit sessions before leaving for the day.
- Don’t leave dozens of layers open in maps when you run schema operations.
- Name and organize datasets, and use one clear master location for each.
- Keep scripts from fighting with users: schedule heavy jobs when nobody works.
- Export critical data to open, stable formats for long-term archives. See Shapefile vs. GeoJSON vs. GeoPackage: Which Format to Use?
- Document datasets and incidents. See Metadata in GIS: Why It Matters and How to Create It.
- Train the team in these rules.
Common Mistakes
- Trying repairs on the only copy.
- Deleting lock files while someone is using the data.
- Deleting a GeoPackage’s
-walfile and losing committed changes. - Copying a geodatabase while it is open, or copying only some of its files.
- Keeping working databases in synchronized folders.
- Editing GeoPackages over network drives.
- Having no backup, or never testing the restore.
- Overwriting the damaged data with a “recovered” version before verifying it.
- Killing a process mid-write because it seems to hang.
- Ignoring warning signs, such as slowdowns, occasional errors and growing file sizes.
- Giving everyone write access to the master dataset.
- Using file formats for tasks that need a server database.
- Skipping validation after recovery, and trusting data that has subtle damage.
- Not recording what happened, so it happens again.
Emergency Checklist
- Stop all work on the dataset.
- Copy the entire dataset, with all component files, to a safe place.
- Note the error messages and recent events.
- Find the latest good backup.
- Check for programs and users that hold the data open, and for stale locks.
- Test reading the copy with a second tool (GDAL or QGIS).
- Export whatever is readable to a different, safe format.
- Use repair tools (compact, recover, integrity checks) only on the copy.
- Restore from a backup if needed, and reapply later edits.
- Validate the result: counts, geometry, topology and attributes.
- Fix the cause, and improve the backup and sync arrangements.
- Document and share the lessons.
Final Thoughts
Data loss is rarely dramatic. It is the product of ordinary decisions: a convenient sync tool, a quick copy, a shared folder, a backup nobody checked. The professionals I respect are not those who never meet corruption, but those who designed their work so that it can’t be catastrophic: they have backups that are tested, databases suited to the number of editors, folders kept away from careless software, and a calm procedure to follow.
Do one thing today. Find the most important dataset in your organization and answer three questions: where is the master copy, who can edit it at the same time, and when was it last restored from backup? If any answer makes you uneasy, you have just found your next task.
Where to go next: continue with QGIS Crashes and Performance Issues: Fixes for software stability, and Shapefile Limitations and Encoding Problems (Field Names, UTF-8) for format-specific limits.



