pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
6+ messages / 5 participants
[nested] [flat]

* BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
@ 2013-12-13 13:13  anitchakkarwar@gmail.com
  0 siblings, 1 reply; 6+ messages in thread

From: anitchakkarwar@gmail.com @ 2013-12-13 13:13 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8681
Logged by:          Anit chakkarwar
Email address:      anitchakkarwar@gmail.com
PostgreSQL version: 9.3.1
Operating system:   Linux
Description:        

I came across one issue while truncating table in Postgres9.3, please find
below steps:


First Scenario:


1. Create table and insert some rows.
2. Now delete two rows.
3. If I delete rows 'n_tup_del' column in pg_stat_user_tables is set 2.
4. Do vacuum now i.e vacuum table <tablename>
5. 'n_tup_del' column in pg_stat_user_tables is still showing  2 records.


Second Scenario:


1. Create table and insert some rows.
2. Now truncate table.
3. n_tup_del column in pg_stat_user_tables is 0.


If I do truncate then n_tup_del value is 0 but all the rows are deleted from
table.


Is this something expected behaviour ? 




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
@ 2013-12-13 17:44  Tom Lane <tgl@sss.pgh.pa.us>
  parent: anitchakkarwar@gmail.com
  0 siblings, 1 reply; 6+ messages in thread

From: Tom Lane @ 2013-12-13 17:44 UTC (permalink / raw)
  To: anitchakkarwar@gmail.com; +Cc: pgsql-bugs

anitchakkarwar@gmail.com writes:
> If I do truncate then n_tup_del value is 0 but all the rows are deleted from
> table.
> Is this something expected behaviour ? 

Yes.  We're certainly not going to make TRUNCATE update that count, since
that would require making a pass over the table to count the to-be-deleted
tuples, and the whole point of TRUNCATE is to not make a pass over the
table.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
@ 2013-12-16 13:21  Anit Chakkarwar <anitchakkarwar@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 6+ messages in thread

From: Anit Chakkarwar @ 2013-12-16 13:21 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Hi Tom,

Thanks, I have one query please refer below scenario.

1. Create table.
2. Insert 100 rows.
3. Delete 2 rows.
4. Truncate table.
5. Do vacuum
6. Insert 20 rows again. (Table count is 20 now)

Now n_tup_del = 2, n_tup_ins=120, n_live_tup=20 in pg_stat_user_tables, but
how can I figure out what has happened to 98 rows?


Regards,
Anit Chakkarwar


On Fri, Dec 13, 2013 at 11:14 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> anitchakkarwar@gmail.com writes:
> > If I do truncate then n_tup_del value is 0 but all the rows are deleted
> from
> > table.
> > Is this something expected behaviour ?
>
> Yes.  We're certainly not going to make TRUNCATE update that count, since
> that would require making a pass over the table to count the to-be-deleted
> tuples, and the whole point of TRUNCATE is to not make a pass over the
> table.
>
>                         regards, tom lane
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
@ 2013-12-16 15:50  Stephen Frost <sfrost@snowman.net>
  parent: Anit Chakkarwar <anitchakkarwar@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Stephen Frost @ 2013-12-16 15:50 UTC (permalink / raw)
  To: Anit Chakkarwar <anitchakkarwar@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs

Anit,

* Anit Chakkarwar (anitchakkarwar@gmail.com) wrote:
> Now n_tup_del = 2, n_tup_ins=120, n_live_tup=20 in pg_stat_user_tables, but
> how can I figure out what has happened to 98 rows?

This is information for statistics- if you need an accurate count,
you'll need to use a trigger and track that information explicitly..
There can be other ways that n_tup_del can end up being inexact.

	Thanks,

		Stephen

Attachments:

  signature.asc (application/pgp-signature, 835B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
@ 2013-12-16 23:06  Rod Taylor <rod.taylor@gmail.com>
  parent: Stephen Frost <sfrost@snowman.net>
  0 siblings, 1 reply; 6+ messages in thread

From: Rod Taylor @ 2013-12-16 23:06 UTC (permalink / raw)
  To: Stephen Frost <sfrost@snowman.net>; +Cc: Anit Chakkarwar <anitchakkarwar@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs

It's still an interesting question.

Why doesn't truncate reset table statistic to 0? The table state prior to a
truncate shouldn't influence vacuum or necessity after the truncate.

Not that vacuuming a recently truncated table would be expensive, but
Analyze timing is a concern.

regards,

Rod



On Mon, Dec 16, 2013 at 10:50 AM, Stephen Frost <sfrost@snowman.net> wrote:

> Anit,
>
> * Anit Chakkarwar (anitchakkarwar@gmail.com) wrote:
> > Now n_tup_del = 2, n_tup_ins=120, n_live_tup=20 in pg_stat_user_tables,
> but
> > how can I figure out what has happened to 98 rows?
>
> This is information for statistics- if you need an accurate count,
> you'll need to use a trigger and track that information explicitly..
> There can be other ways that n_tup_del can end up being inexact.
>
>         Thanks,
>
>                 Stephen
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate
@ 2013-12-17 00:17  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Rod Taylor <rod.taylor@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2013-12-17 00:17 UTC (permalink / raw)
  To: Rod Taylor <rod.taylor@gmail.com>; +Cc: Stephen Frost <sfrost@snowman.net>; Anit Chakkarwar <anitchakkarwar@gmail.com>; pgsql-bugs

Rod Taylor <rod.taylor@gmail.com> writes:
> Why doesn't truncate reset table statistic to 0?

Well, it does reset the counts that correspond to current table size.
This one doesn't though.  n_tup_del is a count of historical operations.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2013-12-17 00:17 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-12-13 13:13 BUG #8681: column 'n_tup_del' of pg_stat_user_tables doesn't change in case of truncate anitchakkarwar@gmail.com
2013-12-13 17:44 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-12-16 13:21   ` Anit Chakkarwar <anitchakkarwar@gmail.com>
2013-12-16 15:50     ` Stephen Frost <sfrost@snowman.net>
2013-12-16 23:06       ` Rod Taylor <rod.taylor@gmail.com>
2013-12-17 00:17         ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox