Re: "truncate all"?

Lists: pgsql-hackers
From: Andreas <e9625203(at)student(dot)tuwien(dot)ac(dot)at>
To: pgsql-hackers(at)postgresql(dot)org
Subject: "truncate all"?
Date: 2003-08-04 09:25:56
Message-ID: 5.2.0.9.0.20030804112330.00b55840@pop.chello.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi!

Would it be possible to implement a "truncate all" that purges all tuples
from *all* tables, without taking account any rules or triggers, but
leaving all table structures and rules, triggers, functions, etc intact
(sequences do not need to reinitialized)?

As far as I understand, the "no truncate if table is referenced" change was
introduced to ensure database integrity. However, if the referencing table
is truncated, too, there should be no problem as far as foreign keys are
concerned, correct?

The rationale behind this suggestion is that in our project we need a
*quick* way to get rid of all the tuples in all tables in order to
accelerate the reinitialization of the database for our unit tests. This
needs to be done fairly often, and so the quicker the unit tests run, the
easier it will be to include many unit tests in our project, thus ensuring
that we can develop efficiently and safely in postgresql.

If you know of some other *quick* way to truncate all tables, please let us
know. BTW: Starting and later rolling back a transaction will not work, as
we also need to check whether the correct exceptions are raised. This "all"
option to "truncate" would really help to accelerate unit tests (besides of
making them more readable) and should be fairly easy to implement, but I am
not sure how to change the relevant postgresql code. I would be glad if
someone could suggest some easy way to do it, and what needs to be observed
to implement such an extension of postgresql. I also hope that such an
extension could be included in future version of postgresql, but for now
some easy patch to the latest version would do as well.

Thanks for your time,
Andi.


From: "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-04 09:40:24
Message-ID: 3F2E7760.30021.23D00108@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 4 Aug 2003 at 11:25, Andreas wrote:
> Would it be possible to implement a "truncate all" that purges all tuples
> from *all* tables, without taking account any rules or triggers, but
> leaving all table structures and rules, triggers, functions, etc intact
> (sequences do not need to reinitialized)?
>
> As far as I understand, the "no truncate if table is referenced" change was
> introduced to ensure database integrity. However, if the referencing table
> is truncated, too, there should be no problem as far as foreign keys are
> concerned, correct?
>
> The rationale behind this suggestion is that in our project we need a
> *quick* way to get rid of all the tuples in all tables in order to
> accelerate the reinitialization of the database for our unit tests. This
> needs to be done fairly often, and so the quicker the unit tests run, the
> easier it will be to include many unit tests in our project, thus ensuring
> that we can develop efficiently and safely in postgresql.
>
> If you know of some other *quick* way to truncate all tables, please let us
> know. BTW: Starting and later rolling back a transaction will not work, as

As a workaround, I would dump the schema to a file using pg_dump, drop the
database and recreate it from schema.

Will that do for you? Unfortunately that is not transaction safe and any
clients connected at that time needs to disconnect first. Hopefully you can do
that in the test environment.

HTH

Bye
Shridhar

--
Bubble Memory, n.: A derogatory term, usually referring to a person's
intelligence. See also "vacuum tube".


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: shridhar_daithankar(at)persistent(dot)co(dot)in
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-04 13:41:25
Message-ID: 1060004485.22273.1729.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2003-08-04 at 05:40, Shridhar Daithankar wrote:
> On 4 Aug 2003 at 11:25, Andreas wrote:
> > Would it be possible to implement a "truncate all" that purges all tuples
> > from *all* tables, without taking account any rules or triggers, but
> > leaving all table structures and rules, triggers, functions, etc intact
> > (sequences do not need to reinitialized)?
> >
> > As far as I understand, the "no truncate if table is referenced" change was
> > introduced to ensure database integrity. However, if the referencing table
> > is truncated, too, there should be no problem as far as foreign keys are
> > concerned, correct?
> >
> > The rationale behind this suggestion is that in our project we need a
> > *quick* way to get rid of all the tuples in all tables in order to
> > accelerate the reinitialization of the database for our unit tests. This
> > needs to be done fairly often, and so the quicker the unit tests run, the
> > easier it will be to include many unit tests in our project, thus ensuring
> > that we can develop efficiently and safely in postgresql.
> >
> > If you know of some other *quick* way to truncate all tables, please let us
> > know. BTW: Starting and later rolling back a transaction will not work, as
>
> As a workaround, I would dump the schema to a file using pg_dump, drop the
> database and recreate it from schema.
>
> Will that do for you? Unfortunately that is not transaction safe and any
> clients connected at that time needs to disconnect first. Hopefully you can do
> that in the test environment.
>

