Обсуждение: canceling a delete

Поиск
Список
Период
Сортировка

canceling a delete

От
"Campbell, Lance"
Дата:

PostgreSQL 9.5.x

 

I logged onto PostgreSQL.  I did a command:

 

Delete from some_table;

 

I realized that I should have had a where clause.  So I canceled the delete with CTRL-C.  PostgreSQL said to canceled the delete.

 

Did PostgreSQL delete any records? 

 

Thanks,

 

Lance

Re: canceling a delete

От
Kevin Grittner
Дата:
On Thu, May 19, 2016 at 2:44 PM, Campbell, Lance <lance@illinois.edu> wrote:
> PostgreSQL 9.5.x

It is always best to show the full version number, just in case one of
the bugs fixed in a minor release could matter for the issue at hand.
(In this case I don't know of any, but there is not much point
checking for sure when I can only guess at what you are running.)

> Delete from some_table;
>
> I realized that I should have had a where clause.  So I canceled the delete
> with CTRL-C.  PostgreSQL said to canceled the delete.

Again, copy/paste of what you saw would allow a response with higher confidence.

> Did PostgreSQL delete any records?

Not if it processed the Ctrl+C before the command completed normally.
Either all rows in the table should be gone or the DELETE had no
effect.

Note that now would be a horrible time to suffer database corruption.
If, for example, you needed to run pg_resetxlog right now, you might
lose a lot of those rows.  Tread carefully.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: canceling a delete

От
"Campbell, Lance"
Дата:
PostgreSQL 9.5.2

Thanks.

This was the input/output on the screen:

username=# delete from some_table;
^CCancel request sent
ERROR:  canceling statement due to user request

This was the output in the PostgreSQL log:

user::2016-05-19 13:37:16 CDT STATEMENT:  delete from some_table;
user::2016-05-19 13:40:38 CDT ERROR:  canceling statement due to user request       
user::2016-05-19 13:40:38 CDT CONTEXT:  while deleting tuple (54598,61) in relation "some_table"

Thanks again!

Lance

-----Original Message-----
From: Kevin Grittner [mailto:kgrittn@gmail.com] 
Sent: Thursday, May 19, 2016 1:55 PM
To: Campbell, Lance <lance@illinois.edu>
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] canceling a delete

On Thu, May 19, 2016 at 2:44 PM, Campbell, Lance <lance@illinois.edu> wrote:
> PostgreSQL 9.5.x

It is always best to show the full version number, just in case one of the bugs fixed in a minor release could matter
forthe issue at hand.
 
(In this case I don't know of any, but there is not much point checking for sure when I can only guess at what you are
running.)

> Delete from some_table;
>
> I realized that I should have had a where clause.  So I canceled the 
> delete with CTRL-C.  PostgreSQL said to canceled the delete.

Again, copy/paste of what you saw would allow a response with higher confidence.

> Did PostgreSQL delete any records?

Not if it processed the Ctrl+C before the command completed normally.
Either all rows in the table should be gone or the DELETE had no effect.

Note that now would be a horrible time to suffer database corruption.
If, for example, you needed to run pg_resetxlog right now, you might lose a lot of those rows.  Tread carefully.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: canceling a delete

От
"David G. Johnston"
Дата:
On Thu, May 19, 2016 at 2:44 PM, Campbell, Lance <lance@illinois.edu> wrote:

PostgreSQL 9.5.x

 

I logged onto PostgreSQL.  I did a command:

 

Delete from some_table;

 

I realized that I should have had a where clause.  So I canceled the delete with CTRL-C.  PostgreSQL said to canceled the delete.

 

Did PostgreSQL delete any records? 

 


​Mostly what Kevin said - though the first thing you should consider doing next time is "BEGIN;"

A single statement either succeeds or fails atomically - so either it deleted ALL records or none.

Once within a transaction you get to change your mind up until you issue a "COMMIT;"

David J.