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-18-2008, 09:10 AM
Simon Riggs
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

On Mon, 2006-11-27 at 18:26 -0500, Tom Lane wrote:
> [ studies code a bit more... ] I'm also wondering whether the forced
> pg_control update at each xlog seg switch is worth its keep. Offhand
> it
> seems like the checkpoint pointer is enough; why are we maintaining
> logId/logSeg in pg_control?


We maintain the values in shared memory to allow us to determine whether
or not its time to checkpoint, and also to ensure that there is one and
only one call to checkpoint. So we need to keep track of this somewhere
and that may as well be where it already is.

However, that doesn't mean we need to update the file on disk each time
we switch xlog files, so I've removed the UpdateControlFile() at that
point. That fsync was done while holding WALWriteLock() so removing it
should be good for a few extra points of speed - at least we know there
were some problems in that area.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(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
  #2 (permalink)  
Old 04-18-2008, 09:10 AM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

"Simon Riggs" <simon@2ndquadrant.com> writes:
> On Mon, 2006-11-27 at 18:26 -0500, Tom Lane wrote:
>> [ studies code a bit more... ] I'm also wondering whether the forced
>> pg_control update at each xlog seg switch is worth its keep. Offhand
>> it seems like the checkpoint pointer is enough; why are we maintaining
>> logId/logSeg in pg_control?


> We maintain the values in shared memory to allow us to determine whether
> or not its time to checkpoint, and also to ensure that there is one and
> only one call to checkpoint. So we need to keep track of this somewhere
> and that may as well be where it already is.


Say again? AFAICT those fields are write-only; the only place we
consult them is to decide whether they need to be updated. My thought
was to remove 'em altogether.

regards, tom lane

---------------------------(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
  #3 (permalink)  
Old 04-18-2008, 09:10 AM
Simon Riggs
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

On Tue, 2006-12-05 at 15:14 -0500, Tom Lane wrote:
> "Simon Riggs" <simon@2ndquadrant.com> writes:
> > On Mon, 2006-11-27 at 18:26 -0500, Tom Lane wrote:
> >> [ studies code a bit more... ] I'm also wondering whether the forced
> >> pg_control update at each xlog seg switch is worth its keep. Offhand
> >> it seems like the checkpoint pointer is enough; why are we maintaining
> >> logId/logSeg in pg_control?

>
> > We maintain the values in shared memory to allow us to determine whether
> > or not its time to checkpoint, and also to ensure that there is one and
> > only one call to checkpoint. So we need to keep track of this somewhere
> > and that may as well be where it already is.

>
> Say again? AFAICT those fields are write-only; the only place we
> consult them is to decide whether they need to be updated. My thought
> was to remove 'em altogether.


Thats what I thought originally.

However, they guard the entrance to RequestCheckpoint() and after they
have been set nobody else will call it - look at the test immediately
prior to the rows changed by the patch. That comparison is why we still
need them and why they aren't just write-only.

So they need to be there, but we just don't need to write them to
pg_control.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(end of broadcast)---------------------------
TIP 3: 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
  #4 (permalink)  
Old 04-18-2008, 09:10 AM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

"Simon Riggs" <simon@2ndquadrant.com> writes:
> On Tue, 2006-12-05 at 15:14 -0500, Tom Lane wrote:
>> Say again? AFAICT those fields are write-only; the only place we
>> consult them is to decide whether they need to be updated. My thought
>> was to remove 'em altogether.


> Thats what I thought originally.


> However, they guard the entrance to RequestCheckpoint() and after they
> have been set nobody else will call it - look at the test immediately
> prior to the rows changed by the patch.


Sure, what would happen is that every backend passing through this code
would execute the several lines of computation needed to decide whether
to call RequestCheckpoint. That's still way cheaper than an xlog switch
as a whole, so it doesn't bother me. I think the first test is probably
effectively redundant anyway, since the whole thing is executed with
WALWriteLock held and so there can be only one backend doing it at a
time --- it's not apparent to me that it's possible for someone else to
have updated pg_control before the backend executing XLogWrite does.

But in any case, the point here is that it doesn't matter whether the
RequestCheckpoint code is inside the update-pg_control test or not.
It was only put there on the thought that we could save some small
number of cycles by not doing it if the update-pg_control test failed.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: 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
  #5 (permalink)  
Old 04-18-2008, 09:10 AM
Simon Riggs
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

On Tue, 2006-12-05 at 16:24 -0500, Tom Lane wrote:
> "Simon Riggs" <simon@2ndquadrant.com> writes:
> > On Tue, 2006-12-05 at 15:14 -0500, Tom Lane wrote:
> >> Say again? AFAICT those fields are write-only; the only place we
> >> consult them is to decide whether they need to be updated. My thought
> >> was to remove 'em altogether.

>
> > Thats what I thought originally.

>
> > However, they guard the entrance to RequestCheckpoint() and after they
> > have been set nobody else will call it - look at the test immediately
> > prior to the rows changed by the patch.

>
> Sure, what would happen is that every backend passing through this code
> would execute the several lines of computation needed to decide whether
> to call RequestCheckpoint. That's still way cheaper than an xlog switch
> as a whole, so it doesn't bother me. I think the first test is probably
> effectively redundant anyway, since the whole thing is executed with
> WALWriteLock held and so there can be only one backend doing it at a
> time --- it's not apparent to me that it's possible for someone else to
> have updated pg_control before the backend executing XLogWrite does.


Right, but the calculation uses RedoRecPtr, which may not be completely
up to date. So presumably you want to re-read the shared memory value
again to make sure we are exactly accurate and allow only one person to
call checkpoint? Either way we have to take a lock. Insert lock causes
deadlock, so we would need to use infolock.

Yes, one backend at a time executes this code, but we need a way to tell
whether the backend is the first to come through that code.

I just left it with the lock it was already requesting. If you really
think it should use infolock then I'll code it that way instead.

> But in any case, the point here is that it doesn't matter whether the
> RequestCheckpoint code is inside the update-pg_control test or not.
> It was only put there on the thought that we could save some small
> number of cycles by not doing it if the update-pg_control test failed.


Understood, that wasn't why I left it that way.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-18-2008, 09:10 AM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

"Simon Riggs" <simon@2ndquadrant.com> writes:
> On Tue, 2006-12-05 at 16:24 -0500, Tom Lane wrote:
>> Sure, what would happen is that every backend passing through this code
>> would execute the several lines of computation needed to decide whether
>> to call RequestCheckpoint.


> Right, but the calculation uses RedoRecPtr, which may not be completely
> up to date. So presumably you want to re-read the shared memory value
> again to make sure we are exactly accurate and allow only one person to
> call checkpoint? Either way we have to take a lock. Insert lock causes
> deadlock, so we would need to use infolock.


Not at all. It's highly unlikely that RedoRecPtr would be so out of
date as to result in a false request for a checkpoint, and if it does,
so what? Worst case is we perform an extra checkpoint.

Also, given the current structure of the routine, this is probably not
the best place for that code at all --- it'd make more sense for it to
be in the just-finished-a-segment code stretch, which would ensure that
it's only done by one backend once per segment.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-18-2008, 09:10 AM
Simon Riggs
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

On Tue, 2006-12-05 at 17:26 -0500, Tom Lane wrote:
> "Simon Riggs" <simon@2ndquadrant.com> writes:
> > On Tue, 2006-12-05 at 16:24 -0500, Tom Lane wrote:
> >> Sure, what would happen is that every backend passing through this code
> >> would execute the several lines of computation needed to decide whether
> >> to call RequestCheckpoint.

>
> > Right, but the calculation uses RedoRecPtr, which may not be completely
> > up to date. So presumably you want to re-read the shared memory value
> > again to make sure we are exactly accurate and allow only one person to
> > call checkpoint? Either way we have to take a lock. Insert lock causes
> > deadlock, so we would need to use infolock.

>
> Not at all. It's highly unlikely that RedoRecPtr would be so out of
> date as to result in a false request for a checkpoint, and if it does,
> so what? Worst case is we perform an extra checkpoint.


On its own, I wouldn't normally agree...

> Also, given the current structure of the routine, this is probably not
> the best place for that code at all --- it'd make more sense for it to
> be in the just-finished-a-segment code stretch, which would ensure that
> it's only done by one backend once per segment.


But thats a much better plan since it requires no locking.

There's a lot more changes there for such a simple fix though and lots
more potential bugs, but I've coded it as you suggest and removed the
fields from pg_control.

Patch passes make check, applies cleanly on HEAD.
pg_resetxlog and pgcontroldata tested.


--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com



---------------------------(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
  #8 (permalink)  
Old 04-18-2008, 09:10 AM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

"Simon Riggs" <simon@2ndquadrant.com> writes:
> [ patch to remove logId/logSeg from pg_control ]


Looking this over, I realize that there's an unresolved problem.
Although it's true that xlog.c itself doesn't use the logId/logSeg
fields for anything interesting, pg_resetxlog relies on them to
determine how far the old WAL extends, so that it can determine a
safely higher start address for the new WAL. This puts a damper
both on my thought of removing the fields altogether, and on Simon's
earlier proposal to update them in shared memory but not immediately
write pg_control during a segment switch.

The proposed patch uses pg_control's last checkpoint location to
drive the end-of-WAL computation, but that is obviously not good
enough, as WAL might have gone many segments beyond that.

Now, underestimating the WAL end address is not fatal; AFAIK the
only consequence would be some complaints about "xlog flush request is
not satisfied" until we had managed to advance the end of WAL past the
largest page LSN present in the data files. But it's still annoying.

What I'm considering is having pg_resetxlog scan the pg_xlog directory
and assume that any segment files present might have been used.

Thoughts?

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
  #9 (permalink)  
Old 04-18-2008, 09:10 AM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

"Simon Riggs" <simon@2ndquadrant.com> writes:
> [ patch to remove logId/logSeg from pg_control ]


Applied with revisions.

regards, tom lane

---------------------------(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, 09:10 AM
Tom Lane
 
Posts: n/a
Default Re: [HACKERS] Configuring BLCKSZ and XLOGSEGSZ (in 8.3)

"Simon Riggs" <simon@2ndquadrant.com> writes:
> Question: What happens when we run out of LogIds?


We die. That will occur after generating 2^64 bytes of WAL, which for
an installation generating 100MB/second would be something over 5000
years if I'm counting correctly.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: 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
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:30 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 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 55