It's becoming common to see this problem in the development environment. My application is not in production yet, but I'm worried this problem could happen.
As I develop new features, I commonly clear some tables when necessary.
I started to get into this problem with one specific table I try to clean.
I delete everything from other tables that could have foreign constraints, but when I try to delete from that specific table,
pgAdmin loses the connection and the database enters in recovery mode.
First I get a warming saying:
"The application has lost the database connection".
If I try several times to connect and execute again, then I get a message
"FATAL: the database system is in recovery mode".
One thing that worked was to execute an update setting some field to it's own value on all rows (i.e update table set field = field). After this I could delete all rows.
I'm actually using
EntityFramework 6 with the
DevArt.PostgreSql plugin to control the database creation, but I generated the table script from
pgAdmin to help understand the table structure. I also added one other table that has a foreign key to the table in question.
The application domain, code and database structure is written in
pt-BR, so I tried to translate the table and fields names to help.
It's an application to control order requests and charges.
CREATE TABLE public.request_event ( id integer NOT NULL DEFAULT nextval('request_event_id_seq'::regclass), id_request integer NOT NULL, type integer NOT NULL, date timestamp without time zone NOT NULL, time_informed boolean NOT NULL, id_user integer, message text COLLATE pg_catalog."default" NOT NULL, visible boolean NOT NULL, occurrence timestamp without time zone NOT NULL DEFAULT '0001-01-01 00:00:00'::timestamp without time zone, CONSTRAINT request_event_pkey PRIMARY KEY (id), CONSTRAINT "FK_request_event_request_id_request" FOREIGN KEY (id_request) REFERENCES public.request (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "FK_request_event_user_id_user" FOREIGN KEY (id_user) REFERENCES public.user (id_person) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) WITH ( OIDS = FALSE ) TABLESPACE pg_default; ALTER TABLE public.request_event OWNER to postgres; CREATE INDEX "IX_request_event_id" ON public.request_event USING btree (id) TABLESPACE pg_default; CREATE INDEX "IX_request_event_id_request" ON public.request_event USING btree (id_request) TABLESPACE pg_default; CREATE INDEX "IX_request_event_id_user" ON public.request_event USING btree (id_user) TABLESPACE pg_default;
CREATE TABLE public.charge_event ( id integer NOT NULL, id_charge integer NOT NULL, CONSTRAINT charge_event_pkey PRIMARY KEY (id), CONSTRAINT "FK_charge_event_charge_id_charge" FOREIGN KEY (id_charge) REFERENCES public.charge (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "FK_charge_event_request_event_id" FOREIGN KEY (id) REFERENCES public.request_event (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) WITH ( OIDS = FALSE ) TABLESPACE pg_default; ALTER TABLE public.charge_event OWNER to postgres; CREATE INDEX "IX_charge_event_id" ON public.charge_event USING btree (id) TABLESPACE pg_default; CREATE INDEX "IX_charge_event_id_charge" ON public.charge_event USING btree (id_charge) TABLESPACE pg_default;
Delete SQL (fail):
DELETE FROM charge_event; DELETE FROM request_event;
Delete SQL (worked):
DELETE FROM charge_event; UPDATE request_event SET type = type; DELETE FROM request_event;