How to cleanly delete Gravity Forms entries with SQL?

I got over 20k entries, and it’s such a pain to click ‘empty trash’ since it always ends with 502 timeout.

I want to delete Form entries using SQL queries, but I’m not sure how to remove all meta/relationships gracefully using SQL, does anyone know? Thanks!

Note, I’ve tested this in my testing environment, but please test this yourself before using on your website. but the following should work:

DELETE FROM gf_entry_meta; 
DELETE FROM gf_entry; 
DELETE FROM gf_entry_notes; 

You’ll need to add your wordpress table prefix (found in wp-config.php) to the beginning of each table name.

This should remove all rows within the table but will not delete any columns nor the table itself.

1 Like

I recommend using the command line and WP CLI with the Gravity Forms add-on:

With that, you can delete entries, as shown here:

If you explain more about which entries you need to delete (are you just emptying trash, or deleting all entries, or something else?) we can help with a possible approach using the WP CLI. Thank you.

Another option might be to simply add a line to your php.ini file (or create one if you don’t already have one) and increase the PHP execution time. The php.ini file can go in your WP root, but it’s safer to keep it in your /wp-admin folder.

The line to add would be something like this:

max_execution_time = 30 (or make the value larger if that is what it’s already at or above)

You can read more about various fixes for a 502 error here:

Also, @michaeledi - I did work out the SQL commands for this, to empty the trash for a specific form. It does not handle deleting attachments, so if that is a concern, SQL is not the way to go, and the WP CLI for Gravity Forms is the way to go.

Once you get to the point that your list of entries/trash is empty for the specific form(s), you may want to look at the Form Connector extension’s Delete an Entry step. If you have time / business rules that determine if/when an entry can/should be deleted, as the last step in your workflow it can automate the deletion for you. Behind the scenes, the delete activity is hooked to a cron event and deleting the single entry involved so you would be very unlikely to encounter the 502’s you describe related to bulk deletions.


1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.