Unix Technical Forum

SEO

vBulletin Search Engine Optimization


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

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2008, 05:53 AM
Alexy Khrabrov
 
Posts: n/a
Default two memory-consuming postgres processes

Greetings -- I have an UPDATE query updating a 100 million row table,
and allocate enough memory via shared_buffers=1500MB. However, I see
two processes in top, the UPDATE process eating about 850 MB and the
writer process eating about 750 MB. The box starts paging. Why is
there the writer taking almost as much space as the UPDATE, and how
can I shrink it?

Cheers,
Alexy

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-05-2008, 05:53 AM
Scott Marlowe
 
Posts: n/a
Default Re: two memory-consuming postgres processes

On Fri, May 2, 2008 at 1:24 PM, Alexy Khrabrov <deliverable@gmail.com> wrote:
> Greetings -- I have an UPDATE query updating a 100 million row table, and
> allocate enough memory via shared_buffers=1500MB. However, I see two
> processes in top, the UPDATE process eating about 850 MB and the writer
> process eating about 750 MB. The box starts paging. Why is there the
> writer taking almost as much space as the UPDATE, and how can I shrink it?


Shared_buffers is NOT the main memory pool for all operations in
pgsql, it is simply the buffer pool used to hold data being operated
on.

Things like sorts etc. use other memory and can exhaust your machine.
However, I'd like to see the output of vmstat 1 or top while this is
happening.

How much memory does this machine have?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-05-2008, 05:53 AM
Alexy Khrabrov
 
Posts: n/a
Default Re: two memory-consuming postgres processes


On May 2, 2008, at 12:30 PM, Scott Marlowe wrote:

> On Fri, May 2, 2008 at 1:24 PM, Alexy Khrabrov
> <deliverable@gmail.com> wrote:
>> Greetings -- I have an UPDATE query updating a 100 million row
>> table, and
>> allocate enough memory via shared_buffers=1500MB. However, I see two
>> processes in top, the UPDATE process eating about 850 MB and the
>> writer
>> process eating about 750 MB. The box starts paging. Why is there
>> the
>> writer taking almost as much space as the UPDATE, and how can I
>> shrink it?

>
> Shared_buffers is NOT the main memory pool for all operations in
> pgsql, it is simply the buffer pool used to hold data being operated
> on.
>
> Things like sorts etc. use other memory and can exhaust your machine.
> However, I'd like to see the output of vmstat 1 or top while this is
> happening.
>
> How much memory does this machine have?


It's a 2GB RAM MacBook. Here's the top for postgres

Processes: 117 total, 2 running, 6 stuck, 109 sleeping... 459
threads
12
:34:27
Load Avg: 0.27, 0.24, 0.32 CPU usage: 8.41% user, 11.06% sys,
80.53% idle
SharedLibs: num = 15, resident = 40M code, 2172K data, 3172K
linkedit.
MemRegions: num = 20719, resident = 265M + 12M private, 1054M shared.
PhysMem: 354M wired, 1117M active, 551M inactive, 2022M used, 19M
free.
VM: 26G + 373M 1176145(160) pageins, 1446482(2) pageouts

PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD
RSIZE VSIZE
51775 postgres 6.8% 2:40.16 1 9 39 1504K 896M 859M+
1562M
51767 postgres 0.0% 0:39.74 1 8 28 752K 896M 752M
1560M

the first is the UPDATE, the second is the writer.

The query is very simple,

netflix=> create index movs_mid_idx on movs(mid);
CREATE INDEX
netflix=> update ratings set offset1=avg-rating from movs where
mid=movie_id;

where the table ratings has about 100 million rows, movs has about
20,000.

I randomly increased values in postgresql.conf to

shared_buffers = 1500MB
max_fsm_pages = 2000000
max_fsm_relations = 10000

Should I set the background writer parameters somehow to decrease the
RAM consumed by the writer?

Cheers,
Alexy

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-05-2008, 05:53 AM
Scott Marlowe
 
Posts: n/a
Default Re: two memory-consuming postgres processes

On Fri, May 2, 2008 at 1:38 PM, Alexy Khrabrov <deliverable@gmail.com> wrote:
>
>
> On May 2, 2008, at 12:30 PM, Scott Marlowe wrote:
>
>
> > On Fri, May 2, 2008 at 1:24 PM, Alexy Khrabrov <deliverable@gmail.com>

