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 04-18-2008, 11:08 AM
Rodrigo Moreno
 
Posts: n/a
Default Degradation of postgres 7.4.5 on FreeBSD/CygWin

Hi All

I'm really desparate about this. The problem has occurried in both of my
customers first with cygwin and now with FreeBSD 5.3.

After 2 months, postgres start get down the performance, and simple queries
that should run in 100ms now tooks about 15 secs.

Another behaviour, the data is growing to much, with no reason, just like
the comparision.

So, to solve problem, for the 5th time, a made a backup, dropped the entire
database, recreate e reimported.

One friend of mine tell me about same problem in linux and he go back to
7.3.x, and with me 5 times.

The old data have this sizes:

$ du -ks * | sort -nr
1379872 base
131202 pg_xlog
390 global
336 serverlog
74 pg_clog
8 postgresql.conf
4 pg_hba.conf
2 postmaster.opts
2 pg_ident.conf
2 PG_VERSION

The Reimported database has this sizes:
$ du -ks * | sort -nr
916496 base
131202 pg_xlog
134 global
14 serverlog
10 pg_clog
8 postgresql.conf
4 pg_hba.conf
2 postmaster.pid
2 postmaster.opts
2 pg_ident.conf
2 PG_VERSION


This Procedure took 100 ms, but before re-import it took about 15secs, in a
process that have a 1000 itens its took about 4 hours to finish, and after
re-import 5 minutes.

The bottleneck is this recursion procedure, that is a part os others
procedure, but it have a simple query.

CREATE OR REPLACE FUNCTION Produt_Repos(numeric, double precision, integer,
integer) RETURNS double precision AS '
DECLARE
xcodpro ALIAS FOR $1;
xPesfor ALIAS FOR $2;
xAno ALIAS FOR $3;
xMes ALIAS FOR $4;
oMatpro RECORD;
xPreRep DOUBLE PRECISION;
nPreRep DOUBLE PRECISION;
xQtdKgs DOUBLE PRECISION;
xPreCus DOUBLE PRECISION;
BEGIN
xPreRep := 0;

IF xPesFor <> 0 THEN
FOR oMatpro IN SELECT a.qtdpro, a.codmat, b.pesfor
FROM matpro a, produt b
WHERE a.codpro = xCodpro
AND b.codpro = a.codmat LOOP

xQtdKgs := oMatpro.QtdPro / xPesFor;
nPreRep := Produt_Repos( oMatpro.codmat, coalesce(oMatpro.pesfor, 0.0),
xAno, xMes);
xPrerep := xPrerep + (nPreRep * xQtdKgs);

IF nPreRep = 0 THEN
SELECT coalesce(PreCus, 0.0) INTO xPreCus FROM produt_fecha WHERE codpro =
oMatPro.codmat and ano = xAno and mes = xMes LIMIT 1;
xPreRep := xPrerep + ( xPrecus * xQtdKgs );
END IF;
END LOOP;
END IF;

RETURN xPreRep;
END;
' LANGUAGE 'plpgsql';



This are my configs:

msginfo:
msgmax: 16384 (max characters in a message)
msgmni: 40 (# of message queues)
msgmnb: 2048 (max characters in a message queue)
msgtql: 40 (max # of messages in system)
msgssz: 8 (size of a message segment)
msgseg: 2048 (# of message segments in system)

shminfo:
shmmax: 163840000 (max shared memory segment size)
shmmin: 1 (min shared memory segment size)
shmmni: 4000 (max number of shared memory identifiers)
shmseg: 128 (max shared memory segments per process)
shmall: 40000 (max amount of shared memory in pages)

seminfo:
semmap: 30 (# of entries in semaphore map)
semmni: 40961 (# of semaphore identifiers)
semmns: 16380 (# of semaphores in system)
semmnu: 30 (# of undo structures in system)
semmsl: 16380 (max # of semaphores per id)
semopm: 100 (max # of operations per semop call)
semume: 10 (max # of undo entries per process)
semusz: 92 (size in bytes of undo structure)
semvmx: 32767 (semaphore maximum value)
semaem: 16384 (adjust on exit max value)


max_connections = 30
shared_buffers = 8192 # min 16, at least max_connections*2, 8KB
each
sort_mem = 32768 # min 64, size in KB
vacuum_mem = 32768 # min 1024, size in KB
max_fsm_pages = 40000 # min max_fsm_relations*16, 6 bytes each
max_fsm_relations = 2000 # min 100, ~50 bytes each

These are my crontab activities:

$ crontab -l
00 13 * * 1-5 /bin/sh /home/postgres/backup.sh >/dev/null 2>&1
00 19 * * 1-5 /bin/sh /home/postgres/backup.sh >/dev/null 2>&1
00 23 * * 1-5 /usr/local/pgsql/bin/psql supre -c "vacuum analyze;"
>>/dev/null 2>&1

00 23 * * 6 /usr/local/pgsql/bin/psql supre -c "reindex database supre;"
>>/dev/null 2>&1

00 23 * * 7 /usr/local/pgsql/bin/psql supre -c "vacuum full analyze;"
>>/dev/null 2>&1



So guys, i'm really desparate about this issue, and i think i'm doing
everthing right. Please help me.

If i tell to my customer that he is having the same problem that in cygwin
version, after spending money to change from windows to freebsd,upgrading
server, etc, problably he will kill me.

Best Regards
Rodrigo Moreno



---------------------------(end of broadcast)---------------------------
TIP 6: 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
  #2 (permalink)  
Old 04-18-2008, 11:08 AM
Steinar H. Gunderson
 
Posts: n/a
Default Re: Degradation of postgres 7.4.5 on FreeBSD/CygWin

On Fri, Feb 18, 2005 at 11:54:34AM -0300, Rodrigo Moreno wrote:
> 00 23 * * 1-5 /usr/local/pgsql/bin/psql supre -c "vacuum analyze;"
>>>/dev/null 2>&1


Isn't vacuum once a day a bit too little with heavy activity? You should
probably consider autovacuum.

> 00 23 * * 6 /usr/local/pgsql/bin/psql supre -c "reindex database supre;"
>>>/dev/null 2>&1


REINDEX DATABASE does (AFAIK) only index the indexes on the system tables in
the database.

/* Steinar */
--
Homepage: http://www.sesse.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
  #3 (permalink)  
Old 04-18-2008, 11:08 AM
Tom Lane
 
Posts: n/a
Default Re: Degradation of postgres 7.4.5 on FreeBSD/CygWin

"Rodrigo Moreno" <rodrigo.miguel@terra.com.br> writes:
> After 2 months, postgres start get down the performance, and simple queries
> that should run in 100ms now tooks about 15 secs.


> Another behaviour, the data is growing to much, with no reason, just like
> the comparision.


Are you vacuuming on a regular basis? Do you have the FSM settings high
enough to cover the database?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 11:08 AM
Steinar H. Gunderson
 
Posts: n/a
Default Re: Degradation of postgres 7.4.5 on FreeBSD/CygWin

On Fri, Feb 18, 2005 at 09:32:25AM -0500, Tom Lane wrote:
> Are you vacuuming on a regular basis? Do you have the FSM settings high
> enough to cover the database?


He posted his cron settings ;-)

/* Steinar */
--
Homepage: http://www.sesse.net/

---------------------------(end of broadcast)---------------------------
TIP 9: 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
  #5 (permalink)  
Old 04-18-2008, 11:08 AM
Rodrigo Moreno
 
Posts: n/a
Default RES: Degradation of postgres 7.4.5 on FreeBSD/CygWin

Hi,

this is only max 15 concurrent conections. And is not a heavy performance
database, so i think this is not necessary vacumm more than once a day.

In another customer, has only 5 users and the database have 300mb, small
database, and has the same behaviour (haven't modified postgresql).
My first instalation was not changed anything in postgresql.conf, but in
this new server (FreeBSD) i have changed some parameters.

as showed in my crontab list, i think this is enough:
00 13 * * 1-5 /bin/sh /home/postgres/backup.sh >/dev/null 2>&1
00 19 * * 1-5 /bin/sh /home/postgres/backup.sh >/dev/null 2>&1
00 23 * * 1-5 /usr/local/pgsql/bin/psql supre -c "vacuum analyze;"
>>/dev/null 2>&1

00 23 * * 6 /usr/local/pgsql/bin/psql supre -c "reindex database supre;"
>>/dev/null 2>&1

00 23 * * 7 /usr/local/pgsql/bin/psql supre -c "vacuum full analyze;"
>>/dev/null 2>&1


These my changed configs in postgresql.conf:
max_connections = 30
shared_buffers = 8192
sort_mem = 32768
vacuum_mem = 32768
max_fsm_pages = 40000
max_fsm_relations = 2000

But why after 2 months the database has 1.3gb and after reimport on 900mb ?

Both customer are smaller databases, but one of them, has 8 years os data,
it's the reason of size 900mb, these are too smaller database.

Regards
Rodrigo Moreno


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-18-2008, 11:08 AM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: RES: Degradation of postgres 7.4.5 on FreeBSD/CygWin

> this is only max 15 concurrent conections. And is not a heavy performance
> database, so i think this is not necessary vacumm more than once a day.
>
> In another customer, has only 5 users and the database have 300mb, small
> database, and has the same behaviour (haven't modified postgresql).
> My first instalation was not changed anything in postgresql.conf, but in
> this new server (FreeBSD) i have changed some parameters.
>
> as showed in my crontab list, i think this is enough:
> 00 13 * * 1-5 /bin/sh /home/postgres/backup.sh >/dev/null 2>&1
> 00 19 * * 1-5 /bin/sh /home/postgres/backup.sh >/dev/null 2>&1
> 00 23 * * 1-5 /usr/local/pgsql/bin/psql supre -c "vacuum analyze;"


We just told you - it's nowhere near enough. Vacuum once an hour. Size
of the database is not that relevant, its size of changes that is.

Chris

---------------------------(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
  #7 (permalink)  
Old 04-18-2008, 11:08 AM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: RES: Degradation of postgres 7.4.5 on FreeBSD/CygWin

> 00 23 * * 1-5 /usr/local/pgsql/bin/psql supre -c "vacuum analyze;"

Also, this is bad - you are not vacuuming all your databases, which will
cause you data loss one day with transaction wraparound. Use the
vacuumdb utility that comes with PostgreSQL instead.

Chris

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-18-2008, 11:08 AM
Tom Lane
 
Posts: n/a
Default Re: RES: Degradation of postgres 7.4.5 on FreeBSD/CygWin

"Rodrigo Moreno" <rodrigo.miguel@terra.com.br> writes:
> max_fsm_pages = 40000
> max_fsm_relations = 2000


> But why after 2 months the database has 1.3gb and after reimport on 900mb ?


40k pages = 320M bytes = 1/3rd of your database. Perhaps you need a
larger setting for max_fsm_pages.

However, 30% bloat of the database doesn't particularly bother me,
especially when you are using infrequent vacuums. Bear in mind that,
for example, the steady-state fill factor of a b-tree index is usually
estimated at less than 70%. A certain amount of wasted space is not
only intended, but essential for reasonable performance.

What you need is to take a more detailed look at the behavior of that
function that's getting so slow. Are the query plans changing? Is
the loop iterating over many more rows than before? You haven't told
us anything that would account for 100x slowdown.

regards, tom lane

---------------------------(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, 11:08 AM
Rodrigo Moreno
 
Posts: n/a
Default RES: RES: Degradation of postgres 7.4.5 on FreeBSD/CygWin

Thanks to all,

at this moment, can't stop the database and put back the old database, but
at night i will take more analyzes on old database and reimported and i put
here the results.

Thanks a lot
Rodrigo

-----Mensagem original-----
De: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Enviada em: sexta-feira, 18 de fevereiro de 2005 12:00
Para: Rodrigo Moreno
Cc: pgsql-performance@postgresql.org
Assunto: Re: RES: [PERFORM] Degradation of postgres 7.4.5 on
FreeBSD/CygWin


"Rodrigo Moreno" <rodrigo.miguel@terra.com.br> writes:
> max_fsm_pages = 40000
> max_fsm_relations = 2000


> But why after 2 months the database has 1.3gb and after reimport on 900mb

?

40k pages = 320M bytes = 1/3rd of your database. Perhaps you need a
larger setting for max_fsm_pages.

However, 30% bloat of the database doesn't particularly bother me,
especially when you are using infrequent vacuums. Bear in mind that,
for example, the steady-state fill factor of a b-tree index is usually
estimated at less than 70%. A certain amount of wasted space is not
only intended, but essential for reasonable performance.

What you need is to take a more detailed look at the behavior of that
function that's getting so slow. Are the query plans changing? Is
the loop iterating over many more rows than before? You haven't told
us anything that would account for 100x slowdown.

regards, tom lane


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-18-2008, 11:09 AM
Rodrigo Moreno
 
Posts: n/a
Default RES: RES: Degradation of postgres 7.4.5 on FreeBSD/CygWin

Hi all,

I Got more improvements using vacuumdb utility and the size of my database
was decreasead from 1.3gb to 900mb.

Only one thing is not right yeat. My procedure perform others 7
subprocedures and with reimported database, it's took about 5 minutes to
complete. With old vacuumed database, the same process took 20minutes, it's
much better than the 4 hours before, but there is little diference.

Now, i have scheduled the vacuumdb --analyze once a day and
vacuumdb --analyze --all --full once a week, i think this is enough.

Now i'll check for reindexes tables and i'll perform analyze in each query
in procedure.

When i get more results, i post here.

Thanks a Lot
Rodrigo Moreno


---------------------------(end of broadcast)---------------------------
TIP 8: 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:52 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 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