Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E79851337B39 for ; Fri, 12 Nov 2010 09:47:38 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 57074-03 for ; Fri, 12 Nov 2010 13:47:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from cerber.thunderworx.net (cerber.thunderworx.net [217.27.32.18]) by mail.postgresql.org (Postfix) with ESMTP id 2585D1336971 for ; Fri, 12 Nov 2010 09:47:31 -0400 (AST) Received: by cerber.thunderworx.net from user; Fri, 12 Nov 2010 15:47:31 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.0.6619.12 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: MVCC performance issue Date: Fri, 12 Nov 2010 15:47:30 +0200 Message-ID: <8BCBF9DB739F034B87FE7C7D30EAE55C279F054F@hqex2k.francoudi.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: MVCC performance issue Thread-Index: AcuBzTkRuYeLMNIpSD+rZ/UEmqBCEA== From: "Kyriacos Kyriacou" To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201011/188 X-Sequence-Number: 41212 This is my first post in this mailing list and I would like to raise an issue that in my opinion is causing performance issues of PostgreSQL especially in a transaction processing environment. In my company we are using PostgreSQL for the last 8 year for our in-house developed billing system (telecom). The last few months we started considering moving to another RDBMS just because of this issue.=20 After all these years, I believe that the biggest improvement that could be done and will boost overall performance especially for enterprise application will be to improve Multiversion Concurrency Control (MVCC) mechanism. In theory this seems to be improving performance for SELECT queries but on tables with very intensive and frequent updates, even that is not fully true because of the fragmentation of data caused by MVCC. I saw cases were a SELECT COUNT(*) on an empty (!!!) table (used as a buffer) took more than 40min to return a result! VACUUM is not a solution in my opinion even though after the introduction of autovacuum daemon situation got much better. PROBLEM DECRIPTION ------------------ By definition of MVCC, when an UPDATE is performed, PostgreSQL creates a new copy of the row in a new location. Any SELECT queries within the same session are accessing the new version of the raw and all other queries from other users are still accessing the old version. When transaction is COMMIT PostgreSQL makes the a new version of the row as the "active" row and expires the old row that remains "dead" and then is up to VACUUM procedure to recover the "dead" rows space and make it available to the database engine. In case that transaction is ROLLBACK then space reserved for the new version of the row is released. The result is to have huge fragmentation on table space, unnecessary updates in all affected indexes, unnecessary costly I/O operations, poor performance on SELECT that retrieves big record sets (i.e. reports etc) and slower updates. As an example, consider updating the "live" balance of a customer for each phone call where the entire customer record has to be duplicated again and again upon each call just for modifying a numeric value!=20 SUGGESTION -------------- 1) When a raw UPDATE is performed, store all "new raw versions" either in separate temporary table space=20 or in a reserved space at the end of each table (can be allocated dynamically) etc=20 2) Any SELECT queries within the same session will be again accessing the new version of the row 3) Any SELECT queries from other users will still be accessing the old version 4) When UPDATE transaction is ROLLBACK just release the space used in new temporary location =20 5) When UPDATE transaction is COMMIT then try to LOCK the old version and overwrite it at the same physical location (NO FRAGMENTATION). 6) Similar mechanism can be applied on INSERTS and DELETES =20 7) In case that transaction was COMMIT, the temporary location can be either released or archived/cleaned on a pre-scheduled basis. This will possibly allow the introduction of a TRANSACTION LOG backup mechanism as a next step.=20 8) After that VACUUM will have to deal only with deletions!!!=20 I understand that my suggestion seems to be too simplified and also that there are many implementation details and difficulties that I am not aware.=20 I strongly believe that the outcome of the discussion regarding this issue will be helpful.=20 Best Regards,=20 Kyriacos Kyriacou Senior Developer/DBA