Unix Technical Forum

SEO

vBulletin Search Engine Optimization


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

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 07:31 AM
DANTE ALEXANDRA
 
Posts: n/a
Default out of memory during query execution

Hello,

I am a PostGreSQL newbie. I work with the 8.1.0 release on AIX 5.3, with
300GB of datas.
Some of the queries launched on this database finish with an "*out of
memory*". The queries which have failed contain a lot of join (between 6
tables), sub-select and aggregate. For these queries, the log file
contains :
psql:Q9.sql:40: ERROR: out of memory
DETAIL: Failed on request of size 148.

On the server used, I got 3GB of memory and 1 CPU.
The settings specified in the "postgresql.conf" are :
# - Memory -
shared_buffers = 12288
#temp_buffers = 1000
#max_prepared_transactions = 5
work_mem = 65536
maintenance_work_mem = 262144
max_stack_depth = 24574

Are some of these values false?
Is the "out of memory" error due to smaller memory available ?
Has somenone ever seen this problem ?

Thank you for your help.

Regards,
Alexandra DANTE

---------------------------(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-09-2008, 07:31 AM
Chris Browne
 
Posts: n/a
Default Re: out of memory during query execution

ALEXANDRA.DANTE@BULL.NET (DANTE ALEXANDRA) writes:
> I am a PostGreSQL newbie. I work with the 8.1.0 release on AIX 5.3,
> with 300GB of datas.
> Some of the queries launched on this database finish with an "*out of
> memory*". The queries which have failed contain a lot of join (between
> 6 tables), sub-select and aggregate. For these queries, the log file
> contains :
> psql:Q9.sql:40: ERROR: out of memory
> DETAIL: Failed on request of size 148.
>
> On the server used, I got 3GB of memory and 1 CPU.
> The settings specified in the "postgresql.conf" are :
> # - Memory -
> shared_buffers = 12288 #temp_buffers = 1000
> #max_prepared_transactions = 5 work_mem = 65536
> maintenance_work_mem = 262144 max_stack_depth = 24574
>
> Are some of these values false?
> Is the "out of memory" error due to smaller memory available ?
> Has somenone ever seen this problem ?


We have seen this problem...

It's *probably* related to the memory model you're using.

I have thus far evaded *fully* understanding the details (and hope
that can persist!), but here are some of the things to consider:

- By default, AIX really prefers to build 32 bit binaries

- The sorta-hacks that IBM put in place on library segmentation (and
this stuff is quite ghastly) mean that any backend will likely have
quite a bit less than 2GB of even theoretically-available memory space.

The problem is probably that the memory model is throttling you to
*WAY* less than 2GB of memory.

You may want to try a 64 bit build. With GCC, this requires something
like the following ./configure incantation...

