Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 11:21 PM
Neil Conway
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

Hannu Krosing wrote:
> *** src/backend/access/transam/xact.c 28 Apr 2005 21:47:10 -0000 1.200
> --- src/backend/access/transam/xact.c 17 May 2005 22:06:34 -0000
> ***************
> *** 1411,1416 ****
> --- 1411,1424 ----
> AfterTriggerBeginXact();
>
> /*
> + * mark the transaction as not VACUUM (vacuum_rel will set isVacuum to true
> + * directly after calling BeginTransactionCommand() )
> + */
> + if (MyProc != NULL)
> + {
> + MyProc->inVacuum = false;
> + }


I'm a little worried about having this set to "true" after a VACUUM is
executed, and only reset to false when the next transaction is begun: it
shouldn't affect correctness right now, but it seems like asking for
trouble. Resetting the flag to "false" after processing a transaction
would probably be worth doing.

> *** src/backend/commands/vacuum.c 6 May 2005 17:24:53 -0000 1.308
> --- src/backend/commands/vacuum.c 17 May 2005 22:06:35 -0000
> ***************
> *** 420,425 ****
> --- 418,428 ----
> if (use_own_xacts)
> {
> StartTransactionCommand();
> + if (MyProc != NULL) /* is this needed here ? */
> + {
> + /* so other vacuums don't look at our xid/xmin in GetOldestXmin() */
> + MyProc->inVacuum = true;
> + }
> /* functions in indexes may want a snapshot set */
> ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
> }


Is it valid to apply this optimization to ANALYZE? Since ANALYZE updates
pg_statistic, ISTM it can affect tuple visibility.

> *** src/backend/storage/ipc/sinval.c 31 Dec 2004 22:00:56 -0000 1.75
> --- src/backend/storage/ipc/sinval.c 17 May 2005 22:06:36 -0000
> ***************
> *** 845,854 ****
> * them as running anyway. We also assume that such xacts
> * can't compute an xmin older than ours, so they needn't be
> * considered in computing globalxmin.
> */
> if (proc == MyProc ||
> !TransactionIdIsNormal(xid) ||
> ! TransactionIdFollowsOrEquals(xid, xmax))
> continue;
>
> if (TransactionIdPrecedes(xid, xmin))
> --- 845,858 ----
> * them as running anyway. We also assume that such xacts
> * can't compute an xmin older than ours, so they needn't be
> * considered in computing globalxmin.
> + *
> + * there is also no need to consider transaxtions runnibg the
> + * vacuum command as it will not affect tuple visibility
> */


Typos.

-Neil

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 11:21 PM
Tom Lane
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

Neil Conway <neilc@samurai.com> writes:
> I'm a little worried about having this set to "true" after a VACUUM is
> executed, and only reset to false when the next transaction is begun: it
> shouldn't affect correctness right now, but it seems like asking for
> trouble. Resetting the flag to "false" after processing a transaction
> would probably be worth doing.


These days I'd be inclined to use a PG_TRY construct to guarantee the
flag is cleared, rather than loading another cleanup operation onto
unrelated code.

The MyProc != NULL tests are a waste of code space. You can't even
acquire an LWLock without MyProc being set, let alone access tables.

The real issue here though is whether anyone can blow a hole in the
xmin assumptions: is there any situation where ignoring a vacuum
transaction breaks things? I haven't had time to think about it
in any detail, but it definitely needs to be thought about.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 11:21 PM
Hannu Krosing
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

On E, 2005-05-23 at 10:16 -0400, Tom Lane wrote:
> Neil Conway <neilc@samurai.com> writes:
> > I'm a little worried about having this set to "true" after a VACUUM is
> > executed, and only reset to false when the next transaction is begun: it
> > shouldn't affect correctness right now, but it seems like asking for
> > trouble. Resetting the flag to "false" after processing a transaction
> > would probably be worth doing.

>
> These days I'd be inclined to use a PG_TRY construct to guarantee the
> flag is cleared, rather than loading another cleanup operation onto
> unrelated code.


Ok, will check out PG_TRY. I hoped that there is some way not to set
inVacuum to false at each transaction start and still be sure that it
will be reverted after vacuum_rel.

So I'll set it once at the start of connection and then maintain it in
vacuum_rel() using PG_TRY.

> The MyProc != NULL tests are a waste of code space. You can't even
> acquire an LWLock without MyProc being set, let alone access tables.


Thanks, I'll get rid of them.

> The real issue here though is whether anyone can blow a hole in the
> xmin assumptions: is there any situation where ignoring a vacuum
> transaction breaks things? I haven't had time to think about it
> in any detail, but it definitely needs to be thought about.


There may be need to exclude vacuum/analyse on system relations from
being ignored by vacuum_rel() as I suspect that the info they both write
to pg_class, pg_attribute, and possibly other tables may be vulnerable
to crashes at right moment.

Also it may be prudent to not exclude other vacuums, when the vacuum_rel
() itself is run on a system relation.

I'm not sure which way it is, as my head gets all thick each time I try
to figure it out ;p.

I can't think of any other cases where it could matter, as at least the
work done inside vacuum_rel() itself seema non-rollbackable.

--
Hannu Krosing <hannu@skype.net>


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 11:21 PM
Tom Lane
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

Hannu Krosing <hannu@skype.net> writes:
> I can't think of any other cases where it could matter, as at least the
> work done inside vacuum_rel() itself seema non-rollbackable.


VACUUM FULL's tuple-moving is definitely roll-back-able, so it might be
prudent to only do this for lazy VACUUM. But on the other hand, VACUUM
FULL holds an exclusive lock on the table so no one else is going to see
its effects concurrently anyway.

As I said, it needs more thought than I've been able to spare for it yet
....

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-17-2008, 11:21 PM
Hannu Krosing
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

