pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #9757: Why reclaim index deleted pages need twice vacuum
3+ messages / 3 participants
[nested] [flat]

* BUG #9757: Why reclaim index deleted pages need twice vacuum
@ 2014-03-28 08:15 digoal@126.com
  2014-03-31 06:54 ` Re: BUG #9757: Why reclaim index deleted pages need twice vacuum Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 3+ messages in thread

From: digoal@126.com @ 2014-03-28 08:15 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      9757
Logged by:          digoal.zhou
Email address:      digoal@126.com
PostgreSQL version: 9.3.3
Operating system:   CentOS 6.4 x64
Description:        

When I'm testing a index page recycling, found that the index page must be
two vacuum can be reused.
The reason is thatVacuum for the first time, the main fork freespace map
file will be generated, but do not generate the index of free space map
file.
THE DETAIL : 
digoal=# create extension pageinspect;
CREATE EXTENSION
digoal=# create table test(id int primary key, info text, crt_time
timestamp);
CREATE TABLE
digoal=# insert into test select
generate_series(1,5000000),md5(random()::text),clock_timestamp();
INSERT 0 5000000
digoal=# delete from test where id<>5000000;
DELETE 4999999
-- the first vacuum, deleted index page can't reuse.
digoal=# vacuum verbose analyze test;
INFO:  vacuuming "public.test"
INFO:  scanned index "test_pkey" to remove 4999999 row versions
DETAIL:  CPU 0.00s/1.75u sec elapsed 1.77 sec.
INFO:  "test": removed 4999999 row versions in 11628 pages
DETAIL:  CPU 0.00s/0.19u sec elapsed 0.22 sec.
INFO:  index "test_pkey" now contains 1 row versions in 3404 pages
DETAIL:  4999999 index row versions were removed.
3398 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  "test": found 4999999 removable, 1 nonremovable row versions in 11628
out of 11628 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.01s/2.83u sec elapsed 2.91 sec.
INFO:  vacuuming "pg_toast.pg_toast_16432"
INFO:  index "pg_toast_16432_index" now contains 0 row versions in 1 pages
DETAIL:  0 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  "pg_toast_16432": found 0 removable, 0 nonremovable row versions in 0
out of 0 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  analyzing "public.test"
INFO:  "test": scanned 11628 of 11628 pages, containing 1 live rows and 0
dead rows; 1 rows in sample, 1 estimated total rows
VACUUM
-- and no index fsm page.
digoal=# select * from
fsm_page_contents(get_raw_page('test_pkey','fsm',0));
ERROR:  could not open file "base/16384/16471_fsm": No such file or
directory
digoal=# select * from
fsm_page_contents(get_raw_page('test_pkey','fsm',1));
ERROR:  could not open file "base/16384/16471_fsm": No such file or
directory
digoal=# select * from
fsm_page_contents(get_raw_page('test_pkey','fsm',2));
ERROR:  could not open file "base/16384/16471_fsm": No such file or
directory
-- but table fsm page generated.
digoal=# select * from fsm_page_contents(get_raw_page('test','fsm',0));
 fsm_page_contents 
-------------------
 0: 244           +
 1: 244           +
 3: 244           +
 7: 244           +
.....so on
-- the second vacuum.
digoal=# vacuum verbose analyze test;
INFO:  vacuuming "public.test"
INFO:  index "test_pkey" now contains 1 row versions in 3404 pages
DETAIL:  0 index row versions were removed.
3400 index pages have been deleted, 3400 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  "test": found 0 removable, 0 nonremovable row versions in 0 out of
11628 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  vacuuming "pg_toast.pg_toast_16432"
INFO:  index "pg_toast_16432_index" now contains 0 row versions in 1 pages
DETAIL:  0 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  "pg_toast_16432": found 0 removable, 0 nonremovable row versions in 0
out of 0 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO:  analyzing "public.test"
INFO:  "test": scanned 11628 of 11628 pages, containing 1 live rows and 0
dead rows; 1 rows in sample, 1 estimated total rows
VACUUM
-- generate the index fsm pages. and this time , the deleted index page can
reuse.
digoal=# select * from
fsm_page_contents(get_raw_page('test_pkey','fsm',0));
 fsm_page_contents 
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
255 + 0:
255 + 1:
255 + 3:
7:255 +





-- 
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] 3+ messages in thread

* Re: BUG #9757: Why reclaim index deleted pages need twice vacuum
  2014-03-28 08:15 BUG #9757: Why reclaim index deleted pages need twice vacuum digoal@126.com
@ 2014-03-31 06:54 ` Heikki Linnakangas <hlinnakangas@vmware.com>
  2014-03-31 07:25   ` Re: BUG #9757: Why reclaim index deleted pages need twice vacuum digoal@126.com <digoal@126.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Heikki Linnakangas @ 2014-03-31 06:54 UTC (permalink / raw)
  To: digoal@126.com; +Cc: pgsql-bugs

On 03/28/2014 10:15 AM, digoal@126.com wrote:
> The following bug has been logged on the website:
>
> Bug reference:      9757
> Logged by:          digoal.zhou
> Email address:      digoal@126.com
> PostgreSQL version: 9.3.3
> Operating system:   CentOS 6.4 x64
> Description:
>
> When I'm testing a index page recycling, found that the index page must be
> two vacuum can be reused.

Yep, that's how the b-tree works [1]. A deleted page cannot be 
immediately reused, because there might be concurrent scans that are 
just about to visit the page. So when a page is deleted, i.e unlinked 
from the tree, it is stamped with the next transaction ID, and left in 
place. The next vacuum checks that the transaction ID is no longer 
visible to anyone, which ensures that there are no transactions running 
that might've seen a reference to that page. Only after that the page 
can be reused.

That's quite pessimal; in most cases the page could be reused much 
earlier, because it is a very tight window for vacuum to delete a page 
just when a concurrent scan has read a link to the page and is about to 
follow it. But B-tree pages are usually not deleted that often that it 
would matter in practice, so there has been no effort to optimize it.

In short, it's not a bug :-).

[1] 
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/access/nbtree/README#l283

- Heikki


-- 
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] 3+ messages in thread

* Re: BUG #9757: Why reclaim index deleted pages need twice vacuum
  2014-03-28 08:15 BUG #9757: Why reclaim index deleted pages need twice vacuum digoal@126.com
  2014-03-31 06:54 ` Re: BUG #9757: Why reclaim index deleted pages need twice vacuum Heikki Linnakangas <hlinnakangas@vmware.com>