CC="gcc -maix64" LDFLAGS="-Wl,-bbigtoc" ./configure
--
(reverse (concatenate 'string "moc.enworbbc" "@" "enworbbc"))
http://cbbrowne.com/info/sgml.html
Rules of the Evil Overlord #86. "I will make sure that my doomsday
device is up to code and properly grounded."
<http://www.eviloverlord.com/>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 07:32 AM
Seneca Cunningham
 
Posts: n/a
Default Re: out of memory during query execution

Chris Browne wrote:
> The problem is probably that the memory model is throttling you to
> *WAY* less than 2GB of memory.
>
> You may want to try a 64 bit build. With GCC, this requires something
> like the following ./configure incantation...
>
> CC="gcc -maix64" LDFLAGS="-Wl,-bbigtoc" ./configure


You'll also want to export OBJECT_MODE=64 before the ./configure line.

--
Seneca Cunningham
scunning@ca.afilias.info

---------------------------(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
  #4 (permalink)  
Old 04-09-2008, 07:32 AM
Tom Lane
 
Posts: n/a
Default Re: out of memory during query execution

DANTE ALEXANDRA <ALEXANDRA.DANTE@BULL.NET> writes:
> I am a PostGreSQL newbie. I work with the 8.1.0 release on AIX 5.3, with
> 300GB of datas.
> Some of the queries launched on this database finish with an "*out of
> memory*". The queries which have failed contain a lot of join (between 6
> tables), sub-select and aggregate. For these queries, the log file
> contains :
> psql:Q9.sql:40: ERROR: out of memory
> DETAIL: Failed on request of size 148.


Hmm ... what ulimit settings are you running the postmaster under?
Could we see the EXPLAIN plans for some of the failing queries?

regards, tom lane

---------------------------(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
  #5 (permalink)  
Old 04-09-2008, 07:32 AM
DANTE ALEXANDRA
 
Posts: n/a
Default Re: out of memory during query execution

Hello,

Thank you for your answer.
The person is charge of building PostGreSQL 8.1.0 has done a 32 bit
build and has used the "cc_r" compiler.
This person does not succeed to build PostGreSQL 8.1.0 with "gcc" and 64
bits. Unfortunatly, I don't have the errors or the logs of the 64 bits
build and I can't tell you what error occurs.

The build done was realized in 32 bits, with the cc_r compiler.
To build POstGreSQL, a rpm was done and the ".spec" file contained the
following instructions :
export OBJECT_MODE=32
../configure CC=/usr/vac/bin/cc_r CFLAGS="-O2 -qmaxmem=-1 -qsrcmsg
-qlargepage" --enable-thread-safety
--without-readline --prefix=%{buildroot}%{prefix}
gmake -j 4
unset OBJECT_MODE

Do you think that my problems of "out of memory" are due to the 32 bits
build ?
Do you think that I must build PostGreSQL wih 64 bits to solve this error ?

Thank you for your help.
Regards,
Alexandra DANTE


Chris Browne a écrit :

>ALEXANDRA.DANTE@BULL.NET (DANTE ALEXANDRA) writes:
>
>
>>I am a PostGreSQL newbie. I work with the 8.1.0 release on AIX 5.3,
>>with 300GB of datas.
>>Some of the queries launched on this database finish with an "*out of
>>memory*". The queries which have failed contain a lot of join (between
>>6 tables), sub-select and aggregate. For these queries, the log file
>>contains :
>>psql:Q9.sql:40: ERROR: out of memory
>>DETAIL: Failed on request of size 148.
>>
>>On the server used, I got 3GB of memory and 1 CPU.
>>The settings specified in the "postgresql.conf" are :
>># - Memory -
>>shared_buffers = 12288 #temp_buffers = 1000
>>#max_prepared_transactions = 5 work_mem = 65536
>>maintenance_work_mem = 262144 max_stack_depth = 24574
>>
>>Are some of these values false?
>>Is the "out of memory" error due to smaller memory available ?
>>Has somenone ever seen this problem ?
>>
>>

>
>We have seen this problem...
>
>It's *probably* related to the memory model you're using.
>
>I have thus far evaded *fully* understanding the details (and hope
>that can persist!), but here are some of the things to consider:
>
>- By default, AIX really prefers to build 32 bit binaries
>
>- The sorta-hacks that IBM put in place on library segmentation (and
>this stuff is quite ghastly) mean that any backend will likely have
>quite a bit less than 2GB of even theoretically-available memory space.
>
>The problem is probably that the memory model is throttling you to
>*WAY* less than 2GB of memory.
>
>You may want to try a 64 bit build. With GCC, this requires something
>like the following ./configure incantation...
>
> CC="gcc -maix64" LDFLAGS="-Wl,-bbigtoc" ./configure
>
>



---------------------------(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-09-2008, 07:32 AM
DANTE ALEXANDRA
 
Posts: n/a
Default Re: out of memory during query execution

Hello,

The postmaster is launched by the user "pg_810" who is not the root user.
When I launch the "ulimit -a" command, I've got :
$ ulimit -a
time(seconds) unlimited
file(blocks) unlimited
data(kbytes) unlimited
stack(kbytes) unlimited
memory(kbytes) unlimited
coredump(blocks) unlimited
nofiles(descriptors) 2000

You will find below the explain plan of one of the queries which has
finished with "out of memory". This query contains aggregate and a
sub-select with 6 joins :
QUERY
PLAN

------------------------------------------------------------------------------------------------------------------------------
---------
GroupAggregate (cost=103283274.03..103283274.07 rows=1 width=76)
-> Sort (cost=103283274.03..103283274.04 rows=1 width=76)
Sort Key: nation.n_name, date_part('year'::text,
(orders.o_orderdate)::timestamp without time zone)
-> Nested Loop (cost=2447049.00..103283274.02 rows=1 width=76)
Join Filter: ("outer".s_nationkey = "inner".n_nationkey)
-> Nested Loop (cost=2447049.00..103283272.45 rows=1
width=55)
-> Nested Loop (cost=2447049.00..103283267.25
rows=1 width=59)
-> Hash Join (cost=2447049.00..103256685.03
rows=4800 width=80)
Hash Cond: ("outer".l_suppkey =
"inner".s_suppkey)
-> Hash Join
(cost=2311445.00..102985544.04 rows=2880228 width=64)
Hash Cond: ("outer".l_partkey =
"inner".p_partkey)
-> Seq Scan on lineitem
(cost=0.00..69142803.64 rows=1800142464 width=56)
-> Hash
(cost=2311205.00..2311205.00 rows=96000 width=8)
-> Seq Scan on part
(cost=0.00..2311205.00 rows=96000 width=8)
Filter:
((p_name)::text ~~ '%green%'::text)
-> Hash (cost=110525.00..110525.00
rows=3000000 width=16)
-> Seq Scan on supplier
(cost=0.00..110525.00 rows=3000000 width=16)
-> Index Scan using i_ps_partkey_suppkey on
partsupp (cost=0.00..5.52 rows=1 width=27)
Index Cond: ((partsupp.ps_partkey =
"outer".l_partkey) AND (partsupp.ps_suppkey = "outer".l_s
uppkey))
-> Index Scan using i_o_orderkey on orders
(cost=0.00..5.19 rows=1 width=12)
Index Cond: (orders.o_orderkey =
"outer".l_orderkey)
-> Seq Scan on nation (cost=0.00..1.25 rows=25 width=37)
(22 rows)

Regards,
Alexandra DANTE

Tom Lane a écrit :

>DANTE ALEXANDRA <ALEXANDRA.DANTE@BULL.NET> writes:
>
>
>>I am a PostGreSQL newbie. I work with the 8.1.0 release on AIX 5.3, with
>>300GB of datas.
>>Some of the queries launched on this database finish with an "*out of
>>memory*". The queries which have failed contain a lot of join (between 6
>>tables), sub-select and aggregate. For these queries, the log file
>>contains :
>>psql:Q9.sql:40: ERROR: out of memory
>>DETAIL: Failed on request of size 148.
>>
>>

>
>Hmm ... what ulimit settings are you running the postmaster under?
>Could we see the EXPLAIN plans for some of the failing queries?
>
> regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
>
>



---------------------------(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-09-2008, 07:32 AM
Martijn van Oosterhout
 
Posts: n/a
Default Re: out of memory during query execution

On Tue, Dec 20, 2005 at 01:35:03PM +0100, DANTE ALEXANDRA wrote:
> You will find below the explain plan of one of the queries which has
> finished with "out of memory". This query contains aggregate and a
> sub-select with 6 joins :


1. Firstly, it could be the Hash node. Does the estimated number of
matches in part (96000 rows) match reality?

2. Secondly, looks like lineitem could use an index on partkey. Maybe it
could then use a more efficient join?

Do you have indexes on the relevent columns?

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFDqAFlIB7bNG8LQkwRAgxZAJ4ngpLOLjZ3sP/rAjv80XY+jWNc8QCfS051
HjKuw4pwWJuF1wFP1N26740=
=+xrY
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-09-2008, 07:32 AM
Seneca Cunningham
 
Posts: n/a
Default Re: out of memory during query execution

DANTE ALEXANDRA wrote:
> The person is charge of building PostGreSQL 8.1.0 has done a 32 bit
> build and has used the "cc_r" compiler.
> This person does not succeed to build PostGreSQL 8.1.0 with "gcc" and 64
> bits. Unfortunatly, I don't have the errors or the logs of the 64 bits
> build and I can't tell you what error occurs.


Too bad, I may have been able to determine what had happened with the
gcc build.

> The build done was realized in 32 bits, with the cc_r compiler.
> To build POstGreSQL, a rpm was done and the ".spec" file contained the
> following instructions :
> export OBJECT_MODE=32
> ./configure CC=/usr/vac/bin/cc_r CFLAGS="-O2 -qmaxmem=-1 -qsrcmsg
> -qlargepage" --enable-thread-safety
> --without-readline --prefix=%{buildroot}%{prefix}
> gmake -j 4
> unset OBJECT_MODE
>
> Do you think that my problems of "out of memory" are due to the 32 bits
> build ?
> Do you think that I must build PostGreSQL wih 64 bits to solve this error ?


It is quite likely that the out of memory errors are due to your use of
the default 32-bit memory model. In that model, a single 256MB memory
segment contains your heap, stack, thread stacks, and other per-process,
non-shared-library data. Switching to 64-bit would stop the errors if
this is true. It is also possible to adjust the amount of space
available to a 32-bit process' heap with the -bmaxdata linker option,
but the largest heap size that I would consider safe with 32-bit is 2GB
and comes with the cost of reducing the amount of shared memory
available to the process.

Setting OBJECT_MODE to 64 before the ./configure and gmake should result
in a 64-bit build, but I don't have a copy of IBM's compiler to test
with. I would be interested in seeing the errors output by the 64-bit
gcc build if another build is attempted.

--
Seneca Cunningham
scunning@ca.afilias.info

---------------------------(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
  #9 (permalink)  
Old 04-09-2008, 07:32 AM
Tom Lane
 
Posts: n/a
Default Re: out of memory during query execution

Martijn van Oosterhout <kleptog@svana.org> writes:
> On Tue, Dec 20, 2005 at 01:35:03PM +0100, DANTE ALEXANDRA wrote:
>> You will find below the explain plan of one of the queries which has
>> finished with "out of memory". This query contains aggregate and a
>> sub-select with 6 joins :


> 1. Firstly, it could be the Hash node. Does the estimated number of
> matches in part (96000 rows) match reality?


Actually, the hash on "supplier" (3000000 rows) looks like a bigger
risk. But if this is 8.1 then there is code in there to spill oversize
hash tables to disk, so I don't understand where the memory is going.

The "out of memory" failure should have provoked a MemoryContextStats
report in the postmaster log. Are there a bunch of lines like
%s: %ld total in %ld blocks; %ld free (%ld chunks); %ld used
and if so could we see 'em?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: 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-09-2008, 07:32 AM
Kevin Murphy
 
Posts: n/a
Default Re: out of memory during query execution

I'm certainly not an AIX expert, but I remember my 32-bit AIX programs
being limited to 256MB of heap by default. When I linked, I think I had
to ask for more maximum data page space using something like:

-bmaxdata:0x40000000

(which asks for 1GB, I believe)

-Kevin Murphy


---------------------------(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 11:10 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