Truncate isn't transaction safe either, so that shouldn't be a problem.

Proper syntax for his feature would seem like:
truncate table [cascade|restrict] ?

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: shridhar_daithankar(at)persistent(dot)co(dot)in, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: "truncate all"?
Date: 2003-08-04 14:28:22
Message-ID: 1060007301.91190.0.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Truncate isn't transaction safe either, so that shouldn't be a problem.

Actually, it is in 7.4

> Proper syntax for his feature would seem like:
> truncate table [cascade|restrict] ?

Agreed.


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Rod Taylor <rbt(at)rbt(dot)ca>
Cc: shridhar_daithankar(at)persistent(dot)co(dot)in, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: "truncate all"?
Date: 2003-08-04 14:43:33
Message-ID: 1060008213.22265.1755.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2003-08-04 at 10:28, Rod Taylor wrote:
> > Truncate isn't transaction safe either, so that shouldn't be a
> problem.
>
> Actually, it is in 7.4

yeah i know, but I assumed he wasn't doing his production unit testing
against 7.4. Course if he is all the better I suppose... :-)

>
> > Proper syntax for his feature would seem like:
> > truncate table [cascade|restrict] ?
>
> Agreed.

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-04 15:35:34
Message-ID: 200308041535.h74FZYw16088@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


This this a TODO? Keep in mind if we follow the syntax of VACUUM and
(7.4) CLUSTER, that the all-database truncate would just be "TRUNACATE".
That seems very risky to me. I wonder if the risk is worth adding this
feature.

---------------------------------------------------------------------------

Robert Treat wrote:
> On Mon, 2003-08-04 at 05:40, Shridhar Daithankar wrote:
> > On 4 Aug 2003 at 11:25, Andreas wrote:
> > > Would it be possible to implement a "truncate all" that purges all tuples
> > > from *all* tables, without taking account any rules or triggers, but
> > > leaving all table structures and rules, triggers, functions, etc intact
> > > (sequences do not need to reinitialized)?
> > >
> > > As far as I understand, the "no truncate if table is referenced" change was
> > > introduced to ensure database integrity. However, if the referencing table
> > > is truncated, too, there should be no problem as far as foreign keys are
> > > concerned, correct?
> > >
> > > The rationale behind this suggestion is that in our project we need a
> > > *quick* way to get rid of all the tuples in all tables in order to
> > > accelerate the reinitialization of the database for our unit tests. This
> > > needs to be done fairly often, and so the quicker the unit tests run, the
> > > easier it will be to include many unit tests in our project, thus ensuring
> > > that we can develop efficiently and safely in postgresql.
> > >
> > > If you know of some other *quick* way to truncate all tables, please let us
> > > know. BTW: Starting and later rolling back a transaction will not work, as
> >
> > As a workaround, I would dump the schema to a file using pg_dump, drop the
> > database and recreate it from schema.
> >
> > Will that do for you? Unfortunately that is not transaction safe and any
> > clients connected at that time needs to disconnect first. Hopefully you can do
> > that in the test environment.
> >
>
> Truncate isn't transaction safe either, so that shouldn't be a problem.
>
> Proper syntax for his feature would seem like:
> truncate table [cascade|restrict] ?
>
>
> Robert Treat
> --
> Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, <shridhar_daithankar(at)persistent(dot)co(dot)in>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: "truncate all"?
Date: 2003-08-04 16:03:27
Message-ID: Pine.LNX.4.33.0308041002540.10372-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I agree, a plain truncate blasting a whole database is a very bad thing.

