Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 164A0633A6B for ; Wed, 13 Jan 2010 00:59:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 78810-05 for ; Wed, 13 Jan 2010 04:59:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.25]) by mail.postgresql.org (Postfix) with ESMTP id 958936328F9 for ; Wed, 13 Jan 2010 00:59:13 -0400 (AST) Received: by ey-out-2122.google.com with SMTP id 22so3973275eye.33 for ; Tue, 12 Jan 2010 20:59:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=FILu8QFYlVzxWciJ9ayOZI24NE4Jhz6enfBYOJM/4Yw=; b=D7qECc5tu9rqpFP/jL9h+0INw/owB7BjE4YKZxtK9eA7UzT5MmpyeJy0zVxxYxdk0M lYMU9JeSb2Ic5zWsZbg9AWFQS8DIKdM0CwO+ypl/XJiJnKIeceRBC/sUIxctj4P56hgz VSG9oS0nWBPyod1OsLVPxzxH8MQ/1PruZ+Pl4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=DpFJN6shBE2in7Ut0x+bBSayi7BW1kZtROZAWxH4IisQ7jgi2UfZyfu8BkVk6vwgAP HVvQv1pzyG5fWVv1Oe5KNeMSSnsjGHT0I+pDmPPlcKrvDI8pl2+wRe2QERvUc7IkKIKs mwN2Qa55ffMOita/RzGVvgI3GWyC5E8Q/luCg= MIME-Version: 1.0 Received: by 10.216.89.194 with SMTP id c44mr3172665wef.199.1263358751825; Tue, 12 Jan 2010 20:59:11 -0800 (PST) Date: Wed, 13 Jan 2010 01:59:11 -0300 Message-ID: Subject: a heavy duty operation on an "unused" table kills my server From: Eduardo Piombino To: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=0016e6d9a3aca0611e047d04a19c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.598 tagged_above=-10 required=5 tests=BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201001/236 X-Sequence-Number: 37116 --0016e6d9a3aca0611e047d04a19c Content-Type: text/plain; charset=ISO-8859-1 Hi list, I'm having a problem when dealing with operations that asks too much CPU from the server. The scenario is this: I have a multithreaded server, each thread with its own connection to the database. Everything is working fine, actually great, actually outstandingly, in normal operation. I've a table named "a" with 1.8 million records, and growing, but I'm ok with it, at least for the moment. Maybe in the near future we will cut it down, backup old data, and free it up. But this is not the issue, as I said, everything is working great. I have a cpl of indexes to help some queries, and that's it. Now my problem started when I tried to do some model refactoring on this production table. First I tried a dumb approach. I connected from pgadmin, opened a new session. I tried an ALTER TABLE on this table just to turn a char(255) field into char(250), and it locked up my system. No surprise, since I had many threads waiting for this alter table to finish. What I did not foresee was that this alter table would take up so much time. Ok, my fault, for not having calculated the time that it would take the ALTER TABLE to complete. Now, with this experience, I tried a simple workaround. Created an empty version of "a" named "a_empty", identical in every sense. renamed "a" to "a_full", and "a_empty" to "a". This procedure costed me like 0 seconds of downtime, and everything kept working smoothly. Maybe a cpl of operations could have failed if they tried to write in the very second that there was actually no table named "a", but since the operation was transactional, the worst scenario was that if the operation should have failed, the client application would just inform of the error and ask the user for a retry. No big deal. Now, this table, that is totally unattached to the system in every way (no one references this table, its like a dumpster for old records), is not begin accessed by no other thread in the system, so an ALTER table on it, to turn a char(255) to char(250), should have no effect on the system. So, with this in mind, I tried the ALTER TABLE this time on the "a_full" (totally unrelated) table. The system went non-responsive again, and this time it had nothing to do with threads waiting for the alter table to complete. The pgAdmin GUI went non-responsive, as well as the application's server GUI, whose threads kept working on the background, but starting to take more and more time for every clients request (up to 25 seconds, which are just ridiculous and completely unacceptable in normal conditions). This resulted in my client applications to start disconnecting after their operations failed due to timeout, and the system basically went down again, from a users point of view. This time, since I saw no relation between my operation on a totally unrelated table, and the server BIG slowdown, I blamed the servers memory. After some tests, I came up to the conclusion that any heavy duty operation on any thread (ALTER TABLE on 1.8 million records tables, updates on this table, or an infinite loop, just to make my point), would affect the whole server. Bottom line is, I can't seem to do any heavy processing on the database (or any operation that would require the server to enter into high CPU usage), and still expect the server to behave normally. Whatever heavy duty operation, DDL, DML, on whatever table (related, or unrelated), on whatever thread, would tear down my servers integrity. My question then is: is there a way to limit the CPU assigned to a specific connection? I mean, I don't care if my ALTER TABLE takes 4 days instead of 4 hours. Something like: pg_set_max_cpu_usage(2/100); and rest assured that no matter what that thread is asking the database to do, it just wont affect the other running threads. Obviosly, assuring that the process itself does not involve any locking of the other threads. Is something like that possible? Thanks in advance, Eduardo. --0016e6d9a3aca0611e047d04a19c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi list, I'm having a problem when dealing with operations that asks to= o much CPU from the server.
The scenario is this:

