Thank you for your quick response Gilberto. Much appreciated.
I may very well follow your recommendation if I can determine if the current delete statement is not doing any work.
QUERY PLAN
--------------------------------------------------------------------------------------------------------
-> Seq Scan on contents_social_posts csp (cost=0.00..951.72 rows=54372 width=18)
-> Seq Scan on social_posts sp (cost=0.00..4978.18 rows=101518 width=10)
-> Seq Scan on contents c (cost=0.00..1075343.73 rows=3970439 width=10)
As you can see, many sequential scans especially 2 on the table we are performing the delete on
\d contents
Table "public.contents"
Column | Type | Modifiers
---------------+-----------------------------+-------------------------------------------------------
id | integer | not null default nextval('contents_id_seq'::regclass)
raw_content | text |
title | text |
description | text |
source_url | text |
published_at | timestamp without time zone |
guid | text |
type | character varying(255) |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
image_url | text |
original_id | character varying(255) |
refined_date | date |
thumbnail_url | text |
user_id | integer |
flagged_at | timestamp without time zone |
flagged_by | integer |
removed_at | timestamp without time zone |
removed_by | integer |
category_id | integer |
parent_id | integer |
parent_type | character varying(255) |
processing | boolean | default false
sharable_id | integer |
sharable_type | character varying(255) |
meta_data | text |
medium_url | text |
pinned_at | date |
pinned_until | date |
banner_url | text |
deleted_at | timestamp without time zone |
Indexes:
"primets_contents_pkey_id" PRIMARY KEY, btree (id), tablespace "prime2indexes"
"primets_content_parent" btree (parent_id, parent_type), tablespace "prime2indexes"
"primets_contents_category" btree (category_id), tablespace "prime2indexes"
"primets_contents_desc_gin" gin (to_tsvector('english'::regconfig, description)), tablespace "prime2indexes"
"primets_contents_guid" btree (guid), tablespace "prime2indexes"
"primets_contents_pin_priority" btree ((GREATEST(refined_date::timestamp without time zone, pinned_until + '1 day'::interval)), id), tablespace "prime2indexes"
"primets_contents_refined_date_id" btree (refined_date, id), tablespace "prime2indexes"
"primets_contents_sharable_id_sharable_type" btree (sharable_id, sharable_type), tablespace "prime2indexes"
"primets_contents_source_gin" gin (to_tsvector('english'::regconfig, source_url)), tablespace "prime2indexes"
"primets_contents_title_gin" gin (to_tsvector('english'::regconfig, title)), tablespace "prime2indexes"
"primets_contents_type" btree (type), tablespace "prime2indexes"
"primets_contents_user_id" btree (user_id), tablespace "prime2indexes"
Triggers:
_replication_logtrigger AFTER INSERT OR DELETE OR UPDATE ON contents FOR EACH ROW EXECUTE PROCEDURE _replication.logtrigger('_replication', '26', 'k')
_replication_truncatetrigger BEFORE TRUNCATE ON contents FOR EACH STATEMENT EXECUTE PROCEDURE _replication.log_truncate('26')
Disabled triggers:
_replication_denyaccess BEFORE INSERT OR DELETE OR UPDATE ON contents FOR EACH ROW EXECUTE PROCEDURE _replication.denyaccess('_replication')
_replication_truncatedeny BEFORE TRUNCATE ON contents FOR EACH STATEMENT EXECUTE PROCEDURE _replication.deny_truncate()