however, "truncate with cascade" would be quite useful.

On Mon, 4 Aug 2003, Bruce Momjian wrote:

>
> This this a TODO? Keep in mind if we follow the syntax of VACUUM and
> (7.4) CLUSTER, that the all-database truncate would just be "TRUNACATE".
> That seems very risky to me. I wonder if the risk is worth adding this
> feature.
>
> ---------------------------------------------------------------------------
>
> Robert Treat wrote:
> > On Mon, 2003-08-04 at 05:40, Shridhar Daithankar wrote:
> > > On 4 Aug 2003 at 11:25, Andreas wrote:
> > > > Would it be possible to implement a "truncate all" that purges all tuples
> > > > from *all* tables, without taking account any rules or triggers, but
> > > > leaving all table structures and rules, triggers, functions, etc intact
> > > > (sequences do not need to reinitialized)?
> > > >
> > > > As far as I understand, the "no truncate if table is referenced" change was
> > > > introduced to ensure database integrity. However, if the referencing table
> > > > is truncated, too, there should be no problem as far as foreign keys are
> > > > concerned, correct?
> > > >
> > > > The rationale behind this suggestion is that in our project we need a
> > > > *quick* way to get rid of all the tuples in all tables in order to
> > > > accelerate the reinitialization of the database for our unit tests. This
> > > > needs to be done fairly often, and so the quicker the unit tests run, the
> > > > easier it will be to include many unit tests in our project, thus ensuring
> > > > that we can develop efficiently and safely in postgresql.
> > > >
> > > > If you know of some other *quick* way to truncate all tables, please let us
> > > > know. BTW: Starting and later rolling back a transaction will not work, as
> > >
> > > As a workaround, I would dump the schema to a file using pg_dump, drop the
> > > database and recreate it from schema.
> > >
> > > Will that do for you? Unfortunately that is not transaction safe and any
> > > clients connected at that time needs to disconnect first. Hopefully you can do
> > > that in the test environment.
> > >
> >
> > Truncate isn't transaction safe either, so that shouldn't be a problem.
> >
> > Proper syntax for his feature would seem like:
> > truncate table [cascade|restrict] ?
> >
> >
> > Robert Treat
> > --
> > Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 8: explain analyze is your friend
> >
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-04 16:19:25
Message-ID: 6986.1060013965@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> This this a TODO? Keep in mind if we follow the syntax of VACUUM and
> (7.4) CLUSTER, that the all-database truncate would just be "TRUNACATE".
> That seems very risky to me. I wonder if the risk is worth adding this
> feature.

I wouldn't care for that either. The prior suggestion of "TRUNCATE tab
CASCADE" (to truncate any tables with FK dependencies on the original
target, instead of failing) seems more reasonable.

regards, tom lane


From: "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: "truncate all"?
Date: 2003-08-04 16:22:21
Message-ID: 3F2ED595.14865.5CF07B@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 4 Aug 2003 at 10:03, scott.marlowe wrote:

> I agree, a plain truncate blasting a whole database is a very bad thing.
>
> however, "truncate with cascade" would be quite useful.

If we could get something simple as getting schema of a table, dropping the
table and recreating empty table, then it should be easy to emulate truncate..

Or is it done that way already?

Bye
Shridhar

--
Either one of us, by himself, is expendable. Both of us are not. -- Kirk,
"The Devil in the Dark", stardate 3196.1


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-04 16:42:03
Message-ID: 200308040942.03024.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Guys,

> I wouldn't care for that either. The prior suggestion of "TRUNCATE tab
> CASCADE" (to truncate any tables with FK dependencies on the original
> target, instead of failing) seems more reasonable.

I agree with Tom ... even the idea of a "TRUNCATE ALL" makes me nervous. If
we had such a feature, I'd advocate that it be superuser only.

As for "TRUNCATE CASCADE" or similar improvements, I agree that they could be
convenient ... but are easily worked around currently. So I wouldn't object
to putting TRUNCATE CASCADE on the todo list, but would argue that it be left
to the people who asked for it to implement it.

As far as