I have a multit= hreaded server, each thread with its own connection to the database. Everyt= hing is working fine, actually great, actually outstandingly, in normal ope= ration.

I've a table named "a" with 1.8 million records, and grow= ing, but I'm ok with it, at least for the moment. Maybe in the near fut= ure we will cut it down, backup old data, and free it up. But this is not t= he issue, as I said, everything is working great. I have a cpl of indexes t= o help some queries, and that's it.

Now my problem started when I tried to do some model refactoring on thi= s production table.

First I tried a dumb approach.
I connected fr= om pgadmin, opened a new session.
I tried an ALTER TABLE on this table j= ust to turn a char(255) field into char(250), and it locked up my system.
No surprise, since I had many threads waiting for this alter table to f= inish. What I did not foresee was that this alter table would take up so mu= ch time. Ok, my fault, for not having calculated the time that it would tak= e the ALTER TABLE to complete.

Now, with this experience, I tried a simple workaround.
Created an e= mpty version of "a" named "a_empty", identical in every= sense.
renamed "a" to "a_full", and "a_empty&q= uot; to "a". This procedure costed me like 0 seconds of downtime,= and everything kept working smoothly. Maybe a cpl of operations could have= failed if they tried to write in the very second that there was actually n= o table named "a", but since the operation was transactional, the= worst scenario was that if the operation should have failed, the client ap= plication would just inform of the error and ask the user for a retry. No b= ig deal.

Now, this table, that is totally unattached to the system in every way = (no one references this table, its like a dumpster for old records), is not= begin accessed by no other thread in the system, so an ALTER table on it, = to turn a char(255) to char(250), should have no effect on the system.

So, with this in mind, I tried the ALTER TABLE this time on the "a= _full" (totally unrelated) table.
The system went non-responsive ag= ain, and this time it had nothing to do with threads waiting for the alter = table to complete. The pgAdmin GUI went non-responsive, as well as the appl= ication's server GUI, whose threads kept working on the background, but= starting to take more and more time for every clients request (up to 25 se= conds, which are just ridiculous and completely unacceptable in normal cond= itions).

This resulted in my client applications to start disconnecting after th= eir operations failed due to timeout, and the system basically went down ag= ain, from a users point of view.

This time, since I saw no relation = between my operation on a totally unrelated table, and the server BIG slowd= own, I blamed the servers memory.

After some tests, I came up to the conclusion that any heavy duty opera= tion on any thread (ALTER TABLE on 1.8 million records tables, updates on t= his table, or an infinite loop, just to make my point), would affect the wh= ole server.

Bottom line is, I can't seem to do any heavy processing on the data= base (or any operation that would require the server to enter into high CPU= usage), and still expect the server to behave normally. Whatever heavy dut= y operation, DDL, DML, on whatever table (related, or unrelated), on whatev= er thread, would tear down my servers integrity.

My question then is: is there a way to limit the CPU assigned to a spec= ific connection?
I mean, I don't care if my ALTER TABLE takes 4 days= instead of 4 hours.

Something like:
pg_set_max_cpu_usage(2/100);=

and rest assured that no matter what that thread is asking the database= to do, it just wont affect the other running threads. Obviosly, assuring t= hat the process itself does not involve any locking of the other threads.
Is something like that possible?

Thanks in advance,
Eduardo.<= br>
--0016e6d9a3aca0611e047d04a19c--