> wrote:
> >
> > > Greetings -- I have an UPDATE query updating a 100 million row table,

> and
> > > allocate enough memory via shared_buffers=1500MB. However, I see two
> > > processes in top, the UPDATE process eating about 850 MB and the writer
> > > process eating about 750 MB. The box starts paging. Why is there the
> > > writer taking almost as much space as the UPDATE, and how can I shrink

> it?
> > >

> >
> > Shared_buffers is NOT the main memory pool for all operations in
> > pgsql, it is simply the buffer pool used to hold data being operated
> > on.
> >
> > Things like sorts etc. use other memory and can exhaust your machine.
> > However, I'd like to see the output of vmstat 1 or top while this is
> > happening.
> >
> > How much memory does this machine have?
> >

>
> It's a 2GB RAM MacBook. Here's the top for postgres
>
> Processes: 117 total, 2 running, 6 stuck, 109 sleeping... 459 threads
> 12:34:27
> Load Avg: 0.27, 0.24, 0.32 CPU usage: 8.41% user, 11.06% sys, 80.53%
> idle
> SharedLibs: num = 15, resident = 40M code, 2172K data, 3172K linkedit.
> MemRegions: num = 20719, resident = 265M + 12M private, 1054M shared.
> PhysMem: 354M wired, 1117M active, 551M inactive, 2022M used, 19M free.
> VM: 26G + 373M 1176145(160) pageins, 1446482(2) pageouts
>
> PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
> 51775 postgres 6.8% 2:40.16 1 9 39 1504K 896M 859M+
> 1562M
> 51767 postgres 0.0% 0:39.74 1 8 28 752K 896M 752M
> 1560M


SOME snipping here.

> I randomly increased values in postgresql.conf to
>
> shared_buffers = 1500MB
> max_fsm_pages = 2000000
> max_fsm_relations = 10000


On a laptop with 2G ram, 1.5Gig shared buffers is probably WAY too high.

> Should I set the background writer parameters somehow to decrease the RAM
> consumed by the writer?


No, the background writer reads through the shared buffers for dirty
ones and writes them out. so, it's not really using MORE memory, it's
just showing that it's attached to the ginormous shared_buffer pool
you've set up.

Lower your shared_buffers to about 512M or so and see how it works.

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-05-2008, 05:53 AM
Tom Lane
 
Posts: n/a
Default Re: two memory-consuming postgres processes

"Scott Marlowe" <scott.marlowe@gmail.com> writes:
> On Fri, May 2, 2008 at 1:38 PM, Alexy Khrabrov <deliverable@gmail.com> wrote:
>> I randomly increased values in postgresql.conf to
>>
>> shared_buffers = 1500MB
>> max_fsm_pages = 2000000
>> max_fsm_relations = 10000


> On a laptop with 2G ram, 1.5Gig shared buffers is probably WAY too high.


s/probably/definitely/, especially seeing that OS X is a bit of a memory
hog itself. I don't think you should figure on more than 1GB being
usefully available to Postgres, and you can't give all or even most of
that space to shared_buffers.

> No, the background writer reads through the shared buffers for dirty
> ones and writes them out. so, it's not really using MORE memory, it's
> just showing that it's attached to the ginormous shared_buffer pool
> you've set up.


Yeah. You have to be aware of top's quirky behavior for shared memory:
on most platforms it will count the shared memory against *each*
process, but only as much of the shared memory as that process has
touched so far. So over time the reported size of any PG process will
tend to climb to something over the shared memory size, but most of that
isn't "real".

I haven't directly checked whether OS X's top behaves that way, but
given your report I think it does.

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-05-2008, 05:53 AM
Greg Smith
 
Posts: n/a
Default Re: two memory-consuming postgres processes

On Fri, 2 May 2008, Alexy Khrabrov wrote:

> I have an UPDATE query updating a 100 million row table, and
> allocate enough memory via shared_buffers=1500MB.


In addition to reducing that as you've been advised, you'll probably need
to increase checkpoint_segments significantly from the default (3) in
order to get good performance on an update that large. Something like 30
would be a reasonable starting point.

I'd suggest doing those two things, seeing how things go, and reporting
back if you still think performance is unacceptable. We'd need to know
your PostgreSQL version in order to really target future suggestions.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-05-2008, 05:53 AM
Alexy Khrabrov
 