--
Josh Berkus
Aglio Database Solutions
San Francisco


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-04 16:53:32
Message-ID: 1060016013.22273.1812.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2003-08-04 at 12:19, Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > This this a TODO? Keep in mind if we follow the syntax of VACUUM and
> > (7.4) CLUSTER, that the all-database truncate would just be "TRUNACATE".
> > That seems very risky to me. I wonder if the risk is worth adding this
> > feature.
>
> I wouldn't care for that either. The prior suggestion of "TRUNCATE tab
> CASCADE" (to truncate any tables with FK dependencies on the original
> target, instead of failing) seems more reasonable.
>

Actually there seems to be an ancillary issue here:

21809=# truncate exception;
ERROR: TRUNCATE cannot be used as table exception_notice_map references
this one via foreign key constraint $1
21809=# TRUNCATE exception_notice_map ;
TRUNCATE TABLE
21809=# truncate exception;
ERROR: TRUNCATE cannot be used as table exception_notice_map references
this one via foreign key constraint $1
21809=# select count(*) from exception_notice_map;
count
-------
0
(1 row)

21809=#

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-17 04:17:55
Message-ID: 200308170417.h7H4HtA07953@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Added to TODO:

* Add TRUNCATE ... CASCADE

---------------------------------------------------------------------------

Josh Berkus wrote:
> Guys,
>
> > I wouldn't care for that either. The prior suggestion of "TRUNCATE tab
> > CASCADE" (to truncate any tables with FK dependencies on the original
> > target, instead of failing) seems more reasonable.
>
> I agree with Tom ... even the idea of a "TRUNCATE ALL" makes me nervous. If
> we had such a feature, I'd advocate that it be superuser only.
>
> As for "TRUNCATE CASCADE" or similar improvements, I agree that they could be
> convenient ... but are easily worked around currently. So I wouldn't object
> to putting TRUNCATE CASCADE on the todo list, but would argue that it be left
> to the people who asked for it to implement it.
>
> As far as
>
> --
> Josh Berkus
> Aglio Database Solutions
> San Francisco
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-17 04:18:20
Message-ID: 200308170418.h7H4IKi08093@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Is this a bug?

---------------------------------------------------------------------------

Robert Treat wrote:
> On Mon, 2003-08-04 at 12:19, Tom Lane wrote:
> > Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > > This this a TODO? Keep in mind if we follow the syntax of VACUUM and
> > > (7.4) CLUSTER, that the all-database truncate would just be "TRUNACATE".
> > > That seems very risky to me. I wonder if the risk is worth adding this
> > > feature.
> >
> > I wouldn't care for that either. The prior suggestion of "TRUNCATE tab
> > CASCADE" (to truncate any tables with FK dependencies on the original
> > target, instead of failing) seems more reasonable.
> >
>
> Actually there seems to be an ancillary issue here:
>
> 21809=# truncate exception;
> ERROR: TRUNCATE cannot be used as table exception_notice_map references
> this one via foreign key constraint $1
> 21809=# TRUNCATE exception_notice_map ;
> TRUNCATE TABLE
> 21809=# truncate exception;
> ERROR: TRUNCATE cannot be used as table exception_notice_map references
> this one via foreign key constraint $1
> 21809=# select count(*) from exception_notice_map;
> count
> -------
> 0
> (1 row)
>
> 21809=#
>
> Robert Treat
> --
> Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <shridhar_daithankar(at)persistent(dot)co(dot)in>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: "truncate all"?
Date: 2003-08-17 04:39:15
Message-ID: 20030816213700.S77393-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Sun, 17 Aug 2003, Bruce Momjian wrote:

> Is this a bug?

I don't think so. I'd say this is the expected behavior. Part of the
point is that it fails without checking for matching rows.