@ 2014-03-31 07:25   ` digoal@126.com <digoal@126.com>
  0 siblings, 0 replies; 3+ messages in thread

From: digoal@126.com @ 2014-03-31 07:25 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-bugs

Thanks very much, but in rare condition, it's a small trouble.




------------------------------------------------------------
公益是一辈子的事, I'm Digoal , Just Do it!
德哥(Digoal.Zhou)
数据库技术经理
***********************************************
杭州斯凯网络科技有限公司
杭州市紫荆花路2号联合大厦B座11层
邮编:   310013
手机:   +86 13484021953
座机:   +86 571 89710948
QQ:     276732431
email:  digoal.zhou@mopo.com
MSN:    zzzqware@hotmail.com
Blog: http://blog.163.com/digoal@126/
Github: https://github.com/digoal

From: Heikki Linnakangas
Date: 2014-03-31 14:54
To: digoal
CC: pgsql-bugs
Subject: Re: [BUGS] BUG #9757: Why reclaim index deleted pages need twice vacuum
On 03/28/2014 10:15 AM, digoal@126.com wrote:
> The following bug has been logged on the website:
>
> Bug reference:      9757
> Logged by:          digoal.zhou
> Email address:      digoal@126.com
> PostgreSQL version: 9.3.3
> Operating system:   CentOS 6.4 x64
> Description:
>
> When I'm testing a index page recycling, found that the index page must be
> two vacuum can be reused.

Yep, that's how the b-tree works [1]. A deleted page cannot be 
immediately reused, because there might be concurrent scans that are 
just about to visit the page. So when a page is deleted, i.e unlinked 
from the tree, it is stamped with the next transaction ID, and left in 
place. The next vacuum checks that the transaction ID is no longer 
visible to anyone, which ensures that there are no transactions running 
that might've seen a reference to that page. Only after that the page 
can be reused.

That's quite pessimal; in most cases the page could be reused much 
earlier, because it is a very tight window for vacuum to delete a page 
just when a concurrent scan has read a link to the page and is about to 
follow it. But B-tree pages are usually not deleted that often that it 
would matter in practice, so there has been no effort to optimize it.

In short, it's not a bug :-).

[1] 
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/access/nbtree/README#l283

- Heikki

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


end of thread, other threads:[~2014-03-31 07:25 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-03-28 08:15 BUG #9757: Why reclaim index deleted pages need twice vacuum digoal@126.com
2014-03-31 06:54 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-03-31 07:25   ` digoal@126.com <digoal@126.com>

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