Posts: n/a
Default Re: two memory-consuming postgres processes


On May 2, 2008, at 1:13 PM, Tom Lane wrote:
> I don't think you should figure on more than 1GB being
> usefully available to Postgres, and you can't give all or even most of
> that space to shared_buffers.



So how should I divide say a 512 MB between shared_buffers and, um,
what else? (new to pg tuning

I naively thought that if I have a 100,000,000 row table, of the form
(integer,integer,smallint,date), and add a real coumn to it, it will
scroll through the memory reasonably fast. Yet when I had
shared_buffers=128 MB, it was hanging there 8 hours before I killed
it, and now with 1500MB is paging again for several hours with no end
in sight. Why can't it just add a column to a row at a time and be
done with it soon enough? It takes inordinately long compared to a
FORTRAN or even python program and there's no index usage for this
table, a sequential scan, why all the paging?

Cheers,
Alexy

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-05-2008, 05:53 AM
Alexy Khrabrov
 
Posts: n/a
Default Re: two memory-consuming postgres processes

On May 2, 2008, at 1:22 PM, Greg Smith wrote:

> On Fri, 2 May 2008, Alexy Khrabrov wrote:
>
>> I have an UPDATE query updating a 100 million row table, and
>> allocate enough memory via shared_buffers=1500MB.

>
> In addition to reducing that as you've been advised, you'll probably
> need to increase checkpoint_segments significantly from the default
> (3) in order to get good performance on an update that large.
> Something like 30 would be a reasonable starting point.
>
> I'd suggest doing those two things, seeing how things go, and
> reporting back if you still think performance is unacceptable. We'd
> need to know your PostgreSQL version in order to really target
> future suggestions.


PostgreSQL 8.3.1, compiled from source on Mac OSX 10.5.2 (Leopard).
Saw the checkpoint_segments warning every ~20sec and increased it to
100 already. Will see what 512 MB buys me, but 128 MB was paging
miserably.

Cheers,
Alexy

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-05-2008, 05:53 AM
Alexy Khrabrov
 
Posts: n/a
Default Re: two memory-consuming postgres processes


On May 2, 2008, at 1:40 PM, Scott Marlowe wrote:
> Again, a database protects your data from getting scrambled should the
> program updating it quit halfway through etc...


Right -- but this is a data mining work, I add a derived column to a
row, and it's computed from that very row and a small second table
which should fit in RAM.

> Have you been vacuuming between these update attempts? Each one has
> created millions of dead rows and bloated your data store. vacuum
> full / cluster / reindex may be needed.


I've read postgresql.conf better and see autovacuum = on is commented
out, so it's on. That explains why shutting down was taking so long
to shut autovacuum down too.

Basically, the derived data is not critical at all, -- can I turn (1)
off transactional behavior for an UPDATE, (2) should I care about
vacuuming being done on the fly when saving RAM, or need I defer it/
manage it manually?

I wonder what MySQL would do here on MyISAM tables without
transactional behavior -- perhaps this is the case more suitable for
them?

Cheers,
Alexy

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-05-2008, 05:53 AM
Craig James
 
Posts: n/a
Default Re: two memory-consuming postgres processes

On Fri, May 2, 2008 at 2:26 PM, Alexy Khrabrov <deliverable@gmail.com> wrote:
> I naively thought that if I have a 100,000,000 row table, of the form
> (integer,integer,smallint,date), and add a real coumn to it, it will scroll
> through the memory reasonably fast.


In Postgres, an update is the same as a delete/insert. That means that changing the data in one column rewrites ALL of the columns for that row, and you end up with a table that's 50% dead space, which you then have to vacuum.

Sometimes if you have a "volatile" column that goes with several "static" columns, you're far better off to create a second table for the volatile data, duplicating the primary key in both tables. In your case, it would mean the difference between 10^8 inserts of (int, float), very fast, compared to what you're doing now, which is 10^8 insert and 10^8 deletes of (int, int, smallint, date, float), followed by a big vacuum/analyze (also slow).

The down side of this design is that later on, it requires a join to fetch all the data for each key.

You do have a primary key on your data, right? Or some sort of index?

Craig

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

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



All times are GMT. The time now is 11:10 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

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 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733