> Robert Treat wrote:
> > On Mon, 2003-08-04 at 12:19, Tom Lane wrote:
> > > Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > > > This this a TODO? Keep in mind if we follow the syntax of VACUUM and
> > > > (7.4) CLUSTER, that the all-database truncate would just be "TRUNACATE".
> > > > That seems very risky to me. I wonder if the risk is worth adding this
> > > > feature.
> > >
> > > I wouldn't care for that either. The prior suggestion of "TRUNCATE tab
> > > CASCADE" (to truncate any tables with FK dependencies on the original
> > > target, instead of failing) seems more reasonable.
> > >
> >
> > Actually there seems to be an ancillary issue here:
> >
> > 21809=# truncate exception;
> > ERROR: TRUNCATE cannot be used as table exception_notice_map references
> > this one via foreign key constraint $1
> > 21809=# TRUNCATE exception_notice_map ;
> > TRUNCATE TABLE
> > 21809=# truncate exception;
> > ERROR: TRUNCATE cannot be used as table exception_notice_map references
> > this one via foreign key constraint $1
> > 21809=# select count(*) from exception_notice_map;
> > count
> > -------
> > 0
> > (1 row)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-17 04:42:06
Message-ID: 8824.1061095326@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> writes:
> On Sun, 17 Aug 2003, Bruce Momjian wrote:
>> Is this a bug?

> I don't think so. I'd say this is the expected behavior. Part of the
> point is that it fails without checking for matching rows.

To do anything else, you'd have to solve some locking and/or
race-condition problems: rows could be inserted in the other table
while the TRUNCATE runs.

regards, tom lane


From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-17 14:34:55
Message-ID: 1061130895.1709.93.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2003-08-17 at 00:42, Tom Lane wrote:
> Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> writes:
> > On Sun, 17 Aug 2003, Bruce Momjian wrote:
> >> Is this a bug?
>
> > I don't think so. I'd say this is the expected behavior. Part of the
> > point is that it fails without checking for matching rows.
>
> To do anything else, you'd have to solve some locking and/or
> race-condition problems: rows could be inserted in the other table
> while the TRUNCATE runs.
>

Seems like you'll have that issue with truncate all wont you? I guess
we'll assume that if you use the cascade statement you understand these
risks and accept them.

Really my previous email was simply to point out to anyone implementing
the truncate cascade that truncate currently doesn't care if there is
really any data in the dependent tables, just that there are dependent
tables.

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
Cc: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-17 15:15:19
Message-ID: 11372.1061133319@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> On Sun, 2003-08-17 at 00:42, Tom Lane wrote:
>> To do anything else, you'd have to solve some locking and/or
>> race-condition problems: rows could be inserted in the other table
>> while the TRUNCATE runs.

> Seems like you'll have that issue with truncate all wont you? I guess
> we'll assume that if you use the cascade statement you understand these
> risks and accept them.

Yeah. A TRUNCATE ALL would need exclusive lock on every table. If
there are any other transactions running, the odds of getting all those
locks without deadlocking are pretty low. TRUNCATE CASCADE would also
have a risk of failing due to deadlock (but with fewer tables in play
it'd have a smaller risk). TRUNCATE RESTRICT should *not* create a
deadlock risk IMHO, and that means it can't lock other tables.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>, Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, shridhar_daithankar(at)persistent(dot)co(dot)in, pgsql-hackers(at)postgresql(dot)org
Subject: Re: "truncate all"?
Date: 2003-08-24 22:57:08
Message-ID: 200308242257.h7OMv8208148@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


TODO updated:

* Allow TRUNCATE ... CASCADE/RESTRICT

---------------------------------------------------------------------------

Tom Lane wrote:
> Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> writes:
> > On Sun, 2003-08-17 at 00:42, Tom Lane wrote:
> >> To do anything else, you'd have to solve some locking and/or
> >> race-condition problems: rows could be inserted in the other table
> >> while the TRUNCATE runs.
>
> > Seems like you'll have that issue with truncate all wont you? I guess
> > we'll assume that if you use the cascade statement you understand these
> > risks and accept them.
>
> Yeah. A TRUNCATE ALL would need exclusive lock on every table. If
> there are any other transactions running, the odds of getting all those
> locks without deadlocking are pretty low. TRUNCATE CASCADE would also
> have a risk of failing due to deadlock (but with fewer tables in play
> it'd have a smaller risk). TRUNCATE RESTRICT should *not* create a
> deadlock risk IMHO, and that means it can't lock other tables.
>
> regards, tom lane
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073