On E, 2005-05-23 at 11:42 -0400, Tom Lane wrote:
> Hannu Krosing <hannu@skype.net> writes:
> > I can't think of any other cases where it could matter, as at least the
> > work done inside vacuum_rel() itself seema non-rollbackable.

>
> VACUUM FULL's tuple-moving is definitely roll-back-able, so it might be
> prudent to only do this for lazy VACUUM. But on the other hand, VACUUM
> FULL holds an exclusive lock on the table so no one else is going to see
> its effects concurrently anyway.


I'm not interested in VACUUM FULL at all. This is improvement mainly for
heavy update OLAP databases, where I would not even think of running
VACUUM FULL.

I'll cheks if there's an easy way to exclude VACUUM FULL.

> As I said, it needs more thought than I've been able to spare for it yet
> ...


Ok, thanks for comments this far .

--
Hannu Krosing <hannu@skype.net>


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-17-2008, 11:36 PM
Hannu Krosing
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

On E, 2005-05-23 at 11:42 -0400, Tom Lane wrote:
> Hannu Krosing <hannu@skype.net> writes:
> > I can't think of any other cases where it could matter, as at least the
> > work done inside vacuum_rel() itself seema non-rollbackable.

>
> VACUUM FULL's tuple-moving is definitely roll-back-able, so it might be
> prudent to only do this for lazy VACUUM. But on the other hand, VACUUM
> FULL holds an exclusive lock on the table so no one else is going to see
> its effects concurrently anyway.


Ok, this is a new version of the vacuum patch with the following changes
following some suggestions in this thread.

* changed the patch to affect only lazy vacuum
* moved inVacuum handling to use PG_TRY
* moved vac_update_relstats() out of lazy_vacuum_rel into a separate
transaction. The code to do this may not be the prettiest, maybe it
should use a separate struct.

--
Hannu Krosing <hannu@skype.net>


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-17-2008, 11:36 PM
Tom Lane
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

Hannu Krosing <hannu@skype.net> writes:
> Ok, this is a new version of the vacuum patch with the following changes
> following some suggestions in this thread.


The more I look at this, the uglier it looks ... and I still haven't
seen any convincing demonstration that it *works*, ie doesn't have
bad side-effects on the transaction-is-in-progress logic. I'm
particularly concerned about what happens to the RecentXmin horizon
for pg_subtrans and pg_multixact operations.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-17-2008, 11:36 PM
Hannu Krosing
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

On P, 2005-07-03 at 12:19 -0400, Tom Lane wrote:
> Hannu Krosing <hannu@skype.net> writes:
> > Ok, this is a new version of the vacuum patch with the following changes
> > following some suggestions in this thread.

>
> The more I look at this, the uglier it looks ... and I still haven't
> seen any convincing demonstration that it *works*, ie doesn't have
> bad side-effects on the transaction-is-in-progress logic.


The function GetOldestXmin is used *only* when determining oldest xmin
for transactions.

> I'm particularly concerned about what happens to the RecentXmin horizon
> for pg_subtrans and pg_multixact operations.


How are they affected by this change ? They should still see the vacuum
as oldest transaction, unless they


Oh, now I see. I'm pretty sure that at the time of original patch, the
*only* uses of GetOldestXmin was from VACUUM and catalog/index.c and
both for the same purpose, but now I see also a call from
access/transam/xlog.c.

Perhaps I should separate the function used by vacuum into another
function, say GetOldestDataChangingXmin(), to keep the possible impact
as localised as possible.

Do you have any specific concerns related to this patch after that ?

Or should I just back off for now and maybe start a separate project for
ironing out patches related to running postgresql in real-world 24/7
OLTP environment (similar to what Bizgres does for OLAP ) ?

--
Hannu Krosing <hannu@skype.net>



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-18-2008, 12:52 AM
Bruce Momjian
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each


Alvaro has just applied a modified version of this patch.

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

Hannu Krosing wrote:
> On E, 2005-05-23 at 11:42 -0400, Tom Lane wrote:
> > Hannu Krosing <hannu@skype.net> writes:
> > > I can't think of any other cases where it could matter, as at least the
> > > work done inside vacuum_rel() itself seema non-rollbackable.

> >
> > VACUUM FULL's tuple-moving is definitely roll-back-able, so it might be
> > prudent to only do this for lazy VACUUM. But on the other hand, VACUUM
> > FULL holds an exclusive lock on the table so no one else is going to see
> > its effects concurrently anyway.

>
> Ok, this is a new version of the vacuum patch with the following changes
> following some suggestions in this thread.
>
> * changed the patch to affect only lazy vacuum
> * moved inVacuum handling to use PG_TRY
> * moved vac_update_relstats() out of lazy_vacuum_rel into a separate
> transaction. The code to do this may not be the prettiest, maybe it
> should use a separate struct.
>
> --
> Hannu Krosing <hannu@skype.net>


[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match


--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-18-2008, 12:52 AM
Alvaro Herrera
 
Posts: n/a
Default Re: PATCH to allow concurrent VACUUMs to not lock each

Bruce Momjian wrote:
>
> Alvaro has just applied a modified version of this patch.


Hannu, I'm curious:

> Hannu Krosing wrote:


> > Ok, this is a new version of the vacuum patch with the following changes
> > following some suggestions in this thread.
> >
> > * changed the patch to affect only lazy vacuum
> > * moved inVacuum handling to use PG_TRY
> > * moved vac_update_relstats() out of lazy_vacuum_rel into a separate
> > transaction. The code to do this may not be the prettiest, maybe it
> > should use a separate struct.


What was idea behind moving vac_update_relstats to a separate
transaction? I'm wondering if it's still needed, if it further enhances
the system somehow, or your patch did something differently than what
was applied.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537