From pgsql-patches-owner@postgresql.org Mon Jan 2 14:41:22 2006 X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6AFF69DC93C for ; Mon, 2 Jan 2006 14:41:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75042-04 for ; Mon, 2 Jan 2006 14:41:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 947669DC81E for ; Mon, 2 Jan 2006 14:41:18 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k02Ieed21704; Mon, 2 Jan 2006 13:40:40 -0500 (EST) From: Bruce Momjian Message-Id: <200601021840.k02Ieed21704@candle.pha.pa.us> Subject: Stats collector performance improvement In-Reply-To: <1667.1134444045@sss.pgh.pa.us> To: Tom Lane Date: Mon, 2 Jan 2006 13:40:40 -0500 (EST) CC: Michael Fuhr , Merlin Moncure , Carlos Benkendorf , PostgreSQL-patches X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1136227240-6886-0_ Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.121] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/11 X-Sequence-Number: 18347 --ELM1136227240-6886-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Tom Lane wrote: > Michael Fuhr writes: > > Further tests show that for this application > > the killer is stats_command_string, not stats_block_level or > > stats_row_level. > > I tried it with pgbench -c 10, and got these results: > 41% reduction in TPS rate for stats_command_string > 9% reduction in TPS rate for stats_block/row_level (any combination) > > strace'ing a backend confirms my belief that stats_block/row_level send > just one stats message per transaction (at least for the relatively > small number of tables touched per transaction by pgbench). However > stats_command_string sends 14(!) --- there are seven commands per > pgbench transaction and each results in sending a message and > later an message. > > Given the rather lackadaisical way in which the stats collector makes > the data available, it seems like the backends are being much too > enthusiastic about posting their stats_command_string status > immediately. Might be worth thinking about how to cut back the > overhead by suppressing some of these messages. I did some research on this because the numbers Tom quotes indicate there is something wrong in the way we process stats_command_string statistics. I made a small test script: if [ ! -f /tmp/pgstat.sql ] then i=0 while [ $i -lt 10000 ] do i=`expr $i + 1` echo "SELECT 1;" done > /tmp/pgstat.sql fi time sql test /dev/null This sends 10,000 "SELECT 1" queries to the backend, and reports the execution time. I found that without stats_command_string defined, it ran in 3.5 seconds. With stats_command_string defined, it took 5.5 seconds, meaning the command string is causing a 57% slowdown. That is way too much considering that the SELECT 1 has to be send from psql to the backend, parsed, optimized, and executed, and the result returned to the psql, while stats_command_string only has to send a string to a backend collector. There is _no_ way that collector should take 57% of the time it takes to run the actual query. With the test program, I tried various options. The basic code we have sends a UDP packet to a statistics buffer process, which recv()'s the packet, puts it into a memory queue buffer, and writes it to a pipe() that is read by the statistics collector process which processes the packet. I tried various ways of speeding up the buffer and collector processes. I found if I put a pg_usleep(100) in the buffer process the backend speed was good, but packets were lost. What I found worked well was to do multiple recv() calls in a loop. The previous code did a select(), then perhaps a recv() and pipe write() based on the results of the select(). This caused many small packets to be written to the pipe and the pipe write overhead seems fairly large. The best fix I found was to loop over the recv() call at most 25 times, collecting a group of packets that can then be sent to the collector in one pipe write. The recv() socket is non-blocking, so a zero return indicates there are no more packets available. Patch attached. This change reduced the stats_command_string time from 5.5 to 3.9, which is closer to the 3.5 seconds with stats_command_string off. A second improvement I discovered is that the statistics collector is calling gettimeofday() for every packet received, so it can determine the timeout for the select() call to write the flat file. I removed that behavior and instead used setitimer() to issue a SIGINT every 500ms, which was the original behavior. This eliminates the gettimeofday() call and makes the code cleaner. Second patch attached. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 --ELM1136227240-6886-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/pgpatches/stat" Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v retrieving revision 1.116 diff -c -c -r1.116 pgstat.c *** src/backend/postmaster/pgstat.c 2 Jan 2006 00:58:00 -0000 1.116 --- src/backend/postmaster/pgstat.c 2 Jan 2006 18:36:43 -0000 *************** *** 1911,1916 **** --- 1911,1918 ---- */ for (;;) { + loop_again: + FD_ZERO(&rfds); FD_ZERO(&wfds); maxfd = -1; *************** *** 1970,2014 **** */ if (FD_ISSET(pgStatSock, &rfds)) { ! len = recv(pgStatSock, (char *) &input_buffer, ! sizeof(PgStat_Msg), 0); ! if (len < 0) ! ereport(ERROR, ! (errcode_for_socket_access(), ! errmsg("could not read statistics message: %m"))); ! ! /* ! * We ignore messages that are smaller than our common header ! */ ! if (len < sizeof(PgStat_MsgHdr)) ! continue; ! ! /* ! * The received length must match the length in the header ! */ ! if (input_buffer.msg_hdr.m_size != len) ! continue; ! /* ! * O.K. - we accept this message. Copy it to the circular ! * msgbuffer. */ ! frm = 0; ! while (len > 0) { ! xfr = PGSTAT_RECVBUFFERSZ - msg_recv; ! if (xfr > len) ! xfr = len; ! Assert(xfr > 0); ! memcpy(msgbuffer + msg_recv, ! ((char *) &input_buffer) + frm, ! xfr); ! msg_recv += xfr; ! if (msg_recv == PGSTAT_RECVBUFFERSZ) ! msg_recv = 0; ! msg_have += xfr; ! frm += xfr; ! len -= xfr; } } --- 1972,2033 ---- */ if (FD_ISSET(pgStatSock, &rfds)) { ! int loops = 0; ! /* ! * While pipewrite() can send multiple data packets, recv() pulls ! * only a single packet per call. For busy systems, doing ! * multiple recv() calls and then one pipewrite() can improve ! * query speed by 40%. 25 was chosen because 25 packets should ! * easily fit in a single pipewrite() call. recv()'s socket is ! * non-blocking. */ ! while (++loops < 25 && ! (len = recv(pgStatSock, (char *) &input_buffer, ! sizeof(PgStat_Msg), 0)) != 0) { ! if (len < 0) ! { ! if (errno == EAGAIN) ! continue; ! ereport(ERROR, ! (errcode_for_socket_access(), ! errmsg("could not read statistics message: %m"))); ! } ! ! /* ! * We ignore messages that are smaller than our common header ! */ ! if (len < sizeof(PgStat_MsgHdr)) ! goto loop_again; ! ! /* ! * The received length must match the length in the header ! */ ! if (input_buffer.msg_hdr.m_size != len) ! goto loop_again; ! ! /* ! * O.K. - we accept this message. Copy it to the circular ! * msgbuffer. ! */ ! frm = 0; ! while (len > 0) ! { ! xfr = PGSTAT_RECVBUFFERSZ - msg_recv; ! if (xfr > len) ! xfr = len; ! Assert(xfr > 0); ! memcpy(msgbuffer + msg_recv, ! ((char *) &input_buffer) + frm, ! xfr); ! msg_recv += xfr; ! if (msg_recv == PGSTAT_RECVBUFFERSZ) ! msg_recv = 0; ! msg_have += xfr; ! frm += xfr; ! len -= xfr; ! } } } *************** *** 2023,2029 **** * caught up, or because more data arrives so that we have more than * PIPE_BUF bytes buffered). This is not good, but is there any way * around it? We have no way to tell when the collector has caught ! * up... */ if (FD_ISSET(writePipe, &wfds)) { --- 2042,2048 ---- * caught up, or because more data arrives so that we have more than * PIPE_BUF bytes buffered). This is not good, but is there any way * around it? We have no way to tell when the collector has caught ! * up. Followup, the pipe rarely fills up. */ if (FD_ISSET(writePipe, &wfds)) { --ELM1136227240-6886-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/pgpatches/stat2" Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v retrieving revision 1.116 diff -c -c -r1.116 pgstat.c *** src/backend/postmaster/pgstat.c 2 Jan 2006 00:58:00 -0000 1.116 --- src/backend/postmaster/pgstat.c 2 Jan 2006 18:21:28 -0000 *************** *** 145,150 **** --- 145,151 ---- static PgStat_StatBeEntry *pgStatBeTable = NULL; static int pgStatNumBackends = 0; + static volatile bool need_statwrite; /* ---------- * Local function forward declarations *************** *** 164,169 **** --- 165,171 ---- NON_EXEC_STATIC void PgstatBufferMain(int argc, char *argv[]); NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]); + static void force_statwrite(SIGNAL_ARGS); static void pgstat_recvbuffer(void); static void pgstat_exit(SIGNAL_ARGS); static void pgstat_die(SIGNAL_ARGS); *************** *** 1548,1560 **** PgStat_Msg msg; fd_set rfds; int readPipe; - int nready; int len = 0; ! struct timeval timeout; ! struct timeval next_statwrite; ! bool need_statwrite; HASHCTL hash_ctl; ! MyProcPid = getpid(); /* reset MyProcPid */ /* --- 1550,1560 ---- PgStat_Msg msg; fd_set rfds; int readPipe; int len = 0; ! struct itimerval timeval; HASHCTL hash_ctl; ! bool need_timer = false; ! MyProcPid = getpid(); /* reset MyProcPid */ /* *************** *** 1572,1578 **** /* kluge to allow buffer process to kill collector; FIXME */ pqsignal(SIGQUIT, pgstat_exit); #endif ! pqsignal(SIGALRM, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, SIG_IGN); pqsignal(SIGUSR2, SIG_IGN); --- 1572,1578 ---- /* kluge to allow buffer process to kill collector; FIXME */ pqsignal(SIGQUIT, pgstat_exit); #endif ! pqsignal(SIGALRM, force_statwrite); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, SIG_IGN); pqsignal(SIGUSR2, SIG_IGN); *************** *** 1597,1608 **** init_ps_display("stats collector process", "", ""); set_ps_display(""); - /* - * Arrange to write the initial status file right away - */ - gettimeofday(&next_statwrite, NULL); need_statwrite = TRUE; /* * Read in an existing statistics stats file or initialize the stats to * zero. --- 1597,1608 ---- init_ps_display("stats collector process", "", ""); set_ps_display(""); need_statwrite = TRUE; + MemSet(&timeval, 0, sizeof(struct itimerval)); + timeval.it_value.tv_sec = PGSTAT_STAT_INTERVAL / 1000; + timeval.it_value.tv_usec = PGSTAT_STAT_INTERVAL % 1000; + /* * Read in an existing statistics stats file or initialize the stats to * zero. *************** *** 1634,1667 **** */ for (;;) { - /* - * If we need to write the status file again (there have been changes - * in the statistics since we wrote it last) calculate the timeout - * until we have to do so. - */ if (need_statwrite) { ! struct timeval now; ! ! gettimeofday(&now, NULL); ! /* avoid assuming that tv_sec is signed */ ! if (now.tv_sec > next_statwrite.tv_sec || ! (now.tv_sec == next_statwrite.tv_sec && ! now.tv_usec >= next_statwrite.tv_usec)) ! { ! timeout.tv_sec = 0; ! timeout.tv_usec = 0; ! } ! else ! { ! timeout.tv_sec = next_statwrite.tv_sec - now.tv_sec; ! timeout.tv_usec = next_statwrite.tv_usec - now.tv_usec; ! if (timeout.tv_usec < 0) ! { ! timeout.tv_sec--; ! timeout.tv_usec += 1000000; ! } ! } } /* --- 1634,1644 ---- */ for (;;) { if (need_statwrite) { ! pgstat_write_statsfile(); ! need_statwrite = false; ! need_timer = true; } /* *************** *** 1673,1681 **** /* * Now wait for something to do. */ ! nready = select(readPipe + 1, &rfds, NULL, NULL, ! (need_statwrite) ? &timeout : NULL); ! if (nready < 0) { if (errno == EINTR) continue; --- 1650,1656 ---- /* * Now wait for something to do. */ ! if (select(readPipe + 1, &rfds, NULL, NULL, NULL) < 0) { if (errno == EINTR) continue; *************** *** 1685,1702 **** } /* - * If there are no descriptors ready, our timeout for writing the - * stats file happened. - */ - if (nready == 0) - { - pgstat_write_statsfile(); - need_statwrite = FALSE; - - continue; - } - - /* * Check if there is a new statistics message to collect. */ if (FD_ISSET(readPipe, &rfds)) --- 1660,1665 ---- *************** *** 1813,1829 **** */ pgStatNumMessages++; ! /* ! * If this is the first message after we wrote the stats file the ! * last time, setup the timeout that it'd be written. ! */ ! if (!need_statwrite) { ! gettimeofday(&next_statwrite, NULL); ! next_statwrite.tv_usec += ((PGSTAT_STAT_INTERVAL) * 1000); ! next_statwrite.tv_sec += (next_statwrite.tv_usec / 1000000); ! next_statwrite.tv_usec %= 1000000; ! need_statwrite = TRUE; } } --- 1776,1787 ---- */ pgStatNumMessages++; ! if (need_timer) { ! if (setitimer(ITIMER_REAL, &timeval, NULL)) ! ereport(ERROR, ! (errmsg("unable to set statistics collector timer: %m"))); ! need_timer = false; } } *************** *** 1848,1853 **** --- 1806,1818 ---- } + static void + force_statwrite(SIGNAL_ARGS) + { + need_statwrite = true; + } + + /* ---------- * pgstat_recvbuffer() - * --ELM1136227240-6886-0_-- From pgsql-patches-owner@postgresql.org Mon Jan 2 14:45:27 2006 X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9FF519DC996 for ; Mon, 2 Jan 2006 14:45:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74666-06 for ; Mon, 2 Jan 2006 14:45:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 7AC9C9DC991 for ; Mon, 2 Jan 2006 14:45:23 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k02IjLoW007839; Mon, 2 Jan 2006 13:45:21 -0500 (EST) To: Bruce Momjian cc: Michael Fuhr , Merlin Moncure , Carlos Benkendorf , PostgreSQL-patches Subject: Re: Stats collector performance improvement In-reply-to: <200601021840.k02Ieed21704@candle.pha.pa.us> References: <200601021840.k02Ieed21704@candle.pha.pa.us> Comments: In-reply-to Bruce Momjian message dated "Mon, 02 Jan 2006 13:40:40 -0500" Date: Mon, 02 Jan 2006 13:45:21 -0500 Message-ID: <7838.1136227521@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/12 X-Sequence-Number: 18348 Bruce Momjian writes: > I found if I put a pg_usleep(100) in the buffer process the backend > speed was good, but packets were lost. What I found worked well was to > do multiple recv() calls in a loop. The previous code did a select(), > then perhaps a recv() and pipe write() based on the results of the > select(). This caused many small packets to be written to the pipe and > the pipe write overhead seems fairly large. The best fix I found was to > loop over the recv() call at most 25 times, collecting a group of > packets that can then be sent to the collector in one pipe write. The > recv() socket is non-blocking, so a zero return indicates there are no > more packets available. Patch attached. This seems incredibly OS-specific. How many platforms did you test it on? A more serious objection is that it will cause the stats machinery to work very poorly if there isn't a steady stream of incoming messages. You can't just sit on 24 messages until the 25th one arrives next week. regards, tom lane From pgsql-patches-owner@postgresql.org Mon Jan 2 15:13:59 2006 X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CD9949DC81E for ; Mon, 2 Jan 2006 15:13:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83012-01 for ; Mon, 2 Jan 2006 15:13:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 328109DC959 for ; Mon, 2 Jan 2006 15:13:55 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k02JDlh26741; Mon, 2 Jan 2006 14:13:47 -0500 (EST) From: Bruce Momjian Message-Id: <200601021913.k02JDlh26741@candle.pha.pa.us> Subject: Re: Stats collector performance improvement In-Reply-To: <7838.1136227521@sss.pgh.pa.us> To: Tom Lane Date: Mon, 2 Jan 2006 14:13:47 -0500 (EST) CC: Michael Fuhr , Merlin Moncure , Carlos Benkendorf , PostgreSQL-patches X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.121] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/13 X-Sequence-Number: 18349 Tom Lane wrote: > Bruce Momjian writes: > > I found if I put a pg_usleep(100) in the buffer process the backend > > speed was good, but packets were lost. What I found worked well was to > > do multiple recv() calls in a loop. The previous code did a select(), > > then perhaps a recv() and pipe write() based on the results of the > > select(). This caused many small packets to be written to the pipe and > > the pipe write overhead seems fairly large. The best fix I found was to > > loop over the recv() call at most 25 times, collecting a group of > > packets that can then be sent to the collector in one pipe write. The > > recv() socket is non-blocking, so a zero return indicates there are no > > more packets available. Patch attached. > > This seems incredibly OS-specific. How many platforms did you test it > on? Only mine. I am posting the patch so others can test it, of course. > A more serious objection is that it will cause the stats machinery to > work very poorly if there isn't a steady stream of incoming messages. > You can't just sit on 24 messages until the 25th one arrives next week. You wouldn't. It exits out of the loop on a not found, checks the pipe write descriptor, and writes on it. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgsql-hackers-owner@postgresql.org Mon Jan 2 16:20:27 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9139F9DC81E for ; Mon, 2 Jan 2006 16:20:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03183-03 for ; Mon, 2 Jan 2006 16:20:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 6BF879DC80F for ; Mon, 2 Jan 2006 16:20:24 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k02KKO5J011925; Mon, 2 Jan 2006 15:20:24 -0500 (EST) To: Bruce Momjian cc: Jan Wieck , pgsql-hackers@postgreSQL.org Subject: Re: Stats collector performance improvement In-reply-to: <200601021840.k02Ieed21704@candle.pha.pa.us> References: <200601021840.k02Ieed21704@candle.pha.pa.us> Comments: In-reply-to Bruce Momjian message dated "Mon, 02 Jan 2006 13:40:40 -0500" Date: Mon, 02 Jan 2006 15:20:24 -0500 Message-ID: <11924.1136233224@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/75 X-Sequence-Number: 78179 [ moving to -hackers ] Bruce Momjian writes: > I did some research on this because the numbers Tom quotes indicate there > is something wrong in the way we process stats_command_string > statistics. > [ ... proposed patch that seems pretty klugy to me ... ] I wonder whether we shouldn't consider something more drastic, like getting rid of the intermediate stats buffer process entirely. The original design for the stats communication code was based on the premise that it's better to drop data than to make backends wait on the stats collector. However, as things have turned out I think this notion is a flop: the people who are using stats at all want the stats to be reliable. We've certainly seen plenty of gripes from people who are unhappy that backend-exit messages got dropped, and anyone who's using autovacuum would really like the tuple update counts to be pretty solid too. If we abandoned the unreliable-communication approach, could we build something with less overhead? regards, tom lane From pgsql-hackers-owner@postgresql.org Mon Jan 2 17:02:14 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CE9659DC959 for ; Mon, 2 Jan 2006 17:02:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26128-05 for ; Mon, 2 Jan 2006 17:02:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 7EEA89DC93F for ; Mon, 2 Jan 2006 17:02:11 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 4390F33A69; Mon, 2 Jan 2006 22:02:13 +0100 (MET) From: "Qingqing Zhou" X-Newsgroups: pgsql.hackers Subject: Re: Stats collector performance improvement Date: Mon, 2 Jan 2006 16:03:20 -0500 Organization: Hub.Org Networking Services Lines: 26 Message-ID: References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original To: pgsql-hackers@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.159 required=5 tests=[AWL=0.159] X-Spam-Score: 0.159 X-Spam-Level: X-Archive-Number: 200601/76 X-Sequence-Number: 78180 "Tom Lane" wrote > > I wonder whether we shouldn't consider something more drastic, like > getting rid of the intermediate stats buffer process entirely. > > The original design for the stats communication code was based on the > premise that it's better to drop data than to make backends wait on > the stats collector. However, as things have turned out I think this > notion is a flop: the people who are using stats at all want the stats > to be reliable. We've certainly seen plenty of gripes from people who > are unhappy that backend-exit messages got dropped, and anyone who's > using autovacuum would really like the tuple update counts to be pretty > solid too. > AFAICS if we can maintain the stats counts solid, then it may hurt performance dramatically. Think if we maintain pgstat_count_heap_insert()/pgstat_count_heap_delete() pretty well, then we get a replacement of count(*). To do so, I believe that will add another lock contention on the target table stats. Regards, Qingqing From pgsql-hackers-owner@postgresql.org Mon Jan 2 17:48:25 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6B2BA9DC857 for ; Mon, 2 Jan 2006 17:48:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54706-08 for ; Mon, 2 Jan 2006 17:48:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.skype.net (mail.skype.net [195.215.8.149]) by postgresql.org (Postfix) with ESMTP id 33CC39DC80F for ; Mon, 2 Jan 2006 17:48:22 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.skype.net (Postfix) with ESMTP id 825DC4DE41; Mon, 2 Jan 2006 22:48:23 +0100 (CET) Received: from [192.168.1.102] (80-235-57-196-dsl.trt.estpak.ee [80.235.57.196]) by mail.skype.net (Postfix) with ESMTP id 5A10B4DE40; Mon, 2 Jan 2006 22:48:22 +0100 (CET) Subject: Re: Stats collector performance improvement From: Hannu Krosing To: Tom Lane Cc: Bruce Momjian , Jan Wieck , pgsql-hackers@postgreSQL.org In-Reply-To: <11924.1136233224@sss.pgh.pa.us> References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Date: Mon, 02 Jan 2006 23:48:15 +0200 Message-Id: <1136238496.4256.9.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/77 X-Sequence-Number: 78181 Ühel kenal päeval, E, 2006-01-02 kell 15:20, kirjutas Tom Lane: > [ moving to -hackers ] > > Bruce Momjian writes: > > I did some research on this because the numbers Tom quotes indicate there > > is something wrong in the way we process stats_command_string > > statistics. > > [ ... proposed patch that seems pretty klugy to me ... ] > > I wonder whether we shouldn't consider something more drastic, like > getting rid of the intermediate stats buffer process entirely. > > The original design for the stats communication code was based on the > premise that it's better to drop data than to make backends wait on > the stats collector. However, as things have turned out I think this > notion is a flop: the people who are using stats at all want the stats > to be reliable. We've certainly seen plenty of gripes from people who > are unhappy that backend-exit messages got dropped, and anyone who's > using autovacuum would really like the tuple update counts to be pretty > solid too. > > If we abandoned the unreliable-communication approach, could we build > something with less overhead? Weell, at least it should be non-WAL, and probably non-fsync, at least optionally . Maybe also inserts inserts + offline aggregator (instead of updates) to avoid lock contention. Something that collects data in blocks of local or per-backend shared memory in each backend and then gives complete blocks to aggregator process. Maybe use 2 alternating blocks per backend - 1 for ongoing stats collection and another given to aggregator. this has a little time shift, but will deliver accurate starts in the end. Things that need up-to-date stats (like pg_stat_activity), should look (and lock) also the ongoing satas collection blocks if needed (how do we know know the *if*) and delay each backend process momentaryly by looking. ----------------- Hannu From pgsql-hackers-owner@postgresql.org Mon Jan 2 17:48:47 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1CBA29DC99B for ; Mon, 2 Jan 2006 17:48:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50010-06 for ; Mon, 2 Jan 2006 17:48:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C54DC9DC991 for ; Mon, 2 Jan 2006 17:48:44 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k02Lmjb5012504; Mon, 2 Jan 2006 16:48:45 -0500 (EST) To: "Qingqing Zhou" cc: pgsql-hackers@postgresql.org Subject: Re: Stats collector performance improvement In-reply-to: References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> Comments: In-reply-to "Qingqing Zhou" message dated "Mon, 02 Jan 2006 16:03:20 -0500" Date: Mon, 02 Jan 2006 16:48:45 -0500 Message-ID: <12503.1136238525@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.061 required=5 tests=[AWL=0.061] X-Spam-Score: 0.061 X-Spam-Level: X-Archive-Number: 200601/78 X-Sequence-Number: 78182 "Qingqing Zhou" writes: > AFAICS if we can maintain the stats counts solid, then it may hurt > performance dramatically. Think if we maintain > pgstat_count_heap_insert()/pgstat_count_heap_delete() pretty well, then we > get a replacement of count(*). Not at all. For one thing, the stats don't attempt to maintain per-transaction state, so they don't have the MVCC issues of count(*). I'm not suggesting any fundamental changes in what is counted or when. The two compromises that were made in the original stats design to make it fast were (1) stats updates lag behind reality, and (2) some updates may be missed entirely. Now that we have a couple of years' field experience with the code, it seems that (1) is acceptable for real usage but (2) not so much. And it's not even clear that we are buying any performance gain from (2), considering that it's adding the overhead of passing the data through an extra process. regards, tom lane From pgsql-hackers-owner@postgresql.org Tue Jan 3 00:07:10 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A1A629DC808 for ; Tue, 3 Jan 2006 00:07:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68820-10 for ; Tue, 3 Jan 2006 00:07:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp012.mail.yahoo.com (smtp012.mail.yahoo.com [216.136.173.32]) by postgresql.org (Postfix) with SMTP id 590759DC806 for ; Tue, 3 Jan 2006 00:07:07 -0400 (AST) Received: (qmail 81422 invoked from network); 3 Jan 2006 04:07:05 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=Yahoo.com; h=Received:Received:Message-ID:Date:From:User-Agent:X-Accept-Language:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=qiBgzOIl0BqwFbQoPS4j4rno6Vnu4eRFKg1654ni8BPnfBPvqT6+jRooWhUInAsMMxytlHSrVdahOUIhCkY9C+EH4LFgVwNuU500W7j6hj4z+6x3AskWnz/jYPAxGxbFV7jP27PahHJ0xLDH3M1sxpyIMi++Bt3qMeVVIb8DoBE= ; Received: from unknown (HELO jupiter.black-lion.info) (janwieck@68.80.245.191 with login) by smtp012.mail.yahoo.com with SMTP; 3 Jan 2006 04:07:05 -0000 Received: from [172.21.8.23] (mars.black-lion.info [192.168.192.101]) (authenticated bits=0) by jupiter.black-lion.info (8.12.10/8.12.9) with ESMTP id k034721o040477; Mon, 2 Jan 2006 23:07:02 -0500 (EST) (envelope-from JanWieck@Yahoo.com) Message-ID: <43B9F861.5040207@Yahoo.com> Date: Mon, 02 Jan 2006 23:06:57 -0500 From: Jan Wieck User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.1) Gecko/20040707 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane CC: Bruce Momjian , pgsql-hackers@postgreSQL.org Subject: Re: Stats collector performance improvement References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> In-Reply-To: <11924.1136233224@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.386 required=5 tests=[AWL=-0.093, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.386 X-Spam-Level: X-Archive-Number: 200601/89 X-Sequence-Number: 78193 On 1/2/2006 3:20 PM, Tom Lane wrote: > [ moving to -hackers ] > > Bruce Momjian writes: >> I did some research on this because the numbers Tom quotes indicate there >> is something wrong in the way we process stats_command_string >> statistics. >> [ ... proposed patch that seems pretty klugy to me ... ] > > I wonder whether we shouldn't consider something more drastic, like > getting rid of the intermediate stats buffer process entirely. > > The original design for the stats communication code was based on the > premise that it's better to drop data than to make backends wait on The original design was geared towards searching for useless/missing indexes and tuning activity like that. This never happened, but instead people tried to use it as a reliable debugging or access statistics aid ... which is fine but not what it originally was intended for. So yes, I think looking at what it usually is used for, a message passing system like SysV message queues (puke) or similar would do a better job. Jan > the stats collector. However, as things have turned out I think this > notion is a flop: the people who are using stats at all want the stats > to be reliable. We've certainly seen plenty of gripes from people who > are unhappy that backend-exit messages got dropped, and anyone who's > using autovacuum would really like the tuple update counts to be pretty > solid too. > > If we abandoned the unreliable-communication approach, could we build > something with less overhead? > > regards, tom lane -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com # From pgsql-hackers-owner@postgresql.org Tue Jan 3 05:40:59 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DE0449DC832 for ; Tue, 3 Jan 2006 05:40:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40916-01 for ; Tue, 3 Jan 2006 05:41:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id 9B8EA9DC806 for ; Tue, 3 Jan 2006 05:40:56 -0400 (AST) Received: from [192.168.0.3] (unknown [84.12.200.250]) by smtp.nildram.co.uk (Postfix) with ESMTP id 2EA0426D8EA; Tue, 3 Jan 2006 09:40:52 +0000 (GMT) Subject: Re: Stats collector performance improvement From: Simon Riggs To: Tom Lane Cc: Qingqing Zhou , pgsql-hackers@postgresql.org In-Reply-To: <12503.1136238525@sss.pgh.pa.us> References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> <12503.1136238525@sss.pgh.pa.us> Content-Type: text/plain Date: Tue, 03 Jan 2006 09:40:53 +0000 Message-Id: <1136281253.5052.113.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.037 required=5 tests=[AWL=0.037] X-Spam-Score: 0.037 X-Spam-Level: X-Archive-Number: 200601/92 X-Sequence-Number: 78196 On Mon, 2006-01-02 at 16:48 -0500, Tom Lane wrote: > The two compromises that were made in the original stats design to make > it fast were (1) stats updates lag behind reality, and (2) some updates > may be missed entirely. Now that we have a couple of years' field > experience with the code, it seems that (1) is acceptable for real usage > but (2) not so much. We decided that the stats update had to occur during execution, in case the statement aborted and row versions were not notified. That means we must notify things as they happen, yet could use a reliable queuing system that could suffer a delay in the stats becoming available. But how often do we lose a backend? Could we simply buffer that a little better? i.e. don't send message to stats unless we have altered at least 10 rows? So we would buffer based upon the importance of the message, not the actual size of the message. That way singleton-statements won't generate the same stats traffic, but we risk losing a buffers worth of row changes should we crash - everything would still work if we lost a few small row change notifications. We can also save lots of cycles on the current statement overhead, which is currently the worst part of the stats, performance-wise. That definitely needs redesign. AFAICS we only ever need to know the SQL statement via the stats system if the statement has been running for more than a few minutes - the main use case is for an admin to be able to diagnose a rogue or hung statement. Pushing the statement to stats every time is just a big overhead. That suggests we should either have a pull or a deferred push (longer-than-X-secs) approach. Best Regards, Simon Riggs From pgsql-patches-owner@postgresql.org Tue Jan 3 05:54:58 2006 X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CD6009DC806 for ; Tue, 3 Jan 2006 05:54:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38364-04 for ; Tue, 3 Jan 2006 05:54:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id A51F09DC83D for ; Tue, 3 Jan 2006 05:54:55 -0400 (AST) Received: from [192.168.0.3] (unknown [84.12.200.250]) by smtp.nildram.co.uk (Postfix) with ESMTP id B4D8C2685D0; Tue, 3 Jan 2006 09:54:55 +0000 (GMT) Subject: Re: Stats collector performance improvement From: Simon Riggs To: Bruce Momjian Cc: Tom Lane , Michael Fuhr , Merlin Moncure , Carlos Benkendorf , PostgreSQL-patches In-Reply-To: <200601021840.k02Ieed21704@candle.pha.pa.us> References: <200601021840.k02Ieed21704@candle.pha.pa.us> Content-Type: text/plain Date: Tue, 03 Jan 2006 09:54:57 +0000 Message-Id: <1136282097.5052.117.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.038 required=5 tests=[AWL=0.038] X-Spam-Score: 0.038 X-Spam-Level: X-Archive-Number: 200601/20 X-Sequence-Number: 18356 On Mon, 2006-01-02 at 13:40 -0500, Bruce Momjian wrote: > This change reduced the stats_command_string time from 5.5 to 3.9, which > is closer to the 3.5 seconds with stats_command_string off. Excellent work, port specific or not. Best Regards, Simon Riggs From pgsql-performance-owner@postgresql.org Tue Jan 3 11:08:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E08469DC983 for ; Tue, 3 Jan 2006 11:08:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92703-08 for ; Tue, 3 Jan 2006 11:08:56 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 54FB69DC83D for ; Tue, 3 Jan 2006 11:08:49 -0400 (AST) Received: from smtp1.asco.de (smtp1.asco.de [217.13.70.154]) by svr4.postgresql.org (Postfix) with ESMTP id 524F75AF034 for ; Tue, 3 Jan 2006 15:08:53 +0000 (GMT) Received: from [192.168.1.72] (pitr.asco.de [192.168.1.72]) (envelope-sender: ) (authenticated j_schicke CRAM-MD5 bits=0) by smtp1.asco.de (8.13.4/8.13.4/Debian-3) with ESMTP id k03F8m5k004059 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 3 Jan 2006 16:08:48 +0100 Date: Tue, 03 Jan 2006 16:08:48 +0100 From: Jens-Wolfhard Schicke Reply-To: Jens-Wolfhard Schicke To: pgsql-performance@postgresql.org Subject: Materialize Subplan and push into inner index conditions Message-ID: X-Mailer: Mulberry/3.1.6 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/1 X-Sequence-Number: 16479 Is it possible to have the planner consider the second plan instead of the=20 first? admpostgres4=3D> explain analyze select * from users where id in (select=20 user_id from user2user_group where user_group_id =3D 769694); =20 QUERY PLAN=20 ----------------------------------------------------------------------------= ----------------------------------------------------------------------------= ------- Hash IN Join (cost=3D4.04..2302.05 rows=3D4 width=3D78) (actual=20 time=3D50.381..200.985 rows=3D2 loops=3D1) Hash Cond: ("outer".id =3D "inner".user_id) -> Append (cost=3D0.00..1931.68 rows=3D77568 width=3D78) (actual=20 time=3D0.004..154.629 rows=3D76413 loops=3D1) -> Seq Scan on users (cost=3D0.00..1024.88 rows=3D44588 = width=3D78)=20 (actual time=3D0.004..36.220 rows=3D43433 loops=3D1) -> Seq Scan on person_user users (cost=3D0.00..906.80 = rows=3D32980=20 width=3D78) (actual time=3D0.005..38.120 rows=3D32980 loops=3D1) -> Hash (cost=3D4.04..4.04 rows=3D2 width=3D4) (actual = time=3D0.020..0.020=20 rows=3D2 loops=3D1) -> Index Scan using user2user_group_user_group_id_idx on=20 user2user_group (cost=3D0.00..4.04 rows=3D2 width=3D4) (actual = time=3D0.011..0.014=20 rows=3D2 loops=3D1) Index Cond: (user_group_id =3D 769694) Total runtime: 201.070 ms (9 rows) admpostgres4=3D> select user_id from user2user_group where user_group_id = =3D=20 769694; user_id --------- 766541 766552 (2 rows) admpostgres4=3D> explain analyze select * from users where id in (766541,=20 766552); QUERY PLAN = ----------------------------------------------------------------------------= ----------------------------------------------------------------- Result (cost=3D4.02..33.48 rows=3D9 width=3D78) (actual = time=3D0.055..0.087=20 rows=3D2 loops=3D1) -> Append (cost=3D4.02..33.48 rows=3D9 width=3D78) (actual = time=3D0.051..0.082=20 rows=3D2 loops=3D1) -> Bitmap Heap Scan on users (cost=3D4.02..18.10 rows=3D5 = width=3D78)=20 (actual time=3D0.051..0.053 rows=3D2 loops=3D1) Recheck Cond: ((id =3D 766541) OR (id =3D 766552)) -> BitmapOr (cost=3D4.02..4.02 rows=3D5 width=3D0) (actual = time=3D0.045..0.045 rows=3D0 loops=3D1) -> Bitmap Index Scan on users_id_idx=20 (cost=3D0.00..2.01 rows=3D2 width=3D0) (actual time=3D0.034..0.034 rows=3D1 = loops=3D1) Index Cond: (id =3D 766541) -> Bitmap Index Scan on users_id_idx=20 (cost=3D0.00..2.01 rows=3D2 width=3D0) (actual time=3D0.008..0.008 rows=3D1 = loops=3D1) Index Cond: (id =3D 766552) -> Bitmap Heap Scan on person_user users (cost=3D4.02..15.37=20 rows=3D4 width=3D78) (actual time=3D0.025..0.025 rows=3D0 loops=3D1) Recheck Cond: ((id =3D 766541) OR (id =3D 766552)) -> BitmapOr (cost=3D4.02..4.02 rows=3D4 width=3D0) (actual = time=3D0.023..0.023 rows=3D0 loops=3D1) -> Bitmap Index Scan on person_user_id_idx=20 (cost=3D0.00..2.01 rows=3D2 width=3D0) (actual time=3D0.017..0.017 rows=3D0 = loops=3D1) Index Cond: (id =3D 766541) -> Bitmap Index Scan on person_user_id_idx=20 (cost=3D0.00..2.01 rows=3D2 width=3D0) (actual time=3D0.004..0.004 rows=3D0 = loops=3D1) Index Cond: (id =3D 766552) Total runtime: 0.177 ms (17 rows) admpostgres4=3D> admpostgres4=3D> \d users; Table "adm.users" Column | Type | Modifiers ------------------+-----------------------------+--------------------- id | integer | not null classid | integer | not null revision | integer | not null rev_start | timestamp without time zone | rev_end | timestamp without time zone | rev_timestamp | timestamp without time zone | not null rev_state | integer | not null default 10 name | character varying | password | character varying | password_expires | timestamp without time zone | password_period | integer | Indexes: "users_pkey" primary key, btree (revision) "users_uidx" unique, btree (revision) "users_id_idx" btree (id) "users_name_idx" btree (rev_state, rev_end, name) "users_rev_end_idx" btree (rev_end) "users_rev_idx" btree (rev_state, rev_end) "users_rev_start_idx" btree (rev_start) "users_rev_state_idx" btree (rev_state) Inherits: revision admpostgres4=3D>\d person_user; Table "adm.person_user" Column | Type | Modifiers ------------------+-----------------------------+--------------------- id | integer | not null classid | integer | not null revision | integer | not null rev_start | timestamp without time zone | rev_end | timestamp without time zone | rev_timestamp | timestamp without time zone | not null rev_state | integer | not null default 10 name | character varying | password | character varying | password_expires | timestamp without time zone | password_period | integer | lastname | character varying | description | character varying | vat_id | character varying | firstname | character varying | sex | integer | birthdate | timestamp without time zone | title | character varying | Indexes: "person_user_pkey" primary key, btree (revision) "person_user_uidx" unique, btree (revision) "person_user_id_idx" btree (id) "person_user_rev_end_idx" btree (rev_end) "person_user_rev_idx" btree (rev_state, rev_end) "person_user_rev_start_idx" btree (rev_start) "person_user_rev_state_idx" btree (rev_state) Inherits: users admpostgres4=3D> admpostgres4=3D> \d user2user_group; Table "adm.user2user_group" Column | Type | Modifiers ---------------+---------+----------- user_id | integer | not null user_group_id | integer | not null Indexes: "user2user_group_pkey" primary key, btree (user_id, user_group_id) "user2user_group_uidx" unique, btree (user_id, user_group_id) "user2user_group_user_group_id_idx" btree (user_group_id) "user2user_group_user_id_idx" btree (user_id) admpostgres4=3D> Mit freundlichem Gru=DF Jens Schicke --=20 Jens Schicke j.schicke@asco.de asco GmbH http://www.asco.de Mittelweg 7 Tel 0531/3906-127 38106 Braunschweig Fax 0531/3906-400 From pgsql-performance-owner@postgresql.org Tue Jan 3 11:43:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 678F89DC83D for ; Tue, 3 Jan 2006 11:43:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07371-06 for ; Tue, 3 Jan 2006 11:43:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 33E0C9DC832 for ; Tue, 3 Jan 2006 11:43:33 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k03FhYew016085; Tue, 3 Jan 2006 10:43:35 -0500 (EST) To: Jens-Wolfhard Schicke cc: pgsql-performance@postgresql.org Subject: Re: Materialize Subplan and push into inner index conditions In-reply-to: References: Comments: In-reply-to Jens-Wolfhard Schicke message dated "Tue, 03 Jan 2006 16:08:48 +0100" Date: Tue, 03 Jan 2006 10:43:34 -0500 Message-ID: <16084.1136303014@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.063 required=5 tests=[AWL=0.063] X-Spam-Score: 0.063 X-Spam-Level: X-Archive-Number: 200601/2 X-Sequence-Number: 16480 Jens-Wolfhard Schicke writes: > Is it possible to have the planner consider the second plan instead of the > first? At the moment, only if you get rid of the inheritance. The planner's not very smart at all when faced with joining inheritance trees. regards, tom lane From pgsql-hackers-owner@postgresql.org Tue Jan 3 12:35:58 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 693209DC832 for ; Tue, 3 Jan 2006 12:35:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18467-10 for ; Tue, 3 Jan 2006 12:35:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from flake.decibel.org (unknown [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 4991D9DC80F for ; Tue, 3 Jan 2006 12:35:56 -0400 (AST) Received: by flake.decibel.org (Postfix, from userid 1001) id 0AABA39841; Tue, 3 Jan 2006 10:35:56 -0600 (CST) Date: Tue, 3 Jan 2006 10:35:56 -0600 From: "Jim C. Nasby" To: Simon Riggs Cc: Tom Lane , Qingqing Zhou , pgsql-hackers@postgresql.org Subject: Re: Stats collector performance improvement Message-ID: <20060103163556.GH82560@pervasive.com> References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> <12503.1136238525@sss.pgh.pa.us> <1136281253.5052.113.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1136281253.5052.113.camel@localhost.localdomain> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.067 required=5 tests=[AWL=0.067] X-Spam-Score: 0.067 X-Spam-Level: X-Archive-Number: 200601/102 X-Sequence-Number: 78206 On Tue, Jan 03, 2006 at 09:40:53AM +0000, Simon Riggs wrote: > On Mon, 2006-01-02 at 16:48 -0500, Tom Lane wrote: > We can also save lots of cycles on the current statement overhead, which > is currently the worst part of the stats, performance-wise. That > definitely needs redesign. AFAICS we only ever need to know the SQL > statement via the stats system if the statement has been running for > more than a few minutes - the main use case is for an admin to be able > to diagnose a rogue or hung statement. Pushing the statement to stats > every time is just a big overhead. That suggests we should either have a > pull or a deferred push (longer-than-X-secs) approach. I would argue that minutes is too long, but of course this could be user-adjustable. I suspect that even waiting just a second could be a huge win, since this only matters if you're executing a lot of statements and you won't be doing that if those statements are taking more than a second or two to execute. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-patches-owner@postgresql.org Tue Jan 3 12:44:28 2006 X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E07549DC80F for ; Tue, 3 Jan 2006 12:44:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21940-07 for ; Tue, 3 Jan 2006 12:44:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 3052E9DC836 for ; Tue, 3 Jan 2006 12:44:22 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k03GhNt21271; Tue, 3 Jan 2006 11:43:23 -0500 (EST) From: Bruce Momjian Message-Id: <200601031643.k03GhNt21271@candle.pha.pa.us> Subject: Re: Stats collector performance improvement In-Reply-To: <200601021840.k02Ieed21704@candle.pha.pa.us> To: Bruce Momjian Date: Tue, 3 Jan 2006 11:43:23 -0500 (EST) CC: Tom Lane , Michael Fuhr , Merlin Moncure , Carlos Benkendorf , PostgreSQL-patches X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1136306603-6886-1_ Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.121] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/21 X-Sequence-Number: 18357 --ELM1136306603-6886-1_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Bruce Momjian wrote: > Tom Lane wrote: > A second improvement I discovered is that the statistics collector is > calling gettimeofday() for every packet received, so it can determine > the timeout for the select() call to write the flat file. I removed > that behavior and instead used setitimer() to issue a SIGINT every > 500ms, which was the original behavior. This eliminates the > gettimeofday() call and makes the code cleaner. Second patch attached. I have applied this second patch, with a few small stylistic improvements. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 --ELM1136306603-6886-1_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/rtmp/diff" Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v retrieving revision 1.116 diff -c -c -r1.116 pgstat.c *** src/backend/postmaster/pgstat.c 2 Jan 2006 00:58:00 -0000 1.116 --- src/backend/postmaster/pgstat.c 3 Jan 2006 16:26:04 -0000 *************** *** 117,123 **** static long pgStatNumMessages = 0; ! static bool pgStatRunningInCollector = FALSE; /* * Place where backends store per-table info to be sent to the collector. --- 117,123 ---- static long pgStatNumMessages = 0; ! static bool pgStatRunningInCollector = false; /* * Place where backends store per-table info to be sent to the collector. *************** *** 145,150 **** --- 145,151 ---- static PgStat_StatBeEntry *pgStatBeTable = NULL; static int pgStatNumBackends = 0; + static volatile bool need_statwrite; /* ---------- * Local function forward declarations *************** *** 164,169 **** --- 165,171 ---- NON_EXEC_STATIC void PgstatBufferMain(int argc, char *argv[]); NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]); + static void force_statwrite(SIGNAL_ARGS); static void pgstat_recvbuffer(void); static void pgstat_exit(SIGNAL_ARGS); static void pgstat_die(SIGNAL_ARGS); *************** *** 1548,1560 **** PgStat_Msg msg; fd_set rfds; int readPipe; - int nready; int len = 0; ! struct timeval timeout; ! struct timeval next_statwrite; ! bool need_statwrite; HASHCTL hash_ctl; ! MyProcPid = getpid(); /* reset MyProcPid */ /* --- 1550,1560 ---- PgStat_Msg msg; fd_set rfds; int readPipe; int len = 0; ! struct itimerval timeval; HASHCTL hash_ctl; ! bool need_timer = false; ! MyProcPid = getpid(); /* reset MyProcPid */ /* *************** *** 1572,1578 **** /* kluge to allow buffer process to kill collector; FIXME */ pqsignal(SIGQUIT, pgstat_exit); #endif ! pqsignal(SIGALRM, SIG_IGN); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, SIG_IGN); pqsignal(SIGUSR2, SIG_IGN); --- 1572,1578 ---- /* kluge to allow buffer process to kill collector; FIXME */ pqsignal(SIGQUIT, pgstat_exit); #endif ! pqsignal(SIGALRM, force_statwrite); pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGUSR1, SIG_IGN); pqsignal(SIGUSR2, SIG_IGN); *************** *** 1597,1613 **** init_ps_display("stats collector process", "", ""); set_ps_display(""); ! /* ! * Arrange to write the initial status file right away ! */ ! gettimeofday(&next_statwrite, NULL); ! need_statwrite = TRUE; /* * Read in an existing statistics stats file or initialize the stats to * zero. */ ! pgStatRunningInCollector = TRUE; pgstat_read_statsfile(&pgStatDBHash, InvalidOid, NULL, NULL); /* --- 1597,1613 ---- init_ps_display("stats collector process", "", ""); set_ps_display(""); ! need_statwrite = true; ! ! MemSet(&timeval, 0, sizeof(struct itimerval)); ! timeval.it_value.tv_sec = PGSTAT_STAT_INTERVAL / 1000; ! timeval.it_value.tv_usec = PGSTAT_STAT_INTERVAL % 1000; /* * Read in an existing statistics stats file or initialize the stats to * zero. */ ! pgStatRunningInCollector = true; pgstat_read_statsfile(&pgStatDBHash, InvalidOid, NULL, NULL); /* *************** *** 1634,1667 **** */ for (;;) { - /* - * If we need to write the status file again (there have been changes - * in the statistics since we wrote it last) calculate the timeout - * until we have to do so. - */ if (need_statwrite) { ! struct timeval now; ! ! gettimeofday(&now, NULL); ! /* avoid assuming that tv_sec is signed */ ! if (now.tv_sec > next_statwrite.tv_sec || ! (now.tv_sec == next_statwrite.tv_sec && ! now.tv_usec >= next_statwrite.tv_usec)) ! { ! timeout.tv_sec = 0; ! timeout.tv_usec = 0; ! } ! else ! { ! timeout.tv_sec = next_statwrite.tv_sec - now.tv_sec; ! timeout.tv_usec = next_statwrite.tv_usec - now.tv_usec; ! if (timeout.tv_usec < 0) ! { ! timeout.tv_sec--; ! timeout.tv_usec += 1000000; ! } ! } } /* --- 1634,1644 ---- */ for (;;) { if (need_statwrite) { ! pgstat_write_statsfile(); ! need_statwrite = false; ! need_timer = true; } /* *************** *** 1673,1681 **** /* * Now wait for something to do. */ ! nready = select(readPipe + 1, &rfds, NULL, NULL, ! (need_statwrite) ? &timeout : NULL); ! if (nready < 0) { if (errno == EINTR) continue; --- 1650,1656 ---- /* * Now wait for something to do. */ ! if (select(readPipe + 1, &rfds, NULL, NULL, NULL) < 0) { if (errno == EINTR) continue; *************** *** 1685,1702 **** } /* - * If there are no descriptors ready, our timeout for writing the - * stats file happened. - */ - if (nready == 0) - { - pgstat_write_statsfile(); - need_statwrite = FALSE; - - continue; - } - - /* * Check if there is a new statistics message to collect. */ if (FD_ISSET(readPipe, &rfds)) --- 1660,1665 ---- *************** *** 1813,1829 **** */ pgStatNumMessages++; ! /* ! * If this is the first message after we wrote the stats file the ! * last time, setup the timeout that it'd be written. ! */ ! if (!need_statwrite) { ! gettimeofday(&next_statwrite, NULL); ! next_statwrite.tv_usec += ((PGSTAT_STAT_INTERVAL) * 1000); ! next_statwrite.tv_sec += (next_statwrite.tv_usec / 1000000); ! next_statwrite.tv_usec %= 1000000; ! need_statwrite = TRUE; } } --- 1776,1787 ---- */ pgStatNumMessages++; ! if (need_timer) { ! if (setitimer(ITIMER_REAL, &timeval, NULL)) ! ereport(ERROR, ! (errmsg("unable to set statistics collector timer: %m"))); ! need_timer = false; } } *************** *** 1848,1853 **** --- 1806,1818 ---- } + static void + force_statwrite(SIGNAL_ARGS) + { + need_statwrite = true; + } + + /* ---------- * pgstat_recvbuffer() - * *************** *** 1865,1871 **** struct timeval timeout; int writePipe = pgStatPipe[1]; int maxfd; - int nready; int len; int xfr; int frm; --- 1830,1835 ---- *************** *** 1907,1912 **** --- 1871,1884 ---- msgbuffer = (char *) palloc(PGSTAT_RECVBUFFERSZ); /* + * Wait for some work to do; but not for more than 10 seconds. (This + * determines how quickly we will shut down after an ungraceful + * postmaster termination; so it needn't be very fast.) + */ + timeout.tv_sec = 10; + timeout.tv_usec = 0; + + /* * Loop forever */ for (;;) *************** *** 1946,1961 **** maxfd = writePipe; } ! /* ! * Wait for some work to do; but not for more than 10 seconds. (This ! * determines how quickly we will shut down after an ungraceful ! * postmaster termination; so it needn't be very fast.) ! */ ! timeout.tv_sec = 10; ! timeout.tv_usec = 0; ! ! nready = select(maxfd + 1, &rfds, &wfds, NULL, &timeout); ! if (nready < 0) { if (errno == EINTR) continue; --- 1918,1924 ---- maxfd = writePipe; } ! if (select(maxfd + 1, &rfds, &wfds, NULL, &timeout) < 0) { if (errno == EINTR) continue; --ELM1136306603-6886-1_-- From pgsql-hackers-owner@postgresql.org Sun Jan 8 08:18:06 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 898EE9DC9BC for ; Sun, 8 Jan 2006 08:18:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74697-05 for ; Sun, 8 Jan 2006 08:18:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.skype.net (mail.skype.net [195.215.8.149]) by postgresql.org (Postfix) with ESMTP id 584C39DC833 for ; Sun, 8 Jan 2006 08:18:03 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.skype.net (Postfix) with ESMTP id 10AA34DD80; Sun, 8 Jan 2006 13:18:05 +0100 (CET) Received: from [192.168.1.102] (80-235-57-196-dsl.trt.estpak.ee [80.235.57.196]) by mail.skype.net (Postfix) with ESMTP id 9724F4DD7B; Sun, 8 Jan 2006 13:18:02 +0100 (CET) Subject: Re: Stats collector performance improvement From: Hannu Krosing To: Simon Riggs Cc: Tom Lane , Qingqing Zhou , pgsql-hackers@postgresql.org In-Reply-To: <1136281253.5052.113.camel@localhost.localdomain> References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> <12503.1136238525@sss.pgh.pa.us> <1136281253.5052.113.camel@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Date: Tue, 03 Jan 2006 23:42:53 +0200 Message-Id: <1136324574.4256.17.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.906 required=5 tests=[AWL=-0.666, DATE_IN_PAST_96_XX=1.572] X-Spam-Score: 0.906 X-Spam-Level: X-Archive-Number: 200601/253 X-Sequence-Number: 78357 Ühel kenal päeval, T, 2006-01-03 kell 09:40, kirjutas Simon Riggs: > We can also save lots of cycles on the current statement overhead, which > is currently the worst part of the stats, performance-wise. That > definitely needs redesign. AFAICS we only ever need to know the SQL > statement via the stats system if the statement has been running for > more than a few minutes - the main use case is for an admin to be able > to diagnose a rogue or hung statement. Interestingly I use pg_stat_activity view to watch for stuck backends, "stuck" in the sense that they have not noticed when client want away and are now waitin the TCP timeout to happen. I query for backends which have been in "" state for longer than XX seconds. I guess that at least some kind of indication for this should be available. Of course this would be much less of a problem if there was a possibility for sime kind of keepalive system to detect when client/frontend goes away. > Pushing the statement to stats > every time is just a big overhead. That suggests we should either have a > pull I could live with "push", where pg_stat_activity would actually ask each live backend for its "current query". This surely happens less often than queries are performed (up to few thousand per sec) ------------- Hannu From pgsql-hackers-owner@postgresql.org Tue Jan 3 19:28:45 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3026B9DC8DA for ; Tue, 3 Jan 2006 19:28:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38248-05 for ; Tue, 3 Jan 2006 19:28:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id C4A569DC83E for ; Tue, 3 Jan 2006 19:28:41 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1EtvZz-0000N5-00; Tue, 03 Jan 2006 18:28:35 -0500 To: "Jim C. Nasby" Cc: Simon Riggs , Tom Lane , Qingqing Zhou , pgsql-hackers@postgresql.org Subject: Re: Stats collector performance improvement References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> <12503.1136238525@sss.pgh.pa.us> <1136281253.5052.113.camel@localhost.localdomain> <20060103163556.GH82560@pervasive.com> In-Reply-To: <20060103163556.GH82560@pervasive.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 03 Jan 2006 18:28:34 -0500 Message-ID: <878xtw6gd9.fsf@stark.xeocode.com> Lines: 24 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.113 required=5 tests=[AWL=0.113] X-Spam-Score: 0.113 X-Spam-Level: X-Archive-Number: 200601/133 X-Sequence-Number: 78237 "Jim C. Nasby" writes: > I would argue that minutes is too long, but of course this could be > user-adjustable. I suspect that even waiting just a second could be a > huge win, since this only matters if you're executing a lot of > statements and you won't be doing that if those statements are taking > more than a second or two to execute. That's not necessarily true at all. You could just as easily have a performance problem caused by a quick statement that is being executed many times as a slow statement that is being executed few times. That is, you could be executing dozens of queries that take seconds or minutes once a second but none of those might be the problem. The problem might be the query that's taking only 300ms that you're executing hundreds of of times a minute. Moreover, if you're not gathering stats for queries that are fast then how will you know whether they're performing properly when you look at them when they do show up? -- greg From pgsql-performance-owner@postgresql.org Tue Jan 3 19:49:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B30789DC83B for ; Tue, 3 Jan 2006 19:49:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48022-01 for ; Tue, 3 Jan 2006 19:49:36 -0400 (AST) X-Greylist: delayed 00:05:01.768482 by SQLgrey- Received: from mtiwmhc13.worldnet.att.net (mtiwmhc13.worldnet.att.net [204.127.131.117]) by postgresql.org (Postfix) with ESMTP id B2FCC9DC889 for ; Tue, 3 Jan 2006 19:49:31 -0400 (AST) Received: from [10.10.10.3] (196.denver-06rh15rt.co.dial-access.att.net[12.73.181.196]) by worldnet.att.net (mtiwmhc13) with ESMTP id <20060103234431113005bvc1e>; Tue, 3 Jan 2006 23:44:32 +0000 Message-ID: <43BB0C5C.8020207@computer.org> Date: Tue, 03 Jan 2006 16:44:28 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: improving write performance for logging application Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/3 X-Sequence-Number: 16481 I have questions about how to improve the write performance of PostgreSQL for logging data from a real-time simulation. We found that MySQL 4.1.3 could log about 1480 objects/second using MyISAM tables or about 1225 objects/second using InnoDB tables, but PostgreSQL 8.0.3 could log only about 540 objects/second. (test system: quad-Itanium2, 8GB memory, SCSI RAID, GigE connection from simulation server, nothing running except system processes and database system under test) We also found that we could improve MySQL performance significantly using MySQL's "INSERT" command extension allowing multiple value-list tuples in a single command; the rate for MyISAM tables improved to about 2600 objects/second. PostgreSQL doesn't support that language extension. Using the COPY command instead of INSERT might help, but since rows are being generated on the fly, I don't see how to use COPY without running a separate process that reads rows from the application and uses COPY to write to the database. The application currently has two processes: the simulation and a data collector that reads events from the sim (queued in shared memory) and writes them as rows to the database, buffering as needed to avoid lost data during periods of high activity. To use COPY I think we would have to split our data collector into two processes communicating via a pipe. Query performance is not an issue: we found that when suitable indexes are added PostgreSQL is fast enough on the kinds of queries our users make. The crux is writing rows to the database fast enough to keep up with the simulation. Are there general guidelines for tuning the PostgreSQL server for this kind of application? The suggestions I've found include disabling fsync (done), increasing the value of wal_buffers, and moving the WAL to a different disk, but these aren't likely to produce the 3x improvement that we need. On the client side I've found only two suggestions: disable autocommit and use COPY instead of INSERT. I think I've effectively disabled autocommit by batching up to several hundred INSERT commands in each PQexec() call, and it isn�t clear that COPY is worth the effort in our application. Thanks. From pgsql-performance-owner@postgresql.org Tue Jan 3 20:00:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8AF219DC87A for ; Tue, 3 Jan 2006 20:00:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49800-06 for ; Tue, 3 Jan 2006 20:00:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4AB189DC83E for ; Tue, 3 Jan 2006 20:00:10 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0400C2J027721; Tue, 3 Jan 2006 19:00:12 -0500 (EST) To: Steve Eckmann cc: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application In-reply-to: <43BB0C5C.8020207@computer.org> References: <43BB0C5C.8020207@computer.org> Comments: In-reply-to Steve Eckmann message dated "Tue, 03 Jan 2006 16:44:28 -0700" Date: Tue, 03 Jan 2006 19:00:12 -0500 Message-ID: <27720.1136332812@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.065 required=5 tests=[AWL=0.065] X-Spam-Score: 0.065 X-Spam-Level: X-Archive-Number: 200601/4 X-Sequence-Number: 16482 Steve Eckmann writes: > We also found that we could improve MySQL performance significantly > using MySQL's "INSERT" command extension allowing multiple value-list > tuples in a single command; the rate for MyISAM tables improved to > about 2600 objects/second. PostgreSQL doesn't support that language > extension. Using the COPY command instead of INSERT might help, but > since rows are being generated on the fly, I don't see how to use COPY > without running a separate process that reads rows from the > application and uses COPY to write to the database. Can you conveniently alter your application to batch INSERT commands into transactions? Ie BEGIN; INSERT ...; ... maybe 100 or so inserts ... COMMIT; BEGIN; ... lather, rinse, repeat ... This cuts down the transactional overhead quite a bit. A downside is that you lose multiple rows if any INSERT fails, but then the same would be true of multiple VALUES lists per INSERT. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 3 20:06:02 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1F0B59DCA22 for ; Tue, 3 Jan 2006 20:06:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54130-02 for ; Tue, 3 Jan 2006 20:06:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 592849DCA07 for ; Tue, 3 Jan 2006 20:05:59 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EtwAC-0007od-3I; Wed, 04 Jan 2006 01:06:00 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1EtwAF-0007gR-00; Wed, 04 Jan 2006 01:06:03 +0100 Date: Wed, 4 Jan 2006 01:06:03 +0100 From: "Steinar H. Gunderson" To: Steve Eckmann Cc: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application Message-ID: <20060104000603.GA29469@uio.no> Mail-Followup-To: Steve Eckmann , pgsql-performance@postgresql.org References: <43BB0C5C.8020207@computer.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <43BB0C5C.8020207@computer.org> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.065 required=5 tests=[AWL=0.065] X-Spam-Score: 0.065 X-Spam-Level: X-Archive-Number: 200601/5 X-Sequence-Number: 16483 On Tue, Jan 03, 2006 at 04:44:28PM -0700, Steve Eckmann wrote: > Are there general guidelines for tuning the PostgreSQL server for this kind > of application? The suggestions I've found include disabling fsync (done), Are you sure you really want this? The results could be catastrophic in case of a crash. > On the client side I've found only two suggestions: disable autocommit and > use COPY instead of INSERT. I think I've effectively disabled autocommit by > batching up to several hundred INSERT commands in each PQexec() call, and > it isn’t clear that COPY is worth the effort in our application. I'm a bit confused here: How can you batch multiple INSERTs into large statements for MySQL, but not batch multiple INSERTs into COPY statements for PostgreSQL? Anyhow, putting it all inside one transaction (or a few) is likely to help quite a lot, but of course less when you have fsync=false. Bunding multiple statements in each PQexec() call won't really give you that; you'll have to tell the database so explicitly. /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Tue Jan 3 20:13:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0B8BD9DC824 for ; Tue, 3 Jan 2006 20:13:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52413-10 for ; Tue, 3 Jan 2006 20:13:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.invendra.net (unknown [66.139.76.16]) by postgresql.org (Postfix) with ESMTP id A65C09DC967 for ; Tue, 3 Jan 2006 20:11:57 -0400 (AST) Received: from web.lang.hm (dsl081-044-215.lax1.dsl.speakeasy.net [64.81.44.215]) by mail.invendra.net (Postfix) with ESMTP id 36B281AC3E9; Tue, 3 Jan 2006 16:11:31 -0800 (PST) Date: Tue, 3 Jan 2006 19:23:23 -0800 (PST) From: dlang To: Tom Lane Cc: Steve Eckmann , Subject: Re: improving write performance for logging application In-Reply-To: <27720.1136332812@sss.pgh.pa.us> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.066 required=5 tests=[AWL=-0.941, DATE_IN_FUTURE_03_06=2.007] X-Spam-Score: 1.066 X-Spam-Level: * X-Archive-Number: 200601/6 X-Sequence-Number: 16484 On Tue, 3 Jan 2006, Tom Lane wrote: > Steve Eckmann writes: > > We also found that we could improve MySQL performance significantly > > using MySQL's "INSERT" command extension allowing multiple value-list > > tuples in a single command; the rate for MyISAM tables improved to > > about 2600 objects/second. PostgreSQL doesn't support that language > > extension. Using the COPY command instead of INSERT might help, but > > since rows are being generated on the fly, I don't see how to use COPY > > without running a separate process that reads rows from the > > application and uses COPY to write to the database. > > Can you conveniently alter your application to batch INSERT commands > into transactions? Ie > > BEGIN; > INSERT ...; > ... maybe 100 or so inserts ... > COMMIT; > BEGIN; > ... lather, rinse, repeat ... > > This cuts down the transactional overhead quite a bit. A downside is > that you lose multiple rows if any INSERT fails, but then the same would > be true of multiple VALUES lists per INSERT. Steve, you mentioned that you data collector buffers the data before sending it to the database, modify it so that each time it goes to send things to the database you send all the data that's in the buffer as a single transaction. I am working on useing postgres to deal with log data and wrote a simple perl script that read in the log files a line at a time, and then wrote them 1000 at a time to the database. On a dual Opteron 240 box with 2G of ram 1x 15krpm SCSI drive (and a untuned postgress install with the compile time defaults) I was getting 5000-8000 lines/sec (I think this was with fsync disabled, but I don't remember for sure). and postgres was complaining that it was overrunning it's log sizes (which limits the speed as it then has to pause to flush the logs) the key thing is to send multiple lines with one transaction as tom shows above. David Lang From pgsql-performance-owner@postgresql.org Wed Jan 4 00:12:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 38F429DC825 for ; Wed, 4 Jan 2006 00:12:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19708-01 for ; Wed, 4 Jan 2006 00:12:55 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 86C619DC9A0 for ; Wed, 4 Jan 2006 00:12:54 -0400 (AST) Received: from mail.auptyma.com (64-60-124-12.cust.telepacific.net [64.60.124.12]) by svr4.postgresql.org (Postfix) with ESMTP id CC58C5AF03F for ; Wed, 4 Jan 2006 04:12:53 +0000 (GMT) Received: from demo1 (64-60-124-12.cust.telepacific.net [64.60.124.12]) (authenticated bits=0) by mail.auptyma.com (8.13.1/8.13.1) with ESMTP id k043rptv011136 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Tue, 3 Jan 2006 19:53:52 -0800 Message-ID: <002b01c610e5$21cc7340$3100000a@demo1> From: "Virag Saksena" To: Subject: Avoiding cartesian product Date: Tue, 3 Jan 2006 20:12:51 -0800 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0028_01C610A2.12B02D40" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.7.5 (mail.auptyma.com [10.0.0.47]); Tue, 03 Jan 2006 19:53:53 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/7 X-Sequence-Number: 16485 This is a multi-part message in MIME format. ------=_NextPart_000_0028_01C610A2.12B02D40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a table which stores cumulative values I would like to display/chart the deltas between successive data = collections If my primary key only increments by 1, I could write a simple query select b.gc_minor - a.gc_minor, b.gc_major - a.gc_major from jam_trace_sys a, jam_trace_sys b where a.trace_id =3D 22 and b.trace_id =3D a.trace_id and b.seq_no =3D a.seq_no + 1 order by a.seq_no; However the difference in sequence number is variable. So (in Oracle) I used to extract the next seq_no using a correlated = sub-query select b.gc_minor - a.gc_minor, b.gc_major - a.gc_major from jam_trace_sys a, jam_trace_sys b where a.trace_id =3D 22 and (b.trace_id, b.seq_no) =3D (select a.trace_id, min(c.seq_no) from jam_trace_sys c where c.trace_id =3D a.trace_id and c.seq_no > a.seq_no) order by a.seq_no; For every row in A, The correlated sub-query from C will execute With an appropriate index, it will just descend the index Btree go one row to the right and return that row (min > :value) and join to table B SELECT STATEMENT SORT ORDER BY TABLE ACCESS BY INDEX ROWID JAM_TRACE_SYS B NESTED LOOPS TABLE ACCESS BY INDEX ROWID JAM_TRACE_SYS A INDEX RANGE SCAN JAM_TRACE_SYS_N1 A INDEX RANGE SCAN JAM_TRACE_SYS_N1 B SORT AGGREGATE INDEX RANGE SCAN JAM_TRACE_SYS_N1 C In postgreSQL A and B are doing a cartesian product then C gets executed for every row in this cartesian product and most of the extra rows get thrown out. Is there any way to force an execution plan like above where the = correlated subquery runs before going to B. The table is small right now, but it will grow to have millions of rows QUERY PLAN -------------------------------------------------------------------------= ---------------------------------------------------------- Sort (cost=3D124911.81..124944.84 rows=3D13213 width=3D20) (actual = time=3D13096.754..13097.053 rows=3D149 loops=3D1) Sort Key: a.seq_no -> Nested Loop (cost=3D4.34..124007.40 rows=3D13213 width=3D20) = (actual time=3D1948.300..13096.329 rows=3D149 loops=3D1) Join Filter: (subplan) -> Seq Scan on jam_trace_sys b (cost=3D0.00..3.75 rows=3D175 = width=3D16) (actual time=3D0.005..0.534 rows=3D175 loops=3D1) -> Materialize (cost=3D4.34..5.85 rows=3D151 width=3D16) = (actual time=3D0.002..0.324 rows=3D150 loops=3D175) -> Seq Scan on jam_trace_sys a (cost=3D0.00..4.19 = rows=3D151 width=3D16) (actual time=3D0.022..0.687 rows=3D150 loops=3D1) Filter: (trace_id =3D 22) SubPlan -> Aggregate (cost=3D4.67..4.67 rows=3D1 width=3D4) (actual = time=3D0.486..0.488 rows=3D1 loops=3D26250) -> Seq Scan on jam_trace_sys c (cost=3D0.00..4.62 = rows=3D15 width=3D4) (actual time=3D0.058..0.311 rows=3D74 = loops=3D26250) Filter: ((trace_id =3D $0) AND (seq_no > $1)) Total runtime: 13097.557 ms (13 rows) pglnx01=3D> \d jam_trace_sys Table "public.jam_trace_sys" Column | Type | Modifiers -----------------+---------+----------- trace_id | integer | seq_no | integer | cpu_utilization | integer | gc_minor | integer | gc_major | integer | heap_used | integer | Indexes: "jam_trace_sys_n1" btree (trace_id, seq_no) pglnx01=3D> select count(*) from jam_trace_Sys ; count ------- 175 (1 row) pglnx01=3D> select trace_id, count(*) from jam_trace_sys group by = trace_id ; trace_id | count ----------+------- 15 | 2 18 | 21 22 | 150 16 | 2 (4 rows) ------=_NextPart_000_0028_01C610A2.12B02D40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I have a table which stores cumulative = values
I=20 would like to display/chart the deltas between successive data=20 collections
 
If my primary key only increments by 1, = I could=20 write a simple query
 
select b.gc_minor - a.gc_minor, = b.gc_major -=20 a.gc_major
  from jam_trace_sys a, jam_trace_sys = b
 where=20 a.trace_id =3D 22
   and b.trace_id =3D = a.trace_id
   and=20 b.seq_no =3D a.seq_no + 1
 order by a.seq_no;
 
However the difference in sequence = number is=20 variable.
So (in Oracle) I used to extract the next seq_no using a = correlated=20 sub-query
 
select b.gc_minor - a.gc_minor, = b.gc_major -=20 a.gc_major
from jam_trace_sys a, jam_trace_sys b
where a.trace_id = =3D=20 22
and (b.trace_id, b.seq_no) =3D
(select a.trace_id, = min(c.seq_no) from=20 jam_trace_sys c
where c.trace_id =3D a.trace_id and c.seq_no >=20 a.seq_no)
 order by a.seq_no;
 
For every row in A, The correlated = sub-query from C=20 will execute
With an appropriate index, it will just descend the = index=20 Btree
go one row to the right and return that row (min > = :value)
and=20 join to table B
 
SELECT STATEMENT
  SORT ORDER=20 BY
   TABLE ACCESS BY INDEX ROWID JAM_TRACE_SYS=20 B
     NESTED=20 LOOPS
       TABLE ACCESS BY INDEX = ROWID=20 JAM_TRACE_SYS  = A
         INDEX=20 RANGE SCAN JAM_TRACE_SYS_N1  = A
      =20 INDEX RANGE SCAN JAM_TRACE_SYS_N1=20 B
         SORT=20 AGGREGATE
          = INDEX=20 RANGE SCAN JAM_TRACE_SYS_N1 C
 
In postgreSQL A and B are doing a = cartesian=20 product
then C gets executed for every row in this cartesian = product
and=20 most of the extra rows get thrown out.
Is there any way to force an = execution=20 plan like above where the correlated subquery runs before going to = B.
The=20 table is small right now, but it will grow to have millions of=20 rows
QUERY=20 PLAN
-----------------------------------------------------------------= ------------------------------------------------------------------
&nb= sp;Sort =20 (cost=3D124911.81..124944.84 rows=3D13213 width=3D20) (actual=20 time=3D13096.754..13097.053 rows=3D149 loops=3D1)
   Sort = Key:=20 a.seq_no
   ->  Nested Loop  = (cost=3D4.34..124007.40=20 rows=3D13213 width=3D20) (actual time=3D1948.300..13096.329 rows=3D149=20 loops=3D1)
         Join = Filter:=20 (subplan)
         = ->  Seq=20 Scan on jam_trace_sys b  (cost=3D0.00..3.75 rows=3D175 width=3D16) = (actual=20 time=3D0.005..0.534 rows=3D175=20 loops=3D1)
         = -> =20 Materialize  (cost=3D4.34..5.85 rows=3D151 width=3D16) (actual = time=3D0.002..0.324=20 rows=3D150=20 loops=3D175)
         &nb= sp;    =20 ->  Seq Scan on jam_trace_sys a  (cost=3D0.00..4.19 = rows=3D151=20 width=3D16) (actual time=3D0.022..0.687 rows=3D150=20 loops=3D1)
          = ;          =20 Filter: (trace_id =3D = 22)
        =20 SubPlan
          =20 ->  Aggregate  (cost=3D4.67..4.67 rows=3D1 width=3D4) = (actual=20 time=3D0.486..0.488 rows=3D1=20 loops=3D26250)
         &= nbsp;      =20 ->  Seq Scan on jam_trace_sys c  (cost=3D0.00..4.62 = rows=3D15 width=3D4)=20 (actual time=3D0.058..0.311 rows=3D74=20 loops=3D26250)
         &= nbsp;           &n= bsp;=20 Filter: ((trace_id =3D $0) AND (seq_no > $1))
 Total runtime: = 13097.557=20 ms
(13 rows)
 
pglnx01=3D> \d=20 jam_trace_sys
     Table=20 "public.jam_trace_sys"
    =20 Column      |  Type   |=20 Modifiers
-----------------+---------+-----------
 trace_id&nb= sp;      =20 | integer=20 |
 seq_no          = |=20 integer |
 cpu_utilization | integer=20 |
 gc_minor        | integer=20 |
 gc_major        | integer=20 |
 heap_used       | integer=20 |
Indexes:
    "jam_trace_sys_n1" btree (trace_id,=20 seq_no)
 
pglnx01=3D> select count(*) from = jam_trace_Sys=20 ;
 count
-------
   175
(1 row)
 
pglnx01=3D> select trace_id, = count(*) from=20 jam_trace_sys group by trace_id ;
 trace_id |=20 count
----------+-------
       15=20 |     2
       18=20 |    21
       22 = |  =20 150
       16 |     = 2
(4=20 rows)
------=_NextPart_000_0028_01C610A2.12B02D40-- From pgsql-performance-owner@postgresql.org Wed Jan 4 09:54:26 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 92C099DC83F for ; Wed, 4 Jan 2006 09:54:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16876-05 for ; Wed, 4 Jan 2006 09:54:29 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 8804A9DC851 for ; Wed, 4 Jan 2006 09:54:23 -0400 (AST) Received: from mailhost.intellivid.com (mailhost.intellivid.com [64.32.200.11]) by svr4.postgresql.org (Postfix) with ESMTP id 2102F5AF075 for ; Wed, 4 Jan 2006 13:54:28 +0000 (GMT) Received: from spectre.intellivid.com (spectre.intellivid.com [192.168.2.68]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client did not present a certificate) by newmail.intellivid.com (Postfix) with ESMTP id 95215F18104; Wed, 4 Jan 2006 08:54:25 -0500 (EST) Subject: Re: improving write performance for logging application From: Ian Westmacott To: Steve Eckmann Cc: pgsql-performance@postgresql.org In-Reply-To: <43BB0C5C.8020207@computer.org> References: <43BB0C5C.8020207@computer.org> Content-Type: text/plain; charset=UTF-8 Organization: Intellivid Corp. Date: Wed, 04 Jan 2006 08:54:25 -0500 Message-Id: <1136382865.24450.7.camel@spectre.intellivid.com> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/8 X-Sequence-Number: 16486 We have a similar application thats doing upwards of 2B inserts per day. We have spent a lot of time optimizing this, and found the following to be most beneficial: 1) use COPY (BINARY if possible) 2) don't use triggers or foreign keys 3) put WAL and tables on different spindles (channels if possible) 4) put as much as you can in each COPY, and put as many COPYs as you can in a single transaction. 5) watch out for XID wraparound 6) tune checkpoint* and bgwriter* parameters for your I/O system On Tue, 2006-01-03 at 16:44 -0700, Steve Eckmann wrote: > I have questions about how to improve the write performance of PostgreSQL for logging data from a real-time simulation. We found that MySQL 4.1.3 could log about 1480 objects/second using MyISAM tables or about 1225 objects/second using InnoDB tables, but PostgreSQL 8.0.3 could log only about 540 objects/second. (test system: quad-Itanium2, 8GB memory, SCSI RAID, GigE connection from simulation server, nothing running except system processes and database system under test) > > We also found that we could improve MySQL performance significantly using MySQL's "INSERT" command extension allowing multiple value-list tuples in a single command; the rate for MyISAM tables improved to about 2600 objects/second. PostgreSQL doesn't support that language extension. Using the COPY command instead of INSERT might help, but since rows are being generated on the fly, I don't see how to use COPY without running a separate process that reads rows from the application and uses COPY to write to the database. The application currently has two processes: the simulation and a data collector that reads events from the sim (queued in shared memory) and writes them as rows to the database, buffering as needed to avoid lost data during periods of high activity. To use COPY I think we would have to split our data collector into two processes communicating via a pipe. > > Query performance is not an issue: we found that when suitable indexes are added PostgreSQL is fast enough on the kinds of queries our users make. The crux is writing rows to the database fast enough to keep up with the simulation. > > Are there general guidelines for tuning the PostgreSQL server for this kind of application? The suggestions I've found include disabling fsync (done), increasing the value of wal_buffers, and moving the WAL to a different disk, but these aren't likely to produce the 3x improvement that we need. On the client side I've found only two suggestions: disable autocommit and use COPY instead of INSERT. I think I've effectively disabled autocommit by batching up to several hundred INSERT commands in each PQexec() call, and it isn’t clear that COPY is worth the effort in our application. > > Thanks. > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster -- Ian Westmacott Intellivid Corp. From pgsql-performance-owner@postgresql.org Wed Jan 4 10:00:21 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E32D39DC83F for ; Wed, 4 Jan 2006 10:00:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17422-09 for ; Wed, 4 Jan 2006 10:00:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mtiwmhc13.worldnet.att.net (mtiwmhc13.worldnet.att.net [204.127.131.117]) by postgresql.org (Postfix) with ESMTP id 2CAFF9DC814 for ; Wed, 4 Jan 2006 10:00:16 -0400 (AST) Received: from [10.10.10.3] (166.denver-06rh16rt-07rh15rt.co.dial-access.att.net[12.73.182.166]) by worldnet.att.net (mtiwmhc13) with ESMTP id <20060104140017113005cacee>; Wed, 4 Jan 2006 14:00:18 +0000 Message-ID: <43BBD4EC.5020207@computer.org> Date: Wed, 04 Jan 2006 07:00:12 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application References: <43BB0C5C.8020207@computer.org> <27720.1136332812@sss.pgh.pa.us> In-Reply-To: <27720.1136332812@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------060004050500060909060100" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.712 required=5 tests=[AWL=-0.233, HTML_10_20=0.945, HTML_MESSAGE=0.001] X-Spam-Score: 0.712 X-Spam-Level: X-Archive-Number: 200601/9 X-Sequence-Number: 16487 This is a multi-part message in MIME format. --------------060004050500060909060100 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Tom Lane wrote: >Steve Eckmann writes: > > >>We also found that we could improve MySQL performance significantly >>using MySQL's "INSERT" command extension allowing multiple value-list >>tuples in a single command; the rate for MyISAM tables improved to >>about 2600 objects/second. PostgreSQL doesn't support that language >>extension. Using the COPY command instead of INSERT might help, but >>since rows are being generated on the fly, I don't see how to use COPY >>without running a separate process that reads rows from the >>application and uses COPY to write to the database. >> >> > >Can you conveniently alter your application to batch INSERT commands >into transactions? Ie > > BEGIN; > INSERT ...; > ... maybe 100 or so inserts ... > COMMIT; > BEGIN; > ... lather, rinse, repeat ... > >This cuts down the transactional overhead quite a bit. A downside is >that you lose multiple rows if any INSERT fails, but then the same would >be true of multiple VALUES lists per INSERT. > > regards, tom lane > > Thanks for the suggestion, Tom. Yes, I think I could do that. But I thought what I was doing now was effectively the same, because the PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to include multiple SQL commands (separated by semicolons) in the command string. Multiple queries sent in a single PQexec call are processed in a single transaction...." Our simulation application has nearly 400 event types, each of which is a C++ class for which we have a corresponding database table. So every thousand events or so I issue one PQexec() call for each event type that has unlogged instances, sending INSERT commands for all instances. For example, PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT INTO FlyingObjectState VALUES (...); ..."); My thought was that this would be a good compromise between minimizing transactions (one per event class per buffering interval instead of one per event) and minimizing disk seeking (since all queries in a single transaction insert rows into the same table). Am I overlooking something here? One thing I haven't tried is increasing the buffering interval from 1000 events to, say, 10,000. It turns out that 1000 is a good number for Versant, the object database system we're replacing, and for MySQL, so I assumed it would be a good number for PostgreSQL, too. Regards, Steve --------------060004050500060909060100 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote:
Steve Eckmann <eckmann@computer.org> writes:
  
We also found that we could improve MySQL performance significantly
using MySQL's "INSERT" command extension allowing multiple value-list
tuples in a single command; the rate for MyISAM tables improved to
about 2600 objects/second. PostgreSQL doesn't support that language
extension. Using the COPY command instead of INSERT might help, but
since rows are being generated on the fly, I don't see how to use COPY
without running a separate process that reads rows from the
application and uses COPY to write to the database.
    

Can you conveniently alter your application to batch INSERT commands
into transactions?  Ie

	BEGIN;
	INSERT ...;
	... maybe 100 or so inserts ...
	COMMIT;
	BEGIN;
	... lather, rinse, repeat ...

This cuts down the transactional overhead quite a bit.  A downside is
that you lose multiple rows if any INSERT fails, but then the same would
be true of multiple VALUES lists per INSERT.

			regards, tom lane
  
Thanks for the suggestion, Tom. Yes, I think I could do that. But I thought what I was doing now was effectively the same, because the PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to include multiple SQL commands (separated by semicolons) in the command string. Multiple queries sent in a single PQexec call are processed in a single transaction...." Our simulation application has nearly 400 event types, each of which is a C++ class for which we have a corresponding database table. So every thousand events or so I issue one PQexec() call for each event type that has unlogged instances, sending INSERT commands for all instances. For example,

    PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT INTO FlyingObjectState VALUES (...); ...");

My thought was that this would be a good compromise between minimizing transactions (one per event class per buffering interval instead of one per event) and minimizing disk seeking (since all queries in a single transaction insert rows into the same table). Am I overlooking something here? One thing I haven't tried is increasing the buffering interval from 1000 events to, say, 10,000. It turns out that 1000 is a good number for Versant, the object database system we're replacing, and for MySQL, so I assumed it would be a good number for PostgreSQL, too.

Regards,  Steve

--------------060004050500060909060100-- From pgsql-performance-owner@postgresql.org Wed Jan 4 10:08:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BBEDC9DC982 for ; Wed, 4 Jan 2006 10:08:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23905-02 for ; Wed, 4 Jan 2006 10:08:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mtiwmhc11.worldnet.att.net (mtiwmhc11.worldnet.att.net [204.127.131.115]) by postgresql.org (Postfix) with ESMTP id 6A3849DC83F for ; Wed, 4 Jan 2006 10:08:36 -0400 (AST) Received: from [10.10.10.3] (166.denver-06rh16rt-07rh15rt.co.dial-access.att.net[12.73.182.166]) by worldnet.att.net (mtiwmhc11) with ESMTP id <2006010414083811100n9bi6e>; Wed, 4 Jan 2006 14:08:39 +0000 Message-ID: <43BBD6E2.6080300@computer.org> Date: Wed, 04 Jan 2006 07:08:34 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Steinar H. Gunderson" CC: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application References: <43BB0C5C.8020207@computer.org> <20060104000603.GA29469@uio.no> In-Reply-To: <20060104000603.GA29469@uio.no> Content-Type: multipart/alternative; boundary="------------070306010906040306040009" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.656 required=5 tests=[AWL=0.176, DNS_FROM_RFC_ABUSE=0.479, HTML_MESSAGE=0.001] X-Spam-Score: 0.656 X-Spam-Level: X-Archive-Number: 200601/10 X-Sequence-Number: 16488 This is a multi-part message in MIME format. --------------070306010906040306040009 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Steinar H. Gunderson wrote: >On Tue, Jan 03, 2006 at 04:44:28PM -0700, Steve Eckmann wrote: > > >>Are there general guidelines for tuning the PostgreSQL server for this kind >>of application? The suggestions I've found include disabling fsync (done), >> >> > >Are you sure you really want this? The results could be catastrophic in case >of a crash. > > > >>On the client side I've found only two suggestions: disable autocommit and >>use COPY instead of INSERT. I think I've effectively disabled autocommit by >>batching up to several hundred INSERT commands in each PQexec() call, and >>it isn’t clear that COPY is worth the effort in our application. >> >> > >I'm a bit confused here: How can you batch multiple INSERTs into large >statements for MySQL, but not batch multiple INSERTs into COPY statements for >PostgreSQL? > >Anyhow, putting it all inside one transaction (or a few) is likely to help >quite a lot, but of course less when you have fsync=false. Bunding multiple >statements in each PQexec() call won't really give you that; you'll have to >tell the database so explicitly. > >/* Steinar */ > > Thanks, Steinar. I don't think we would really run with fsync off, but I need to document the performance tradeoffs. You're right that my explanation was confusing; probably because I'm confused about how to use COPY! I could batch multiple INSERTS using COPY statements, I just don't see how to do it without adding another process to read from STDIN, since the application that is currently the database client is constructing rows on the fly. I would need to get those rows into some process's STDIN stream or into a server-side file before COPY could be used, right? You're comment about bundling multiple statements in each PQexec() call seems to disagree with a statement in 27.3.1 that I interpret as saying each PQexec() call corresponds to a single transaction. Are you sure my interpretation is wrong? Regards, Steve --------------070306010906040306040009 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Steinar H. Gunderson wrote:
On Tue, Jan 03, 2006 at 04:44:28PM -0700, Steve Eckmann wrote:
  
Are there general guidelines for tuning the PostgreSQL server for this kind 
of application? The suggestions I've found include disabling fsync (done),
    

Are you sure you really want this? The results could be catastrophic in case
of a crash.

  
On the client side I've found only two suggestions: disable autocommit and 
use COPY instead of INSERT. I think I've effectively disabled autocommit by 
batching up to several hundred INSERT commands in each PQexec() call, and 
it isn’t clear that COPY is worth the effort in our application.
    

I'm a bit confused here: How can you batch multiple INSERTs into large
statements for MySQL, but not batch multiple INSERTs into COPY statements for
PostgreSQL?

Anyhow, putting it all inside one transaction (or a few) is likely to help
quite a lot, but of course less when you have fsync=false. Bunding multiple
statements in each PQexec() call won't really give you that; you'll have to
tell the database so explicitly.

/* Steinar */
  
Thanks, Steinar. I don't think we would really run with fsync off, but I need to document the performance tradeoffs. You're right that my explanation was confusing; probably because I'm confused about how to use COPY! I could batch multiple INSERTS using COPY statements, I just don't see how to do it without adding another process to read from STDIN, since the application that is currently the database client is constructing rows on the fly. I would need to get those rows into some process's STDIN stream or into a server-side file before COPY could be used, right?

You're comment about bundling multiple statements in each PQexec() call seems to disagree with a statement in 27.3.1 that I interpret as saying each PQexec() call corresponds to a single transaction. Are you sure my interpretation is wrong?

Regards, Steve --------------070306010906040306040009-- From pgsql-performance-owner@postgresql.org Wed Jan 4 10:13:21 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D007B9DC835 for ; Wed, 4 Jan 2006 10:13:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23861-04 for ; Wed, 4 Jan 2006 10:13:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mtiwmhc12.worldnet.att.net (mtiwmhc12.worldnet.att.net [204.127.131.116]) by postgresql.org (Postfix) with ESMTP id 9919A9DC84E for ; Wed, 4 Jan 2006 10:13:18 -0400 (AST) Received: from [10.10.10.3] (166.denver-06rh16rt-07rh15rt.co.dial-access.att.net[12.73.182.166]) by worldnet.att.net (mtiwmhc12) with ESMTP id <20060104141316112002870be>; Wed, 4 Jan 2006 14:13:21 +0000 Message-ID: <43BBD7F9.2060406@computer.org> Date: Wed, 04 Jan 2006 07:13:13 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dlang CC: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------050703080005020101070803" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.597 required=5 tests=[AWL=0.117, DNS_FROM_RFC_ABUSE=0.479, HTML_MESSAGE=0.001] X-Spam-Score: 0.597 X-Spam-Level: X-Archive-Number: 200601/11 X-Sequence-Number: 16489 This is a multi-part message in MIME format. --------------050703080005020101070803 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit dlang wrote: >On Tue, 3 Jan 2006, Tom Lane wrote: > > > >>Steve Eckmann writes: >> >> >>>We also found that we could improve MySQL performance significantly >>>using MySQL's "INSERT" command extension allowing multiple value-list >>>tuples in a single command; the rate for MyISAM tables improved to >>>about 2600 objects/second. PostgreSQL doesn't support that language >>>extension. Using the COPY command instead of INSERT might help, but >>>since rows are being generated on the fly, I don't see how to use COPY >>>without running a separate process that reads rows from the >>>application and uses COPY to write to the database. >>> >>> >>Can you conveniently alter your application to batch INSERT commands >>into transactions? Ie >> >> BEGIN; >> INSERT ...; >> ... maybe 100 or so inserts ... >> COMMIT; >> BEGIN; >> ... lather, rinse, repeat ... >> >>This cuts down the transactional overhead quite a bit. A downside is >>that you lose multiple rows if any INSERT fails, but then the same would >>be true of multiple VALUES lists per INSERT. >> >> > >Steve, you mentioned that you data collector buffers the data before >sending it to the database, modify it so that each time it goes to send >things to the database you send all the data that's in the buffer as a >single transaction. > >I am working on useing postgres to deal with log data and wrote a simple >perl script that read in the log files a line at a time, and then wrote >them 1000 at a time to the database. On a dual Opteron 240 box with 2G of >ram 1x 15krpm SCSI drive (and a untuned postgress install with the compile >time defaults) I was getting 5000-8000 lines/sec (I think this was with >fsync disabled, but I don't remember for sure). and postgres was >complaining that it was overrunning it's log sizes (which limits the speed >as it then has to pause to flush the logs) > >the key thing is to send multiple lines with one transaction as tom shows >above. > >David Lang > Thanks, David. I will look more carefully at how to batch multiple rows per PQexec() call. Regards, Steve. --------------050703080005020101070803 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit dlang wrote:
On Tue, 3 Jan 2006, Tom Lane wrote:

  
Steve Eckmann <eckmann@computer.org> writes:
    
We also found that we could improve MySQL performance significantly
using MySQL's "INSERT" command extension allowing multiple value-list
tuples in a single command; the rate for MyISAM tables improved to
about 2600 objects/second. PostgreSQL doesn't support that language
extension. Using the COPY command instead of INSERT might help, but
since rows are being generated on the fly, I don't see how to use COPY
without running a separate process that reads rows from the
application and uses COPY to write to the database.
      
Can you conveniently alter your application to batch INSERT commands
into transactions?  Ie

	BEGIN;
	INSERT ...;
	... maybe 100 or so inserts ...
	COMMIT;
	BEGIN;
	... lather, rinse, repeat ...

This cuts down the transactional overhead quite a bit.  A downside is
that you lose multiple rows if any INSERT fails, but then the same would
be true of multiple VALUES lists per INSERT.
    

Steve, you mentioned that you data collector buffers the data before
sending it to the database, modify it so that each time it goes to send
things to the database you send all the data that's in the buffer as a
single transaction.

I am working on useing postgres to deal with log data and wrote a simple
perl script that read in the log files a line at a time, and then wrote
them 1000 at a time to the database. On a dual Opteron 240 box with 2G of
ram 1x 15krpm SCSI drive (and a untuned postgress install with the compile
time defaults) I was getting 5000-8000 lines/sec (I think this was with
fsync disabled, but I don't remember for sure). and postgres was
complaining that it was overrunning it's log sizes (which limits the speed
as it then has to pause to flush the logs)

the key thing is to send multiple lines with one transaction as tom shows
above.

David Lang
Thanks, David. I will look more carefully at how to batch multiple rows per PQexec() call.  Regards, Steve.
--------------050703080005020101070803-- From pgsql-performance-owner@postgresql.org Wed Jan 4 10:16:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9358C9DC982 for ; Wed, 4 Jan 2006 10:16:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24887-01 for ; Wed, 4 Jan 2006 10:16:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mtiwmhc11.worldnet.att.net (mtiwmhc11.worldnet.att.net [204.127.131.115]) by postgresql.org (Postfix) with ESMTP id 58C2F9DC983 for ; Wed, 4 Jan 2006 10:16:33 -0400 (AST) Received: from [10.10.10.3] (166.denver-06rh16rt-07rh15rt.co.dial-access.att.net[12.73.182.166]) by worldnet.att.net (mtiwmhc11) with ESMTP id <2006010414163611100n974je>; Wed, 4 Jan 2006 14:16:37 +0000 Message-ID: <43BBD8C1.9080807@computer.org> Date: Wed, 04 Jan 2006 07:16:33 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ian Westmacott CC: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> In-Reply-To: <1136382865.24450.7.camel@spectre.intellivid.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.538 required=5 tests=[AWL=0.059, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.538 X-Spam-Level: X-Archive-Number: 200601/12 X-Sequence-Number: 16490 Ian Westmacott wrote: >We have a similar application thats doing upwards of 2B inserts >per day. We have spent a lot of time optimizing this, and found the >following to be most beneficial: > >1) use COPY (BINARY if possible) >2) don't use triggers or foreign keys >3) put WAL and tables on different spindles (channels if possible) >4) put as much as you can in each COPY, and put as many COPYs as > you can in a single transaction. >5) watch out for XID wraparound >6) tune checkpoint* and bgwriter* parameters for your I/O system > Thanks, Ian. I will look at how to implement your suggestions. Regards, Steve From pgsql-performance-owner@postgresql.org Wed Jan 4 10:29:04 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4CBC39DC9D5 for ; Wed, 4 Jan 2006 10:29:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25834-06 for ; Wed, 4 Jan 2006 10:29:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth08.mail.atl.earthlink.net (smtpauth08.mail.atl.earthlink.net [209.86.89.68]) by postgresql.org (Postfix) with ESMTP id A98819DC9A0 for ; Wed, 4 Jan 2006 10:29:00 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=kFtJPct1bagcyo94gQOdu/JZKEOm+GpFBx/HUujzv3GKPZQraP+S+Q86S4CiG/np; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:Content-Transfer-Encoding:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.244.95] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth08.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1Eu9dQ-0006aB-7J; Wed, 04 Jan 2006 09:29:04 -0500 Message-Id: <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Wed, 04 Jan 2006 09:29:00 -0500 To: Ian Westmacott ,pgsql-performance@postgresql.org From: Ron Subject: Re: improving write performance for logging In-Reply-To: <1136382865.24450.7.camel@spectre.intellivid.com> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; format=flowed Content-Transfer-Encoding: quoted-printable X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc3418500f0e0914cba15b2cb04bac4831350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.244.95 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.406 required=5 tests=[AWL=-0.073, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.406 X-Spam-Level: X-Archive-Number: 200601/13 X-Sequence-Number: 16491 2B is a lot of inserts. If you had to guess,=20 what do you think is the maximum number of inserts you could do in a day? How large is each record being inserted? How much can you put in a COPY and how many COPYs=20 can you put into a transactions? What values are you using for bgwriter* and checkpoint*? What HW on you running on and what kind of performance do you typically get? Inquiring minds definitely want to know ;-) Ron At 08:54 AM 1/4/2006, Ian Westmacott wrote: >We have a similar application thats doing upwards of 2B inserts >per day. We have spent a lot of time optimizing this, and found the >following to be most beneficial: > >1) use COPY (BINARY if possible) >2) don't use triggers or foreign keys >3) put WAL and tables on different spindles (channels if possible) >4) put as much as you can in each COPY, and put as many COPYs as > you can in a single transaction. >5) watch out for XID wraparound >6) tune checkpoint* and bgwriter* parameters for your I/O system > >On Tue, 2006-01-03 at 16:44 -0700, Steve Eckmann wrote: > > I have questions about how to improve the=20 > write performance of PostgreSQL for logging=20 > data from a real-time simulation. We found that=20 > MySQL 4.1.3 could log about 1480 objects/second=20 > using MyISAM tables or about 1225=20 > objects/second using InnoDB tables, but=20 > PostgreSQL 8.0.3 could log only about 540=20 > objects/second. (test system: quad-Itanium2,=20 > 8GB memory, SCSI RAID, GigE connection from=20 > simulation server, nothing running except=20 > system processes and database system under test) > > > > We also found that we could improve MySQL=20 > performance significantly using MySQL's=20 > "INSERT" command extension allowing multiple=20 > value-list tuples in a single command; the rate=20 > for MyISAM tables improved to about 2600=20 > objects/second. PostgreSQL doesn't support that=20 > language extension. Using the COPY command=20 > instead of INSERT might help, but since rows=20 > are being generated on the fly, I don't see how=20 > to use COPY without running a separate process=20 > that reads rows from the application and uses=20 > COPY to write to the database. The application=20 > currently has two processes: the simulation and=20 > a data collector that reads events from the sim=20 > (queued in shared memory) and writes them as=20 > rows to the database, buffering as needed to=20 > avoid lost data during periods of high=20 > activity. To use COPY I think we would have to=20 > split our data collector into two processes communicating via a pipe. > > > > Query performance is not an issue: we found=20 > that when suitable indexes are added PostgreSQL=20 > is fast enough on the kinds of queries our=20 > users make. The crux is writing rows to the=20 > database fast enough to keep up with the simulation. > > > > Are there general guidelines for tuning the=20 > PostgreSQL server for this kind of application?=20 > The suggestions I've found include disabling=20 > fsync (done), increasing the value of=20 > wal_buffers, and moving the WAL to a different=20 > disk, but these aren't likely to produce the 3x=20 > improvement that we need. On the client side=20 > I've found only two suggestions: disable=20 > autocommit and use COPY instead of INSERT. I=20 > think I've effectively disabled autocommit by=20 > batching up to several hundred INSERT commands=20 > in each PQexec() call, and it isn=E2=80=99t clear=20 > that COPY is worth the effort in our application. > > > > Thanks. > > > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 2: Don't 'kill -9' the postmaster >-- >Ian Westmacott >Intellivid Corp. > > >---------------------------(end of broadcast)--------------------------- >TIP 4: Have you searched our list archives? > > http://archives.postgresql.org From pgsql-performance-owner@postgresql.org Wed Jan 4 11:39:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D60EC9DC814 for ; Wed, 4 Jan 2006 11:39:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39182-06 for ; Wed, 4 Jan 2006 11:39:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8FCF19DC863 for ; Wed, 4 Jan 2006 11:39:25 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k04FdP20002899; Wed, 4 Jan 2006 10:39:26 -0500 (EST) To: Steve Eckmann cc: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application In-reply-to: <43BBD4EC.5020207@computer.org> References: <43BB0C5C.8020207@computer.org> <27720.1136332812@sss.pgh.pa.us> <43BBD4EC.5020207@computer.org> Comments: In-reply-to Steve Eckmann message dated "Wed, 04 Jan 2006 07:00:12 -0700" Date: Wed, 04 Jan 2006 10:39:25 -0500 Message-ID: <2898.1136389165@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.065 required=5 tests=[AWL=0.065] X-Spam-Score: 0.065 X-Spam-Level: X-Archive-Number: 200601/14 X-Sequence-Number: 16492 Steve Eckmann writes: > Thanks for the suggestion, Tom. Yes, I think I could do that. But I > thought what I was doing now was effectively the same, because the > PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to > include multiple SQL commands (separated by semicolons) in the command > string. Multiple queries sent in a single PQexec call are processed in a > single transaction...." Our simulation application has nearly 400 event > types, each of which is a C++ class for which we have a corresponding > database table. So every thousand events or so I issue one PQexec() call > for each event type that has unlogged instances, sending INSERT commands > for all instances. For example, > PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT > INTO FlyingObjectState VALUES (...); ..."); Hmm. I'm not sure if that's a good idea or not. You're causing the server to take 1000 times the normal amount of memory to hold the command parsetrees, and if there are any O(N^2) behaviors in parsing you could be getting hurt badly by that. (I'd like to think there are not, but would definitely not swear to it.) OTOH you're reducing the number of network round trips which is a good thing. Have you actually measured to see what effect this approach has? It might be worth building a test server with profiling enabled to see if the use of such long command strings creates any hot spots in the profile. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 4 11:40:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A63B89DC84E for ; Wed, 4 Jan 2006 11:40:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40092-02-3 for ; Wed, 4 Jan 2006 11:40:32 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204]) by postgresql.org (Postfix) with ESMTP id 148EE9DCA22 for ; Wed, 4 Jan 2006 11:40:25 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so1845626wxc for ; Wed, 04 Jan 2006 07:40:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references; b=d3F3KdEbP7pCro4pC2ARXOQJh6MtdHQxf2EuzYgBROOYTzGbYXswm+9C5rQrLaQ9dOtvyAHkfDRiUju3/2p8AkIHBQsDhQy3+Abkpq82FmKI1oR5V1VdmXQwqegKqiVAfjJGQ3OTc1nYauKa0THHRRy46bhtbnw9XuZGNbEfZpw= Received: by 10.70.8.4 with SMTP id 4mr12606172wxh; Wed, 04 Jan 2006 07:40:31 -0800 (PST) Received: by 10.70.14.7 with HTTP; Wed, 4 Jan 2006 07:40:31 -0800 (PST) Message-ID: Date: Wed, 4 Jan 2006 09:40:31 -0600 From: Kelly Burkhart To: Steve Eckmann Subject: Re: improving write performance for logging application Cc: pgsql-performance@postgresql.org In-Reply-To: <43BBD6E2.6080300@computer.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2696_747897.1136389231093" References: <43BB0C5C.8020207@computer.org> <20060104000603.GA29469@uio.no> <43BBD6E2.6080300@computer.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/15 X-Sequence-Number: 16493 ------=_Part_2696_747897.1136389231093 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/4/06, Steve Eckmann wrote: > > Thanks, Steinar. I don't think we would really run with fsync off, but I > need to document the performance tradeoffs. You're right that my explanat= ion > was confusing; probably because I'm confused about how to use COPY! I cou= ld > batch multiple INSERTS using COPY statements, I just don't see how to do = it > without adding another process to read from STDIN, since the application > that is currently the database client is constructing rows on the fly. I > would need to get those rows into some process's STDIN stream or into a > server-side file before COPY could be used, right? Steve, You can use copy without resorting to another process. See the libpq documentation for 'Functions Associated with the copy Command". We do something like this: char *mbuf; // allocate space and fill mbuf with appropriately formatted data somehow PQexec( conn, "begin" ); PQexec( conn, "copy mytable from stdin" ); PQputCopyData( conn, mbuf, strlen(mbuf) ); PQputCopyEnd( conn, NULL ); PQexec( conn, "commit" ); -K ------=_Part_2696_747897.1136389231093 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/4/06, Steve Eckmann <eckmann@computer.org> wrote:
Thanks, Steinar. I don't think we would really run with fsync off, but I need to document the performance tradeoffs. You're right that my explanation was confusing; probably because I'm confused about how to use COPY! I could batch multiple INSERTS using COPY statements, I just don't see how to do it without adding another process to read from STDIN, since the application that is currently the database client is constructing rows on the fly. I would need to get those rows into some process's STDIN stream or into a server-side file before COPY could be used, right?

Steve,

You can use copy without resorting to another process.  See the libpq documentation for 'Functions Associated with the copy Command".  We do something like this:

char *mbuf;

// allocate space and fill mbuf with appropriately formatted data somehow
PQexec( conn, "begin" );
PQexec( conn, "copy mytable from stdin" );
PQputCopyData( conn, mbuf, strlen(mbuf) );
PQputCopyEnd( conn, NULL );
PQexec( conn, "commit" );

-K
------=_Part_2696_747897.1136389231093-- From pgsql-performance-owner@postgresql.org Wed Jan 4 12:00:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 83CEE9DC93B for ; Wed, 4 Jan 2006 12:00:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42563-07 for ; Wed, 4 Jan 2006 12:00:39 -0400 (AST) X-Greylist: delayed 02:06:12.448686 by SQLgrey- Received: from mailhost.intellivid.com (mailhost.intellivid.com [64.32.200.11]) by postgresql.org (Postfix) with ESMTP id 581059DC942 for ; Wed, 4 Jan 2006 12:00:39 -0400 (AST) Received: from spectre.intellivid.com (spectre.intellivid.com [192.168.2.68]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client did not present a certificate) by newmail.intellivid.com (Postfix) with ESMTP id A3894F18106; Wed, 4 Jan 2006 11:00:38 -0500 (EST) Subject: Re: improving write performance for logging From: Ian Westmacott To: Ron Cc: pgsql-performance@postgresql.org In-Reply-To: <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> Content-Type: text/plain Organization: Intellivid Corp. Date: Wed, 04 Jan 2006 11:00:38 -0500 Message-Id: <1136390438.24450.49.camel@spectre.intellivid.com> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/16 X-Sequence-Number: 16494 On Wed, 2006-01-04 at 09:29 -0500, Ron wrote: > 2B is a lot of inserts. If you had to guess, > what do you think is the maximum number of inserts you could do in a day? It seems we are pushing it there. Our intentions are to scale much further, but our plans are to distribute at this point. > How large is each record being inserted? They are small: 32 (data) bytes. > How much can you put in a COPY and how many COPYs > can you put into a transactions? These are driven by the application; we do about 60 COPYs and a couple dozen INSERT/UPDATE/DELETEs in a single transaction. Each COPY is doing a variable number of rows, up to several hundred. We do 15 of these transactions per second. > What values are you using for bgwriter* and checkpoint*? bgwriter is 100%/500 pages, and checkpoint is 50 segments/300 seconds. wal_buffers doesn't do much for us, and fsync is enabled. > What HW on you running on and what kind of performance do you typically get? The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3). The tables are on a 10-spindle (SCSI) RAID50 with dual U320 controllers (XFS). This is overkill for writing and querying the data, but we need to constantly ANALYZE and VACUUM in the background without interrupting the inserts (the app is 24x7). The databases are 4TB, so these operations can be lengthy. -- Ian Westmacott Intellivid Corp. From pgsql-performance-owner@postgresql.org Wed Jan 4 18:49:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BF7119DC9A4 for ; Wed, 4 Jan 2006 18:49:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17906-05-2 for ; Wed, 4 Jan 2006 18:49:52 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 1A7529DC9C4 for ; Wed, 4 Jan 2006 18:49:48 -0400 (AST) Received: from mail.goldpocket.com (mail1.goldpocket.com [38.101.116.14]) by svr4.postgresql.org (Postfix) with ESMTP id 10C175AF02B for ; Wed, 4 Jan 2006 22:49:51 +0000 (GMT) Received: from localhost (unknown [127.0.0.1]) by mail.goldpocket.com (Postfix) with ESMTP id E9D34E048F84 for ; Wed, 4 Jan 2006 22:49:48 +0000 (UTC) Received: from mail.goldpocket.com ([127.0.0.1]) by localhost (mail.goldpocket.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 31802-05 for ; Wed, 4 Jan 2006 14:49:45 -0800 (PST) Received: from mail1.goldpocket.com (srvgpimail1.gpi.local [10.10.0.13]) by mail.goldpocket.com (Postfix) with ESMTP id 64B94E048F10 for ; Wed, 4 Jan 2006 14:49:45 -0800 (PST) Received: from mliberman.gpi.local ([10.10.0.158]) by mail1.goldpocket.com with Microsoft SMTPSVC(6.0.3790.211); Wed, 4 Jan 2006 14:49:45 -0800 From: Mark Liberman Organization: Mixed Signals, Inc. To: pgsql-performance@postgresql.org Subject: Help in avoiding a query 'Warm-Up' period/shared buffer cache Date: Wed, 4 Jan 2006 14:49:43 -0800 User-Agent: KMail/1.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601041449.43557.mliberman@mixedsignals.com> X-OriginalArrivalTime: 04 Jan 2006 22:49:45.0981 (UTC) FILETIME=[28CFFAD0:01C61181] X-Virus-Scanned: amavisd-new at goldpocket.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/17 X-Sequence-Number: 16495 Hello, We have a web-application running against a postgres 8.1 database, and basically, every time I run a report after no other reports have been run for several hours, the report will take significantly longer (e.g. 30 seconds), then if I re-run the report again, or run the report when the web-application has been used recently (< 1 second). Keep in mind that our web-app might issue 30 or more individual queries to return a given report and that this behavior is not just isolated to a single report-type - it basically happens for any of the reports after the web-app has been inactive. Also, I can trace it back to the timing of the underlying queries, which show this same behavior (e.g. it's not because of overhead in our web-app). So, it appears to be some sort of caching issue. I'm not 100% clear on how the shared buffer cache works, and what we might do to make sure that we don't have these periods where queries take a long time. Since our users' typical usage scenario is to not use the web-app for a long time and then come back and use it, if reports which generally take a second are taking 30 seconds, we have a real problem. I have isolated a single example of one such query which is very slow when no other queries have been run, and then speeds up significantly on the second run. First run, after a night of inactivity: explain analyze SELECT average_size, end_time FROM 1min_events WHERE file_id = '137271' AND end_time > now() - interval '2 minutes' ORDER BY end_time DESC LIMIT 1; Limit (cost=47.06..47.06 rows=1 width=24) (actual time=313.585..313.585 rows=1 loops=1) -> Sort (cost=47.06..47.06 rows=1 width=24) (actual time=313.584..313.584 rows=1 loops=1) Sort Key: end_time -> Bitmap Heap Scan on 1min_events (cost=44.03..47.05 rows=1 width=24) (actual time=313.562..313.568 rows=2 loops=1) Recheck Cond: ((end_time > (now() - '00:02:00'::interval)) AND (file_id = 137271)) -> BitmapAnd (cost=44.03..44.03 rows=1 width=0) (actual time=313.551..313.551 rows=0 loops=1) -> Bitmap Index Scan on 1min_events_end_idx (cost=0.00..5.93 rows=551 width=0) (actual time=0.076..0.076 rows=46 loops=1) Index Cond: (end_time > (now() - '00:02:00'::interval)) -> Bitmap Index Scan on 1min_events_file_id_begin_idx (cost=0.00..37.85 rows=3670 width=0) (actual time=313.468..313.468 rows=11082 loops=1) Index Cond: (file_id = 137271) Total runtime: 313.643 ms (11 rows) Second run, after that: explain analyze SELECT average_size, end_time FROM 1min_events WHERE file_id = '137271' AND end_time > now() - interval '2 minutes' ORDER BY end_time DESC LIMIT 1; Limit (cost=47.06..47.06 rows=1 width=24) (actual time=2.209..2.209 rows=1 loops=1) -> Sort (cost=47.06..47.06 rows=1 width=24) (actual time=2.208..2.208 rows=1 loops=1) Sort Key: end_time -> Bitmap Heap Scan on 1min_events (cost=44.03..47.05 rows=1 width=24) (actual time=2.192..2.194 rows=2 loops=1) Recheck Cond: ((end_time > (now() - '00:02:00'::interval)) AND (file_id = 137271)) -> BitmapAnd (cost=44.03..44.03 rows=1 width=0) (actual time=2.186..2.186 rows=0 loops=1) -> Bitmap Index Scan on 1min_events_end_idx (cost=0.00..5.93 rows=551 width=0) (actual time=0.076..0.076 rows=46 loops=1) Index Cond: (end_time > (now() - '00:02:00'::interval)) -> Bitmap Index Scan on 1min_events_file_id_begin_idx (cost=0.00..37.85 rows=3670 width=0) (actual time=2.106..2.106 rows=11082 loops=1) Index Cond: (file_id = 137271) Total runtime: 2.276 ms (11 rows) One of the things that is perplexing about the initial slowness of this query is that it's accessing the most recent rows in a given table (e.g. those in the last 2 minutes). So, I would expect the OS cache to be updated with these new rows. Some general information about the server / db: 1) The database is 25G, and has about 60 tables - some very small, but several > 5 MM rows. 2) The table I am querying against above (1min_events) has 5.5 MM rows, but is indexed on end_time, as well as a compound index on file_id, begin_time 3) The following are running on the server that holds the db: a) A program which is reading files and making several (5-10) database calls per minute (these calls tend to take < 100 ms each). These calls are inserting 10's of rows into several of the tables. b) An apache web-server c) The 8.1 postgres DB d) we are running periodic CRON jobs (generally at 11pm, 1 am and 3am) that truncate some of the older data e) we have autovacuum on with a 60 second naptime and and low scale factors 0.2, so analyzes and vacuums happen throughout the day - vacuums are generally triggered by the truncate CRON jobs too. 4) Some of our config settings: shared_buffers = 8192 work_mem = 8192 Total RAM on server is 1 Gig Basically any advice as to what to look at to avoid this situation would be greatly appreciated. Is this simply a matter of tuning the shared_buffers parameter? If not, is scheduling a set of queries to force the proper loading of the cache a logical solution? Thanks in advance, Mark From pgsql-performance-owner@postgresql.org Wed Jan 4 20:16:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3D3BE9DC817 for ; Wed, 4 Jan 2006 20:16:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31921-05 for ; Wed, 4 Jan 2006 20:16:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mtiwmhc12.worldnet.att.net (mtiwmhc12.worldnet.att.net [204.127.131.116]) by postgresql.org (Postfix) with ESMTP id 286389DC802 for ; Wed, 4 Jan 2006 20:16:48 -0400 (AST) Received: from [10.10.10.3] (98.denver-06rh15rt.co.dial-access.att.net[12.73.181.98]) by worldnet.att.net (mtiwmhc12) with ESMTP id <200601050016491120027ar6e>; Thu, 5 Jan 2006 00:16:50 +0000 Message-ID: <43BC656D.2090103@computer.org> Date: Wed, 04 Jan 2006 17:16:45 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application References: <43BB0C5C.8020207@computer.org> <27720.1136332812@sss.pgh.pa.us> <43BBD4EC.5020207@computer.org> <2898.1136389165@sss.pgh.pa.us> In-Reply-To: <2898.1136389165@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------060807030805020204060006" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.502 required=5 tests=[AWL=0.022, DNS_FROM_RFC_ABUSE=0.479, HTML_MESSAGE=0.001] X-Spam-Score: 0.502 X-Spam-Level: X-Archive-Number: 200601/18 X-Sequence-Number: 16496 This is a multi-part message in MIME format. --------------060807030805020204060006 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Tom Lane wrote: >Steve Eckmann writes: > > >> <>Thanks for the suggestion, Tom. Yes, I think I could do that. But I >> thought what I was doing now was effectively the same, because the >> PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to >> include multiple SQL commands (separated by semicolons) in the command >> string. Multiple queries sent in a single PQexec call are processed in a >> single transaction...." Our simulation application has nearly 400 event >> types, each of which is a C++ class for which we have a corresponding >> database table. So every thousand events or so I issue one PQexec() call >> for each event type that has unlogged instances, sending INSERT commands >> for all instances. For example, > >> PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT >>INTO FlyingObjectState VALUES (...); ..."); >> >> > >Hmm. I'm not sure if that's a good idea or not. You're causing the >server to take 1000 times the normal amount of memory to hold the >command parsetrees, and if there are any O(N^2) behaviors in parsing >you could be getting hurt badly by that. (I'd like to think there are >not, but would definitely not swear to it.) OTOH you're reducing the >number of network round trips which is a good thing. Have you actually >measured to see what effect this approach has? It might be worth >building a test server with profiling enabled to see if the use of such >long command strings creates any hot spots in the profile. > > regards, tom lane > > No, I haven't measured it. I will compare this approach with others that have been suggested. Thanks. -steve --------------060807030805020204060006 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote:
Steve Eckmann <eckmann@computer.org> writes:
  
<>Thanks for the suggestion, Tom. Yes, I think I could do that. But I
thought what I was doing now was effectively the same, because the
PostgreSQL 8.0.0 Documentation says (section 27.3.1): "It is allowed to
include multiple SQL commands (separated by semicolons) in the command
string. Multiple queries sent in a single PQexec call are processed in a
single transaction...." Our simulation application has nearly 400 event
types, each of which is a C++ class for which we have a corresponding
database table. So every thousand events or so I issue one PQexec() call
for each event type that has unlogged instances, sending INSERT commands
for all instances. For example,
    PQexec(dbConn, "INSERT INTO FlyingObjectState VALUES (...); INSERT 
INTO FlyingObjectState VALUES (...); ...");
    

Hmm.  I'm not sure if that's a good idea or not.  You're causing the
server to take 1000 times the normal amount of memory to hold the
command parsetrees, and if there are any O(N^2) behaviors in parsing
you could be getting hurt badly by that.  (I'd like to think there are
not, but would definitely not swear to it.)  OTOH you're reducing the
number of network round trips which is a good thing.  Have you actually
measured to see what effect this approach has?  It might be worth
building a test server with profiling enabled to see if the use of such
long command strings creates any hot spots in the profile.

			regards, tom lane
  
No, I haven't measured it. I will compare this approach with others that have been suggested. Thanks.  -steve
--------------060807030805020204060006-- From pgsql-performance-owner@postgresql.org Wed Jan 4 20:19:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BBB199DC802 for ; Wed, 4 Jan 2006 20:19:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29120-10 for ; Wed, 4 Jan 2006 20:19:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mtiwmhc13.worldnet.att.net (mtiwmhc13.worldnet.att.net [204.127.131.117]) by postgresql.org (Postfix) with ESMTP id C563E9DC817 for ; Wed, 4 Jan 2006 20:19:11 -0400 (AST) Received: from [10.10.10.3] (98.denver-06rh15rt.co.dial-access.att.net[12.73.181.98]) by worldnet.att.net (mtiwmhc13) with ESMTP id <20060105001912113005dguce>; Thu, 5 Jan 2006 00:19:13 +0000 Message-ID: <43BC65FC.3000903@computer.org> Date: Wed, 04 Jan 2006 17:19:08 -0700 From: Steve Eckmann User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kelly Burkhart CC: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging application References: <43BB0C5C.8020207@computer.org> <20060104000603.GA29469@uio.no> <43BBD6E2.6080300@computer.org> In-Reply-To: Content-Type: multipart/alternative; boundary="------------040705060505070209090406" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.499 required=5 tests=[AWL=0.019, DNS_FROM_RFC_ABUSE=0.479, HTML_MESSAGE=0.001] X-Spam-Score: 0.499 X-Spam-Level: X-Archive-Number: 200601/19 X-Sequence-Number: 16497 This is a multi-part message in MIME format. --------------040705060505070209090406 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Kelly Burkhart wrote: > On 1/4/06, Steve Eckmann > wrote: > > Thanks, Steinar. I don't think we would really run with fsync off, > but I need to document the performance tradeoffs. You're right > that my explanation was confusing; probably because I'm confused > about how to use COPY! I could batch multiple INSERTS using COPY > statements, I just don't see how to do it without adding another > process to read from STDIN, since the application that is > currently the database client is constructing rows on the fly. I > would need to get those rows into some process's STDIN stream or > into a server-side file before COPY could be used, right? > > > Steve, > > You can use copy without resorting to another process. See the libpq > documentation for 'Functions Associated with the copy Command". We do > something like this: > > char *mbuf; > > // allocate space and fill mbuf with appropriately formatted data somehow > > PQexec( conn, "begin" ); > PQexec( conn, "copy mytable from stdin" ); > PQputCopyData( conn, mbuf, strlen(mbuf) ); > PQputCopyEnd( conn, NULL ); > PQexec( conn, "commit" ); > > -K Thanks for the concrete example, Kelly. I had read the relevant libpq doc but didn't put the pieces together. Regards, Steve --------------040705060505070209090406 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Kelly Burkhart wrote:
On 1/4/06, Steve Eckmann <eckmann@computer.org> wrote:
Thanks, Steinar. I don't think we would really run with fsync off, but I need to document the performance tradeoffs. You're right that my explanation was confusing; probably because I'm confused about how to use COPY! I could batch multiple INSERTS using COPY statements, I just don't see how to do it without adding another process to read from STDIN, since the application that is currently the database client is constructing rows on the fly. I would need to get those rows into some process's STDIN stream or into a server-side file before COPY could be used, right?

Steve,

You can use copy without resorting to another process.  See the libpq documentation for 'Functions Associated with the copy Command".  We do something like this:

char *mbuf;

// allocate space and fill mbuf with appropriately formatted data somehow

PQexec( conn, "begin" );
PQexec( conn, "copy mytable from stdin" );
PQputCopyData( conn, mbuf, strlen(mbuf) );
PQputCopyEnd( conn, NULL );
PQexec( conn, "commit" );

-K
Thanks for the concrete example, Kelly. I had read the relevant libpq doc but didn't put the pieces together.

Regards,  Steve
--------------040705060505070209090406-- From pgsql-patches-owner@postgresql.org Wed Jan 4 20:40:18 2006 X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B7B4B9DC817 for ; Wed, 4 Jan 2006 20:40:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 37136-02 for ; Wed, 4 Jan 2006 20:40:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id D04DC9DCA95 for ; Wed, 4 Jan 2006 20:40:11 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k050dgv22567; Wed, 4 Jan 2006 19:39:42 -0500 (EST) From: Bruce Momjian Message-Id: <200601050039.k050dgv22567@candle.pha.pa.us> Subject: Re: Stats collector performance improvement In-Reply-To: <200601021840.k02Ieed21704@candle.pha.pa.us> To: Bruce Momjian Date: Wed, 4 Jan 2006 19:39:42 -0500 (EST) CC: Tom Lane , Michael Fuhr , Merlin Moncure , Carlos Benkendorf , PostgreSQL-patches X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1136421582-25820-0_ Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.121] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/36 X-Sequence-Number: 18372 --ELM1136421582-25820-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Bruce Momjian wrote: > I did some research on this because the numbers Tom quotes indicate there > is something wrong in the way we process stats_command_string > statistics. > ... > This sends 10,000 "SELECT 1" queries to the backend, and reports the > execution time. I found that without stats_command_string defined, it > ran in 3.5 seconds. With stats_command_string defined, it took 5.5 > seconds, meaning the command string is causing a 57% slowdown. That is > way too much considering that the SELECT 1 has to be send from psql to > the backend, parsed, optimized, and executed, and the result returned to > the psql, while stats_command_string only has to send a string to a > backend collector. There is _no_ way that collector should take 57% of > the time it takes to run the actual query. I have updated information on this performance issue. It seems it is the blocking activity of recv() that is slowing down the buffer process and hence the backends. Basically, I found if I use select() or recv() to block until data arrives, I see the huge performance loss reported above. If I loop over the recv() call in non-blocking mode, I see almost no performance hit from stats_command_string (no backend slowdown), but of course that consumes all the CPU (bad). What I found worked perfectly was to do a non-blocking recv(), and if no data was returned, change the socket to blocking mode and loop back over the recv(). This allowed for no performance loss, and prevented infinite looping over the recv() call. My theory is that the kernel blocking logic of select() or recv() is somehow locking up the socket for a small amount of time, therefore slowing down the backend. With the on/off blocking, the packets arrive in groups, we get a few packets then block when nothing is available. The test program: TMPFILE=/tmp/pgstat.sql export TMPFILE if [ ! -f $TMPFILE ] then i=0 while [ $i -lt 10000 ] do i=`expr $i + 1` echo "SELECT 1;" done > $TMPFILE fi time psql test < $TMPFILE >/dev/null is basically sending 30k packets of roughly 26 bytes each, or roughly 800k in 3.5 seconds, meaning there is a packet every 0.0001 seconds. I wouldn't have thought that was too much volume for a dual Xeon BSD machine, but it seems it might be. Tom seeing 44% slowdown from pgbench means Linux might have an issue too. Two patches are attached. The first patch shows the use of the on/off blocking method to have almost zero overhead for reading from the socket. (The packets are discarded.) The second patch removes the buffer process entirely and uses the on/off buffering to process the incoming packets. I tried running two test scripts simultaneously and saw almost no packet loss. Also keep in mind we are writing the stat file twice a second, which might need to be pushed into a separate process. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 --ELM1136421582-25820-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/pgpatches/stat.test" Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v retrieving revision 1.118 diff -c -c -r1.118 pgstat.c *** src/backend/postmaster/pgstat.c 3 Jan 2006 19:54:08 -0000 1.118 --- src/backend/postmaster/pgstat.c 4 Jan 2006 23:22:44 -0000 *************** *** 1839,1845 **** int msg_recv = 0; /* next receive index */ int msg_have = 0; /* number of bytes stored */ bool overflow = false; ! /* * Identify myself via ps */ --- 1839,1847 ---- int msg_recv = 0; /* next receive index */ int msg_have = 0; /* number of bytes stored */ bool overflow = false; ! bool is_block_mode = false; ! int cnt = 0, bloops = 0, nbloops = 0; ! /* * Identify myself via ps */ *************** *** 1870,1875 **** --- 1872,1921 ---- */ msgbuffer = (char *) palloc(PGSTAT_RECVBUFFERSZ); + + while (1) + { + #if 0 + FD_ZERO(&rfds); + FD_ZERO(&wfds); + maxfd = -1; + FD_SET(pgStatSock, &rfds); + maxfd = pgStatSock; + + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + select(maxfd + 1, &rfds, &wfds, NULL, &timeout); + #endif + + if (is_block_mode) + bloops++; + else + nbloops++; + + len = recv(pgStatSock, (char *) &input_buffer, + sizeof(PgStat_Msg), 0); + if (len > 0) + cnt += len; + + //fprintf(stderr, "len = %d, errno = %d\n", len, errno); + + if (len > 0 && is_block_mode) + { + pg_set_noblock(pgStatSock); + is_block_mode = false; + } + else if (len < 0 && errno == EAGAIN && !is_block_mode) + { + pg_set_block(pgStatSock); + is_block_mode = true; + } + // if ((bloops + nbloops) % 1000 == 0) + // fprintf(stderr, "cnt = %d, len = %d, bloops = %d, nbloops = %d\n", cnt, len, bloops, nbloops); + } + + exit(1); + /* * Loop forever */ --ELM1136421582-25820-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/pgpatches/stat.nobuffer" Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v retrieving revision 1.118 diff -c -c -r1.118 pgstat.c *** src/backend/postmaster/pgstat.c 3 Jan 2006 19:54:08 -0000 1.118 --- src/backend/postmaster/pgstat.c 4 Jan 2006 23:06:26 -0000 *************** *** 109,117 **** * ---------- */ NON_EXEC_STATIC int pgStatSock = -1; - NON_EXEC_STATIC int pgStatPipe[2] = {-1, -1}; static struct sockaddr_storage pgStatAddr; - static pid_t pgStatCollectorPid = 0; static time_t last_pgstat_start_time; --- 109,115 ---- *************** *** 166,172 **** NON_EXEC_STATIC void PgstatBufferMain(int argc, char *argv[]); NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]); static void force_statwrite(SIGNAL_ARGS); - static void pgstat_recvbuffer(void); static void pgstat_exit(SIGNAL_ARGS); static void pgstat_die(SIGNAL_ARGS); static void pgstat_beshutdown_hook(int code, Datum arg); --- 164,169 ---- *************** *** 1491,1536 **** pgstat_parseArgs(argc, argv); #endif - /* - * Start a buffering process to read from the socket, so we have a little - * more time to process incoming messages. - * - * NOTE: the process structure is: postmaster is parent of buffer process - * is parent of collector process. This way, the buffer can detect - * collector failure via SIGCHLD, whereas otherwise it wouldn't notice - * collector failure until it tried to write on the pipe. That would mean - * that after the postmaster started a new collector, we'd have two buffer - * processes competing to read from the UDP socket --- not good. - */ - if (pgpipe(pgStatPipe) < 0) - ereport(ERROR, - (errcode_for_socket_access(), - errmsg("could not create pipe for statistics buffer: %m"))); - /* child becomes collector process */ ! #ifdef EXEC_BACKEND ! pgStatCollectorPid = pgstat_forkexec(STAT_PROC_COLLECTOR); ! #else ! pgStatCollectorPid = fork(); ! #endif ! switch (pgStatCollectorPid) ! { ! case -1: ! ereport(ERROR, ! (errmsg("could not fork statistics collector: %m"))); ! ! #ifndef EXEC_BACKEND ! case 0: ! /* child becomes collector process */ ! PgstatCollectorMain(0, NULL); ! break; ! #endif ! ! default: ! /* parent becomes buffer process */ ! closesocket(pgStatPipe[0]); ! pgstat_recvbuffer(); ! } exit(0); } --- 1488,1495 ---- pgstat_parseArgs(argc, argv); #endif /* child becomes collector process */ ! PgstatCollectorMain(0, NULL); exit(0); } *************** *** 1548,1559 **** PgstatCollectorMain(int argc, char *argv[]) { PgStat_Msg msg; - fd_set rfds; - int readPipe; - int len = 0; - struct itimerval timeval; HASHCTL hash_ctl; bool need_timer = false; MyProcPid = getpid(); /* reset MyProcPid */ --- 1507,1517 ---- PgstatCollectorMain(int argc, char *argv[]) { PgStat_Msg msg; HASHCTL hash_ctl; bool need_timer = false; + struct itimerval timeval; + bool is_block_mode = false; + int loops = 0; MyProcPid = getpid(); /* reset MyProcPid */ *************** *** 1587,1596 **** pgstat_parseArgs(argc, argv); #endif - /* Close unwanted files */ - closesocket(pgStatPipe[1]); - closesocket(pgStatSock); - /* * Identify myself via ps */ --- 1545,1550 ---- *************** *** 1626,1791 **** pgStatBeTable = (PgStat_StatBeEntry *) palloc0(sizeof(PgStat_StatBeEntry) * MaxBackends); - readPipe = pgStatPipe[0]; - /* * Process incoming messages and handle all the reporting stuff until * there are no more messages. */ for (;;) { if (need_statwrite) { ! pgstat_write_statsfile(); need_statwrite = false; need_timer = true; } ! /* ! * Setup the descriptor set for select(2) ! */ ! FD_ZERO(&rfds); ! FD_SET(readPipe, &rfds); ! ! /* ! * Now wait for something to do. ! */ ! if (select(readPipe + 1, &rfds, NULL, NULL, NULL) < 0) { ! if (errno == EINTR) ! continue; ! ereport(ERROR, ! (errcode_for_socket_access(), ! errmsg("select() failed in statistics collector: %m"))); } ! /* ! * Check if there is a new statistics message to collect. ! */ ! if (FD_ISSET(readPipe, &rfds)) ! { ! /* ! * We may need to issue multiple read calls in case the buffer ! * process didn't write the message in a single write, which is ! * possible since it dumps its buffer bytewise. In any case, we'd ! * need two reads since we don't know the message length ! * initially. ! */ ! int nread = 0; ! int targetlen = sizeof(PgStat_MsgHdr); /* initial */ ! bool pipeEOF = false; ! while (nread < targetlen) { ! len = piperead(readPipe, ((char *) &msg) + nread, ! targetlen - nread); ! if (len < 0) ! { ! if (errno == EINTR) ! continue; ! ereport(ERROR, ! (errcode_for_socket_access(), ! errmsg("could not read from statistics collector pipe: %m"))); ! } ! if (len == 0) /* EOF on the pipe! */ { ! pipeEOF = true; ! break; ! } ! nread += len; ! if (nread == sizeof(PgStat_MsgHdr)) ! { ! /* we have the header, compute actual msg length */ ! targetlen = msg.msg_hdr.m_size; ! if (targetlen < (int) sizeof(PgStat_MsgHdr) || ! targetlen > (int) sizeof(msg)) ! { ! /* ! * Bogus message length implies that we got out of ! * sync with the buffer process somehow. Abort so that ! * we can restart both processes. ! */ ! ereport(ERROR, ! (errmsg("invalid statistics message length"))); ! } } } ! ! /* ! * EOF on the pipe implies that the buffer process exited. Fall ! * out of outer loop. ! */ ! if (pipeEOF) ! break; ! ! /* ! * Distribute the message to the specific function handling it. ! */ ! switch (msg.msg_hdr.m_type) { ! case PGSTAT_MTYPE_DUMMY: ! break; ! case PGSTAT_MTYPE_BESTART: ! pgstat_recv_bestart((PgStat_MsgBestart *) &msg, nread); ! break; ! case PGSTAT_MTYPE_BETERM: ! pgstat_recv_beterm((PgStat_MsgBeterm *) &msg, nread); ! break; ! case PGSTAT_MTYPE_TABSTAT: ! pgstat_recv_tabstat((PgStat_MsgTabstat *) &msg, nread); ! break; ! case PGSTAT_MTYPE_TABPURGE: ! pgstat_recv_tabpurge((PgStat_MsgTabpurge *) &msg, nread); ! break; ! case PGSTAT_MTYPE_ACTIVITY: ! pgstat_recv_activity((PgStat_MsgActivity *) &msg, nread); ! break; ! case PGSTAT_MTYPE_DROPDB: ! pgstat_recv_dropdb((PgStat_MsgDropdb *) &msg, nread); ! break; ! case PGSTAT_MTYPE_RESETCOUNTER: ! pgstat_recv_resetcounter((PgStat_MsgResetcounter *) &msg, ! nread); ! break; ! case PGSTAT_MTYPE_AUTOVAC_START: ! pgstat_recv_autovac((PgStat_MsgAutovacStart *) &msg, nread); ! break; ! case PGSTAT_MTYPE_VACUUM: ! pgstat_recv_vacuum((PgStat_MsgVacuum *) &msg, nread); ! break; ! case PGSTAT_MTYPE_ANALYZE: ! pgstat_recv_analyze((PgStat_MsgAnalyze *) &msg, nread); ! break; ! default: ! break; ! } ! /* ! * Globally count messages. ! */ ! pgStatNumMessages++; ! if (need_timer) ! { ! if (setitimer(ITIMER_REAL, &timeval, NULL)) ! ereport(ERROR, ! (errmsg("unable to set statistics collector timer: %m"))); ! need_timer = false; ! } } /* * Note that we do NOT check for postmaster exit inside the loop; only * EOF on the buffer pipe causes us to fall out. This ensures we * don't exit prematurely if there are still a few messages in the --- 1580,1704 ---- pgStatBeTable = (PgStat_StatBeEntry *) palloc0(sizeof(PgStat_StatBeEntry) * MaxBackends); /* * Process incoming messages and handle all the reporting stuff until * there are no more messages. */ for (;;) { + int nread; + if (need_statwrite) { ! //pgstat_write_statsfile(); need_statwrite = false; need_timer = true; } ! if (need_timer) { ! if (setitimer(ITIMER_REAL, &timeval, NULL)) ! ereport(ERROR, ! (errmsg("unable to set statistics collector timer: %m"))); ! need_timer = false; } ! nread = recv(pgStatSock, (char *) &msg, ! sizeof(PgStat_Msg), 0); ! if (nread > 0 && is_block_mode) /* got data */ ! { ! pg_set_noblock(pgStatSock); ! is_block_mode = false; ! } ! else if (nread < 0) ! { ! if (errno == EAGAIN) { ! if (!is_block_mode) { ! /* no data, block mode */ ! pg_set_block(pgStatSock); ! is_block_mode = true; } + continue; } ! else if (errno == EINTR) { ! if (!PostmasterIsAlive(true)) ! ereport(ERROR, ! (errmsg("stats collector exited: %m"))); ! continue; ! } ! else ! ereport(ERROR, ! (errmsg("stats collector exited: %m"))); ! } ! //fprintf(stderr, "nread = %d, type = %d\n", nread, msg.msg_hdr.m_type); ! if (++loops % 1000 == 0) ! fprintf(stderr, "loops = %d\n", loops); ! /* ! * Distribute the message to the specific function handling it. ! */ ! switch (msg.msg_hdr.m_type) ! { ! case PGSTAT_MTYPE_DUMMY: ! break; ! case PGSTAT_MTYPE_BESTART: ! pgstat_recv_bestart((PgStat_MsgBestart *) &msg, nread); ! break; ! case PGSTAT_MTYPE_BETERM: ! pgstat_recv_beterm((PgStat_MsgBeterm *) &msg, nread); ! break; ! case PGSTAT_MTYPE_TABSTAT: ! pgstat_recv_tabstat((PgStat_MsgTabstat *) &msg, nread); ! break; ! case PGSTAT_MTYPE_TABPURGE: ! pgstat_recv_tabpurge((PgStat_MsgTabpurge *) &msg, nread); ! break; ! case PGSTAT_MTYPE_ACTIVITY: ! pgstat_recv_activity((PgStat_MsgActivity *) &msg, nread); ! break; ! case PGSTAT_MTYPE_DROPDB: ! pgstat_recv_dropdb((PgStat_MsgDropdb *) &msg, nread); ! break; ! case PGSTAT_MTYPE_RESETCOUNTER: ! pgstat_recv_resetcounter((PgStat_MsgResetcounter *) &msg, ! nread); ! break; ! case PGSTAT_MTYPE_AUTOVAC_START: ! pgstat_recv_autovac((PgStat_MsgAutovacStart *) &msg, nread); ! break; ! case PGSTAT_MTYPE_VACUUM: ! pgstat_recv_vacuum((PgStat_MsgVacuum *) &msg, nread); ! break; ! case PGSTAT_MTYPE_ANALYZE: ! pgstat_recv_analyze((PgStat_MsgAnalyze *) &msg, nread); ! break; ! default: ! break; } /* + * Globally count messages. + */ + pgStatNumMessages++; + + + /* * Note that we do NOT check for postmaster exit inside the loop; only * EOF on the buffer pipe causes us to fall out. This ensures we * don't exit prematurely if there are still a few messages in the *************** *** 1813,2032 **** } - /* ---------- - * pgstat_recvbuffer() - - * - * This is the body of the separate buffering process. Its only - * purpose is to receive messages from the UDP socket as fast as - * possible and forward them over a pipe into the collector itself. - * If the collector is slow to absorb messages, they are buffered here. - * ---------- - */ - static void - pgstat_recvbuffer(void) - { - fd_set rfds; - fd_set wfds; - struct timeval timeout; - int writePipe = pgStatPipe[1]; - int maxfd; - int len; - int xfr; - int frm; - PgStat_Msg input_buffer; - char *msgbuffer; - int msg_send = 0; /* next send index in buffer */ - int msg_recv = 0; /* next receive index */ - int msg_have = 0; /* number of bytes stored */ - bool overflow = false; - - /* - * Identify myself via ps - */ - init_ps_display("stats buffer process", "", ""); - set_ps_display(""); - - /* - * We want to die if our child collector process does. There are two ways - * we might notice that it has died: receive SIGCHLD, or get a write - * failure on the pipe leading to the child. We can set SIGPIPE to kill - * us here. Our SIGCHLD handler was already set up before we forked (must - * do it that way, else it's a race condition). - */ - pqsignal(SIGPIPE, SIG_DFL); - PG_SETMASK(&UnBlockSig); - - /* - * Set the write pipe to nonblock mode, so that we cannot block when the - * collector falls behind. - */ - if (!pg_set_noblock(writePipe)) - ereport(ERROR, - (errcode_for_socket_access(), - errmsg("could not set statistics collector pipe to nonblocking mode: %m"))); - - /* - * Allocate the message buffer - */ - msgbuffer = (char *) palloc(PGSTAT_RECVBUFFERSZ); - - /* - * Loop forever - */ - for (;;) - { - FD_ZERO(&rfds); - FD_ZERO(&wfds); - maxfd = -1; - - /* - * As long as we have buffer space we add the socket to the read - * descriptor set. - */ - if (msg_have <= (int) (PGSTAT_RECVBUFFERSZ - sizeof(PgStat_Msg))) - { - FD_SET(pgStatSock, &rfds); - maxfd = pgStatSock; - overflow = false; - } - else - { - if (!overflow) - { - ereport(LOG, - (errmsg("statistics buffer is full"))); - overflow = true; - } - } - - /* - * If we have messages to write out, we add the pipe to the write - * descriptor set. - */ - if (msg_have > 0) - { - FD_SET(writePipe, &wfds); - if (writePipe > maxfd) - maxfd = writePipe; - } - - /* - * Wait for some work to do; but not for more than 10 seconds. (This - * determines how quickly we will shut down after an ungraceful - * postmaster termination; so it needn't be very fast.) struct timeout - * is modified by some operating systems. - */ - timeout.tv_sec = 10; - timeout.tv_usec = 0; - - if (select(maxfd + 1, &rfds, &wfds, NULL, &timeout) < 0) - { - if (errno == EINTR) - continue; - ereport(ERROR, - (errcode_for_socket_access(), - errmsg("select() failed in statistics buffer: %m"))); - } - - /* - * If there is a message on the socket, read it and check for - * validity. - */ - if (FD_ISSET(pgStatSock, &rfds)) - { - len = recv(pgStatSock, (char *) &input_buffer, - sizeof(PgStat_Msg), 0); - if (len < 0) - ereport(ERROR, - (errcode_for_socket_access(), - errmsg("could not read statistics message: %m"))); - - /* - * We ignore messages that are smaller than our common header - */ - if (len < sizeof(PgStat_MsgHdr)) - continue; - - /* - * The received length must match the length in the header - */ - if (input_buffer.msg_hdr.m_size != len) - continue; - - /* - * O.K. - we accept this message. Copy it to the circular - * msgbuffer. - */ - frm = 0; - while (len > 0) - { - xfr = PGSTAT_RECVBUFFERSZ - msg_recv; - if (xfr > len) - xfr = len; - Assert(xfr > 0); - memcpy(msgbuffer + msg_recv, - ((char *) &input_buffer) + frm, - xfr); - msg_recv += xfr; - if (msg_recv == PGSTAT_RECVBUFFERSZ) - msg_recv = 0; - msg_have += xfr; - frm += xfr; - len -= xfr; - } - } - - /* - * If the collector is ready to receive, write some data into his - * pipe. We may or may not be able to write all that we have. - * - * NOTE: if what we have is less than PIPE_BUF bytes but more than the - * space available in the pipe buffer, most kernels will refuse to - * write any of it, and will return EAGAIN. This means we will - * busy-loop until the situation changes (either because the collector - * caught up, or because more data arrives so that we have more than - * PIPE_BUF bytes buffered). This is not good, but is there any way - * around it? We have no way to tell when the collector has caught - * up... - */ - if (FD_ISSET(writePipe, &wfds)) - { - xfr = PGSTAT_RECVBUFFERSZ - msg_send; - if (xfr > msg_have) - xfr = msg_have; - Assert(xfr > 0); - len = pipewrite(writePipe, msgbuffer + msg_send, xfr); - if (len < 0) - { - if (errno == EINTR || errno == EAGAIN) - continue; /* not enough space in pipe */ - ereport(ERROR, - (errcode_for_socket_access(), - errmsg("could not write to statistics collector pipe: %m"))); - } - /* NB: len < xfr is okay */ - msg_send += len; - if (msg_send == PGSTAT_RECVBUFFERSZ) - msg_send = 0; - msg_have -= len; - } - - /* - * Make sure we forwarded all messages before we check for postmaster - * termination. - */ - if (msg_have != 0 || FD_ISSET(pgStatSock, &rfds)) - continue; - - /* - * If the postmaster has terminated, we die too. (This is no longer - * the normal exit path, however.) - */ - if (!PostmasterIsAlive(true)) - exit(0); - } - } - /* SIGQUIT signal handler for buffer process */ static void pgstat_exit(SIGNAL_ARGS) --- 1726,1731 ---- *************** *** 2049,2054 **** --- 1748,1754 ---- exit(0); } + /* SIGCHLD signal handler for buffer process */ static void pgstat_die(SIGNAL_ARGS) --ELM1136421582-25820-0_-- From pgsql-performance-owner@postgresql.org Thu Jan 5 07:30:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8B4879DC9CA for ; Thu, 5 Jan 2006 07:30:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57525-02 for ; Thu, 5 Jan 2006 07:30:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id 57AD09DC950 for ; Thu, 5 Jan 2006 07:30:00 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mfe4e.m.pppool.de [89.49.254.78]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 610BE24400F; Thu, 5 Jan 2006 12:36:19 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 2E48E180001F8; Thu, 5 Jan 2006 12:29:59 +0100 (CET) Message-ID: <43BD0337.60000@logix-tt.com> Date: Thu, 05 Jan 2006 12:29:59 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Jeffrey W. Baker" Cc: pgperf Subject: Re: Invulnerable VACUUM process thrashing everything References: <1135894162.2223.4.camel@toonses.gghcwest.com> In-Reply-To: <1135894162.2223.4.camel@toonses.gghcwest.com> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/20 X-Sequence-Number: 16498 Hi, Jeffrey, Jeffrey W. Baker wrote: > A few WEEKS ago, the autovacuum on my instance of pg 7.4 unilaterally > decided to VACUUM a table which has not been updated in over a year and > is more than one terabyte on the disk. Hmm, maybe this is the Transaction ID wraparound emerging, and VACUUM is freezing the rows. Did you VACUUM FREEZE the table after the last modifications? > # kill -HUP 15308 > # kill -INT 15308 > # kill -PIPE 15308 Did you try kill -TERM? This always cleanly ended VACUUMing backends on our machines within seconds. > I assume that if I kill this with SIGKILL, that will bring down every > other postgres process, so that should be avoided. But surely there is > a way to interrupt this. If I had some reason to shut down the > instance, I'd be screwed, it seems. Yes, SIGKILL will make the postmaster shut down all running backend instances, the same as SIGSEGV and possibly a few others. The reason is that the postmaster assumes some internal data structure corruption in the shared memory pages is possible on an "unclean" backend abort, and thus quits immediately to minimize the possibility of those corruptions to propagate to the disks. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Thu Jan 5 11:16:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 750559DC861 for ; Thu, 5 Jan 2006 11:16:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02299-03 for ; Thu, 5 Jan 2006 11:16:57 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id B147D9DC812 for ; Thu, 5 Jan 2006 11:16:50 -0400 (AST) Received: from ar-sd.net (unknown [81.196.35.136]) by svr4.postgresql.org (Postfix) with ESMTP id AEFDA5AF07B for ; Thu, 5 Jan 2006 15:16:55 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id 60A6622F0D for ; Thu, 5 Jan 2006 17:16:51 +0200 (EET) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12744-05 for ; Thu, 5 Jan 2006 17:16:50 +0200 (EET) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id 2573825CE5 for ; Thu, 5 Jan 2006 17:16:50 +0200 (EET) Message-ID: <001d01c6120b$0d783600$0b00a8c0@forge> From: "Andy" To: Subject: Improving Inner Join Performance Date: Thu, 5 Jan 2006 17:16:47 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_001A_01C6121B.CF02C500" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/21 X-Sequence-Number: 16499 This is a multi-part message in MIME format. ------=_NextPart_000_001A_01C6121B.CF02C500 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi to all,=20 I have the following query: SELECT count(*) FROM orders o INNER JOIN report r ON r.id_order=3Do.id WHERE o.id_status>3 Explaing analyze: Aggregate (cost=3D8941.82..8941.82 rows=3D1 width=3D0) (actual = time=3D1003.297..1003.298 rows=3D1 loops=3D1) -> Hash Join (cost=3D3946.28..8881.72 rows=3D24041 width=3D0) = (actual time=3D211.985..951.545 rows=3D72121 loops=3D1) Hash Cond: ("outer".id_order =3D "inner".id) -> Seq Scan on report r (cost=3D0.00..2952.21 rows=3D72121 = width=3D4) (actual time=3D0.005..73.869 rows=3D72121 loops=3D1) -> Hash (cost=3D3787.57..3787.57 rows=3D24682 width=3D4) = (actual time=3D211.855..211.855 rows=3D0 loops=3D1) -> Seq Scan on orders o (cost=3D0.00..3787.57 = rows=3D24682 width=3D4) (actual time=3D0.047..147.170 rows=3D72121 = loops=3D1) Filter: (id_status > 3) Total runtime: 1003.671 ms I could use it in the following format, because I have to the moment = only the 4,6 values for the id_status. SELECT count(*) FROM orders o INNER JOIN report r ON r.id_order=3Do.id WHERE o.id_status IN (4,6) Explain analyze: Aggregate (cost=3D5430.04..5430.04 rows=3D1 width=3D0) (actual = time=3D1472.877..1472.877 rows=3D1 loops=3D1) -> Hash Join (cost=3D2108.22..5428.23 rows=3D720 width=3D0) (actual = time=3D342.080..1419.775 rows=3D72121 loops=3D1) Hash Cond: ("outer".id_order =3D "inner".id) -> Seq Scan on report r (cost=3D0.00..2952.21 rows=3D72121 = width=3D4) (actual time=3D0.036..106.217 rows=3D72121 loops=3D1) -> Hash (cost=3D2106.37..2106.37 rows=3D739 width=3D4) (actual = time=3D342.011..342.011 rows=3D0 loops=3D1) -> Index Scan using orders_id_status_idx, = orders_id_status_idx on orders o (cost=3D0.00..2106.37 rows=3D739 = width=3D4) (actual time=3D0.131..268.397 rows=3D72121 loops=3D1) Index Cond: ((id_status =3D 4) OR (id_status =3D 6)) Total runtime: 1474.356 ms How can I improve this query's performace?? The ideea is to count all = the values that I have in the database for the following conditions. If = the users puts in some other search fields on the where then the query = runs faster but in this format sometimes it takes a lot lot of = time(sometimes even 2,3 seconds).=20 Can this be tuned somehow??? Regards,=20 Andy. ------=_NextPart_000_001A_01C6121B.CF02C500 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi to all,
 
I have the following = query:
 
SELECT count(*) FROM orders=20 o
      INNER JOIN report r ON=20 r.id_order=3Do.id
      WHERE=20 o.id_status>3
 
Explaing analyze:
Aggregate  = (cost=3D8941.82..8941.82 rows=3D1=20 width=3D0) (actual time=3D1003.297..1003.298 rows=3D1 = loops=3D1)
  -> =20 Hash Join  (cost=3D3946.28..8881.72 rows=3D24041 width=3D0) (actual = time=3D211.985..951.545 rows=3D72121=20 loops=3D1)
        Hash Cond:=20 ("outer".id_order =3D = "inner".id)
       =20 ->  Seq Scan on report r  (cost=3D0.00..2952.21 = rows=3D72121 width=3D4)=20 (actual time=3D0.005..73.869 rows=3D72121=20 loops=3D1)
        ->  = Hash =20 (cost=3D3787.57..3787.57 rows=3D24682 width=3D4) (actual = time=3D211.855..211.855 rows=3D0=20 loops=3D1)
          = ;   =20 ->  Seq Scan on orders o  (cost=3D0.00..3787.57 = rows=3D24682 width=3D4)=20 (actual time=3D0.047..147.170 rows=3D72121=20 loops=3D1)
          = ;         =20 Filter: (id_status > 3)
Total runtime: 1003.671 ms
 
 
I could use it in the following format, = because I=20 have to the moment only the 4,6 values for the id_status.
 
SELECT count(*) FROM orders=20 o
      INNER JOIN report r ON=20 r.id_order=3Do.id
      WHERE = o.id_status IN=20 (4,6)
 
Explain analyze:
Aggregate =20 (cost=3D5430.04..5430.04 rows=3D1 width=3D0) (actual = time=3D1472.877..1472.877 rows=3D1=20 loops=3D1)
  ->  Hash Join  = (cost=3D2108.22..5428.23 rows=3D720=20 width=3D0) (actual time=3D342.080..1419.775 rows=3D72121=20 loops=3D1)
        Hash Cond:=20 ("outer".id_order =3D = "inner".id)
       =20 ->  Seq Scan on report r  (cost=3D0.00..2952.21 = rows=3D72121 width=3D4)=20 (actual time=3D0.036..106.217 rows=3D72121=20 loops=3D1)
        ->  = Hash =20 (cost=3D2106.37..2106.37 rows=3D739 width=3D4) (actual = time=3D342.011..342.011 rows=3D0=20 loops=3D1)
          = ;   =20 ->  Index Scan using orders_id_status_idx, orders_id_status_idx = on=20 orders o  (cost=3D0.00..2106.37 rows=3D739 width=3D4) (actual = time=3D0.131..268.397=20 rows=3D72121=20 loops=3D1)
          = ;         =20 Index Cond: ((id_status =3D 4) OR (id_status =3D 6))
Total runtime: = 1474.356=20 ms
How can I improve this query's = performace?? The=20 ideea is to count all the values that I have in the database for the = following=20 conditions. If the users puts in some other search fields on the where = then the=20 query runs faster but in this format sometimes it takes a lot lot of=20 time(sometimes even 2,3 seconds).
 
Can this be tuned = somehow???
 
Regards,
Andy.
 
 
------=_NextPart_000_001A_01C6121B.CF02C500-- From pgsql-performance-owner@postgresql.org Thu Jan 5 12:44:14 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3EBA29DC85F for ; Thu, 5 Jan 2006 12:44:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28643-09 for ; Thu, 5 Jan 2006 12:44:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id BB9449DC817 for ; Thu, 5 Jan 2006 12:44:08 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mea6f.m.pppool.de [89.49.234.111]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 8D3EC24400F; Thu, 5 Jan 2006 17:50:25 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id D904D184B9036; Thu, 5 Jan 2006 17:44:05 +0100 (CET) Message-ID: <43BD4CD5.8080207@logix-tt.com> Date: Thu, 05 Jan 2006 17:44:05 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: What's the best hardver for PostgreSQL 8.1? References: <43A84D03.7090002@ritek.hu> <200512212209.50234.caseroj@comcast.net> <200512212231.55100.caseroj@comcast.net> <20051224135042.484c6e32.frank@wiles.org> <6.2.5.6.0.20051224161551.01dc5d98@earthlink.net> In-Reply-To: X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/22 X-Sequence-Number: 16500 Hi, William, William Yu wrote: > Random write performance (small block that only writes to 1 drive): > 1 write requires N-1 reads + N writes --> 1/2N-1 % This is not true. Most Raid-5 engines use XOR or similar checksum methods. As opposed to cryptographic checksums, those can be updated and corrected incrementally. check_new = check_old xor data_old xor data_new So 2 reads and 2 writes are enough: read data and checksum, then adjust the checksum via the data difference, and write data and new checksum. And often, the old data block still is in cache, accounting to 1 read and two writes. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Thu Jan 5 15:19:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EC7859DC9C5 for ; Thu, 5 Jan 2006 15:19:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58536-05 for ; Thu, 5 Jan 2006 15:19:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from frank.wiles.org (frank.wiles.org [24.124.39.75]) by postgresql.org (Postfix) with ESMTP id 77D309DC857 for ; Thu, 5 Jan 2006 15:19:51 -0400 (AST) Received: from kungfu (frank.wiles.org [127.0.0.1]) by frank.wiles.org (8.13.1/8.13.1) with SMTP id k05JJiBZ005253; Thu, 5 Jan 2006 13:19:44 -0600 Date: Thu, 5 Jan 2006 13:20:06 -0600 From: Frank Wiles To: "Andy" Cc: pgsql-performance@postgresql.org Subject: Re: Improving Inner Join Performance Message-Id: <20060105132006.19c7cd31.frank@wiles.org> In-Reply-To: <001d01c6120b$0d783600$0b00a8c0@forge> References: <001d01c6120b$0d783600$0b00a8c0@forge> X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.04 required=5 tests=[AWL=0.040] X-Spam-Score: 0.04 X-Spam-Level: X-Archive-Number: 200601/23 X-Sequence-Number: 16501 On Thu, 5 Jan 2006 17:16:47 +0200 "Andy" wrote: > Hi to all, > > I have the following query: > > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=o.id > WHERE o.id_status>3 > How can I improve this query's performace?? The ideea is to count all > the values that I have in the database for the following conditions. > If the users puts in some other search fields on the where then the > query runs faster but in this format sometimes it takes a lot lot of > time(sometimes even 2,3 seconds). > > Can this be tuned somehow??? Do you have an index on report.id_order ? Try creating an index for it if not and run a vacuum analyze on the table to see if it gets rid of the sequence scan in the plan. --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From pgsql-performance-owner@postgresql.org Thu Jan 5 19:11:08 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CC03C9DC802 for ; Thu, 5 Jan 2006 19:11:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26959-09 for ; Thu, 5 Jan 2006 19:11:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 4E53B9DC812 for ; Thu, 5 Jan 2006 19:11:04 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id C8FA533A69; Fri, 6 Jan 2006 00:11:04 +0100 (MET) From: "Qingqing Zhou" X-Newsgroups: pgsql.performance Subject: Re: Help in avoiding a query 'Warm-Up' period/shared buffer cache Date: Thu, 5 Jan 2006 18:12:13 -0500 Organization: Hub.Org Networking Services Lines: 31 Message-ID: References: <200601041449.43557.mliberman@mixedsignals.com> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.154 required=5 tests=[AWL=0.154] X-Spam-Score: 0.154 X-Spam-Level: X-Archive-Number: 200601/24 X-Sequence-Number: 16502 "Mark Liberman" wrote > > First run, after a night of inactivity: > > -> Bitmap Index Scan on 1min_events_file_id_begin_idx > (cost=0.00..37.85 rows=3670 width=0) (actual time=313.468..313.468 > rows=11082 > loops=1) > Index Cond: (file_id = 137271) > Total runtime: 313.643 ms > > Second run, after that: > > -> Bitmap Index Scan on 1min_events_file_id_begin_idx > (cost=0.00..37.85 rows=3670 width=0) (actual time=2.106..2.106 rows=11082 > loops=1) > Index Cond: (file_id = 137271) > Total runtime: 2.276 ms It is clear that the first query takes longer time because of the IO time of index 1min_events_file_id_begin_idx (see 313.468 vs. 2.106). I am afraid currently there is no easy solution for this situation, unless you could predicate which part of relation/index your query will use, then you can preload or "warm-up" cache for it. Regards, Qingqing From pgsql-performance-owner@postgresql.org Thu Jan 5 20:53:26 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C54489DCAB1 for ; Thu, 5 Jan 2006 20:53:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49616-09 for ; Thu, 5 Jan 2006 20:53:28 -0400 (AST) X-Greylist: delayed 00:15:06.076248 by SQLgrey- Received: from fdlnint02.fds.com (fdlnint02.fds.com [208.15.91.51]) by postgresql.org (Postfix) with ESMTP id 273869DCA87 for ; Thu, 5 Jan 2006 20:53:22 -0400 (AST) Subject: Slow query. Any way to speed up? To: pgsql-performance@postgresql.org X-Mailer: Lotus Notes Release 6.5.4 March 27, 2005 Message-ID: From: Patrick Hatcher Date: Thu, 5 Jan 2006 16:38:17 -0800 X-MIMETrack: Serialize by Router on FDLNINT02/FSG/SVR/FDS(Release 6.5.2|June 01, 2004) at 01/05/2006 07:53:30 PM MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/25 X-Sequence-Number: 16503 Pg: 7.4.9 RH: ES v3 Quad-Xeon 16G ram The following SQL takes 4+ mins to run. I have indexes on all join fields and I've tried rearranging the table orders but haven't had any luck. I have done the usual vacuums analyze and even vacuum FULL just to make sure but still the same results. The ending resultset is around 169K rows which, if I'm reading the analyze output, is more than double. Any suggestions? TIA -patrick Select gmmid, gmmname, divid, divname, feddept, fedvend,itemnumber as mstyle,amc_week_id, sum(tran_itm_total) as net_dollars FROM public.tbldetaillevel_report a2 join cdm.cdm_ddw_tran_item a1 on a1.item_upc = a2.upc join public.date_dim a3 on a3.date_dim_id = a1.cal_date where a3.date_dim_id between '2005-10-30' and '2005-12-31' and a1.appl_id in ('MCOM','NET') and a1.tran_typ_id in ('S','R') group by 1,2,3,4,5,6,7,8 order by 1,2,3,4,5,6,7,8 GroupAggregate (cost=1646283.56..1648297.72 rows=73242 width=65) -> Sort (cost=1646283.56..1646466.67 rows=73242 width=65) Sort Key: a2.gmmid, a2.gmmname, a2.divid, a2.divname, a2.feddept, a2.fedvend, a2.itemnumber, a3.amc_week_id -> Merge Join (cost=1595839.67..1640365.47 rows=73242 width=65) Merge Cond: ("outer".upc = "inner".item_upc) -> Index Scan using report_upc_idx on tbldetaillevel_report a2 (cost=0.00..47236.85 rows=366234 width=58) -> Sort (cost=1595839.67..1596022.77 rows=73242 width=23) Sort Key: a1.item_upc -> Hash Join (cost=94.25..1589921.57 rows=73242 width=23) Hash Cond: ("outer".cal_date = "inner".date_dim_id) -> Seq Scan on cdm_ddw_tran_item a1 (cost=0.00..1545236.00 rows=8771781 width=23) Filter: ((((appl_id)::text = 'MCOM'::text) OR ((appl_id)::text = 'NET'::text)) AND ((tran_typ_id = 'S'::bpchar) OR (tran_typ_id = 'R'::bpchar))) -> Hash (cost=94.09..94.09 rows=64 width=8) -> Index Scan using date_date_idx on date_dim a3 (cost=0.00..94.09 rows=64 width=8) Index Cond: ((date_dim_id >= '2005-10-30'::date) AND (date_dim_id <= '2005-12-31'::date)) -- Table: tbldetaillevel_report -- DROP TABLE tbldetaillevel_report; CREATE TABLE tbldetaillevel_report ( pageid int4, feddept int4, fedvend int4, oz_description varchar(254), price_owned_retail float8, oz_color varchar(50), oz_size varchar(50), total_oh int4 DEFAULT 0, total_oo int4 DEFAULT 0, vendorname varchar(40), dunsnumber varchar(9), current_week int4, current_period int4, week_end date, varweek int4, varperiod int4, upc int8, itemnumber varchar(15), mkd_status int2, inforem_flag int2 ) WITH OIDS; -- DROP INDEX report_dept_vend_idx; CREATE INDEX report_dept_vend_idx ON tbldetaillevel_report USING btree (feddept, fedvend); -- Index: report_upc_idx -- DROP INDEX report_upc_idx; CREATE INDEX report_upc_idx ON tbldetaillevel_report USING btree (upc); -- Table: cdm.cdm_ddw_tran_item -- DROP TABLE cdm.cdm_ddw_tran_item; CREATE TABLE cdm.cdm_ddw_tran_item ( appl_xref varchar(22), intr_xref varchar(13), tran_typ_id char(1), cal_date date, cal_time time, tran_itm_total numeric(15,2), itm_qty int4, itm_price numeric(8,2), item_id int8, item_upc int8, item_pid varchar(20), item_desc varchar(30), nrf_color_name varchar(10), nrf_size_name varchar(10), dept_id int4, vend_id int4, mkstyl int4, item_group varchar(20), appl_id varchar(20), cost float8 DEFAULT 0, onhand int4 DEFAULT 0, onorder int4 DEFAULT 0, avail int4 DEFAULT 0, owned float8 DEFAULT 0, fill_store_loc int4, ddw_tran_key bigserial NOT NULL, price_type_id int2 DEFAULT 999, last_update date DEFAULT ('now'::text)::date, tran_id int8, tran_seq_nbr int4, CONSTRAINT ddw_tritm_pk PRIMARY KEY (ddw_tran_key) ) WITHOUT OIDS; -- Index: cdm.cdm_ddw_tran_item_applid_idx -- DROP INDEX cdm.cdm_ddw_tran_item_applid_idx; CREATE INDEX cdm_ddw_tran_item_applid_idx ON cdm.cdm_ddw_tran_item USING btree (appl_id); -- Index: cdm.cdm_ddw_tran_item_cal_date -- DROP INDEX cdm.cdm_ddw_tran_item_cal_date; CREATE INDEX cdm_ddw_tran_item_cal_date ON cdm.cdm_ddw_tran_item USING btree (cal_date); -- Index: cdm.cdm_ddw_tran_item_trn_type -- DROP INDEX cdm.cdm_ddw_tran_item_trn_type; CREATE INDEX cdm_ddw_tran_item_trn_type ON cdm.cdm_ddw_tran_item USING btree (tran_typ_id); -- Index: cdm.ddw_ti_upc_idx -- DROP INDEX cdm.ddw_ti_upc_idx; CREATE INDEX ddw_ti_upc_idx ON cdm.cdm_ddw_tran_item USING btree (item_upc); -- Index: cdm.ddw_tran_item_dept_idx -- DROP INDEX cdm.ddw_tran_item_dept_idx; CREATE INDEX ddw_tran_item_dept_idx ON cdm.cdm_ddw_tran_item USING btree (dept_id); -- Index: cdm.ddw_trn_ittotal_idx -- DROP INDEX cdm.ddw_trn_ittotal_idx; CREATE INDEX ddw_trn_ittotal_idx ON cdm.cdm_ddw_tran_item USING btree (tran_itm_total); -- Table: date_dim -- DROP TABLE date_dim; CREATE TABLE date_dim ( date_dim_id date NOT NULL, amc_date char(8), amc_day_nbr int2 NOT NULL, amc_week int2 NOT NULL, amc_period int2 NOT NULL, amc_quarter int2 NOT NULL, amc_season int2 NOT NULL, amc_year int4 NOT NULL, amc_period_id int4 NOT NULL, amc_week_id int4 NOT NULL, nbr_weeks_per_peri int2 NOT NULL, nbr_weeks_per_year int2 NOT NULL, calendar_day int2 NOT NULL, calendar_month int2 NOT NULL, julian_day int2 NOT NULL, CONSTRAINT date_dimph PRIMARY KEY (date_dim_id) ) WITH OIDS; -- Index: amc_weekid_idx -- DROP INDEX amc_weekid_idx; CREATE INDEX amc_weekid_idx ON date_dim USING btree (amc_week_id); -- Index: date_date_idx -- DROP INDEX date_date_idx; CREATE INDEX date_date_idx ON date_dim USING btree (date_dim_id); Patrick Hatcher Development Manager Analytics/MIO Macys.com From pgsql-performance-owner@postgresql.org Thu Jan 5 21:08:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C99369DCAD6 for ; Thu, 5 Jan 2006 21:08:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50518-09 for ; Thu, 5 Jan 2006 21:08:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from flake.decibel.org (unknown [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 5F5729DCA6F for ; Thu, 5 Jan 2006 21:08:18 -0400 (AST) Received: by flake.decibel.org (Postfix, from userid 1001) id 486963982E; Thu, 5 Jan 2006 19:08:22 -0600 (CST) Date: Thu, 5 Jan 2006 19:08:22 -0600 From: "Jim C. Nasby" To: Ian Westmacott Cc: Ron , pgsql-performance@postgresql.org Subject: Re: improving write performance for logging Message-ID: <20060106010822.GK43311@pervasive.com> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> <1136390438.24450.49.camel@spectre.intellivid.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1136390438.24450.49.camel@spectre.intellivid.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.075 required=5 tests=[AWL=0.075] X-Spam-Score: 0.075 X-Spam-Level: X-Archive-Number: 200601/26 X-Sequence-Number: 16504 On Wed, Jan 04, 2006 at 11:00:38AM -0500, Ian Westmacott wrote: > The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3). > The tables are on a 10-spindle (SCSI) RAID50 with dual U320 > controllers (XFS). This is overkill for writing and querying the data, > but we need to constantly ANALYZE and VACUUM in the > background without interrupting the inserts (the app is 24x7). The > databases are 4TB, so these operations can be lengthy. How come you're using RAID50 instead of just RAID0? Or was WAL being on RAID0 a typo? -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Thu Jan 5 22:17:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1437F9DCA6A for ; Thu, 5 Jan 2006 22:17:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65623-02 for ; Thu, 5 Jan 2006 22:17:35 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 04A389DC85C for ; Thu, 5 Jan 2006 22:17:29 -0400 (AST) Received: from mail.goldpocket.com (mail1.goldpocket.com [38.101.116.14]) by svr4.postgresql.org (Postfix) with ESMTP id 025215AF041 for ; Fri, 6 Jan 2006 02:17:33 +0000 (GMT) Received: from localhost (unknown [127.0.0.1]) by mail.goldpocket.com (Postfix) with ESMTP id 4DB9BE048BAD for ; Fri, 6 Jan 2006 02:17:31 +0000 (UTC) Received: from mail.goldpocket.com ([127.0.0.1]) by localhost (mail.goldpocket.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 29327-13 for ; Thu, 5 Jan 2006 18:17:21 -0800 (PST) Received: from mail1.goldpocket.com (srvgpimail1.gpi.local [10.10.0.13]) by mail.goldpocket.com (Postfix) with ESMTP id 57951E048F33 for ; Thu, 5 Jan 2006 18:17:21 -0800 (PST) Received: from mliberman.gpi.local ([10.10.0.158]) by mail1.goldpocket.com with Microsoft SMTPSVC(6.0.3790.211); Thu, 5 Jan 2006 18:17:21 -0800 From: Mark Liberman Organization: Mixed Signals, Inc. To: pgsql-performance@postgresql.org Subject: Re: Help in avoiding a query 'Warm-Up' period/shared buffer cache Date: Thu, 5 Jan 2006 18:15:36 -0800 User-Agent: KMail/1.8.1 References: <200601041449.43557.mliberman@mixedsignals.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601051815.36181.mliberman@mixedsignals.com> X-OriginalArrivalTime: 06 Jan 2006 02:17:21.0340 (UTC) FILETIME=[5332AFC0:01C61267] X-Virus-Scanned: amavisd-new at goldpocket.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/27 X-Sequence-Number: 16505 On Thursday 05 January 2006 15:12, Qingqing Zhou wrote: > "Mark Liberman" wrote > > > First run, after a night of inactivity: > > > > -> Bitmap Index Scan on > > 1min_events_file_id_begin_idx (cost=0.00..37.85 rows=3670 width=0) > > (actual time=313.468..313.468 rows=11082 > > loops=1) > > Index Cond: (file_id = 137271) > > Total runtime: 313.643 ms > > > > Second run, after that: > > > > -> Bitmap Index Scan on > > 1min_events_file_id_begin_idx (cost=0.00..37.85 rows=3670 width=0) > > (actual time=2.106..2.106 rows=11082 loops=1) > > Index Cond: (file_id = 137271) > > Total runtime: 2.276 ms > > It is clear that the first query takes longer time because of the IO time > of index 1min_events_file_id_begin_idx (see 313.468 vs. 2.106). I am afraid > currently there is no easy solution for this situation, unless you could > predicate which part of relation/index your query will use, then you can > preload or "warm-up" cache for it. > > Regards, > Qingqing Thanks Qingqing, this actually helped me determine that the compound index, 1min_events_file_id_begin_idx, is not the proper index to use as it is based on file_id and begin_time - the later of which is not involved in the where clause. It is only using that index to "filter" out the listed file_id. Now, my follow-up question / assumption. I am assuming that the IO time is so long on that index because it has to read the entire index (for that file_id) into memory (because it cannot just scan the rows with a certain date range because we are not using begin_time in the where clause). But, if I replaced that compound index with the proper compound index of file_id / end_time, it would give similar performance results to the scan on 1min_events_end_idx (which was < 1 ms). E.g. the latest rows that were updated are more likely to be in the cache - and it is smart enough to only read the index rows that it needs. Alternatively, I could create a single index on file_id (and rely upon the new bitmap scan capabilities in 1.2). But, I fear that, although this will be smaller than the erroneous compound index on file_id / begin_time, it will still display the same behavior in that it will need to read all rows from that index for the appropriate file_id - and since the data goes back every minute for 60 days, that IO might be large. Obviously, I will be testing this - but it might take a few days, as I haven't figure out how to simulate the "period of inactivity" to get the data flushed out of the cache ... so I have to run this each morning. But, any confirmation / corrections to my assumptions are greatly appreciated. E.g. is the compound index the way to go, or the solo index on file_id? Thanks, Mark From pgsql-performance-owner@postgresql.org Thu Jan 5 22:53:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7E11E9DC827 for ; Thu, 5 Jan 2006 22:53:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70411-09 for ; Thu, 5 Jan 2006 22:53:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.invendra.net (sbx-01.invendra.net [66.139.76.16]) by postgresql.org (Postfix) with ESMTP id 5FBC39DC802 for ; Thu, 5 Jan 2006 22:51:33 -0400 (AST) Received: from david.lang.hm (dsl081-044-215.lax1.dsl.speakeasy.net [64.81.44.215]) by mail.invendra.net (Postfix) with ESMTP id B2BC81AC3EC; Thu, 5 Jan 2006 18:51:47 -0800 (PST) Date: Thu, 5 Jan 2006 18:50:22 -0800 (PST) From: David Lang X-X-Sender: dlang@david.lang.hm To: Mark Liberman Cc: pgsql-performance@postgresql.org Subject: Re: Help in avoiding a query 'Warm-Up' period/shared buffer In-Reply-To: <200601051815.36181.mliberman@mixedsignals.com> Message-ID: References: <200601041449.43557.mliberman@mixedsignals.com> <200601051815.36181.mliberman@mixedsignals.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200601/28 X-Sequence-Number: 16506 On Thu, 5 Jan 2006, Mark Liberman wrote: > Obviously, I will be testing this - but it might take a few days, as I haven't > figure out how to simulate the "period of inactivity" to get the data flushed > out of the cache ... so I have to run this each morning. cat large_file >/dev/null will probably do a pretty good job of this (especially if large_file is noticably larger then the amount of ram you have) David Lang From pgsql-performance-owner@postgresql.org Thu Jan 5 23:06:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EA7209DCAE5 for ; Thu, 5 Jan 2006 23:06:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76935-08 for ; Thu, 5 Jan 2006 23:06:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id A23949DCAEF for ; Thu, 5 Jan 2006 23:06:51 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 3085033A69; Fri, 6 Jan 2006 04:06:56 +0100 (MET) From: "Qingqing Zhou" X-Newsgroups: pgsql.performance Subject: Re: Help in avoiding a query 'Warm-Up' period/shared buffer cache Date: Thu, 5 Jan 2006 22:08:05 -0500 Organization: Hub.Org Networking Services Lines: 22 Message-ID: References: <200601041449.43557.mliberman@mixedsignals.com> <200601051815.36181.mliberman@mixedsignals.com> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.153 required=5 tests=[AWL=0.153] X-Spam-Score: 0.153 X-Spam-Level: X-Archive-Number: 200601/29 X-Sequence-Number: 16507 "Mark Liberman" wrote > > Now, my follow-up question / assumption. I am assuming that the IO time > is > so long on that index because it has to read the entire index (for that > file_id) into memory > > any confirmation / corrections to my assumptions are greatly appreciated. > E.g. is > the compound index the way to go, or the solo index on file_id? > Only part of the index file is read. It is a btree index. Keep the index smaller but sufficient to guide your search is always good because even by the guidiance of the index, a heap visit to get the real data is not avoidable. Regards, Qingqing From pgsql-performance-owner@postgresql.org Thu Jan 5 23:14:19 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3B58F9DC85C for ; Thu, 5 Jan 2006 23:14:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77864-08 for ; Thu, 5 Jan 2006 23:14:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from flake.decibel.org (unknown [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id BC80A9DC81A for ; Thu, 5 Jan 2006 23:14:16 -0400 (AST) Received: by flake.decibel.org (Postfix, from userid 1001) id DE6C539834; Thu, 5 Jan 2006 21:14:21 -0600 (CST) Date: Thu, 5 Jan 2006 21:14:21 -0600 From: "Jim C. Nasby" To: David Lang Cc: Mark Liberman , pgsql-performance@postgresql.org Subject: Re: Help in avoiding a query 'Warm-Up' period/shared buffer Message-ID: <20060106031421.GM43311@pervasive.com> References: <200601041449.43557.mliberman@mixedsignals.com> <200601051815.36181.mliberman@mixedsignals.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/30 X-Sequence-Number: 16508 On Thu, Jan 05, 2006 at 06:50:22PM -0800, David Lang wrote: > On Thu, 5 Jan 2006, Mark Liberman wrote: > > >Obviously, I will be testing this - but it might take a few days, as I > >haven't > >figure out how to simulate the "period of inactivity" to get the data > >flushed > >out of the cache ... so I have to run this each morning. > > cat large_file >/dev/null > > will probably do a pretty good job of this (especially if large_file is > noticably larger then the amount of ram you have) The following C code is much faster... /* * $Id: clearmem.c,v 1.1 2003/06/29 20:41:33 decibel Exp $ * * Utility to clear out a chunk of memory and zero it. Useful for flushing disk buffers */ int main(int argc, char *argv[]) { if (!calloc(atoi(argv[1]), 1024*1024)) { printf("Error allocating memory.\n"); } } Compile it and then pass in the number of MB of memory to allocate on the command line. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 6 01:08:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B746F9DC802 for ; Fri, 6 Jan 2006 01:08:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98037-07 for ; Fri, 6 Jan 2006 01:08:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 252029DCB61 for ; Fri, 6 Jan 2006 01:07:58 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0657vcx018084; Fri, 6 Jan 2006 00:07:57 -0500 (EST) To: Patrick Hatcher cc: pgsql-performance@postgresql.org Subject: Re: Slow query. Any way to speed up? In-reply-to: References: Comments: In-reply-to Patrick Hatcher message dated "Thu, 05 Jan 2006 16:38:17 -0800" Date: Fri, 06 Jan 2006 00:07:57 -0500 Message-ID: <18083.1136524077@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.07 required=5 tests=[AWL=0.070] X-Spam-Score: 0.07 X-Spam-Level: X-Archive-Number: 200601/31 X-Sequence-Number: 16509 Patrick Hatcher writes: > The following SQL takes 4+ mins to run. I have indexes on all join fields > and I've tried rearranging the table orders but haven't had any luck. Please show EXPLAIN ANALYZE output, not just EXPLAIN. It's impossible to tell whether the planner is making any wrong guesses when you can't see the actual times/rowcounts ... (BTW, 7.4 is looking pretty long in the tooth.) regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 6 05:21:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DA5279DC85E for ; Fri, 6 Jan 2006 05:21:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65134-10 for ; Fri, 6 Jan 2006 05:21:33 -0400 (AST) X-Greylist: delayed 18:04:38.378849 by SQLgrey- Received: from ar-sd.net (unknown [81.196.35.136]) by postgresql.org (Postfix) with ESMTP id 24B819DC803 for ; Fri, 6 Jan 2006 05:21:29 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id 29A8B284B5 for ; Fri, 6 Jan 2006 11:21:31 +0200 (EET) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17835-04 for ; Fri, 6 Jan 2006 11:21:29 +0200 (EET) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id C0D2827488 for ; Fri, 6 Jan 2006 11:21:29 +0200 (EET) Message-ID: <007f01c612a2$94b1a5b0$0b00a8c0@forge> From: "Andy" To: References: <001d01c6120b$0d783600$0b00a8c0@forge> <20060105132006.19c7cd31.frank@wiles.org> Subject: Re: Improving Inner Join Performance Date: Fri, 6 Jan 2006 11:21:31 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/32 X-Sequence-Number: 16510 Yes I have indexes an all join fields. The tables have around 30 columns each and around 100k rows. The database is vacuumed every hour. Andy. ----- Original Message ----- From: "Frank Wiles" To: "Andy" Cc: Sent: Thursday, January 05, 2006 9:20 PM Subject: Re: [PERFORM] Improving Inner Join Performance > On Thu, 5 Jan 2006 17:16:47 +0200 > "Andy" wrote: > >> Hi to all, >> >> I have the following query: >> >> SELECT count(*) FROM orders o >> INNER JOIN report r ON r.id_order=o.id >> WHERE o.id_status>3 > >> How can I improve this query's performace?? The ideea is to count all >> the values that I have in the database for the following conditions. >> If the users puts in some other search fields on the where then the >> query runs faster but in this format sometimes it takes a lot lot of >> time(sometimes even 2,3 seconds). >> >> Can this be tuned somehow??? > > Do you have an index on report.id_order ? Try creating an index for > it if not and run a vacuum analyze on the table to see if it gets > rid of the sequence scan in the plan. > > --------------------------------- > Frank Wiles > http://www.wiles.org > --------------------------------- > > > From pgsql-performance-owner@postgresql.org Fri Jan 6 05:45:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B827A9DCA6D for ; Fri, 6 Jan 2006 05:45:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72043-02 for ; Fri, 6 Jan 2006 05:45:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [151.155.5.143]) by postgresql.org (Postfix) with ESMTP id 854109DC8A7 for ; Fri, 6 Jan 2006 05:45:18 -0400 (AST) Received: from [172.16.1.181] grzm [61.197.227.146] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 1.6 $ on Linux; Fri, 06 Jan 2006 02:45:13 -0700 In-Reply-To: <007f01c612a2$94b1a5b0$0b00a8c0@forge> References: <001d01c6120b$0d783600$0b00a8c0@forge> <20060105132006.19c7cd31.frank@wiles.org> <007f01c612a2$94b1a5b0$0b00a8c0@forge> Mime-Version: 1.0 (Apple Message framework v746.2) X-Priority: 3 Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <10D92D77-0DC5-4772-98CD-A6799E3A39C8@myrealbox.com> Cc: Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: Improving Inner Join Performance Date: Fri, 6 Jan 2006 18:45:06 +0900 To: "Andy" X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.01 required=5 tests=[AWL=-0.322, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.01 X-Spam-Level: * X-Archive-Number: 200601/33 X-Sequence-Number: 16511 On Jan 6, 2006, at 18:21 , Andy wrote: > Yes I have indexes an all join fields. The tables have around 30 > columns each and around 100k rows. The database is vacuumed every > hour. Just to chime in, VACUUM != VACUUM ANALYZE. ANALYZE is what updates database statistics and affects query planning. VACUUM alone does not do this. >> Do you have an index on report.id_order ? Try creating an index for >> it if not and run a vacuum analyze on the table to see if it gets >> rid of the sequence scan in the plan. Michael Glaesemann grzm myrealbox com From pgsql-performance-owner@postgresql.org Fri Jan 6 05:55:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 19CB49DC816 for ; Fri, 6 Jan 2006 05:55:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69536-09 for ; Fri, 6 Jan 2006 05:55:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ar-sd.net (unknown [81.196.35.136]) by postgresql.org (Postfix) with ESMTP id B79939DC803 for ; Fri, 6 Jan 2006 05:55:42 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id AF341363ED; Fri, 6 Jan 2006 11:55:44 +0200 (EET) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17873-08; Fri, 6 Jan 2006 11:55:41 +0200 (EET) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id C029F27EBF; Fri, 6 Jan 2006 11:55:41 +0200 (EET) Message-ID: <00b201c612a7$5bca49a0$0b00a8c0@forge> From: "Andy" To: "Michael Glaesemann" Cc: References: <001d01c6120b$0d783600$0b00a8c0@forge> <20060105132006.19c7cd31.frank@wiles.org> <007f01c612a2$94b1a5b0$0b00a8c0@forge> <10D92D77-0DC5-4772-98CD-A6799E3A39C8@myrealbox.com> Subject: Re: Improving Inner Join Performance Date: Fri, 6 Jan 2006 11:54:46 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/34 X-Sequence-Number: 16512 Sorry, I had to be more specific. VACUUM ANALYZE is performed every hour. Regards, Andy. ----- Original Message ----- From: "Michael Glaesemann" To: "Andy" Cc: Sent: Friday, January 06, 2006 11:45 AM Subject: Re: [PERFORM] Improving Inner Join Performance > > On Jan 6, 2006, at 18:21 , Andy wrote: > >> Yes I have indexes an all join fields. The tables have around 30 >> columns each and around 100k rows. The database is vacuumed every >> hour. > > Just to chime in, VACUUM != VACUUM ANALYZE. ANALYZE is what updates > database statistics and affects query planning. VACUUM alone does not > do this. > >>> Do you have an index on report.id_order ? Try creating an index for >>> it if not and run a vacuum analyze on the table to see if it gets >>> rid of the sequence scan in the plan. > > Michael Glaesemann > grzm myrealbox com > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > > From pgsql-performance-owner@postgresql.org Fri Jan 6 05:56:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B8F789DC845 for ; Fri, 6 Jan 2006 05:56:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71312-07 for ; Fri, 6 Jan 2006 05:56:33 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.200]) by postgresql.org (Postfix) with ESMTP id 35D6F9DCAEF for ; Fri, 6 Jan 2006 05:56:28 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 14so3489703nzn for ; Fri, 06 Jan 2006 01:56:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=qaVVnvUn6e34GuBvIa2jydHHWsbxm7V+ustea2kOPKeD9lFFtnItGgvZcPKQMAJHI55SdMyUy1o8LW0Tqni7V2LdK5xxq9ohYd5h/LEks13+chcR36UYarbzcy64lCRdIUBrQf3etHes+RsnDbkcg+OOkK3fsdLqlSZydm79nAc= Received: by 10.64.150.20 with SMTP id x20mr1731625qbd; Fri, 06 Jan 2006 01:56:31 -0800 (PST) Received: by 10.64.210.15 with HTTP; Fri, 6 Jan 2006 01:56:31 -0800 (PST) Message-ID: <5e744e3d0601060156y3f68ad0dn152c946254ee9fd3@mail.gmail.com> Date: Fri, 6 Jan 2006 15:26:31 +0530 From: Pandurangan R S To: Andy Subject: Re: Improving Inner Join Performance Cc: pgsql-performance@postgresql.org In-Reply-To: <001d01c6120b$0d783600$0b00a8c0@forge> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <001d01c6120b$0d783600$0b00a8c0@forge> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.124 required=5 tests=[AWL=0.124] X-Spam-Score: 0.124 X-Spam-Level: X-Archive-Number: 200601/35 X-Sequence-Number: 16513 > If the users puts in some other search fields on the where then the query= runs faster but > in this format sometimes it takes a lot lot of time(some= times even 2,3 seconds). Can you eloborate under what conditions which query is slower? On 1/5/06, Andy wrote: > > Hi to all, > > I have the following query: > > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=3Do.id > WHERE o.id_status>3 > > Explaing analyze: > Aggregate (cost=3D8941.82..8941.82 rows=3D1 width=3D0) (actual > time=3D1003.297..1003.298 rows=3D1 loops=3D1) > -> Hash Join (cost=3D3946.28..8881.72 rows=3D24041 width=3D0) (actual > time=3D211.985..951.545 rows=3D72121 loops=3D1) > Hash Cond: ("outer".id_order =3D "inner".id) > -> Seq Scan on report r (cost=3D0.00..2952.21 rows=3D72121 widt= h=3D4) > (actual time=3D0.005..73.869 rows=3D72121 loops=3D1) > -> Hash (cost=3D3787.57..3787.57 rows=3D24682 width=3D4) (actua= l > time=3D211.855..211.855 rows=3D0 loops=3D1) > -> Seq Scan on orders o (cost=3D0.00..3787.57 rows=3D2468= 2 > width=3D4) (actual time=3D0.047..147.170 rows=3D72121 loops=3D1) > Filter: (id_status > 3) > Total runtime: 1003.671 ms > > > I could use it in the following format, because I have to the moment only > the 4,6 values for the id_status. > > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=3Do.id > WHERE o.id_status IN (4,6) > > Explain analyze: > Aggregate (cost=3D5430.04..5430.04 rows=3D1 width=3D0) (actual > time=3D1472.877..1472.877 rows=3D1 loops=3D1) > -> Hash Join (cost=3D2108.22..5428.23 rows=3D720 width=3D0) (actual > time=3D342.080..1419.775 rows=3D72121 loops=3D1) > Hash Cond: ("outer".id_order =3D "inner".id) > -> Seq Scan on report r (cost=3D0.00..2952.21 rows=3D72121 widt= h=3D4) > (actual time=3D0.036..106.217 rows=3D72121 loops=3D1) > -> Hash (cost=3D2106.37..2106.37 rows=3D739 width=3D4) (actual > time=3D342.011..342.011 rows=3D0 loops=3D1) > -> Index Scan using orders_id_status_idx, > orders_id_status_idx on orders o (cost=3D0.00..2106.37 rows=3D739 width= =3D4) > (actual time=3D0.131..268.397 rows=3D72121 loops=3D1) > Index Cond: ((id_status =3D 4) OR (id_status =3D 6)) > Total runtime: 1474.356 ms > > How can I improve this query's performace?? The ideea is to count all the > values that I have in the database for the following conditions. If the > users puts in some other search fields on the where then the query runs > faster but in this format sometimes it takes a lot lot of time(sometimes > even 2,3 seconds). > > Can this be tuned somehow??? > > Regards, > Andy. > > From pgsql-performance-owner@postgresql.org Fri Jan 6 06:21:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5B8509DCA6D for ; Fri, 6 Jan 2006 06:21:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78148-01 for ; Fri, 6 Jan 2006 06:21:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ar-sd.net (unknown [81.196.35.136]) by postgresql.org (Postfix) with ESMTP id 891EB9DC8DF for ; Fri, 6 Jan 2006 06:21:25 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id 86E4B357FB; Fri, 6 Jan 2006 12:21:27 +0200 (EET) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17873-10; Fri, 6 Jan 2006 12:21:25 +0200 (EET) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id 0372025A4F; Fri, 6 Jan 2006 12:21:24 +0200 (EET) Message-ID: <00c001c612aa$f39ed1d0$0b00a8c0@forge> From: "Andy" To: "Pandurangan R S" Cc: References: <001d01c6120b$0d783600$0b00a8c0@forge> <5e744e3d0601060156y3f68ad0dn152c946254ee9fd3@mail.gmail.com> Subject: Re: Improving Inner Join Performance Date: Fri, 6 Jan 2006 12:21:25 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/36 X-Sequence-Number: 16514 At the moment: o.id_status>3 can have values only 4 and 6. The 6 is around 90% from the whole table. This is why seq scan is made. Now, depending on the user input the query can have more where fields. For example: SELECT count(*) FROM orders o INNER JOIN report r ON r.id_order=o.id WHERE o.id_status > 3 AND r.id_zufriden=7 Aggregate (cost=7317.15..7317.15 rows=1 width=0) (actual time=213.418..213.419 rows=1 loops=1) -> Hash Join (cost=3139.00..7310.80 rows=2540 width=0) (actual time=57.554..212.215 rows=1308 loops=1) Hash Cond: ("outer".id = "inner".id_order) -> Seq Scan on orders o (cost=0.00..3785.31 rows=72216 width=4) (actual time=0.014..103.292 rows=72121 loops=1) Filter: (id_status > 3) -> Hash (cost=3132.51..3132.51 rows=2597 width=4) (actual time=57.392..57.392 rows=0 loops=1) -> Seq Scan on report r (cost=0.00..3132.51 rows=2597 width=4) (actual time=0.019..56.220 rows=1308 loops=1) Filter: (id_zufriden = 7) Total runtime: 213.514 ms These examples can go on and on. If I run this query SELECT count(*) FROM orders o INNER JOIN report r ON r.id_order=o.id WHERE o.id_status>3 under normal system load the average response time is between 1.3 > 2.5 seconds. Sometimes even more. If I run it rapidly a few times then it respondes faster(that is normal I supose). The ideea of this query is to count all the possible results that the user can have. I use this to build pages of results. Andy. ----- Original Message ----- From: "Pandurangan R S" To: "Andy" Cc: Sent: Friday, January 06, 2006 11:56 AM Subject: Re: [PERFORM] Improving Inner Join Performance > If the users puts in some other search fields on the where then the query > runs faster but > in this format sometimes it takes a lot lot of > time(sometimes even 2,3 seconds). Can you eloborate under what conditions which query is slower? On 1/5/06, Andy wrote: > > Hi to all, > > I have the following query: > > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=o.id > WHERE o.id_status>3 > > Explaing analyze: > Aggregate (cost=8941.82..8941.82 rows=1 width=0) (actual > time=1003.297..1003.298 rows=1 loops=1) > -> Hash Join (cost=3946.28..8881.72 rows=24041 width=0) (actual > time=211.985..951.545 rows=72121 loops=1) > Hash Cond: ("outer".id_order = "inner".id) > -> Seq Scan on report r (cost=0.00..2952.21 rows=72121 width=4) > (actual time=0.005..73.869 rows=72121 loops=1) > -> Hash (cost=3787.57..3787.57 rows=24682 width=4) (actual > time=211.855..211.855 rows=0 loops=1) > -> Seq Scan on orders o (cost=0.00..3787.57 rows=24682 > width=4) (actual time=0.047..147.170 rows=72121 loops=1) > Filter: (id_status > 3) > Total runtime: 1003.671 ms > > > I could use it in the following format, because I have to the moment only > the 4,6 values for the id_status. > > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=o.id > WHERE o.id_status IN (4,6) > > Explain analyze: > Aggregate (cost=5430.04..5430.04 rows=1 width=0) (actual > time=1472.877..1472.877 rows=1 loops=1) > -> Hash Join (cost=2108.22..5428.23 rows=720 width=0) (actual > time=342.080..1419.775 rows=72121 loops=1) > Hash Cond: ("outer".id_order = "inner".id) > -> Seq Scan on report r (cost=0.00..2952.21 rows=72121 width=4) > (actual time=0.036..106.217 rows=72121 loops=1) > -> Hash (cost=2106.37..2106.37 rows=739 width=4) (actual > time=342.011..342.011 rows=0 loops=1) > -> Index Scan using orders_id_status_idx, > orders_id_status_idx on orders o (cost=0.00..2106.37 rows=739 width=4) > (actual time=0.131..268.397 rows=72121 loops=1) > Index Cond: ((id_status = 4) OR (id_status = 6)) > Total runtime: 1474.356 ms > > How can I improve this query's performace?? The ideea is to count all the > values that I have in the database for the following conditions. If the > users puts in some other search fields on the where then the query runs > faster but in this format sometimes it takes a lot lot of time(sometimes > even 2,3 seconds). > > Can this be tuned somehow??? > > Regards, > Andy. > > From pgsql-performance-owner@postgresql.org Fri Jan 6 10:00:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 404F99DC997 for ; Fri, 6 Jan 2006 10:00:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20339-01 for ; Fri, 6 Jan 2006 10:00:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mailhost.intellivid.com (mailhost.intellivid.com [64.32.200.11]) by postgresql.org (Postfix) with ESMTP id F14699DC949 for ; Fri, 6 Jan 2006 10:00:03 -0400 (AST) Received: from spectre.intellivid.com (spectre.intellivid.com [192.168.2.68]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client did not present a certificate) by newmail.intellivid.com (Postfix) with ESMTP id 01C78F18111; Fri, 6 Jan 2006 09:00:07 -0500 (EST) Subject: Re: improving write performance for logging From: Ian Westmacott To: "Jim C. Nasby" Cc: pgsql-performance@postgresql.org In-Reply-To: <20060106010822.GK43311@pervasive.com> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> <1136390438.24450.49.camel@spectre.intellivid.com> <20060106010822.GK43311@pervasive.com> Content-Type: text/plain Organization: Intellivid Corp. Date: Fri, 06 Jan 2006 09:00:06 -0500 Message-Id: <1136556006.31602.5.camel@spectre.intellivid.com> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/37 X-Sequence-Number: 16515 On Thu, 2006-01-05 at 19:08 -0600, Jim C. Nasby wrote: > On Wed, Jan 04, 2006 at 11:00:38AM -0500, Ian Westmacott wrote: > > The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3). > > The tables are on a 10-spindle (SCSI) RAID50 with dual U320 > > controllers (XFS). This is overkill for writing and querying the data, > > but we need to constantly ANALYZE and VACUUM in the > > background without interrupting the inserts (the app is 24x7). The > > databases are 4TB, so these operations can be lengthy. > > How come you're using RAID50 instead of just RAID0? Or was WAL being on > RAID0 a typo? We use RAID50 instead of RAID0 for the tables for some fault-tolerance. We use RAID0 for the WAL for performance. I'm missing the implication of the question... -- Ian Westmacott Intellivid Corp. From pgsql-performance-owner@postgresql.org Fri Jan 6 10:04:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7FAEB9DC997 for ; Fri, 6 Jan 2006 10:04:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19015-03 for ; Fri, 6 Jan 2006 10:04:03 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 091E59DC88C for ; Fri, 6 Jan 2006 10:03:58 -0400 (AST) Received: from dd01.profihoster.net (dd01.profihoster.net [85.190.12.140]) by svr4.postgresql.org (Postfix) with ESMTP id C00795AF04B for ; Fri, 6 Jan 2006 14:03:59 +0000 (GMT) Received: from [192.168.54.10] (e180180114.adsl.alicedsl.de [85.180.180.114]) by dd01.profihoster.net (Postfix) with ESMTP id 8E9DF2381FF for ; Fri, 6 Jan 2006 15:00:33 +0100 (CET) Message-ID: <43BE78BE.3070508@laliluna.de> Date: Fri, 06 Jan 2006 15:03:42 +0100 From: Sebastian Hennebrueder User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: effizient query with jdbc References: <20051215080714.03919654@malmo.geotask.ch> In-Reply-To: <20051215080714.03919654@malmo.geotask.ch> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/38 X-Sequence-Number: 16516 You could issue one query containing a select uuid FROM MDM.KEYWORDS_INFO WHERE KEYWORDS_ID in (xy) where xy is a large comma separated list of your values. Best Regards / Viele Gr��e Sebastian Hennebrueder ----- http://www.laliluna.de * Tutorials for JSP, JavaServer Faces, Struts, Hibernate and EJB * Seminars and Education at reasonable prices * Get professional support and consulting for these technologies Johannes B�hler schrieb: > Hi, > I have a java.util.List of values (10000) which i wanted to use for a > query in the where clause of an simple select statement. iterating > over the list and and use an prepared Statement is quite slow. Is > there a more efficient way to execute such a query. Thanks for any > help. Johannes > ..... > List ids = new ArrayList(); > > .... List is filled with 10000 values ... > > List uuids = new ArrayList(); > PreparedStatement pstat = db.prepareStatement("SELECT UUID FROM > MDM.KEYWORDS_INFO WHERE KEYWORDS_ID = ?"); for (Iterator iter = > ids.iterator(); iter.hasNext();) { String id = (String) iter.next(); > pstat.setString(1, id); > rs = pstat.executeQuery(); > if (rs.next()) { > uuids.add(rs.getString(1)); > } > rs.close(); > } > ... > > > >---------------------------(end of broadcast)--------------------------- >TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > > > > From pgsql-performance-owner@postgresql.org Fri Jan 6 11:26:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A251A9DC816 for ; Fri, 6 Jan 2006 11:26:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33346-06 for ; Fri, 6 Jan 2006 11:26:46 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.192]) by postgresql.org (Postfix) with ESMTP id 36B549DC863 for ; Fri, 6 Jan 2006 11:26:38 -0400 (AST) Received: by wproxy.gmail.com with SMTP id 57so2849132wri for ; Fri, 06 Jan 2006 07:26:44 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Gjdv1v+vE+9xqgOsanWJzgu7frvcqxwAMkiV4ZpGPcQEKu8JEtbgMPPqZBex2z4TY90VGf3VgUFm03yy3KsOtLigPXBhGHfgG9OW+7ugwm5y75MIHjce4xEAfLOgWC8GglnRv/vlzosjwwHieT8fv7Si5AZLyxY01fXc5aaIEn4= Received: by 10.54.114.7 with SMTP id m7mr5319889wrc; Fri, 06 Jan 2006 07:26:43 -0800 (PST) Received: by 10.54.92.14 with HTTP; Fri, 6 Jan 2006 07:26:43 -0800 (PST) Message-ID: Date: Fri, 6 Jan 2006 10:26:43 -0500 From: Jaime Casanova To: Andy Subject: Re: Improving Inner Join Performance Cc: Pandurangan R S , pgsql-performance@postgresql.org In-Reply-To: <00c001c612aa$f39ed1d0$0b00a8c0@forge> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <001d01c6120b$0d783600$0b00a8c0@forge> <5e744e3d0601060156y3f68ad0dn152c946254ee9fd3@mail.gmail.com> <00c001c612aa$f39ed1d0$0b00a8c0@forge> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.082 required=5 tests=[AWL=0.082] X-Spam-Score: 0.082 X-Spam-Level: X-Archive-Number: 200601/39 X-Sequence-Number: 16517 On 1/6/06, Andy wrote: > At the moment: o.id_status>3 can have values only 4 and 6. The 6 is aroun= d > 90% from the whole table. This is why seq scan is made. > given this if you make id_status > 3 you will never use an index because you will be scanning 4 and 6 the only values in this field as you say, and even if there were any other value 6 is 90% of whole table, so an index for this will not be used... > Now, depending on the user input the query can have more where fields. Fo= r > example: > SELECT count(*) FROM orders o > INNER JOIN report r ON r.id_order=3Do.id > WHERE o.id_status > 3 AND r.id_zufriden=3D7 > here the planner can be more selective, and of course the query is faster... if you will be loading data load it all then make tests... but because your actual data the planner will always choose to scan the entire orders table for o.id_status > 3... -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;) From pgsql-performance-owner@postgresql.org Sat Jan 7 14:28:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6F3B39DC82F for ; Sat, 7 Jan 2006 14:28:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31912-03 for ; Sat, 7 Jan 2006 14:28:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by postgresql.org (Postfix) with ESMTP id 4AF849DC81A for ; Sat, 7 Jan 2006 14:28:05 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0ISQ00IBFJATYDY2@vms046.mailsrvcs.net> for pgsql-performance@postgresql.org; Sat, 07 Jan 2006 12:28:06 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id EC4C06000EE for ; Sat, 07 Jan 2006 13:28:04 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 10006-01 for ; Sat, 07 Jan 2006 13:28:04 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 4B11160013F; Fri, 06 Jan 2006 11:03:12 -0500 (EST) Date: Fri, 06 Jan 2006 11:03:12 -0500 From: Michael Stone Subject: Re: improving write performance for logging In-reply-to: <1136556006.31602.5.camel@spectre.intellivid.com> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060106160311.GH32630@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> <1136390438.24450.49.camel@spectre.intellivid.com> <20060106010822.GK43311@pervasive.com> <1136556006.31602.5.camel@spectre.intellivid.com> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.468 required=5 tests=[AWL=-0.337, DATE_IN_PAST_24_48=0.805] X-Spam-Score: 0.468 X-Spam-Level: X-Archive-Number: 200601/49 X-Sequence-Number: 16527 On Fri, Jan 06, 2006 at 09:00:06AM -0500, Ian Westmacott wrote: >We use RAID50 instead of RAID0 for the tables for some fault-tolerance. >We use RAID0 for the WAL for performance. > >I'm missing the implication of the question... If you have the WAL on RAID 0 you have no fault tolerance, regardless of what level you use for the tables. Mike Stone From pgsql-performance-owner@postgresql.org Fri Jan 6 12:37:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7A7059DC816 for ; Fri, 6 Jan 2006 12:37:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46536-08 for ; Fri, 6 Jan 2006 12:37:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from flake.decibel.org (unknown [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 5ABE09DC84A for ; Fri, 6 Jan 2006 12:37:32 -0400 (AST) Received: by flake.decibel.org (Postfix, from userid 1001) id 252173982E; Fri, 6 Jan 2006 10:37:32 -0600 (CST) Date: Fri, 6 Jan 2006 10:37:32 -0600 From: "Jim C. Nasby" To: Ian Westmacott Cc: pgsql-performance@postgresql.org Subject: Re: improving write performance for logging Message-ID: <20060106163732.GL3902@pervasive.com> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> <1136390438.24450.49.camel@spectre.intellivid.com> <20060106010822.GK43311@pervasive.com> <1136556006.31602.5.camel@spectre.intellivid.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1136556006.31602.5.camel@spectre.intellivid.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.079 required=5 tests=[AWL=0.079] X-Spam-Score: 0.079 X-Spam-Level: X-Archive-Number: 200601/40 X-Sequence-Number: 16518 On Fri, Jan 06, 2006 at 09:00:06AM -0500, Ian Westmacott wrote: > On Thu, 2006-01-05 at 19:08 -0600, Jim C. Nasby wrote: > > On Wed, Jan 04, 2006 at 11:00:38AM -0500, Ian Westmacott wrote: > > > The WAL is a 2-spindle (SATA) RAID0 with its own controller (ext3). > > > The tables are on a 10-spindle (SCSI) RAID50 with dual U320 > > > controllers (XFS). This is overkill for writing and querying the data, > > > but we need to constantly ANALYZE and VACUUM in the > > > background without interrupting the inserts (the app is 24x7). The > > > databases are 4TB, so these operations can be lengthy. > > > > How come you're using RAID50 instead of just RAID0? Or was WAL being on > > RAID0 a typo? > > We use RAID50 instead of RAID0 for the tables for some fault-tolerance. > We use RAID0 for the WAL for performance. > > I'm missing the implication of the question... The problem is that if you lose WAL or the data, you've lost everything. So you might as well use raid0 for the data if you're using it for WAL. Or switch WAL to raid1. Actually, a really good controller *might* be able to do a good job of raid5 for WAL. Or just use raid10. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 6 14:55:37 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DD7789DC8A9 for ; Fri, 6 Jan 2006 14:55:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78737-03 for ; Fri, 6 Jan 2006 14:55:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fdlnint02.fds.com (fdlnint02.fds.com [208.15.91.51]) by postgresql.org (Postfix) with ESMTP id 6E8249DC816 for ; Fri, 6 Jan 2006 14:55:31 -0400 (AST) In-Reply-To: <18083.1136524077@sss.pgh.pa.us> Subject: Re: Slow query. Any way to speed up? To: Tom Lane Cc: pgsql-performance@postgresql.org X-Mailer: Lotus Notes Release 6.5.4 March 27, 2005 Message-ID: From: Patrick Hatcher Date: Fri, 6 Jan 2006 10:55:28 -0800 X-MIMETrack: Serialize by Router on FDLNINT02/FSG/SVR/FDS(Release 6.5.2|June 01, 2004) at 01/06/2006 01:55:36 PM MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/41 X-Sequence-Number: 16519 Duh sorry. We will eventually move to 8.x, it's just a matter of finding the time: Explain analyze Select gmmid, gmmname, divid, divname, feddept, fedvend,itemnumber as mstyle,amc_week_id, sum(tran_itm_total) as net_dollars FROM public.tbldetaillevel_report a2 join cdm.cdm_ddw_tran_item a1 on a1.item_upc = a2.upc join public.date_dim a3 on a3.date_dim_id = a1.cal_date where a3.date_dim_id between '2005-10-30' and '2005-12-31' and a1.appl_id in ('MCOM','NET') and a1.tran_typ_id in ('S','R') group by 1,2,3,4,5,6,7,8 order by 1,2,3,4,5,6,7,8 GroupAggregate (cost=1648783.47..1650793.74 rows=73101 width=65) (actual time=744556.289..753136.278 rows=168343 loops=1) -> Sort (cost=1648783.47..1648966.22 rows=73101 width=65) (actual time=744556.236..746634.566 rows=1185096 loops=1) Sort Key: a2.gmmid, a2.gmmname, a2.divid, a2.divname, a2.feddept, a2.fedvend, a2.itemnumber, a3.amc_week_id -> Merge Join (cost=1598067.59..1642877.78 rows=73101 width=65) (actual time=564862.772..636550.484 rows=1185096 loops=1) Merge Cond: ("outer".upc = "inner".item_upc) -> Index Scan using report_upc_idx on tbldetaillevel_report a2 (cost=0.00..47642.36 rows=367309 width=58) (actual time=82.512..65458.137 rows=365989 loops=1) -> Sort (cost=1598067.59..1598250.34 rows=73100 width=23) (actual time=564764.506..566529.796 rows=1248862 loops=1) Sort Key: a1.item_upc -> Hash Join (cost=94.25..1592161.99 rows=73100 width=23) (actual time=493500.913..548924.039 rows=1248851 loops=1) Hash Cond: ("outer".cal_date = "inner".date_dim_id) -> Seq Scan on cdm_ddw_tran_item a1 (cost=0.00..1547562.88 rows=8754773 width=23) (actual time=14.219..535704.691 rows=10838135 loops=1) Filter: ((((appl_id)::text = 'MCOM'::text) OR ((appl_id)::text = 'NET'::text)) AND ((tran_typ_id = 'S'::bpchar) OR (tran_typ_id = 'R'::bpchar))) -> Hash (cost=94.09..94.09 rows=64 width=8) (actual time=362.953..362.953 rows=0 loops=1) -> Index Scan using date_date_idx on date_dim a3 (cost=0.00..94.09 rows=64 width=8) (actual time=93.710..362.802 rows=63 loops=1) Index Cond: ((date_dim_id >= '2005-10-30'::date) AND (date_dim_id <= '2005-12-31'::date)) Total runtime: 753467.847 ms Patrick Hatcher Development Manager Analytics/MIO Macys.com 415-422-1610 Tom Lane To Patrick Hatcher 01/05/06 09:07 PM cc pgsql-performance@postgresql.org Subject Re: [PERFORM] Slow query. Any way to speed up? Patrick Hatcher writes: > The following SQL takes 4+ mins to run. I have indexes on all join fields > and I've tried rearranging the table orders but haven't had any luck. Please show EXPLAIN ANALYZE output, not just EXPLAIN. It's impossible to tell whether the planner is making any wrong guesses when you can't see the actual times/rowcounts ... (BTW, 7.4 is looking pretty long in the tooth.) regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 6 15:03:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 902599DC98F for ; Fri, 6 Jan 2006 15:03:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78756-06 for ; Fri, 6 Jan 2006 15:03:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mailhost.intellivid.com (mailhost.intellivid.com [64.32.200.11]) by postgresql.org (Postfix) with ESMTP id 7502C9DC959 for ; Fri, 6 Jan 2006 15:02:57 -0400 (AST) Received: from spectre.intellivid.com (spectre.intellivid.com [192.168.2.68]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client did not present a certificate) by newmail.intellivid.com (Postfix) with ESMTP id 77AD8F1810A; Fri, 6 Jan 2006 14:02:58 -0500 (EST) Subject: Re: improving write performance for logging From: Ian Westmacott To: "Jim C. Nasby" Cc: pgsql-performance@postgresql.org In-Reply-To: <20060106163732.GL3902@pervasive.com> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> <1136390438.24450.49.camel@spectre.intellivid.com> <20060106010822.GK43311@pervasive.com> <1136556006.31602.5.camel@spectre.intellivid.com> <20060106163732.GL3902@pervasive.com> Content-Type: text/plain Organization: Intellivid Corp. Date: Fri, 06 Jan 2006 14:02:57 -0500 Message-Id: <1136574178.31602.13.camel@spectre.intellivid.com> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/42 X-Sequence-Number: 16520 On Fri, 2006-01-06 at 10:37 -0600, Jim C. Nasby wrote: > The problem is that if you lose WAL or the data, you've lost everything. > So you might as well use raid0 for the data if you're using it for WAL. > Or switch WAL to raid1. Actually, a really good controller *might* be > able to do a good job of raid5 for WAL. Or just use raid10. If the WAL is lost, can you lose more than the data since the last checkpoint? -- Ian Westmacott Intellivid Corp. From pgsql-performance-owner@postgresql.org Fri Jan 6 16:24:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ED24C9DC867 for ; Fri, 6 Jan 2006 16:24:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92288-07 for ; Fri, 6 Jan 2006 16:24:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 456599DC816 for ; Fri, 6 Jan 2006 16:24:09 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k06KO9vj022454; Fri, 6 Jan 2006 15:24:09 -0500 (EST) To: Patrick Hatcher cc: pgsql-performance@postgresql.org Subject: Re: Slow query. Any way to speed up? In-reply-to: References: Comments: In-reply-to Patrick Hatcher message dated "Fri, 06 Jan 2006 10:55:28 -0800" Date: Fri, 06 Jan 2006 15:24:09 -0500 Message-ID: <22453.1136579049@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200601/43 X-Sequence-Number: 16521 Patrick Hatcher writes: > -> Seq Scan on cdm_ddw_tran_item a1 > (cost=0.00..1547562.88 rows=8754773 width=23) (actual > time=14.219..535704.691 rows=10838135 loops=1) > Filter: ((((appl_id)::text = 'MCOM'::text) > OR ((appl_id)::text = 'NET'::text)) AND ((tran_typ_id = 'S'::bpchar) OR > (tran_typ_id = 'R'::bpchar))) The bulk of the time is evidently going into this step. You didn't say how big cdm_ddw_tran_item is, but unless it's in the billion-row range, an indexscan isn't going to help for pulling out 10 million rows. This may be about the best you can do :-( If it *is* in the billion-row range, PG 8.1's bitmap indexscan facility would probably help. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 6 16:27:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 41A419DC84A for ; Fri, 6 Jan 2006 16:27:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92396-10 for ; Fri, 6 Jan 2006 16:27:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id DFEB69DC816 for ; Fri, 6 Jan 2006 16:27:46 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k06KRkXk022490; Fri, 6 Jan 2006 15:27:46 -0500 (EST) To: Ian Westmacott cc: "Jim C. Nasby" , pgsql-performance@postgresql.org Subject: Re: improving write performance for logging In-reply-to: <1136574178.31602.13.camel@spectre.intellivid.com> References: <43BB0C5C.8020207@computer.org> <1136382865.24450.7.camel@spectre.intellivid.com> <7.0.1.0.2.20060104092139.01c37da0@earthlink.net> <1136390438.24450.49.camel@spectre.intellivid.com> <20060106010822.GK43311@pervasive.com> <1136556006.31602.5.camel@spectre.intellivid.com> <20060106163732.GL3902@pervasive.com> <1136574178.31602.13.camel@spectre.intellivid.com> Comments: In-reply-to Ian Westmacott message dated "Fri, 06 Jan 2006 14:02:57 -0500" Date: Fri, 06 Jan 2006 15:27:46 -0500 Message-ID: <22489.1136579266@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200601/44 X-Sequence-Number: 16522 Ian Westmacott writes: > If the WAL is lost, can you lose more than the data since the last > checkpoint? The problem is that you might have partially-applied actions since the last checkpoint, rendering your database inconsistent; then *all* the data is suspect if not actually corrupt. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 6 18:59:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8496A9DCB65 for ; Fri, 6 Jan 2006 18:59:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17550-10 for ; Fri, 6 Jan 2006 18:59:43 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 72E609DCA62 for ; Fri, 6 Jan 2006 18:59:38 -0400 (AST) Received: from vulcan.rootr.net (deuterium.rootr.net [203.194.209.160]) by svr4.postgresql.org (Postfix) with ESMTP id B21405AF049 for ; Fri, 6 Jan 2006 22:59:40 +0000 (GMT) Received: from [192.168.42.14] (meatloaf.fotap.org [63.211.45.38]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by vulcan.rootr.net (Postfix) with ESMTP id 182143C1B; Fri, 6 Jan 2006 22:56:37 +0000 (UTC) Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: multipart/signed; micalg=sha1; boundary=Apple-Mail-23--632624939; protocol="application/pkcs7-signature" Message-Id: X-Image-Url: http://fotap.org/~osi/mail/peter.royal@pobox.com From: peter royal Subject: help tuning queries on large database Date: Fri, 6 Jan 2006 17:59:24 -0500 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/45 X-Sequence-Number: 16523 --Apple-Mail-23--632624939 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Howdy. I'm running into scaling problems when testing with a 16gb (data +indexes) database. I can run a query, and it returns in a few seconds. If I run it again, it returns in a few milliseconds. I realize this is because during subsequent runs, the necessary disk pages have been cached by the OS. I have experimented with having all 8 disks in a single RAID0 set, a single RAID10 set, and currently 4 RAID0 sets of 2 disks each. There hasn't been an appreciable difference in the overall performance of my test suite (which randomly generates queries like the samples below as well as a few other types. this problem manifests itself on other queries in the test suite as well). So, my question is, is there anything I can do to boost performance with what I've got, or am I in a position where the only 'fix' is more faster disks? I can't think of any schema/index changes that would help, since everything looks pretty optimal from the 'explain analyze' output. I'd like to get a 10x improvement when querying from the 'cold' state. Thanks for any assistance. The advice from reading this list to getting to where I am now has been invaluable. -peter Configuration: PostgreSQL 8.1.1 shared_buffers = 10000 # (It was higher, 50k, but didn't help any, so brought down to free ram for disk cache) work_mem = 8196 random_page_cost = 3 effective_cache_size = 250000 Hardware: CentOS 4.2 (Linux 2.6.9-22.0.1.ELsmp) Areca ARC-1220 8-port PCI-E controller 8 x Hitachi Deskstar 7K80 (SATA2) (7200rpm) 2 x Opteron 242 @ 1.6ghz 3gb RAM (should be 4gb, but separate Linux issue preventing us from getting it to see all of it) Tyan Thunder K8WE RAID Layout: 4 2-disk RAID0 sets created Each raid set is a tablespace, formatted ext3. The majority of the database is in the primary tablespace, and the popular object_data table is in its own tablespace. Sample 1: triple_store=# explain analyze SELECT DISTINCT O.subject AS oid FROM object_data O, object_tags T1, tags T2 WHERE O.type = 179 AND O.subject = T1.object_id AND T1.tag_id = T2.tag_id AND T2.tag = 'transmitter\'s' LIMIT 1000; QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------------ ------------------------- Limit (cost=1245.07..1245.55 rows=97 width=4) (actual time=3702.697..3704.665 rows=206 loops=1) -> Unique (cost=1245.07..1245.55 rows=97 width=4) (actual time=3702.691..3703.900 rows=206 loops=1) -> Sort (cost=1245.07..1245.31 rows=97 width=4) (actual time=3702.686..3703.056 rows=206 loops=1) Sort Key: o.subject -> Nested Loop (cost=2.82..1241.87 rows=97 width=4) (actual time=97.166..3701.970 rows=206 loops=1) -> Nested Loop (cost=2.82..678.57 rows=186 width=4) (actual time=59.903..1213.170 rows=446 loops=1) -> Index Scan using tags_tag_key on tags t2 (cost=0.00..5.01 rows=1 width=4) (actual time=13.139..13.143 rows=1 loops=1) Index Cond: (tag = 'transmitter''s'::text) -> Bitmap Heap Scan on object_tags t1 (cost=2.82..670.65 rows=233 width=8) (actual time=46.751..1198.198 rows=446 loops=1) Recheck Cond: (t1.tag_id = "outer".tag_id) -> Bitmap Index Scan on object_tags_tag_id_object_id (cost=0.00..2.82 rows=233 width=0) (actual time=31.571..31.571 rows=446 loops=1) Index Cond: (t1.tag_id = "outer".tag_id) -> Index Scan using object_data_pkey on object_data o (cost=0.00..3.02 rows=1 width=4) (actual time=5.573..5.574 rows=0 loops=446) Index Cond: (o.subject = "outer".object_id) Filter: ("type" = 179) Total runtime: 3705.166 ms (16 rows) triple_store=# explain analyze SELECT DISTINCT O.subject AS oid FROM object_data O, object_tags T1, tags T2 WHERE O.type = 179 AND O.subject = T1.object_id AND T1.tag_id = T2.tag_id AND T2.tag = 'transmitter\'s' LIMIT 1000; QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------------ ----------------------- Limit (cost=1245.07..1245.55 rows=97 width=4) (actual time=11.037..12.923 rows=206 loops=1) -> Unique (cost=1245.07..1245.55 rows=97 width=4) (actual time=11.031..12.190 rows=206 loops=1) -> Sort (cost=1245.07..1245.31 rows=97 width=4) (actual time=11.027..11.396 rows=206 loops=1) Sort Key: o.subject -> Nested Loop (cost=2.82..1241.87 rows=97 width=4) (actual time=0.430..10.461 rows=206 loops=1) -> Nested Loop (cost=2.82..678.57 rows=186 width=4) (actual time=0.381..3.479 rows=446 loops=1) -> Index Scan using tags_tag_key on tags t2 (cost=0.00..5.01 rows=1 width=4) (actual time=0.058..0.061 rows=1 loops=1) Index Cond: (tag = 'transmitter''s'::text) -> Bitmap Heap Scan on object_tags t1 (cost=2.82..670.65 rows=233 width=8) (actual time=0.310..1.730 rows=446 loops=1) Recheck Cond: (t1.tag_id = "outer".tag_id) -> Bitmap Index Scan on object_tags_tag_id_object_id (cost=0.00..2.82 rows=233 width=0) (actual time=0.199..0.199 rows=446 loops=1) Index Cond: (t1.tag_id = "outer".tag_id) -> Index Scan using object_data_pkey on object_data o (cost=0.00..3.02 rows=1 width=4) (actual time=0.009..0.010 rows=0 loops=446) Index Cond: (o.subject = "outer".object_id) Filter: ("type" = 179) Total runtime: 13.411 ms (16 rows) triple_store=# Sample 2: triple_store=# explain analyze SELECT DISTINCT O.subject AS oid FROM object_data O, object_tags T1, tags T2 WHERE O.type = 93 AND O.subject = T1.object_id AND T1.tag_id = T2.tag_id AND T2.tag = 'current' LIMIT 1000; QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------------ ------------------------- Limit (cost=1241.88..1241.88 rows=1 width=4) (actual time=6411.409..6411.409 rows=0 loops=1) -> Unique (cost=1241.88..1241.88 rows=1 width=4) (actual time=6411.405..6411.405 rows=0 loops=1) -> Sort (cost=1241.88..1241.88 rows=1 width=4) (actual time=6411.400..6411.400 rows=0 loops=1) Sort Key: o.subject -> Nested Loop (cost=2.82..1241.87 rows=1 width=4) (actual time=6411.386..6411.386 rows=0 loops=1) -> Nested Loop (cost=2.82..678.57 rows=186 width=4) (actual time=46.045..2229.978 rows=446 loops=1) -> Index Scan using tags_tag_key on tags t2 (cost=0.00..5.01 rows=1 width=4) (actual time=11.798..11.802 rows=1 loops=1) Index Cond: (tag = 'current'::text) -> Bitmap Heap Scan on object_tags t1 (cost=2.82..670.65 rows=233 width=8) (actual time=34.222..2216.321 rows=446 loops=1) Recheck Cond: (t1.tag_id = "outer".tag_id) -> Bitmap Index Scan on object_tags_tag_id_object_id (cost=0.00..2.82 rows=233 width=0) (actual time=25.523..25.523 rows=446 loops=1) Index Cond: (t1.tag_id = "outer".tag_id) -> Index Scan using object_data_pkey on object_data o (cost=0.00..3.02 rows=1 width=4) (actual time=9.370..9.370 rows=0 loops=446) Index Cond: (o.subject = "outer".object_id) Filter: ("type" = 93) Total runtime: 6411.516 ms (16 rows) triple_store=# explain analyze SELECT DISTINCT O.subject AS oid FROM object_data O, object_tags T1, tags T2 WHERE O.type = 93 AND O.subject = T1.object_id AND T1.tag_id = T2.tag_id AND T2.tag = 'current' LIMIT 1000; QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------------ ----------------------- Limit (cost=1241.88..1241.88 rows=1 width=4) (actual time=9.437..9.437 rows=0 loops=1) -> Unique (cost=1241.88..1241.88 rows=1 width=4) (actual time=9.431..9.431 rows=0 loops=1) -> Sort (cost=1241.88..1241.88 rows=1 width=4) (actual time=9.426..9.426 rows=0 loops=1) Sort Key: o.subject -> Nested Loop (cost=2.82..1241.87 rows=1 width=4) (actual time=9.414..9.414 rows=0 loops=1) -> Nested Loop (cost=2.82..678.57 rows=186 width=4) (actual time=0.347..3.477 rows=446 loops=1) -> Index Scan using tags_tag_key on tags t2 (cost=0.00..5.01 rows=1 width=4) (actual time=0.039..0.042 rows=1 loops=1) Index Cond: (tag = 'current'::text) -> Bitmap Heap Scan on object_tags t1 (cost=2.82..670.65 rows=233 width=8) (actual time=0.297..1.688 rows=446 loops=1) Recheck Cond: (t1.tag_id = "outer".tag_id) -> Bitmap Index Scan on object_tags_tag_id_object_id (cost=0.00..2.82 rows=233 width=0) (actual time=0.185..0.185 rows=446 loops=1) Index Cond: (t1.tag_id = "outer".tag_id) -> Index Scan using object_data_pkey on object_data o (cost=0.00..3.02 rows=1 width=4) (actual time=0.009..0.009 rows=0 loops=446) Index Cond: (o.subject = "outer".object_id) Filter: ("type" = 93) Total runtime: 9.538 ms (16 rows) triple_store=# Schema: triple_store=# \d object_data Table "public.object_data" Column | Type | Modifiers ---------------+-----------------------------+----------- subject | integer | not null type | integer | not null owned_by | integer | not null created_by | integer | not null created | timestamp without time zone | not null last_modified | timestamp without time zone | not null label | text | Indexes: "object_data_pkey" PRIMARY KEY, btree (subject) "object_data_type_created_by" btree ("type", created_by) "object_data_type_owned_by" btree ("type", owned_by) Foreign-key constraints: "object_data_created_by_fkey" FOREIGN KEY (created_by) REFERENCES objects(object_id) DEFERRABLE INITIALLY DEFERRED "object_data_owned_by_fkey" FOREIGN KEY (owned_by) REFERENCES objects(object_id) DEFERRABLE INITIALLY DEFERRED "object_data_type_fkey" FOREIGN KEY ("type") REFERENCES objects (object_id) DEFERRABLE INITIALLY DEFERRED Tablespace: "alt_2" triple_store=# \d object_tags Table "public.object_tags" Column | Type | Modifiers -----------+---------+----------- object_id | integer | not null tag_id | integer | not null Indexes: "object_tags_pkey" PRIMARY KEY, btree (object_id, tag_id) "object_tags_tag_id" btree (tag_id) "object_tags_tag_id_object_id" btree (tag_id, object_id) Foreign-key constraints: "object_tags_object_id_fkey" FOREIGN KEY (object_id) REFERENCES objects(object_id) DEFERRABLE INITIALLY DEFERRED "object_tags_tag_id_fkey" FOREIGN KEY (tag_id) REFERENCES tags (tag_id) DEFERRABLE INITIALLY DEFERRED triple_store=# \d tags Table "public.tags" Column | Type | Modifiers --------+--------- +------------------------------------------------------- tag_id | integer | not null default nextval('tags_tag_id_seq'::regclass) tag | text | not null Indexes: "tags_pkey" PRIMARY KEY, btree (tag_id) "tags_tag_key" UNIQUE, btree (tag) -- (peter.royal|osi)@pobox.com - http://fotap.org/~osi --Apple-Mail-23--632624939 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGOzCCAvQw ggJdoAMCAQICAw8s0TANBgkqhkiG9w0BAQQFADBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVt YWlsIElzc3VpbmcgQ0EwHhcNMDUwNzIxMTIwNjQyWhcNMDYwNzIxMTIwNjQyWjBkMRIwEAYDVQQE EwlSb3lhbCwgSlIxDjAMBgNVBCoTBVBldGVyMRgwFgYDVQQDEw9QZXRlciBSb3lhbCwgSlIxJDAi BgkqhkiG9w0BCQEWFXBldGVyLnJveWFsQHBvYm94LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP ADCCAQoCggEBAPW/zCQAZyBIXRLanqpajpr+Q5I0ETdvKKDtEd3SjFS22fVJrAd8+uQErV6s79Jx 0ZJG1+GqexKOm5t/sRYtMWUWvJen6Utc6pd6If4mEKPq4y0LjLp2Rlk4trlXzA33z+QLsZAoJV7x DDSd/E+WZztJDELSWgWgDUHvoKbhCW35qpPiSPRrrIi4GmWg4m9b0MeCBNpIxn8in9qx2HhI5XcK zcD2ueUxcb2u99BqzQZ0dq/xaJ9cG1l/yZoBFjescJ41W0SVU4EQEf5Xqz6m7uy0/MVdTx+z944B 6oMZfAgay1icNUJjriWbVvkdkx1AZAFgSD+jpllKo/VJdMcdE6sCAwEAAaMyMDAwIAYDVR0RBBkw F4EVcGV0ZXIucm95YWxAcG9ib3guY29tMAwGA1UdEwEB/wQCMAAwDQYJKoZIhvcNAQEEBQADgYEA MmCS+sAaGppFzT8WnkkLDmbSl7DXceHtm7vpg6zsp9g9BySYxyMfHGkqXuhyI4UCfVa1Y8/YdBRJ lpCVjRbHVicCDWuWkPWc97RpiAjnv+uZNcmXQgdAtdUXTvpMoLteRkouZeGKwsXnCLyhlPYB8jvC tVTMzuMCPJZVhV7kzPMwggM/MIICqKADAgECAgENMA0GCSqGSIb3DQEBBQUAMIHRMQswCQYDVQQG EwJaQTEVMBMGA1UECBMMV2VzdGVybiBDYXBlMRIwEAYDVQQHEwlDYXBlIFRvd24xGjAYBgNVBAoT EVRoYXd0ZSBDb25zdWx0aW5nMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2VzIERpdmlz aW9uMSQwIgYDVQQDExtUaGF3dGUgUGVyc29uYWwgRnJlZW1haWwgQ0ExKzApBgkqhkiG9w0BCQEW HHBlcnNvbmFsLWZyZWVtYWlsQHRoYXd0ZS5jb20wHhcNMDMwNzE3MDAwMDAwWhcNMTMwNzE2MjM1 OTU5WjBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRk LjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwgZ8wDQYJKoZI hvcNAQEBBQADgY0AMIGJAoGBAMSmPFVzVftOucqZWh5owHUEcJ3f6f+jHuy9zfVb8hp2vX8MOmHy v1HOAdTlUAow1wJjWiyJFXCO3cnwK4Vaqj9xVsuvPAsH5/EfkTYkKhPPK9Xzgnc9A74r/rsYPge/ QIACZNenprufZdHFKlSFD0gEf6e20TxhBEAeZBlyYLf7AgMBAAGjgZQwgZEwEgYDVR0TAQH/BAgw BgEB/wIBADBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLnRoYXd0ZS5jb20vVGhhd3RlUGVy c29uYWxGcmVlbWFpbENBLmNybDALBgNVHQ8EBAMCAQYwKQYDVR0RBCIwIKQeMBwxGjAYBgNVBAMT EVByaXZhdGVMYWJlbDItMTM4MA0GCSqGSIb3DQEBBQUAA4GBAEiM0VCD6gsuzA2jZqxnD3+vrL7C F6FDlpSdf0whuPg2H6otnzYvwPQcUCCTcDz9reFhYsPZOhl+hLGZGwDFGguCdJ4lUJRix9sncVcl jd2pnDmOjCBPZV+V2vf3h9bGCE6u9uo05RAaWzVNd+NWIXiC3CEZNd4ksdMdRv9dX2VPMYIC5zCC AuMCAQEwaTBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg THRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0ECAw8s0TAJ BgUrDgMCGgUAoIIBUzAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0w NjAxMDYyMjU5MjVaMCMGCSqGSIb3DQEJBDEWBBRNJqJHN9hKtCr7l4IOPUzbLBAzmzB4BgkrBgEE AYI3EAQxazBpMGIxCzAJBgNVBAYTAlpBMSUwIwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAoUHR5 KSBMdGQuMSwwKgYDVQQDEyNUaGF3dGUgUGVyc29uYWwgRnJlZW1haWwgSXNzdWluZyBDQQIDDyzR MHoGCyqGSIb3DQEJEAILMWugaTBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1 bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3Vp bmcgQ0ECAw8s0TANBgkqhkiG9w0BAQEFAASCAQALG3XHPFWDArWTlioJlT/TKTcG2k5YgIHWwuaf 9srC2cssy7qMuNYvT3uOau7nfgc60fjC6lCG5T+U5eXz4oczXk9hXJ+I6xV3KkdHWgTHHFuY6OzP SRW8fm0T9yu/G57DJZ/z864lq7UTclCu83Pp0pwOJCYRjT1DKPoOeG5aOhhvVi5y9ElD1k17NeEB wUpF5hQ4Mxy3aAjhrqSxo5WFSwgYAYDK6cmlRA9DX8xTrad2C44clFpgceIPR9n1OGFrM2PRG/RJ c7mquZZa0XXUU1NY7mLXAFBZRrkLoRcsJCHO1dn2QfTyNr9nY9K75hadDxUTdMBrVcD94WVt13kB AAAAAAAA --Apple-Mail-23--632624939-- From pgsql-performance-owner@postgresql.org Fri Jan 6 19:48:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 663959DCB11 for ; Fri, 6 Jan 2006 19:48:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25659-09 for ; Fri, 6 Jan 2006 19:48:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 04B4C9DCB65 for ; Fri, 6 Jan 2006 19:47:59 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k06Nlt9g023744; Fri, 6 Jan 2006 18:47:55 -0500 (EST) To: peter royal cc: pgsql-performance@postgresql.org Subject: Re: help tuning queries on large database In-reply-to: References: Comments: In-reply-to peter royal message dated "Fri, 06 Jan 2006 17:59:24 -0500" Date: Fri, 06 Jan 2006 18:47:55 -0500 Message-ID: <23743.1136591275@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.073 required=5 tests=[AWL=0.073] X-Spam-Score: 0.073 X-Spam-Level: X-Archive-Number: 200601/46 X-Sequence-Number: 16524 peter royal writes: > So, my question is, is there anything I can do to boost performance > with what I've got, or am I in a position where the only 'fix' is > more faster disks? I can't think of any schema/index changes that > would help, since everything looks pretty optimal from the 'explain > analyze' output. I'd like to get a 10x improvement when querying from > the 'cold' state. I don't think you have any hope of improving the "cold" state much. The right way to think about this is not to be in the "cold" state. Check your kernel parameters and make sure it's not set to limit the amount of memory used for cache (I'm not actually sure if there is such a limit on Linux, but there definitely is on some other Unixen). Look around and see if you can reduce the memory used by processes, or even better, offload non-database tasks to other machines. Basically you need to get as much of the database as you can to stay in disk cache. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 6 21:09:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C55A99DCA21 for ; Fri, 6 Jan 2006 21:09:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40704-04 for ; Fri, 6 Jan 2006 21:09:37 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 76D759DCA03 for ; Fri, 6 Jan 2006 21:09:32 -0400 (AST) Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.193]) by svr4.postgresql.org (Postfix) with ESMTP id A41755AF068 for ; Sat, 7 Jan 2006 01:09:36 +0000 (GMT) Received: by nproxy.gmail.com with SMTP id n29so25417nfc for ; Fri, 06 Jan 2006 17:08:26 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=E+dQHh2XrAIbRLmcsT5JiOfXzkaqnkMBhM7VDIm29GqVvdIWfn1qwlIaVNLoZsG4VGUfJYpagWIVdUkX9pBk9P8Sfvj63BNZNFToro6eOTAjfAjfTlk+8odvGkiksZ8zWedBv+oZs9v9P3ddNhKkAWjmcd8hv7sOdyZmy8DlRtk= Received: by 10.48.218.8 with SMTP id q8mr1455nfg; Fri, 06 Jan 2006 17:08:26 -0800 (PST) Received: by 10.48.164.6 with HTTP; Fri, 6 Jan 2006 17:08:25 -0800 (PST) Message-ID: <45b42ce40601061708m1232c537tf901a806a7a3213d@mail.gmail.com> Date: Sat, 7 Jan 2006 01:08:25 +0000 From: Harry Jackson To: pgsql-performance@postgresql.org Subject: Re: help tuning queries on large database In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 Content-Disposition: inline References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/47 X-Sequence-Number: 16525 T24gMS82LzA2LCBwZXRlciByb3lhbCA8cGV0ZXIucm95YWxAcG9ib3guY29tPiB3cm90ZToKPiBQ b3N0Z3JlU1FMIDguMS4xCj4KPiBzaGFyZWRfYnVmZmVycyA9IDEwMDAwICAjIChJdCB3YXMgaGln aGVyLCA1MGssIGJ1dCBkaWRuJ3QgaGVscCBhbnksCj4gc28gYnJvdWdodCBkb3duIHRvIGZyZWUg cmFtIGZvciBkaXNrIGNhY2hlKQo+IHdvcmtfbWVtID0gODE5Ngo+IHJhbmRvbV9wYWdlX2Nvc3Qg PSAzCj4gZWZmZWN0aXZlX2NhY2hlX3NpemUgPSAyNTAwMDAKCkkgaGF2ZSBwbGF5ZWQgd2l0aCBi b3RoIGRpc2sgY2FjaGUgc2V0dGluZ3MgYW5kIHNoYXJlZCBidWZmZXJzIGFuZCBJCmZvdW5kIHRo YXQgaWYgSSBpbmNyZWFzZWQgdGhlIHNoYXJlZCBidWZmZXJzIGFib3ZlIGEgY2VydGFpbiB2YWx1 ZQpwZXJmb3JtYW5jZSB3b3VsZCBpbmNyZWFzZSBkcmFtYXRpY2FsbHkuIFBsYXlpbmcgd2l0aCB0 aGUgZWZmZWN0aXZlCmNhY2hlIGRpZCBub3QgaGF2ZSB0aGUgc2FtZSBhbW91bnQgb2YgaW1wYWN0 LiBJIGFtIGN1cnJlbnRseSBydW5uaW5nCndpdGgKCnNoYXJlZF9idWZmZXJzID0gMjU0Mjg4ICMg YXBwcm94IDIuMUdiCgphbmQgdGhpcyBpcyBvbiBhIHNtYWxsZXIgZGF0YXNldCB0aGFuIHlvdXJz LgoKLS0KSGFycnkKaHR0cDovL3d3dy5oamFja3Nvbi5vcmcKaHR0cDovL3d3dy51a2x1Zy5jby51 awo= From pgsql-performance-owner@postgresql.org Fri Jan 6 21:21:48 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A91059DC81F for ; Fri, 6 Jan 2006 21:21:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42239-05 for ; Fri, 6 Jan 2006 21:21:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.invendra.net (sbx-01.invendra.net [66.139.76.16]) by postgresql.org (Postfix) with ESMTP id AD6A49DCAB1 for ; Fri, 6 Jan 2006 21:19:58 -0400 (AST) Received: from david.lang.hm (dsl081-044-215.lax1.dsl.speakeasy.net [64.81.44.215]) by mail.invendra.net (Postfix) with ESMTP id BCB401AC3EC; Fri, 6 Jan 2006 17:20:14 -0800 (PST) Date: Fri, 6 Jan 2006 17:18:48 -0800 (PST) From: David Lang X-X-Sender: dlang@david.lang.hm To: Tom Lane Cc: peter royal , pgsql-performance@postgresql.org Subject: Re: help tuning queries on large database In-Reply-To: <23743.1136591275@sss.pgh.pa.us> Message-ID: References: <23743.1136591275@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200601/48 X-Sequence-Number: 16526 On Fri, 6 Jan 2006, Tom Lane wrote: > Date: Fri, 06 Jan 2006 18:47:55 -0500 > From: Tom Lane > To: peter royal > Cc: pgsql-performance@postgresql.org > Subject: Re: [PERFORM] help tuning queries on large database > > peter royal writes: >> So, my question is, is there anything I can do to boost performance >> with what I've got, or am I in a position where the only 'fix' is >> more faster disks? I can't think of any schema/index changes that >> would help, since everything looks pretty optimal from the 'explain >> analyze' output. I'd like to get a 10x improvement when querying from >> the 'cold' state. > > I don't think you have any hope of improving the "cold" state much. > The right way to think about this is not to be in the "cold" state. > Check your kernel parameters and make sure it's not set to limit > the amount of memory used for cache (I'm not actually sure if there > is such a limit on Linux, but there definitely is on some other Unixen). Linux doesn't have any ability to limit the amount of memory used for caching (there are periodicly requests for such a feature) David Lang > Look around and see if you can reduce the memory used by processes, > or even better, offload non-database tasks to other machines. > > Basically you need to get as much of the database as you can to stay > in disk cache. > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > From pgsql-hackers-owner@postgresql.org Sun Jan 8 12:49:29 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 86C149DC84B for ; Sun, 8 Jan 2006 12:49:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31447-10 for ; Sun, 8 Jan 2006 12:49:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id EE0849DC827 for ; Sun, 8 Jan 2006 12:49:19 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1EvdjF-0005JU-00; Sun, 08 Jan 2006 11:49:13 -0500 To: Hannu Krosing Cc: Simon Riggs , Tom Lane , Qingqing Zhou , pgsql-hackers@postgresql.org Subject: Re: Stats collector performance improvement References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> <12503.1136238525@sss.pgh.pa.us> <1136281253.5052.113.camel@localhost.localdomain> <1136324574.4256.17.camel@localhost.localdomain> In-Reply-To: <1136324574.4256.17.camel@localhost.localdomain> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 08 Jan 2006 11:49:12 -0500 Message-ID: <87wtha1x87.fsf@stark.xeocode.com> Lines: 15 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.115 required=5 tests=[AWL=0.115] X-Spam-Score: 0.115 X-Spam-Level: X-Archive-Number: 200601/262 X-Sequence-Number: 78366 Hannu Krosing writes: > Interestingly I use pg_stat_activity view to watch for stuck backends, > "stuck" in the sense that they have not noticed when client want away > and are now waitin the TCP timeout to happen. I query for backends which > have been in "" state for longer than XX seconds. I guess that at > least some kind of indication for this should be available. You mean like the tcp_keepalives_idle option? http://www.postgresql.org/docs/8.1/interactive/runtime-config-connection.html#GUC-TCP-KEEPALIVES-IDLE -- greg From pgsql-performance-owner@postgresql.org Sat Jan 14 01:50:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6DBBA9DCC00 for ; Mon, 9 Jan 2006 05:13:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20903-01 for ; Mon, 9 Jan 2006 05:13:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 92DD59DC844 for ; Mon, 9 Jan 2006 05:13:49 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 495C433A69; Mon, 9 Jan 2006 10:13:50 +0100 (MET) From: vimal.gupta@gmail.com X-Newsgroups: pgsql.performance Subject: Hanging Query Date: 8 Jan 2006 09:34:30 -0800 Organization: http://groups.google.com Lines: 22 Message-ID: <1136741670.479720.284080@f14g2000cwb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=219.65.218.137; posting-account=YZ-Tcw0AAAAxiPQWFqzp1c3H22tl8g8e To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.431 required=5 tests=[DATE_IN_PAST_12_24=0.881, NO_REAL_NAME=0.55] X-Spam-Score: 1.431 X-Spam-Level: * X-Archive-Number: 200601/177 X-Sequence-Number: 16655 We have to inserts a records(15000- 20000) into a table which also contains (15000-20000) records, then after insertion, we have to delete the records according to a business rule. Above process is taking place in a transaction and we are using batches of 128 to insert records. Everything works fine on QA environment but somehow after inserts, delete query hangs in production environment. Delete query has some joins with other table and a self join. There is no exception as we have done enough exception handling. It simply hangs with no trace in application logs. When I do "ps aux" , I see postgres 5294 41.3 2.4 270120 38092 pts/4 R 10:41 52:56 postgres: nuuser nm 127.0.0.1 DELETE Postgres 7.3.4 on Linux.. Thanks for any help.. Vimal From pgsql-performance-owner@postgresql.org Sun Jan 8 14:42:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 19DC09DC9E8 for ; Sun, 8 Jan 2006 14:42:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62633-03 for ; Sun, 8 Jan 2006 14:42:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46]) by postgresql.org (Postfix) with ESMTP id AA7719DC942 for ; Sun, 8 Jan 2006 14:42:39 -0400 (AST) Received: from 172.16.1.110 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D2)); Sun, 08 Jan 2006 13:42:32 -0500 X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Sun, 8 Jan 2006 13:42:32 -0500 Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.106]) with Microsoft Exchange Server HTTP-DAV ; Sun, 8 Jan 2006 18:42:31 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Sun, 08 Jan 2006 10:42:31 -0800 Subject: Re: help tuning queries on large database From: "Luke Lonergan" To: "peter royal" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] help tuning queries on large database Thread-Index: AcYTFQFEbemu7xT0Q2qfSxqTQl+g7gBbkbeJ In-Reply-To: MIME-Version: 1.0 X-OriginalArrivalTime: 08 Jan 2006 18:42:32.0444 (UTC) FILETIME=[48FCDBC0:01C61483] X-WSS-ID: 6FDF82923TO9542830-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.318 required=5 tests=[AWL=0.065, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.318 X-Spam-Level: * X-Archive-Number: 200601/50 X-Sequence-Number: 16528 Peter, On 1/6/06 2:59 PM, "peter royal" wrote: > I have experimented with having all 8 disks in a single RAID0 set, a > single RAID10 set, and currently 4 RAID0 sets of 2 disks each. There > hasn't been an appreciable difference in the overall performance of > my test suite (which randomly generates queries like the samples > below as well as a few other types. this problem manifests itself on > other queries in the test suite as well). Have you tested the underlying filesystem for it's performance? Run this: time bash -c 'dd if=/dev/zero of=/my_file_system/bigfile bs=8k count= && sync' Then run this: time dd if=/my_file_system/bigfile bs=8k of=/dev/null And report the times here please. With your 8 disks in any of the RAID0 configurations you describe, you should be getting 480MB/s. In the RAID10 configuration you should get 240. Note that ext3 will not go faster than about 300MB/s in our experience. You should use xfs, which will run *much* faster. You should also experiment with using larger readahead, which you can implement like this: blockdev --setra 16384 /dev/ E.g. "blockdev --setra 16384 /dev/sda" This will set the readahead of Linux block device reads to 16MB. Using 3Ware's newest controllers we have seen 500MB/s + on 8 disk drives in RAID0 on CentOS 4.1 with xfs. Note that you will need to run the "CentOS unsupported kernel" to get xfs. > So, my question is, is there anything I can do to boost performance > with what I've got, or am I in a position where the only 'fix' is > more faster disks? I can't think of any schema/index changes that > would help, since everything looks pretty optimal from the 'explain > analyze' output. I'd like to get a 10x improvement when querying from > the 'cold' state. From what you describe, one of these is likely: - hardware isn't configured properly or a driver problem. - you need to use xfs and tune your Linux readahead - Luke From pgsql-performance-owner@postgresql.org Sun Jan 8 17:35:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 490D69DC872 for ; Sun, 8 Jan 2006 17:35:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93007-03 for ; Sun, 8 Jan 2006 17:35:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth01.mail.atl.earthlink.net (smtpauth01.mail.atl.earthlink.net [209.86.89.61]) by postgresql.org (Postfix) with ESMTP id 70FCA9DC829 for ; Sun, 8 Jan 2006 17:35:11 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=P6T42sB+mHuEITYgWmIhKJRHBWyE99Aslv4QwfpiNQdnGH0HiK7/Q1SrfSmxSzPP; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.244.95] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth01.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1EviC0-0005bp-AQ; Sun, 08 Jan 2006 16:35:12 -0500 Message-Id: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Sun, 08 Jan 2006 16:35:11 -0500 To: peter royal ,pgsql-performance@postgresql.org From: Ron Subject: Re: help tuning queries on large database In-Reply-To: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc7f3e1ab5d3cb6e4f8ba86a22f85bce05350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.244.95 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.412 required=5 tests=[AWL=-0.067, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.412 X-Spam-Level: X-Archive-Number: 200601/51 X-Sequence-Number: 16529 I'll second all of Luke Lonergan's comments and add these. You should be able to increase both "cold" and "warm" performance (as well as data integrity. read below.) considerably. Ron At 05:59 PM 1/6/2006, peter royal wrote: >Howdy. > >I'm running into scaling problems when testing with a 16gb (data >+indexes) database. > >I can run a query, and it returns in a few seconds. If I run it >again, it returns in a few milliseconds. I realize this is because >during subsequent runs, the necessary disk pages have been cached by >the OS. > >I have experimented with having all 8 disks in a single RAID0 set, a >single RAID10 set, and currently 4 RAID0 sets of 2 disks each. There >hasn't been an appreciable difference in the overall performance of >my test suite (which randomly generates queries like the samples >below as well as a few other types. this problem manifests itself on >other queries in the test suite as well). > >So, my question is, is there anything I can do to boost performance >with what I've got, or am I in a position where the only 'fix' is >more faster disks? I can't think of any schema/index changes that >would help, since everything looks pretty optimal from the 'explain >analyze' output. I'd like to get a 10x improvement when querying from >the 'cold' state. > >Thanks for any assistance. The advice from reading this list to >getting to where I am now has been invaluable. >-peter > > >Configuration: > >PostgreSQL 8.1.1 > >shared_buffers = 10000 # (It was higher, 50k, but didn't help any, >so brought down to free ram for disk cache) >work_mem = 8196 >random_page_cost = 3 >effective_cache_size = 250000 > > >Hardware: > >CentOS 4.2 (Linux 2.6.9-22.0.1.ELsmp) Upgrade your kernel to at least 2.6.12 There's a known issue with earlier versions of the 2.6.x kernel and 64b CPUs like the Opteron. See kernel.org for details. >Areca ARC-1220 8-port PCI-E controller Make sure you have 1GB or 2GB of cache. Get the battery backup and set the cache for write back rather than write through. >8 x Hitachi Deskstar 7K80 (SATA2) (7200rpm) >2 x Opteron 242 @ 1.6ghz >3gb RAM (should be 4gb, but separate Linux issue preventing us from >getting it to see all of it) >Tyan Thunder K8WE The K8WE has 8 DIMM slots. That should be good for 16 or 32 GB of RAM (Depending on whether the mainboard recognizes 4GB DIMMs or not. Ask Tyan about the latest K8WE firmare.). If nothing else, 1GB DIMMs are now so cheap that you should have no problems having 8GB on the K8WE. A 2.6.12 or later based Linux distro should have NO problems using more than 4GB or RAM. Among the other tricks having lots of RAM allows: If some of your tables are Read Only or VERY rarely written to, you can preload them at boot time and make them RAM resident using the /etc/tmpfs trick. In addition there is at least one company making a cheap battery backed PCI-X card that can hold up to 4GB of RAM and pretend to be a small HD to the OS. I don't remember any names at the moment, but there have been posts here and at storage.review.com on such products. >RAID Layout: > >4 2-disk RAID0 sets created You do know that a RAID 0 set provides _worse_ data protection than a single HD? Don't use RAID 0 for any data you want kept reliably. With 8 HDs, the best config is probably 1 2HD RAID 1 + 1 6HD RAID 10 or 2 4HD RAID 10's It is certainly true that once you have done everything you can with RAM, the next set of HW optimizations is to add HDs. The more the better up to a the limits of your available PCI-X bandwidth. In short, a 2nd RAID fully populated controller is not unreasonable. From pgsql-performance-owner@postgresql.org Mon Jan 9 03:56:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 205689DCB9B for ; Mon, 9 Jan 2006 03:56:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07077-01 for ; Mon, 9 Jan 2006 03:56:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ar-sd.net (unknown [81.196.35.136]) by postgresql.org (Postfix) with ESMTP id BA0949DC9DA for ; Mon, 9 Jan 2006 03:56:52 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id 510EE22F6D; Mon, 9 Jan 2006 09:56:53 +0200 (EET) Received: from ar-sd.net ([127.0.0.1]) by localhost (linz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00325-09; Mon, 9 Jan 2006 09:56:51 +0200 (EET) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id 9F5E521289; Mon, 9 Jan 2006 09:56:51 +0200 (EET) Message-ID: <009301c614f2$41d55920$0b00a8c0@forge> From: "Andy" To: "Frank Wiles" Cc: References: <001d01c6120b$0d783600$0b00a8c0@forge><20060105132006.19c7cd31.frank@wiles.org><001601c61297$20da58e0$0b00a8c0@forge> <20060106111231.28cdcb72.frank@wiles.org> Subject: Re: Improving Inner Join Performance Date: Mon, 9 Jan 2006 09:56:52 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0090_01C61503.04235F30" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at ar-sd.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.119, HTML_MESSAGE=0.001] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/52 X-Sequence-Number: 16530 This is a multi-part message in MIME format. ------=_NextPart_000_0090_01C61503.04235F30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable shared_buffers =3D 10240 effective_cache_size =3D 64000 RAM on server: 1Gb.=20 Andy. ----- Original Message -----=20 From: "Frank Wiles" To: "Andy" Sent: Friday, January 06, 2006 7:12 PM Subject: Re: [PERFORM] Improving Inner Join Performance > On Fri, 6 Jan 2006 09:59:30 +0200 > "Andy" wrote: >=20 >> Yes I have indexes an all join fields.=20 >> The tables have around 30 columns each and around 100k rows.=20 >> The database is vacuumed every hour. =20 >=20 > What are you settings for:=20 >=20 > shared_buffers=20 > effective_cache_size >=20 > And how much RAM do you have in the server?=20 >=20 > --------------------------------- > Frank Wiles > http://www.wiles.org > --------------------------------- >=20 >=20 > ------=_NextPart_000_0090_01C61503.04235F30 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

shared_buffers =3D = 10240
effective_cache_size =3D=20 64000
RAM on server: 1Gb. =

Andy.

----- Original Message -----

From: "Frank Wiles" <frank@wiles.org>
To: "Andy" <frum@ar-sd.net>
Sent: Friday, January 06, 2006 7:12 = PM
Subject: Re: [PERFORM] Improving Inner = Join=20 Performance

> On Fri, 6 Jan 2006 09:59:30 +0200
> "Andy" = <
frum@ar-sd.net> = wrote:
>=20
>> Yes I have indexes an all join fields.
>> The = tables have=20 around 30 columns each and around 100k rows.
>> The database = is=20 vacuumed every hour. 
>
>  What are you settings = for:=20
>
>  shared_buffers
> =20 effective_cache_size
>
>  And how much RAM do you have = in the=20 server?
>=20
> ---------------------------------
>   = Frank Wiles=20 <
frank@wiles.org>
>  
http://www.wiles.org
> ---------------------------------
>
>=20
>
------=_NextPart_000_0090_01C61503.04235F30-- From pgsql-performance-owner@postgresql.org Mon Jan 9 06:58:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3F4629DC801 for ; Mon, 9 Jan 2006 06:58:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39164-05 for ; Mon, 9 Jan 2006 06:58:25 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 9D4529DC810 for ; Mon, 9 Jan 2006 06:58:21 -0400 (AST) Received: from smtp8.wanadoo.fr (smtp8.wanadoo.fr [193.252.22.23]) by svr4.postgresql.org (Postfix) with ESMTP id B195F5AF068 for ; Mon, 9 Jan 2006 10:58:24 +0000 (GMT) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf0808.wanadoo.fr (SMTP Server) with ESMTP id 87E521C00237 for ; Mon, 9 Jan 2006 11:58:21 +0100 (CET) Received: from [192.168.2.50] (LNeuilly-152-21-104-92.w193-253.abo.wanadoo.fr [193.253.37.92]) by mwinf0808.wanadoo.fr (SMTP Server) with ESMTP id 520121C0021F for ; Mon, 9 Jan 2006 11:58:21 +0100 (CET) X-ME-UUID: 20060109105821336.520121C0021F@mwinf0808.wanadoo.fr Message-ID: <43C241CB.3060908@free.fr> Date: Mon, 09 Jan 2006 11:58:19 +0100 From: TNO User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: fr, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: [PERFORMANCE] Beetwen text and varchar field X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/53 X-Sequence-Number: 16531 Hello what is the best for a char field with less than 1000 characters? a text field or a varchar(1000) thanks From pgsql-performance-owner@postgresql.org Mon Jan 9 07:49:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5AB329DCA2C for ; Mon, 9 Jan 2006 07:49:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48066-03 for ; Mon, 9 Jan 2006 07:49:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id B5DB19DCA30 for ; Mon, 9 Jan 2006 07:49:34 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EvvWq-0007h8-BZ; Mon, 09 Jan 2006 12:49:36 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1EvvWu-0007WE-00; Mon, 09 Jan 2006 12:49:40 +0100 Date: Mon, 9 Jan 2006 12:49:40 +0100 From: "Steinar H. Gunderson" To: TNO Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Beetwen text and varchar field Message-ID: <20060109114940.GB28748@uio.no> Mail-Followup-To: TNO , pgsql-performance@postgresql.org References: <43C241CB.3060908@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <43C241CB.3060908@free.fr> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/54 X-Sequence-Number: 16532 On Mon, Jan 09, 2006 at 11:58:19AM +0100, TNO wrote: > what is the best for a char field with less than 1000 characters? > a text field or a varchar(1000) They will be equivalent. text and varchar are the same type internally -- the only differences are that varchar can have a length (but does not need one), and that some casts are only defined for text. If there's really a natural thousand-character limit to the data in question, use varchar(1000); if not, use text or varchar, whatever you'd like. /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Mon Jan 9 09:51:21 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5AE4C9DC817 for ; Mon, 9 Jan 2006 09:51:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66857-08 for ; Mon, 9 Jan 2006 09:51:23 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 932479DC801 for ; Mon, 9 Jan 2006 09:51:16 -0400 (AST) Received: from mail.barettadeit.com (unknown [213.255.109.130]) by svr4.postgresql.org (Postfix) with ESMTP id 902D05AF048 for ; Mon, 9 Jan 2006 13:51:20 +0000 (GMT) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id C27D7B927 for ; Mon, 9 Jan 2006 14:55:03 +0100 (CET) Message-ID: <43C26A5F.7040702@barettadeit.com> Date: Mon, 09 Jan 2006 14:51:27 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: 500x speed-down: Wrong query plan? Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/55 X-Sequence-Number: 16533 Hello gentlemen, Although this is my first post on the list, I am a fairly experienced PostgreSQL programmer. I am writing an ERP application suite using PostgreSQL as the preferred DBMS. Let me state that the SQL DDL is automatically generated by a CASE tool from an ER model. The generated schema contains the appropriate primary key and foreign key constraints, as defined by the original ER model, as well as "reverse indexes" on foreign keys, allowing (in theory) rapid backward navigation of foreign keys in joins. Let me show a sample join of two tables in the database schema. The information provided is quite extensive. I'm sorry for that, but I think it is better to provide the list with all the relevant information. Package: postgresql-7.4 Priority: optional Section: misc Installed-Size: 7860 Maintainer: Martin Pitt Architecture: i386 Version: 1:7.4.9-2 Table "public.articolo" Column | Type | Modifiers -------------------------+-----------------------------+----------------------------------------------------- bigoid | bigint | not null default nextval('object_bigoid_seq'::text) metadata | text | finalized | timestamp without time zone | xdbs_created | timestamp without time zone | default now() xdbs_modified | timestamp without time zone | id_ente | text | not null barcode | text | tipo | text | id_produttore | text | not null id_articolo | text | not null venditore_id_ente | text | id_prodotto | text | aggregato_id_ente | text | aggregato_id_produttore | text | aggregato_id_articolo | text | descr | text | url | text | datasheet | text | scheda_sicurezza | text | peso | numeric | lunghezza | numeric | larghezza | numeric | altezza | numeric | volume | numeric | max_strati | numeric | um | text | Indexes: "articolo_pkey" primary key, btree (id_ente, id_produttore, id_articolo) "articolo_unique_barcode_index" unique, btree (barcode) "articolo_modified_index" btree (xdbs_modified) Foreign-key constraints: "$4" FOREIGN KEY (um) REFERENCES um(um) DEFERRABLE INITIALLY DEFERRED "$3" FOREIGN KEY (aggregato_id_ente, aggregato_id_produttore, aggregato_id_articolo) REFERENCES articolo(id_ente, id_produttore, id_articolo) DEFERRABLE INITIALLY DEFERRED "$2" FOREIGN KEY (venditore_id_ente, id_prodotto) REFERENCES prodotto(venditore_id_ente, id_prodotto) DEFERRABLE INITIALLY DEFERRED "$1" FOREIGN KEY (id_ente) REFERENCES ente(id_ente) DEFERRABLE INITIALLY DEFERRED Rules: articolo_delete_rule AS ON DELETE TO articolo DO INSERT INTO articolo_trash (id_ente, id_produttore, id_articolo, venditore_id_ente, id_prodotto, aggregato_id_ente, aggregato_id_produttore, aggregato_id_articolo, descr, url, datasheet, scheda_sicurezza, peso, lunghezza, larghezza, altezza, volume, max_strati, um, barcode, tipo, bigoid, metadata, finalized, xdbs_created, xdbs_modified) VALUES (old.id_ente, old.id_produttore, old.id_articolo, old.venditore_id_ente, old.id_prodotto, old.aggregato_id_ente, old.aggregato_id_produttore, old.aggregato_id_articolo, old.descr, old.url, old.datasheet, old.scheda_sicurezza, old.peso, old.lunghezza, old.larghezza, old.altezza, old.volume, old.max_strati, old.um, old.barcode, old.tipo, old.bigoid, old.metadata, old.finalized, old.xdbs_created, old.xdbs_modified) articolo_update_rule AS ON UPDATE TO articolo WHERE ((new.xdbs_modified)::timestamp with time zone <> now()) DO INSERT INTO articolo_trash (id_ente, id_produttore, id_articolo, venditore_id_ente, id_prodotto, aggregato_id_ente, aggregato_id_produttore, aggregato_id_articolo, descr, url, datasheet, scheda_sicurezza, peso, lunghezza, larghezza, altezza, volume, max_strati, um, barcode, tipo, bigoid, metadata, finalized, xdbs_created, xdbs_modified) VALUES (old.id_ente, old.id_produttore, old.id_articolo, old.venditore_id_ente, old.id_prodotto, old.aggregato_id_ente, old.aggregato_id_produttore, old.aggregato_id_articolo, old.descr, old.url, old.datasheet, old.scheda_sicurezza, old.peso, old.lunghezza, old.larghezza, old.altezza, old.volume, old.max_strati, old.um, old.barcode, old.tipo, old.bigoid, old.metadata, old.finalized, old.xdbs_created, old.xdbs_modified) Triggers: articolo_update_trigger BEFORE UPDATE ON articolo FOR EACH ROW EXECUTE PROCEDURE xdbs_update_trigger() Inherits: object, barcode Table "public.ubicazione" Column | Type | Modifiers ---------------+-----------------------------+----------------------------------------------------- bigoid | bigint | not null default nextval('object_bigoid_seq'::text) metadata | text | finalized | timestamp without time zone | xdbs_created | timestamp without time zone | default now() xdbs_modified | timestamp without time zone | id_ente | text | not null barcode | text | tipo | text | id_magazzino | text | not null id_settore | text | not null id_area | text | not null id_ubicazione | text | not null flavor | text | peso_max | numeric | lunghezza | numeric | larghezza | numeric | altezza | numeric | volume_max | numeric | inventario | integer | default 0 allarme | text | manutenzione | text | id_produttore | text | id_articolo | text | quantita | numeric | in_prelievo | numeric | in_deposito | numeric | lotto | text | scadenza | date | Indexes: "ubicazione_pkey" primary key, btree (id_ente, id_magazzino, id_settore, id_area, id_ubicazione) "ubicazione_id_ubicazione_key" unique, btree (id_ubicazione) "ubicazione_fkey_articolo" btree (id_ente, id_produttore, id_articolo) "ubicazione_modified_index" btree (xdbs_modified) Foreign-key constraints: "$5" FOREIGN KEY (id_ente, id_produttore, id_articolo) REFERENCES articolo(id_ente, id_produttore, id_articolo) DEFERRABLE INITIALLY DEFERRED "$4" FOREIGN KEY (manutenzione) REFERENCES manutenzione(manutenzione) DEFERRABLE INITIALLY DEFERRED "$3" FOREIGN KEY (allarme) REFERENCES allarme(allarme) DEFERRABLE INITIALLY DEFERRED "$2" FOREIGN KEY (flavor) REFERENCES flavor(flavor) DEFERRABLE INITIALLY DEFERRED "$1" FOREIGN KEY (id_ente, id_magazzino, id_settore, id_area) REFERENCES area(id_ente, id_magazzino, id_settore, id_area) DEFERRABLE INITIALLY DEFERRED Rules: ubicazione_delete_rule AS ON DELETE TO ubicazione DO INSERT INTO ubicazione_trash (id_ente, id_magazzino, id_settore, id_area, id_ubicazione, flavor, peso_max, lunghezza, larghezza, altezza, volume_max, inventario, allarme, manutenzione, id_produttore, id_articolo, quantita, in_prelievo, in_deposito, lotto, scadenza, barcode, tipo, bigoid, metadata, finalized, xdbs_created, xdbs_modified) VALUES (old.id_ente, old.id_magazzino, old.id_settore, old.id_area, old.id_ubicazione, old.flavor, old.peso_max, old.lunghezza, old.larghezza, old.altezza, old.volume_max, old.inventario, old.allarme, old.manutenzione, old.id_produttore, old.id_articolo, old.quantita, old.in_prelievo, old.in_deposito, old.lotto, old.scadenza, old.barcode, old.tipo, old.bigoid, old.metadata, old.finalized, old.xdbs_created, old.xdbs_modified) ubicazione_update_rule AS ON UPDATE TO ubicazione WHERE ((new.xdbs_modified)::timestamp with time zone <> now()) DO INSERT INTO ubicazione_trash (id_ente, id_magazzino, id_settore, id_area, id_ubicazione, flavor, peso_max, lunghezza, larghezza, altezza, volume_max, inventario, allarme, manutenzione, id_produttore, id_articolo, quantita, in_prelievo, in_deposito, lotto, scadenza, barcode, tipo, bigoid, metadata, finalized, xdbs_created, xdbs_modified) VALUES (old.id_ente, old.id_magazzino, old.id_settore, old.id_area, old.id_ubicazione, old.flavor, old.peso_max, old.lunghezza, old.larghezza, old.altezza, old.volume_max, old.inventario, old.allarme, old.manutenzione, old.id_produttore, old.id_articolo, old.quantita, old.in_prelievo, old.in_deposito, old.lotto, old.scadenza, old.barcode, old.tipo, old.bigoid, old.metadata, old.finalized, old.xdbs_created, old.xdbs_modified) Triggers: ubicazione_update_trigger BEFORE UPDATE ON ubicazione FOR EACH ROW EXECUTE PROCEDURE xdbs_update_trigger() Inherits: object, barcode ****************************************************************************** Here is the first join. This is planned correctly. Execution times are irrelevant. dmd-freerp-1-alex=# explain analyze SELECT * FROM articolo JOIN ubicazione USING (id_ente, id_produttore, id_articolo) WHERE ubicazione.id_ente = 'dmd' AND allarme IS NULL AND manutenzione IS NULL AND ubicazione.xdbs_modified > '2006-01-08 18:25:00+01'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..8.73 rows=1 width=1146) (actual time=0.247..0.247 rows=0 loops=1) -> Index Scan using ubicazione_modified_index on ubicazione (cost=0.00..3.03 rows=1 width=536) (actual time=0.239..0.239 rows=0 loops=1) Index Cond: (xdbs_modified > '2006-01-08 18:25:00'::timestamp without time zone) Filter: ((id_ente = 'dmd'::text) AND (allarme IS NULL) AND (manutenzione IS NULL)) -> Index Scan using articolo_pkey on articolo (cost=0.00..5.69 rows=1 width=653) (never executed) Index Cond: (('dmd'::text = articolo.id_ente) AND (articolo.id_produttore = "outer".id_produttore) AND (articolo.id_articolo = "outer".id_articolo)) Total runtime: 0.556 ms (7 rows) ********************************************************************* Here's the second join on the same tables. This times a different set of indexes should be used to perform the join, but even in this case I would expect the planner to generate a nested loop of two index scans. Instead, this is what happens. dmd-freerp-1-alex=# explain analyze SELECT * FROM articolo JOIN ubicazione USING (id_ente, id_produttore, id_articolo) WHERE ubicazione.id_ente = 'dmd' AND allarme IS NULL AND manutenzione IS NULL AND articolo.xdbs_modified > '2006-01-08 18:25:00+01'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..1017.15 rows=1 width=1146) (actual time=258.648..258.648 rows=0 loops=1) -> Seq Scan on ubicazione (cost=0.00..1011.45 rows=1 width=536) (actual time=0.065..51.617 rows=12036 loops=1) Filter: ((id_ente = 'dmd'::text) AND (allarme IS NULL) AND (manutenzione IS NULL)) -> Index Scan using articolo_pkey on articolo (cost=0.00..5.69 rows=1 width=653) (actual time=0.011..0.011 rows=0 loops=12036) Index Cond: (('dmd'::text = articolo.id_ente) AND (articolo.id_produttore = "outer".id_produttore) AND (articolo.id_articolo = "outer".id_articolo)) Filter: (xdbs_modified > '2006-01-08 18:25:00'::timestamp without time zone) Total runtime: 258.975 ms (7 rows) This time, a sequential scan on the rightmost table is used to perform the join. This is quite plainly a wrong choice, since the number of tuples in the articolo having xdbs_modified > '2006-01-08 18:25:00' is 0. I also tried increasing the amount of collected statistics to 1000 with "ALTER TABLE articolo ALTER COLUMN xdbs_modified SET STATISTICS 1000" and subsequently vacuum-analyzed the db, so as to give the planner as much information as possible to realize that articolo ought to be index-scanned with the articolo_modified_index B-tree index. The correct query plan is to perform a nested loop join with an index scan on articolo using xdbs_modified_index and a corresponding index scan on ubicazione using ubicazione_fkey_articolo. I am currently resorting to selecting from the single tables and performing the join in the application code rather than in the DB. This is currently the only viable alternative for me, as a 500x speed-down simply cannot be tolerated. What I do not understand is why the planner behaves so differently in the two cases. Any ideas? Would upgrading to more recent versions of postgresql make any difference? Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Mon Jan 9 10:37:04 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AA2F89DC8AD for ; Mon, 9 Jan 2006 10:37:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78453-01 for ; Mon, 9 Jan 2006 10:37:06 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.197]) by postgresql.org (Postfix) with ESMTP id 9592F9DC896 for ; Mon, 9 Jan 2006 10:37:00 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so2527128wxc for ; Mon, 09 Jan 2006 06:37:05 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=EgZyn9uqc7KhGG6DeGRR8T+IbXTdQgu5VXT2EC6MyifiFL9mgrDlTR1LSv4X4yZo0eAE6mq9xfC2VHBJJfKcPxpQ4N7TWzVMraUb75MHHJpXWddtjGyJxrc61Usj8lQrsgwEse3TJWu8AY0YAaaQenm+Bs9wGlXpSEJOPdHMr8w= Received: by 10.70.47.7 with SMTP id u7mr3827807wxu; Mon, 09 Jan 2006 06:37:05 -0800 (PST) Received: by 10.70.14.7 with HTTP; Mon, 9 Jan 2006 06:37:04 -0800 (PST) Message-ID: Date: Mon, 9 Jan 2006 08:37:04 -0600 From: Kelly Burkhart To: Ron Subject: Re: help tuning queries on large database Cc: pgsql-performance@postgresql.org In-Reply-To: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_22338_28722305.1136817424951" References: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/56 X-Sequence-Number: 16534 ------=_Part_22338_28722305.1136817424951 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/8/06, Ron wrote: > > > Among the other tricks having lots of RAM allows: > If some of your tables are Read Only or VERY rarely written to, you > can preload them at boot time and make them RAM resident using the > /etc/tmpfs trick. What is the /etc/tmpfs trick? -K ------=_Part_22338_28722305.1136817424951 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/8/06, Ron <rjpeace@earthlink.net> wrote:
<snip>
Among the other tricks having lots of RAM allows:
If som= e of your tables are Read Only or VERY rarely written to, you
can preloa= d them at boot time and make them RAM resident using the
/etc/tmpfs tric= k.

What is the /etc/tmpfs trick?

-K


------=_Part_22338_28722305.1136817424951-- From pgsql-performance-owner@postgresql.org Mon Jan 9 11:08:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 408E39DC88F for ; Mon, 9 Jan 2006 11:08:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83693-03 for ; Mon, 9 Jan 2006 11:08:47 -0400 (AST) X-Greylist: delayed 00:06:40.206759 by SQLgrey- Received: from roast.hq.mobyt.it (194-185-112-82.f5.ngi.it [194.185.112.82]) by postgresql.org (Postfix) with SMTP id 085F69DC89C for ; Mon, 9 Jan 2006 11:08:39 -0400 (AST) Received: (qmail 12763 invoked from network); 9 Jan 2006 15:58:56 +0100 Received: from webdev.hq.mobyt.it (HELO ?10.20.20.4?) (10.20.20.4) by 0 with SMTP; 9 Jan 2006 15:58:56 +0100 Message-ID: <43C27AFA.7060604@beccati.com> Date: Mon, 09 Jan 2006 16:02:18 +0100 From: Matteo Beccati User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Alessandro Baretta CC: pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong query plan? References: <43C26A5F.7040702@barettadeit.com> In-Reply-To: <43C26A5F.7040702@barettadeit.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/57 X-Sequence-Number: 16535 Hi Alessandro, > Nested Loop (cost=0.00..1017.15 rows=1 width=1146) (actual > time=258.648..258.648 rows=0 loops=1) > -> Seq Scan on ubicazione (cost=0.00..1011.45 rows=1 width=536) > (actual time=0.065..51.617 rows=12036 loops=1) > Filter: ((id_ente = 'dmd'::text) AND (allarme IS NULL) AND > (manutenzione IS NULL)) The problem seems here. The planner expects one matching row (and that's why it chooses a nested loop), but 12036 rows are matching this condition. Are you sure that you recentrly ANALYZED the table "ubicazione"? If so, try to increase statistics for the id_ente column. P.S. There is also an italian mailing list, if you are interested :) Best regards -- Matteo Beccati http://phpadsnew.com http://phppgads.com From pgsql-performance-owner@postgresql.org Mon Jan 9 11:30:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 363249DC806 for ; Mon, 9 Jan 2006 11:30:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86693-04 for ; Mon, 9 Jan 2006 11:30:25 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by postgresql.org (Postfix) with ESMTP id 9D35F9DC83D for ; Mon, 9 Jan 2006 11:30:17 -0400 (AST) Received: by wproxy.gmail.com with SMTP id i28so2648263wra for ; Mon, 09 Jan 2006 07:30:22 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=W11kni/t21JDT7lM1EB+2ogPXzV8Ca4A7Qr/D2DtQIcRexynaQNYDkkc1Vs/0ZrbPs9DfriSHO0JBbJgkoYyvpSwIcIRtVU3whjNeapO2PWdbXZ0MKanq3HU0Cj92hkGoB78qMjTlIoH7DnyU1sgtDzdvQTgEI071RHqTe94SS8= Received: by 10.54.84.1 with SMTP id h1mr8197069wrb; Mon, 09 Jan 2006 07:30:21 -0800 (PST) Received: by 10.54.92.14 with HTTP; Mon, 9 Jan 2006 07:30:21 -0800 (PST) Message-ID: Date: Mon, 9 Jan 2006 10:30:21 -0500 From: Jaime Casanova To: Alessandro Baretta Subject: Re: 500x speed-down: Wrong query plan? Cc: pgsql-performance@postgresql.org In-Reply-To: <43C26A5F.7040702@barettadeit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <43C26A5F.7040702@barettadeit.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.081 required=5 tests=[AWL=0.081] X-Spam-Score: 0.081 X-Spam-Level: X-Archive-Number: 200601/58 X-Sequence-Number: 16536 On 1/9/06, Alessandro Baretta wrote: > Hello gentlemen, > > Although this is my first post on the list, I am a fairly experienced Pos= tgreSQL > programmer. I am writing an ERP application suite using PostgreSQL as the > preferred DBMS. Let me state that the SQL DDL is automatically generated = by a > CASE tool from an ER model. The generated schema contains the appropriate > primary key and foreign key constraints, as defined by the original ER mo= del, as > well as "reverse indexes" on foreign keys, allowing (in theory) rapid bac= kward > navigation of foreign keys in joins. > > Let me show a sample join of two tables in the database schema. The infor= mation > provided is quite extensive. I'm sorry for that, but I think it is better= to > provide the list with all the relevant information. > > Package: postgresql-7.4 maybe, because you are in developing state, you can start to think in upgrading to 8.1 -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;) From pgsql-performance-owner@postgresql.org Mon Jan 9 11:40:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D46DA9DC896 for ; Mon, 9 Jan 2006 11:40:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87912-07 for ; Mon, 9 Jan 2006 11:40:36 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.196]) by postgresql.org (Postfix) with ESMTP id 9CC459DC83D for ; Mon, 9 Jan 2006 11:40:27 -0400 (AST) Received: by nproxy.gmail.com with SMTP id i2so245388nfe for ; Mon, 09 Jan 2006 07:40:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=jLuQj8wz/7HWIvj5VbQ30b7kMhdMTWoICWSC9GncWrofkLJHRa4i7Ev0pkw+yYa+PbSunh16K0a8tqQA/bF/s9UezlRRSPbgiJNghzf4KYnQGStc14b8FGcAUoEB+hlDFW1xloBT+snAZNRNFOyCsK9/RyWSgbktnHGccfei00w= Received: by 10.48.218.8 with SMTP id q8mr118848nfg; Mon, 09 Jan 2006 07:40:31 -0800 (PST) Received: by 10.48.164.6 with HTTP; Mon, 9 Jan 2006 07:40:31 -0800 (PST) Message-ID: <45b42ce40601090740q29e441ffh6407c38f614d5b50@mail.gmail.com> Date: Mon, 9 Jan 2006 15:40:31 +0000 From: Harry Jackson To: pgsql-performance@postgresql.org Subject: Re: help tuning queries on large database In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 Content-Disposition: inline References: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/59 X-Sequence-Number: 16537 T24gMS85LzA2LCBLZWxseSBCdXJraGFydCA8a2VsbHkuYnVya2hhcnRAZ21haWwuY29tPiB3cm90 ZToKPiBPbiAxLzgvMDYsIFJvbiA8cmpwZWFjZUBlYXJ0aGxpbmsubmV0PiB3cm90ZToKPiA+IDxz bmlwPgo+ID4gQW1vbmcgdGhlIG90aGVyIHRyaWNrcyBoYXZpbmcgbG90cyBvZiBSQU0gYWxsb3dz Ogo+ID4gSWYgc29tZSBvZiB5b3VyIHRhYmxlcyBhcmUgUmVhZCBPbmx5IG9yIFZFUlkgcmFyZWx5 IHdyaXR0ZW4gdG8sIHlvdQo+ID4gY2FuIHByZWxvYWQgdGhlbSBhdCBib290IHRpbWUgYW5kIG1h a2UgdGhlbSBSQU0gcmVzaWRlbnQgdXNpbmcgdGhlCj4gPiAvZXRjL3RtcGZzIHRyaWNrLgo+Cj4g IFdoYXQgaXMgdGhlIC9ldGMvdG1wZnMgdHJpY2s/CgpJIHRoaW5rIGhlIG1lYW5zIHlvdSBjYW4g Y3JlYXRlIGEgZGlyZWN0b3J5IHRoYXQgbW91bnRzIGFuZCBhcmVhIG9mClJBTS4gSWYgeW91IHB1 dCB0aGUgdGFibGVzIG9uIGl0IHRoZW4gaXQgd2lsbCBiZSB2ZXJ5IGZhc3QuIEkgd291bGQKbm90 IHJlY29tbWVuZCBpdCBmb3IgYW55dGhpbmcgeW91IGNhbm5vdCBhZmZvcmQgdG8gbG9vc2UuCgpJ IGhhdmUgYWxzbyB0cmllZCBpdCBhbmQgZm91bmQgdGhhdCBpdCBkaWQgbm90IHByb2R1Y2UgYXMg Z29vZCBhcwpwZXJmb3JtYW5jZSBhcyBJIGV4cGVjdGVkLgoKLS0KSGFycnkKaHR0cDovL3d3dy5o amFja3Nvbi5vcmcKaHR0cDovL3d3dy51a2x1Zy5jby51awo= From pgsql-hackers-owner@postgresql.org Mon Jan 9 11:48:20 2006 X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 098B09DC806 for ; Mon, 9 Jan 2006 11:48:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90315-10 for ; Mon, 9 Jan 2006 11:48:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.skype.net (mail.skype.net [195.215.8.149]) by postgresql.org (Postfix) with ESMTP id A208A9DC809 for ; Mon, 9 Jan 2006 11:48:16 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.skype.net (Postfix) with ESMTP id 52E8E4DD95; Mon, 9 Jan 2006 16:48:20 +0100 (CET) Received: from [192.168.0.95] (joltid-gw.joltid.org [195.50.194.24]) by mail.skype.net (Postfix) with ESMTP id 39AF34DD93; Mon, 9 Jan 2006 16:48:17 +0100 (CET) Subject: Re: Stats collector performance improvement From: Hannu Krosing To: Greg Stark Cc: Simon Riggs , Tom Lane , Qingqing Zhou , pgsql-hackers@postgresql.org In-Reply-To: <87wtha1x87.fsf@stark.xeocode.com> References: <200601021840.k02Ieed21704@candle.pha.pa.us> <11924.1136233224@sss.pgh.pa.us> <12503.1136238525@sss.pgh.pa.us> <1136281253.5052.113.camel@localhost.localdomain> <1136324574.4256.17.camel@localhost.localdomain> <87wtha1x87.fsf@stark.xeocode.com> Content-Type: text/plain; charset=utf-8 Date: Mon, 09 Jan 2006 17:48:21 +0200 Message-Id: <1136821701.4076.1.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.024 required=5 tests=[AWL=0.024] X-Spam-Score: 0.024 X-Spam-Level: X-Archive-Number: 200601/289 X-Sequence-Number: 78393 Ühel kenal päeval, P, 2006-01-08 kell 11:49, kirjutas Greg Stark: > Hannu Krosing writes: > > > Interestingly I use pg_stat_activity view to watch for stuck backends, > > "stuck" in the sense that they have not noticed when client want away > > and are now waitin the TCP timeout to happen. I query for backends which > > have been in "" state for longer than XX seconds. I guess that at > > least some kind of indication for this should be available. > > You mean like the tcp_keepalives_idle option? > > http://www.postgresql.org/docs/8.1/interactive/runtime-config-connection.html#GUC-TCP-KEEPALIVES-IDLE > Kind of, only I'd like to be able to set timeouts less than 120 minutes. from: http://developer.apple.com/documentation/mac/NetworkingOT/NetworkingWOT-390.html#HEADING390-0 kp_timeout Set the requested timeout value, in minutes. Specify a value of T_UNSPEC to use the default value. You may specify any positive value for this field of 120 minutes or greater. The timeout value is not an absolute requirement; if you specify a value less than 120 minutes, TCP will renegotiate a timeout of 120 minutes. ----------- Hannu From pgsql-performance-owner@postgresql.org Mon Jan 9 11:59:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DD0A39DC97F for ; Mon, 9 Jan 2006 11:59:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94165-04 for ; Mon, 9 Jan 2006 11:59:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.204]) by postgresql.org (Postfix) with ESMTP id 829469DC809 for ; Mon, 9 Jan 2006 11:59:35 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so115838uge for ; Mon, 09 Jan 2006 07:59:34 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=Y+OR/u8Acgyur69w3M04+rYukEdtfxwZJfMJF4pLp8RPdDyGfSN7c5nfw4unjleggFFnj8NNjg6WnA7MKWsCjBs4w/0OMtA/CpBGjHoUlLf/ohSSXCl9zI+l3LLb6mOcyePmOxT3yc8+HxWcsq5otLx4fWByYt+5I8lVQiOPbdE= Received: by 10.67.22.9 with SMTP id z9mr7598266ugi; Mon, 09 Jan 2006 07:59:33 -0800 (PST) Received: from ?192.168.3.4? ( [81.182.248.121]) by mx.gmail.com with ESMTP id m1sm11878125ugc.2006.01.09.07.59.33; Mon, 09 Jan 2006 07:59:33 -0800 (PST) Message-ID: <43C28854.9000605@gmail.com> Date: Mon, 09 Jan 2006 16:59:16 +0100 From: =?UTF-8?B?U3rFsWNzIEfDoWJvcg==?= User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" Subject: Re: Avoiding cartesian product References: <002b01c610e5$21cc7340$3100000a@demo1> In-Reply-To: <002b01c610e5$21cc7340$3100000a@demo1> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/60 X-Sequence-Number: 16538 Dear Virag, AFAIK aggregates aren't indexed in postgres (at least not before 8.1, which indexes min and max, iirc). Also, I don't think you need to exactly determine the trace_id. Try this one (OTOH; might be wrong): select DISTINCT ON (a.trace_id, a.seq_no) -- See below b.gc_minor - a.gc_minor, b.gc_major - a.gc_major from jam_trace_sys a, jam_trace_sys b where a.trace_id = 22 and b.trace_id = a.trace_id and b.seq_no > a.seq_no -- Simply ">" is enough order by a.trace_id, a.seq_no, b.seq_no; -- DISTINCT, see below The trick is that DISTINCT takes the first one in each group (IIRC it is granted, at least someone told me on one of these lists :) ) so if you order by the DISTINCT attributes and then by b.seq_no, you'll get the smallest of appropriate b.seq_no values for each DISTINCT values. The idea of DISTINCTing by both columns is to make sure the planner finds the index. (lately I had a similar problem: WHERE a=1 ORDER BY b LIMIT 1 used an index on b, instead of an (a,b) index. Using ORDER BY a,b solved it) HTH, -- G. On 2006.01.04. 5:12, Virag Saksena wrote: > > I have a table which stores cumulative values > I would like to display/chart the deltas between successive data > collections > > If my primary key only increments by 1, I could write a simple query > > select b.gc_minor - a.gc_minor, b.gc_major - a.gc_major > from jam_trace_sys a, jam_trace_sys b > where a.trace_id = 22 > and b.trace_id = a.trace_id > and b.seq_no = a.seq_no + 1 > order by a.seq_no; > > However the difference in sequence number is variable. > So (in Oracle) I used to extract the next seq_no using a correlated > sub-query > > select b.gc_minor - a.gc_minor, b.gc_major - a.gc_major > from jam_trace_sys a, jam_trace_sys b > where a.trace_id = 22 > and (b.trace_id, b.seq_no) = > (select a.trace_id, min(c.seq_no) from jam_trace_sys c > where c.trace_id = a.trace_id and c.seq_no > a.seq_no) > order by a.seq_no; > > For every row in A, The correlated sub-query from C will execute > With an appropriate index, it will just descend the index Btree > go one row to the right and return that row (min > :value) > and join to table B > > SELECT STATEMENT > SORT ORDER BY > TABLE ACCESS BY INDEX ROWID JAM_TRACE_SYS B > NESTED LOOPS > TABLE ACCESS BY INDEX ROWID JAM_TRACE_SYS A > INDEX RANGE SCAN JAM_TRACE_SYS_N1 A > INDEX RANGE SCAN JAM_TRACE_SYS_N1 B > SORT AGGREGATE > INDEX RANGE SCAN JAM_TRACE_SYS_N1 C > > In postgreSQL A and B are doing a cartesian product > then C gets executed for every row in this cartesian product > and most of the extra rows get thrown out. > Is there any way to force an execution plan like above where the > correlated subquery runs before going to B. > The table is small right now, but it will grow to have millions of rows > QUERY PLAN > ----------------------------------------------------------------------------------------------------------------------------------- > Sort (cost=124911.81..124944.84 rows=13213 width=20) (actual > time=13096.754..13097.053 rows=149 loops=1) > Sort Key: a.seq_no > -> Nested Loop (cost=4.34..124007.40 rows=13213 width=20) (actual > time=1948.300..13096.329 rows=149 loops=1) > Join Filter: (subplan) > -> Seq Scan on jam_trace_sys b (cost=0.00..3.75 rows=175 > width=16) (actual time=0.005..0.534 rows=175 loops=1) > -> Materialize (cost=4.34..5.85 rows=151 width=16) (actual > time=0.002..0.324 rows=150 loops=175) > -> Seq Scan on jam_trace_sys a (cost=0.00..4.19 > rows=151 width=16) (actual time=0.022..0.687 rows=150 loops=1) > Filter: (trace_id = 22) > SubPlan > -> Aggregate (cost=4.67..4.67 rows=1 width=4) (actual > time=0.486..0.488 rows=1 loops=26250) > -> Seq Scan on jam_trace_sys c (cost=0.00..4.62 > rows=15 width=4) (actual time=0.058..0.311 rows=74 loops=26250) > Filter: ((trace_id = $0) AND (seq_no > $1)) > Total runtime: 13097.557 ms > (13 rows) > > pglnx01=> \d jam_trace_sys > Table "public.jam_trace_sys" > Column | Type | Modifiers > -----------------+---------+----------- > trace_id | integer | > seq_no | integer | > cpu_utilization | integer | > gc_minor | integer | > gc_major | integer | > heap_used | integer | > Indexes: > "jam_trace_sys_n1" btree (trace_id, seq_no) > > pglnx01=> select count(*) from jam_trace_Sys ; > count > ------- > 175 > (1 row) > > pglnx01=> select trace_id, count(*) from jam_trace_sys group by trace_id ; > trace_id | count > ----------+------- > 15 | 2 > 18 | 21 > 22 | 150 > 16 | 2 > (4 rows) From pgsql-performance-owner@postgresql.org Mon Jan 9 12:23:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 485989DCA18 for ; Mon, 9 Jan 2006 12:22:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96591-06 for ; Mon, 9 Jan 2006 12:22:57 -0400 (AST) X-Greylist: delayed 02:31:37.52876 by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 83AE89DC9C8 for ; Mon, 9 Jan 2006 12:22:56 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id DE4147D2589; Mon, 9 Jan 2006 17:26:43 +0100 (CET) Message-ID: <43C28DEA.60801@barettadeit.com> Date: Mon, 09 Jan 2006 17:23:06 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Matteo Beccati Cc: pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong query plan? References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> In-Reply-To: <43C27AFA.7060604@beccati.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/61 X-Sequence-Number: 16539 Matteo Beccati wrote: > Hi Alessandro, > >> Nested Loop (cost=0.00..1017.15 rows=1 width=1146) (actual >> time=258.648..258.648 rows=0 loops=1) >> -> Seq Scan on ubicazione (cost=0.00..1011.45 rows=1 width=536) >> (actual time=0.065..51.617 rows=12036 loops=1) >> Filter: ((id_ente = 'dmd'::text) AND (allarme IS NULL) AND >> (manutenzione IS NULL)) > > > The problem seems here. The planner expects one matching row (and that's > why it chooses a nested loop), but 12036 rows are matching this condition. > > Are you sure that you recentrly ANALYZED the table "ubicazione"? If so, > try to increase statistics for the id_ente column. No, this is not the problem. I increased the amount of statistics with ALTER TABLE ... SET STATISTICS 1000, which is as much as I can have. The problem is that the planner simply ignores the right query plan, which is orders of magnitude less costly. Keep in mind that the XDBS--the CASE tool I use--makes heavy use of indexes, and generates all relevant indexes in relation to the join paths which are implicit in the ER model "relations". In this case, both ubicazione and articolo have indexes on the join fields: Indexes: "articolo_pkey" primary key, btree (id_ente, id_produttore, id_articolo) "ubicazione_fkey_articolo" btree (id_ente, id_produttore, id_articolo) Notice that only the "articolo_pkey" is a unique index, while "ubicazione_fkey_articolo" allows duplicates. This second index is not used by the planner. Both tables also have a "bookkeeping" index on xdbs_modified. I am selecting "recently inserted or updated" tuples, which are usually a very small fraction of the table--if there are any. The index on xdbs_modified is B-tree allowing a very quick index scan to find the few tuples having xdbs_modified > '[some recent timestamp]'. Hence, the optimal plan for both queries is to perform an index scan using the _modified_index on the table upon which I specify the xdbs_modified > '...' condition, and the join-fields index on the other table. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Sat Jan 14 01:50:16 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E9ACC9DCA1C for ; Mon, 9 Jan 2006 13:10:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10744-09 for ; Mon, 9 Jan 2006 13:10:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 953959DC9F2 for ; Mon, 9 Jan 2006 13:10:09 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 260C433A6B; Mon, 9 Jan 2006 18:10:09 +0100 (MET) From: "Bernard Dhooghe" X-Newsgroups: pgsql.performance Subject: >= forces row compare and not index elements compare when possible Date: 9 Jan 2006 09:10:02 -0800 Organization: http://groups.google.com Lines: 71 Message-ID: <1136826602.613297.42010@f14g2000cwb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.0 uni-box.delen.be:3128 (squid/2.5.STABLE4) Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=194.78.88.169; posting-account=dAC2RA0AAABP3w9IS1tT7yDUke-pPYRn To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.179 required=5 tests=[AWL=0.251, FORGED_YAHOO_RCVD=0.928] X-Spam-Score: 1.179 X-Spam-Level: * X-Archive-Number: 200601/178 X-Sequence-Number: 16656 Suppose a table with structure: Table "public.t4" Column | Type | Modifiers --------+---------------+----------- c1 | character(10) | not null c2 | character(6) | not null c3 | date | not null c4 | character(30) | c5 | numeric(10,2) | not null Indexes: "t4_prim" PRIMARY KEY, btree (c1, c2, c3) Then 2 queries echo "explain select * from t4 where (c1,c2,c3) >= ('A','B','1990-01-01') order by c1,c2,c3"|psql test QUERY PLAN ---------------------------------------------------------------------------------- Index Scan using t4_prim on t4 (cost=0.00..54.69 rows=740 width=75) Filter: (ROW(c1, c2, c3) >= ROW('A'::bpchar, 'B'::bpchar, '1990-01-01'::date)) (2 rows) and echo "explain select * from t4 where (c1,c2,c3) >= ('A','B','1990-01-01') orde> QUERY PLAN ---------------------------------------------------------------------------------- Index Scan using t4_prim on t4 (cost=0.00..54.69 rows=740 width=75) Filter: (ROW(c1, c2, c3) >= ROW('A'::bpchar, 'B'::bpchar, '1990-01-01'::date)) (2 rows) So switching from (c1,c2,c3) compare from = to >= makes the optimizer see the where clause as a row filter, which is not really the case. Further echo "explain select * from t4 where (c1,c2) = ('A','B') order by c1,c2,c3"|ps> QUERY PLAN ------------------------------------------------------------------- Index Scan using t4_prim on t4 (cost=0.00..4.83 rows=1 width=75) Index Cond: ((c1 = 'A'::bpchar) AND (c2 = 'B'::bpchar)) (2 rows) here again the index can be used (again), the row count can be greater than one. but echo "explain select * from t4 where (c1,c2) >= ('A','B') order by c1,c2,c3"|p> QUERY PLAN ---------------------------------------------------------------------- Index Scan using t4_prim on t4 (cost=0.00..52.84 rows=740 width=75) Filter: (ROW(c1, c2) >= ROW('A'::bpchar, 'B'::bpchar)) (2 rows) So >= (or <=) is not optimized against an index where it could be. Bernard Dhooghe From pgsql-performance-owner@postgresql.org Mon Jan 9 13:23:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4617B9DC835 for ; Mon, 9 Jan 2006 13:23:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15639-08 for ; Mon, 9 Jan 2006 13:23:33 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 83F349DC86A for ; Mon, 9 Jan 2006 13:23:32 -0400 (AST) Received: from vulcan.rootr.net (deuterium.rootr.net [203.194.209.160]) by svr4.postgresql.org (Postfix) with ESMTP id EDDFD5AF054 for ; Mon, 9 Jan 2006 17:23:30 +0000 (GMT) Received: from [192.168.42.14] (meatloaf.fotap.org [63.211.45.38]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by vulcan.rootr.net (Postfix) with ESMTP id A5D273C0A for ; Mon, 9 Jan 2006 17:20:19 +0000 (UTC) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: References: Content-Type: multipart/signed; micalg=sha1; boundary=Apple-Mail-37--393594288; protocol="application/pkcs7-signature" Message-Id: <414814B8-556C-47DB-B364-A5A681CC3522@pobox.com> X-Image-Url: http://fotap.org/~osi/mail/peter.royal@pobox.com From: peter royal Subject: Re: help tuning queries on large database Date: Mon, 9 Jan 2006 12:23:15 -0500 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/62 X-Sequence-Number: 16540 --Apple-Mail-37--393594288 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 8, 2006, at 1:42 PM, Luke Lonergan wrote: > Have you tested the underlying filesystem for it's performance? > Run this: > time bash -c 'dd if=/dev/zero of=/my_file_system/bigfile bs=8k > count= && sync' This is a 2-disk RAID0 [root@bigboy /opt/alt-2]# time bash -c 'dd if=/dev/zero of=/opt/alt-2/ bigfile bs=8k count=1000000 && sync' 1000000+0 records in 1000000+0 records out real 1m27.143s user 0m0.276s sys 0m37.338s 'iostat -x' showed writes peaking at ~100MB/s > Then run this: > time dd if=/my_file_system/bigfile bs=8k of=/dev/null [root@bigboy /opt/alt-2]# time dd if=/opt/alt-2/bigfile bs=8k of=/dev/ null 1000000+0 records in 1000000+0 records out real 1m9.846s user 0m0.189s sys 0m11.099s 'iostat -x' showed reads peaking at ~116MB/s Again with kernel 2.6.15: [root@bigboy ~]# time bash -c 'dd if=/dev/zero of=/opt/alt-2/bigfile bs=8k count=1000000 && sync' 1000000+0 records in 1000000+0 records out real 1m29.144s user 0m0.204s sys 0m48.415s [root@bigboy ~]# time dd if=/opt/alt-2/bigfile bs=8k of=/dev/null 1000000+0 records in 1000000+0 records out real 1m9.701s user 0m0.168s sys 0m11.933s > And report the times here please. With your 8 disks in any of the > RAID0 > configurations you describe, you should be getting 480MB/s. In the > RAID10 > configuration you should get 240. Not anywhere near that. I'm scouring the 'net looking to see what needs to be tuned at the HW level. > You should also experiment with using larger readahead, which you can > implement like this: > blockdev --setra 16384 /dev/ > > E.g. "blockdev --setra 16384 /dev/sda" wow, this helped nicely. Without using the updated kernel, it took 28% off my testcase time. > From what you describe, one of these is likely: > - hardware isn't configured properly or a driver problem. Using the latest Areca driver, looking to see if there is some configuration that was missed. > - you need to use xfs and tune your Linux readahead Will try XFS soon, concentrating on the 'dd' speed issue first. On Jan 8, 2006, at 4:35 PM, Ron wrote: >> Areca ARC-1220 8-port PCI-E controller > > Make sure you have 1GB or 2GB of cache. Get the battery backup and > set the cache for write back rather than write through. The card we've got doesn't have a SODIMM socket, since its only an 8- port card. My understanding was that was cache used when writing? > A 2.6.12 or later based Linux distro should have NO problems using > more than 4GB or RAM. Upgraded the kernel to 2.6.15, then we were able to set the BIOS option for the 'Memory Hole' to 'Software' and it saw all 4G (under 2.6.11 we got a kernel panic with that set) >> RAID Layout: >> >> 4 2-disk RAID0 sets created > You do know that a RAID 0 set provides _worse_ data protection than > a single HD? Don't use RAID 0 for any data you want kept reliably. yup, aware of that. was planning on RAID10 for production, but just broke it out into RAID0 sets for testing (from what I read, I gathered that the read performance of RAID0 and RAID10 were comparable) thanks for all the suggestions, I'll report back as I continue testing. -pete -- (peter.royal|osi)@pobox.com - http://fotap.org/~osi --Apple-Mail-37--393594288 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGOzCCAvQw ggJdoAMCAQICAw8s0TANBgkqhkiG9w0BAQQFADBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVt YWlsIElzc3VpbmcgQ0EwHhcNMDUwNzIxMTIwNjQyWhcNMDYwNzIxMTIwNjQyWjBkMRIwEAYDVQQE EwlSb3lhbCwgSlIxDjAMBgNVBCoTBVBldGVyMRgwFgYDVQQDEw9QZXRlciBSb3lhbCwgSlIxJDAi BgkqhkiG9w0BCQEWFXBldGVyLnJveWFsQHBvYm94LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP ADCCAQoCggEBAPW/zCQAZyBIXRLanqpajpr+Q5I0ETdvKKDtEd3SjFS22fVJrAd8+uQErV6s79Jx 0ZJG1+GqexKOm5t/sRYtMWUWvJen6Utc6pd6If4mEKPq4y0LjLp2Rlk4trlXzA33z+QLsZAoJV7x DDSd/E+WZztJDELSWgWgDUHvoKbhCW35qpPiSPRrrIi4GmWg4m9b0MeCBNpIxn8in9qx2HhI5XcK zcD2ueUxcb2u99BqzQZ0dq/xaJ9cG1l/yZoBFjescJ41W0SVU4EQEf5Xqz6m7uy0/MVdTx+z944B 6oMZfAgay1icNUJjriWbVvkdkx1AZAFgSD+jpllKo/VJdMcdE6sCAwEAAaMyMDAwIAYDVR0RBBkw F4EVcGV0ZXIucm95YWxAcG9ib3guY29tMAwGA1UdEwEB/wQCMAAwDQYJKoZIhvcNAQEEBQADgYEA MmCS+sAaGppFzT8WnkkLDmbSl7DXceHtm7vpg6zsp9g9BySYxyMfHGkqXuhyI4UCfVa1Y8/YdBRJ lpCVjRbHVicCDWuWkPWc97RpiAjnv+uZNcmXQgdAtdUXTvpMoLteRkouZeGKwsXnCLyhlPYB8jvC tVTMzuMCPJZVhV7kzPMwggM/MIICqKADAgECAgENMA0GCSqGSIb3DQEBBQUAMIHRMQswCQYDVQQG EwJaQTEVMBMGA1UECBMMV2VzdGVybiBDYXBlMRIwEAYDVQQHEwlDYXBlIFRvd24xGjAYBgNVBAoT EVRoYXd0ZSBDb25zdWx0aW5nMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2VzIERpdmlz aW9uMSQwIgYDVQQDExtUaGF3dGUgUGVyc29uYWwgRnJlZW1haWwgQ0ExKzApBgkqhkiG9w0BCQEW HHBlcnNvbmFsLWZyZWVtYWlsQHRoYXd0ZS5jb20wHhcNMDMwNzE3MDAwMDAwWhcNMTMwNzE2MjM1 OTU5WjBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRk LjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwgZ8wDQYJKoZI hvcNAQEBBQADgY0AMIGJAoGBAMSmPFVzVftOucqZWh5owHUEcJ3f6f+jHuy9zfVb8hp2vX8MOmHy v1HOAdTlUAow1wJjWiyJFXCO3cnwK4Vaqj9xVsuvPAsH5/EfkTYkKhPPK9Xzgnc9A74r/rsYPge/ QIACZNenprufZdHFKlSFD0gEf6e20TxhBEAeZBlyYLf7AgMBAAGjgZQwgZEwEgYDVR0TAQH/BAgw BgEB/wIBADBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLnRoYXd0ZS5jb20vVGhhd3RlUGVy c29uYWxGcmVlbWFpbENBLmNybDALBgNVHQ8EBAMCAQYwKQYDVR0RBCIwIKQeMBwxGjAYBgNVBAMT EVByaXZhdGVMYWJlbDItMTM4MA0GCSqGSIb3DQEBBQUAA4GBAEiM0VCD6gsuzA2jZqxnD3+vrL7C F6FDlpSdf0whuPg2H6otnzYvwPQcUCCTcDz9reFhYsPZOhl+hLGZGwDFGguCdJ4lUJRix9sncVcl jd2pnDmOjCBPZV+V2vf3h9bGCE6u9uo05RAaWzVNd+NWIXiC3CEZNd4ksdMdRv9dX2VPMYIC5zCC AuMCAQEwaTBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg THRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0ECAw8s0TAJ BgUrDgMCGgUAoIIBUzAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0w NjAxMDkxNzIzMTZaMCMGCSqGSIb3DQEJBDEWBBRg7zqkp7BY228TbXHwfoVhm6SikDB4BgkrBgEE AYI3EAQxazBpMGIxCzAJBgNVBAYTAlpBMSUwIwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAoUHR5 KSBMdGQuMSwwKgYDVQQDEyNUaGF3dGUgUGVyc29uYWwgRnJlZW1haWwgSXNzdWluZyBDQQIDDyzR MHoGCyqGSIb3DQEJEAILMWugaTBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1 bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3Vp bmcgQ0ECAw8s0TANBgkqhkiG9w0BAQEFAASCAQDwpFpde5eNOKm3hEUFjs+R5XeRBkzaVXzqLVjb 6IFYOV8XsBPGyc8YPbgC4QD7KoG4gO5vSkclrt9wrQrxNC845UdI6dYttPWHnNxkr5k9B3w6MR9K 1IzZY5CPnsqcDp/kKxUqUP6E97q0swaDcn6DHeQiw8i8kzWF0Grutoyu+FmixoCjuJyLX28rN9fk MAgWthoNJISFkkkF9c/mK2tvJSR8n3VRYjfKnKG8wmnucpDJEedRIJfM67tRD7wXOsZ8S/oe/qAr jZNQKMzmM6VcMDCoAWn2oeHRGEi2uc+nqWiihvSvQ01k7QYlN/esv/UTQeYfMtjmoIiuB42fJz9c AAAAAAAA --Apple-Mail-37--393594288-- From pgsql-performance-owner@postgresql.org Mon Jan 9 14:41:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 04D129DC809 for ; Mon, 9 Jan 2006 14:41:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76490-05 for ; Mon, 9 Jan 2006 14:41:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8FD809DC806 for ; Mon, 9 Jan 2006 14:41:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k09If5rr006720; Mon, 9 Jan 2006 13:41:05 -0500 (EST) To: Alessandro Baretta cc: Matteo Beccati , pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong query plan? In-reply-to: <43C28DEA.60801@barettadeit.com> References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> <43C28DEA.60801@barettadeit.com> Comments: In-reply-to Alessandro Baretta message dated "Mon, 09 Jan 2006 17:23:06 +0100" Date: Mon, 09 Jan 2006 13:41:05 -0500 Message-ID: <6719.1136832065@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/63 X-Sequence-Number: 16541 Alessandro Baretta writes: > Matteo Beccati wrote: >> Are you sure that you recentrly ANALYZED the table "ubicazione"? If so, >> try to increase statistics for the id_ente column. > No, this is not the problem. I increased the amount of statistics with ALTER > TABLE ... SET STATISTICS 1000, which is as much as I can have. What Matteo wanted to know is if you'd done an ANALYZE afterward. ALTER TABLE SET STATISTICS doesn't in itself update the statistics. What do you get from EXPLAIN SELECT * FROM articolo WHERE articolo.xdbs_modified > '2006-01-08 18:25:00+01'; I'm curious to see how many rows the planner thinks this will produce, and whether it will use the index or not. Also, I gather from the plan choices that the condition id_ente = 'dmd' isn't very selective ... what fraction of the rows in each table satisfy that? regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 9 14:50:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A3F2E9DC84E for ; Mon, 9 Jan 2006 14:50:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83092-06 for ; Mon, 9 Jan 2006 14:50:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 59FC69DC814 for ; Mon, 9 Jan 2006 14:50:09 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id 36B247D258A; Mon, 9 Jan 2006 19:53:57 +0100 (CET) Message-ID: <43C2B06B.4050506@barettadeit.com> Date: Mon, 09 Jan 2006 19:50:19 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Matteo Beccati , pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong query plan? References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> <43C28DEA.60801@barettadeit.com> <6719.1136832065@sss.pgh.pa.us> In-Reply-To: <6719.1136832065@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/64 X-Sequence-Number: 16542 Tom Lane wrote: > Alessandro Baretta writes: > >>Matteo Beccati wrote: >> >>>Are you sure that you recentrly ANALYZED the table "ubicazione"? If so, >>>try to increase statistics for the id_ente column. > > >>No, this is not the problem. I increased the amount of statistics with ALTER >>TABLE ... SET STATISTICS 1000, which is as much as I can have. > > > What Matteo wanted to know is if you'd done an ANALYZE afterward. ALTER > TABLE SET STATISTICS doesn't in itself update the statistics. I probably forgot to mention that I have vacuum-analyze the after this operation, and, since I did not manage to get the index to work, I vacuum-analyzed several times more, just to be on the safe side. > What do you get from > > EXPLAIN SELECT * FROM articolo WHERE articolo.xdbs_modified > '2006-01-08 18:25:00+01'; > > I'm curious to see how many rows the planner thinks this will produce, > and whether it will use the index or not. dmd-freerp-1-alex=# EXPLAIN ANALYZE SELECT * FROM articolo WHERE articolo.xdbs_modified > '2006-01-08 18:25:00+01'; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using articolo_modified_index on articolo (cost=0.00..3914.91 rows=17697 width=653) (actual time=0.032..0.032 rows=0 loops=1) Index Cond: (xdbs_modified > '2006-01-08 18:25:00'::timestamp without time zone) Total runtime: 0.150 ms (3 rows) The planner gets tricked only by *SOME* join queries. > Also, I gather from the plan choices that the condition id_ente = 'dmd' > isn't very selective ... what fraction of the rows in each table > satisfy that? In most situation, this condition selects all the tuples. "id_ente" selects the "owner of the data". Since, in most situations, companies do not share a database between them--although the application allows it--filtering according to 'id_ente' is like to filtering at all. Yet, this field is used in the indexes, so the condition ought to be specified in the queries anyhow. -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-admin-owner@postgresql.org Mon Jan 9 14:54:54 2006 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 41EEB9DC944 for ; Mon, 9 Jan 2006 14:54:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84911-04 for ; Mon, 9 Jan 2006 14:54:50 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.193]) by postgresql.org (Postfix) with ESMTP id 909679DC835 for ; Mon, 9 Jan 2006 14:54:48 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so2571026wxc for ; Mon, 09 Jan 2006 10:54:49 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=Yjuflp2qdI4yPL7zFLpR3kELXbj4qEEtoTCVT75E10wHrCmi57+6eyLv3q1Tp126a4h83QhBnkXC8vEdoQyoskHbjXSZnery/PXnMFkL226WeMRJOlshSZ6ye1sBx/6FfccA0/TF7HJIrdp3jOPUAXrGvLfKVkCcARmC9Yb2Kec= Received: by 10.70.15.12 with SMTP id 12mr5467937wxo; Mon, 09 Jan 2006 10:54:49 -0800 (PST) Received: by 10.70.84.7 with HTTP; Mon, 9 Jan 2006 10:54:48 -0800 (PST) Message-ID: <1d219a6f0601091054q70283291v9deba2cb3c7b8fe@mail.gmail.com> Date: Mon, 9 Jan 2006 13:54:48 -0500 From: Chris Hoover To: "pgsql-admin@postgresql.org" , pgsql-performance@postgresql.org Subject: Memory Usage Question MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_84319_23632822.1136832888923" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.431 required=5 tests=[AWL=-0.212, HTML_00_10=0.642, HTML_MESSAGE=0.001] X-Spam-Score: 0.431 X-Spam-Level: X-Archive-Number: 200601/96 X-Sequence-Number: 20184 ------=_Part_84319_23632822.1136832888923 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Question, How exactly is Postgres and Linux use the memory? I have serveral databases that have multi GB indexes on very large tables. On our current servers, the indexes can fit into memory but not the data (servers have 8 - 12 GB). However, my boss is wanting to get new servers for me but does not want to keep the memory requirements as high as they ar= e now (this will allow us to get more servers to spread our 200+ databases over). Question, if I have a 4GB+ index for a table on a server with 4GB ram, and = I submit a query that does an index scan, does Postgres read the entire index= , or just read the index until it finds the matching value (our extra large indexes are primary keys). I am looking for real number to give to my boss the say either having a primary key larger than our memory is bad (and how to clearly justfify it), or it is ok. If it is ok, what are the trade offs in performance?\ Obviously, I want more memory, but I have to prove the need to my boss sinc= e it raises the cost of the servers a fair amount. Thanks for any help, Chris ------=_Part_84319_23632822.1136832888923 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Question,

How exactly is Postgres and Linux use the memory?

I have serveral databases that have multi GB indexes on very large tables.  On our current servers, the indexes can fit into memory but not the data (servers have 8 - 12 GB).  However, my boss is wanting to get new servers for me but does not want to keep the memory requirements as high as they are now (this will allow us to get more servers to spread our 200+ databases over).

Question, if I have a 4GB+ index for a table on a server with 4GB ram, and I submit a query that does an index scan, does Postgres read the entire index, or just read the index until it finds the matching value (our extra large indexes are primary keys).

I am looking for real number to give to my boss the say either having a primary key larger than our memory is bad (and how to clearly justfify it), or it is ok.

If it is ok, what are the trade offs in performance?\

Obviously, I want more memory, but I have to prove the need to my boss sinc= e it raises the cost of the servers a fair amount.

Thanks for any help,

Chris
------=_Part_84319_23632822.1136832888923-- From pgsql-performance-owner@postgresql.org Mon Jan 9 14:56:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 309519DC835 for ; Mon, 9 Jan 2006 14:56:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81073-08 for ; Mon, 9 Jan 2006 14:56:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 98AFF9DC814 for ; Mon, 9 Jan 2006 14:56:51 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k09IuowC006915; Mon, 9 Jan 2006 13:56:50 -0500 (EST) To: Alessandro Baretta cc: Matteo Beccati , pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong query plan? In-reply-to: <43C2B06B.4050506@barettadeit.com> References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> <43C28DEA.60801@barettadeit.com> <6719.1136832065@sss.pgh.pa.us> <43C2B06B.4050506@barettadeit.com> Comments: In-reply-to Alessandro Baretta message dated "Mon, 09 Jan 2006 19:50:19 +0100" Date: Mon, 09 Jan 2006 13:56:50 -0500 Message-ID: <6914.1136833010@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/66 X-Sequence-Number: 16544 Alessandro Baretta writes: > Tom Lane wrote: >> I'm curious to see how many rows the planner thinks this will produce, >> and whether it will use the index or not. > dmd-freerp-1-alex=# EXPLAIN ANALYZE SELECT * FROM articolo WHERE > articolo.xdbs_modified > '2006-01-08 18:25:00+01'; > QUERY PLAN > ------------------------------------------------------------------------------------------------------------------------------------------- > Index Scan using articolo_modified_index on articolo (cost=0.00..3914.91 > rows=17697 width=653) (actual time=0.032..0.032 rows=0 loops=1) > Index Cond: (xdbs_modified > '2006-01-08 18:25:00'::timestamp without time zone) > Total runtime: 0.150 ms > (3 rows) Well, there's your problem: 17697 rows estimated vs 0 actual. With a closer row estimate it would've probably done the right thing for the join problem. How many rows are really in the table, anyway? Could we see the pg_stats row for articolo.xdbs_modified? regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 9 15:02:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DC0899DC8A3 for ; Mon, 9 Jan 2006 15:02:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 88826-06 for ; Mon, 9 Jan 2006 15:01:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw04.mi8.com [63.240.6.44]) by postgresql.org (Postfix) with ESMTP id 38CFE9DC86A for ; Mon, 9 Jan 2006 15:01:54 -0400 (AST) Received: from 172.16.1.24 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D4)); Mon, 09 Jan 2006 14:01:44 -0500 X-Server-Uuid: C8FB4D43-1108-484A-A898-3CBCC7906230 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by d01smtp03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 9 Jan 2006 14:01:43 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Mon, 9 Jan 2006 19:01:43 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Mon, 09 Jan 2006 11:01:43 -0800 Subject: Re: help tuning queries on large database From: "Luke Lonergan" To: "peter royal" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] help tuning queries on large database Thread-Index: AcYVQYj+wSPLZwlXTgKAJVCFm3MktQADZgxN In-Reply-To: <414814B8-556C-47DB-B364-A5A681CC3522@pobox.com> MIME-Version: 1.0 X-OriginalArrivalTime: 09 Jan 2006 19:01:43.0970 (UTC) FILETIME=[21C38820:01C6154F] X-WSS-ID: 6FDC6C9212G10261419-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.285 required=5 tests=[AWL=0.032, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.285 X-Spam-Level: * X-Archive-Number: 200601/67 X-Sequence-Number: 16545 Peter, On 1/9/06 9:23 AM, "peter royal" wrote: > This is a 2-disk RAID0 Your 2-disk results look fine - what about your 8-disk results? Given that you want to run in production with RAID10, the most you should expect is 2x the 2-disk results using all 8 of your disks. If you want the best rate for production while preserving data integrity, I recommend running your Areca in RAID5, in which case you should expect 3.5x your 2-disk results (7 drives). You can assume you'll get that if you use XFS + readahead. OTOH - I'd like to see your test results anyway :-) - Luke From pgsql-admin-owner@postgresql.org Mon Jan 9 16:36:02 2006 X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 87C719DC996; Mon, 9 Jan 2006 16:35:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36644-05; Mon, 9 Jan 2006 16:35:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from flake.decibel.org (unknown [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id BD1059DC81C; Mon, 9 Jan 2006 16:35:56 -0400 (AST) Received: by flake.decibel.org (Postfix, from userid 1001) id 2AA733983A; Mon, 9 Jan 2006 14:35:58 -0600 (CST) Date: Mon, 9 Jan 2006 14:35:58 -0600 From: "Jim C. Nasby" To: Chris Hoover Cc: "pgsql-admin@postgresql.org" , pgsql-performance@postgresql.org Subject: Re: Memory Usage Question Message-ID: <20060109203558.GO3902@pervasive.com> References: <1d219a6f0601091054q70283291v9deba2cb3c7b8fe@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d219a6f0601091054q70283291v9deba2cb3c7b8fe@mail.gmail.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.081 required=5 tests=[AWL=0.081] X-Spam-Score: 0.081 X-Spam-Level: X-Archive-Number: 200601/99 X-Sequence-Number: 20187 On Mon, Jan 09, 2006 at 01:54:48PM -0500, Chris Hoover wrote: > Question, if I have a 4GB+ index for a table on a server with 4GB ram, and I > submit a query that does an index scan, does Postgres read the entire index, > or just read the index until it finds the matching value (our extra large > indexes are primary keys). Well, the idea behind an index is that if you need a specific value from it, you can get there very quickly, reading a minimum of data along the way. So basically, PostgreSQL won't normally read an entire index. > I am looking for real number to give to my boss the say either having a > primary key larger than our memory is bad (and how to clearly justfify it), > or it is ok. > > If it is ok, what are the trade offs in performance?\ > > Obviously, I want more memory, but I have to prove the need to my boss since > it raises the cost of the servers a fair amount. Well, if you add a sleep to the following code, you can tie up some amount of memory, which would allow you to simulate having less memory available. Though over time I think the kernel might decide to page that memory out, so it's not perfect. int main(int argc, char *argv[]) { if (!calloc(atoi(argv[1]), 1024*1024)) { printf("Error allocating memory.\n"); } } In a nutshell, PostgreSQL and the OS will generally work together to only cache data that is being used fairly often. In the case of a large PK index, if you're not actually reading a large distribution of the values in the index you probably aren't even caching the entire index even now. There may be some kind of linux tool that would show you what portion of a file is currently cached, which would help answer that question (but remember that hopefully whatever parts of the index are cached by PostgreSQL itself won't also be cached by the OS as well). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Mon Jan 9 16:59:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3A9619DC81C for ; Mon, 9 Jan 2006 16:59:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46765-04 for ; Mon, 9 Jan 2006 16:59:49 -0400 (AST) X-Greylist: delayed 03:36:20.780397 by SQLgrey- Received: from vulcan.rootr.net (deuterium.rootr.net [203.194.209.160]) by postgresql.org (Postfix) with ESMTP id 023AF9DC851 for ; Mon, 9 Jan 2006 16:59:45 -0400 (AST) Received: from [192.168.42.14] (meatloaf.fotap.org [63.211.45.38]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by vulcan.rootr.net (Postfix) with ESMTP id E94913C0A for ; Mon, 9 Jan 2006 20:56:41 +0000 (UTC) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: References: Content-Type: multipart/signed; micalg=sha1; boundary=Apple-Mail-43--380610352; protocol="application/pkcs7-signature" Message-Id: <5CBD78E6-FB37-442C-B7E9-6F1DA03C8AEC@pobox.com> X-Image-Url: http://fotap.org/~osi/mail/peter.royal@pobox.com From: peter royal Subject: Re: help tuning queries on large database Date: Mon, 9 Jan 2006 15:59:39 -0500 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/69 X-Sequence-Number: 16547 --Apple-Mail-43--380610352 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jan 9, 2006, at 2:01 PM, Luke Lonergan wrote: > Peter, > > On 1/9/06 9:23 AM, "peter royal" wrote: > >> This is a 2-disk RAID0 > > Your 2-disk results look fine - what about your 8-disk results? after some further research the 2-disk RAID0 numbers are not bad. I have a single drive of the same type hooked up to the SATA2 port on the motherboard to boot from, and its performance numbers are (linux 2.6.15, ext3): [root@bigboy ~]# time bash -c 'dd if=/dev/zero of=/tmp/bigfile bs=8k count=1000000 && sync' 1000000+0 records in 1000000+0 records out real 4m55.032s user 0m0.256s sys 0m47.299s [root@bigboy ~]# time dd if=/tmp/bigfile bs=8k of=/dev/null 1000000+0 records in 1000000+0 records out real 3m27.229s user 0m0.156s sys 0m13.377s so, there is a clear advantage to RAID over a single drive. now, some stats in a 8-disk configuration: 8-disk RAID0, ext3, 16k read-ahead [root@bigboy /opt/pgdata]# time bash -c 'dd if=/dev/zero of=/opt/ pgdata/bigfile bs=8k count=1000000 && sync' 1000000+0 records in 1000000+0 records out real 0m53.030s user 0m0.204s sys 0m42.015s [root@bigboy /opt/pgdata]# time dd if=/opt/pgdata/bigfile bs=8k of=/ dev/null 1000000+0 records in 1000000+0 records out real 0m23.232s user 0m0.144s sys 0m13.213s 8-disk RAID0, xfs, 16k read-ahead [root@bigboy /opt/pgdata]# time bash -c 'dd if=/dev/zero of=/opt/ pgdata/bigfile bs=8k count=1000000 && sync' 1000000+0 records in 1000000+0 records out real 0m32.177s user 0m0.212s sys 0m21.277s [root@bigboy /opt/pgdata]# time dd if=/opt/pgdata/bigfile bs=8k of=/ dev/null 1000000+0 records in 1000000+0 records out real 0m21.814s user 0m0.172s sys 0m13.881s ... WOW.. highly impressed with the XFS write speed! going to stick with that! Overall, I got a 50% boost in the overall speed of my test suite by using XFS and the 16k read-ahead. > Given that you want to run in production with RAID10, the most you > should > expect is 2x the 2-disk results using all 8 of your disks. If you > want the > best rate for production while preserving data integrity, I recommend > running your Areca in RAID5, in which case you should expect 3.5x your > 2-disk results (7 drives). You can assume you'll get that if you > use XFS + > readahead. OTOH - I'd like to see your test results anyway :-) I've been avoiding RAID5 after reading how performance drops when a drive is out/rebuilding. The performance benefit will outweigh the cost I think. Thanks for the help! -pete -- (peter.royal|osi)@pobox.com - http://fotap.org/~osi --Apple-Mail-43--380610352 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGOzCCAvQw ggJdoAMCAQICAw8s0TANBgkqhkiG9w0BAQQFADBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhh d3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVt YWlsIElzc3VpbmcgQ0EwHhcNMDUwNzIxMTIwNjQyWhcNMDYwNzIxMTIwNjQyWjBkMRIwEAYDVQQE EwlSb3lhbCwgSlIxDjAMBgNVBCoTBVBldGVyMRgwFgYDVQQDEw9QZXRlciBSb3lhbCwgSlIxJDAi BgkqhkiG9w0BCQEWFXBldGVyLnJveWFsQHBvYm94LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP ADCCAQoCggEBAPW/zCQAZyBIXRLanqpajpr+Q5I0ETdvKKDtEd3SjFS22fVJrAd8+uQErV6s79Jx 0ZJG1+GqexKOm5t/sRYtMWUWvJen6Utc6pd6If4mEKPq4y0LjLp2Rlk4trlXzA33z+QLsZAoJV7x DDSd/E+WZztJDELSWgWgDUHvoKbhCW35qpPiSPRrrIi4GmWg4m9b0MeCBNpIxn8in9qx2HhI5XcK zcD2ueUxcb2u99BqzQZ0dq/xaJ9cG1l/yZoBFjescJ41W0SVU4EQEf5Xqz6m7uy0/MVdTx+z944B 6oMZfAgay1icNUJjriWbVvkdkx1AZAFgSD+jpllKo/VJdMcdE6sCAwEAAaMyMDAwIAYDVR0RBBkw F4EVcGV0ZXIucm95YWxAcG9ib3guY29tMAwGA1UdEwEB/wQCMAAwDQYJKoZIhvcNAQEEBQADgYEA MmCS+sAaGppFzT8WnkkLDmbSl7DXceHtm7vpg6zsp9g9BySYxyMfHGkqXuhyI4UCfVa1Y8/YdBRJ lpCVjRbHVicCDWuWkPWc97RpiAjnv+uZNcmXQgdAtdUXTvpMoLteRkouZeGKwsXnCLyhlPYB8jvC tVTMzuMCPJZVhV7kzPMwggM/MIICqKADAgECAgENMA0GCSqGSIb3DQEBBQUAMIHRMQswCQYDVQQG EwJaQTEVMBMGA1UECBMMV2VzdGVybiBDYXBlMRIwEAYDVQQHEwlDYXBlIFRvd24xGjAYBgNVBAoT EVRoYXd0ZSBDb25zdWx0aW5nMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2VzIERpdmlz aW9uMSQwIgYDVQQDExtUaGF3dGUgUGVyc29uYWwgRnJlZW1haWwgQ0ExKzApBgkqhkiG9w0BCQEW HHBlcnNvbmFsLWZyZWVtYWlsQHRoYXd0ZS5jb20wHhcNMDMwNzE3MDAwMDAwWhcNMTMwNzE2MjM1 OTU5WjBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRk LjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwgZ8wDQYJKoZI hvcNAQEBBQADgY0AMIGJAoGBAMSmPFVzVftOucqZWh5owHUEcJ3f6f+jHuy9zfVb8hp2vX8MOmHy v1HOAdTlUAow1wJjWiyJFXCO3cnwK4Vaqj9xVsuvPAsH5/EfkTYkKhPPK9Xzgnc9A74r/rsYPge/ QIACZNenprufZdHFKlSFD0gEf6e20TxhBEAeZBlyYLf7AgMBAAGjgZQwgZEwEgYDVR0TAQH/BAgw BgEB/wIBADBDBgNVHR8EPDA6MDigNqA0hjJodHRwOi8vY3JsLnRoYXd0ZS5jb20vVGhhd3RlUGVy c29uYWxGcmVlbWFpbENBLmNybDALBgNVHQ8EBAMCAQYwKQYDVR0RBCIwIKQeMBwxGjAYBgNVBAMT EVByaXZhdGVMYWJlbDItMTM4MA0GCSqGSIb3DQEBBQUAA4GBAEiM0VCD6gsuzA2jZqxnD3+vrL7C F6FDlpSdf0whuPg2H6otnzYvwPQcUCCTcDz9reFhYsPZOhl+hLGZGwDFGguCdJ4lUJRix9sncVcl jd2pnDmOjCBPZV+V2vf3h9bGCE6u9uo05RAaWzVNd+NWIXiC3CEZNd4ksdMdRv9dX2VPMYIC5zCC AuMCAQEwaTBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg THRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0ECAw8s0TAJ BgUrDgMCGgUAoIIBUzAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0w NjAxMDkyMDU5MzlaMCMGCSqGSIb3DQEJBDEWBBRIvCtd1gDnoCzFcBRWqGKhdqQRlzB4BgkrBgEE AYI3EAQxazBpMGIxCzAJBgNVBAYTAlpBMSUwIwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAoUHR5 KSBMdGQuMSwwKgYDVQQDEyNUaGF3dGUgUGVyc29uYWwgRnJlZW1haWwgSXNzdWluZyBDQQIDDyzR MHoGCyqGSIb3DQEJEAILMWugaTBiMQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1 bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3Vp bmcgQ0ECAw8s0TANBgkqhkiG9w0BAQEFAASCAQDpBy0v3WHf8lpDJ8zcXWaQon+0DoIfPbg3Wb65 S8jf85PH/2fa3RZVMiHVffgHUmvnS3XnmnGPUyupl1GvX6mcxH9mUxfqkmukX+UvH+jYMcibJb/3 kaIkNiwIj/VZraxphwa5d1I56WPfZeuDcbeg5IgApr1WQ7Nf/0w5XN4q7npqFWshY0v1/Y+h1pnn 2HG243R077TKtCfPt8G6WS5ABPNwsEq/44yT993B4Gr2BEjNHaGccCQIX4GtRgzMKXnz+X9LbH5x snC6c9wH4EDn3ED76mgVHnHk/l7ZDQcmvIfXss8kubhTmS5C0lr/xXd10puj5HSxqq4OSF2YMTgw AAAAAAAA --Apple-Mail-43--380610352-- From pgsql-performance-owner@postgresql.org Mon Jan 9 18:01:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 262D29DC806 for ; Mon, 9 Jan 2006 18:01:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73780-06 for ; Mon, 9 Jan 2006 18:01:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw04.mi8.com [63.240.6.44]) by postgresql.org (Postfix) with ESMTP id 6BED59DC9B6 for ; Mon, 9 Jan 2006 17:29:46 -0400 (AST) Received: from 172.16.1.25 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D4)); Mon, 09 Jan 2006 16:29:32 -0500 X-Server-Uuid: C8FB4D43-1108-484A-A898-3CBCC7906230 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 9 Jan 2006 16:29:32 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Mon, 9 Jan 2006 21:29:31 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Mon, 09 Jan 2006 13:29:30 -0800 Subject: Re: help tuning queries on large database From: "Luke Lonergan" To: "peter royal" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] help tuning queries on large database Thread-Index: AcYVX8QmxXtNzF+OQJOhbvE3iqeNtQABAIvI In-Reply-To: <5CBD78E6-FB37-442C-B7E9-6F1DA03C8AEC@pobox.com> MIME-Version: 1.0 X-OriginalArrivalTime: 09 Jan 2006 21:29:32.0388 (UTC) FILETIME=[C7C0BA40:01C61563] X-WSS-ID: 6FDC0A3612G10370531-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.29 required=5 tests=[AWL=0.037, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.29 X-Spam-Level: * X-Archive-Number: 200601/70 X-Sequence-Number: 16548 Peter, On 1/9/06 12:59 PM, "peter royal" wrote: > Overall, I got a 50% boost in the overall speed of my test suite by > using XFS and the 16k read-ahead. Yes, it all looks pretty good for your config, though it looks like you might be adapter limited with the Areca - you should have seen a read time with XFS of about 17 seconds. OTOH - with RAID5, you are probably about balanced, you should see a read time of about 19 seconds and instead you'll get your 22 which isn't too big of a deal. > Thanks for the help! Sure - no problem! BTW - I'm running tests right now with the 3Ware 9550SX controllers. Two of them on one machine running simultaneously with 16 drives and we're getting 800MB/s sustained read times. That's a 32GB file read in 40 seconds (!!) At that rate, we're only about 3x slower than memory access (practically limited at around 2GB/s even though the system bus peak is 10GB/s). So, the point is, if you want to get close to your "warm" speed, you need to get your disk I/O as close to main memory speed as you can. With parallel I/O you can do that (see Bizgres MPP for more). - Luke From pgsql-performance-owner@postgresql.org Mon Jan 9 19:50:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0E1DF9DC9C8 for ; Mon, 9 Jan 2006 19:50:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31103-07 for ; Mon, 9 Jan 2006 19:50:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 816DE9DC95F for ; Mon, 9 Jan 2006 19:50:32 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k09NoV022662; Mon, 9 Jan 2006 18:50:31 -0500 (EST) From: Bruce Momjian Message-Id: <200601092350.k09NoV022662@candle.pha.pa.us> Subject: Re: [PERFORMANCE] Beetwen text and varchar field In-Reply-To: <20060109114940.GB28748@uio.no> To: "Steinar H. Gunderson" Date: Mon, 9 Jan 2006 18:50:31 -0500 (EST) CC: TNO , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/71 X-Sequence-Number: 16549 See the FAQ. --------------------------------------------------------------------------- Steinar H. Gunderson wrote: > On Mon, Jan 09, 2006 at 11:58:19AM +0100, TNO wrote: > > what is the best for a char field with less than 1000 characters? > > a text field or a varchar(1000) > > They will be equivalent. text and varchar are the same type internally -- the > only differences are that varchar can have a length (but does not need one), > and that some casts are only defined for text. > > If there's really a natural thousand-character limit to the data in question, > use varchar(1000); if not, use text or varchar, whatever you'd like. > > /* Steinar */ > -- > Homepage: http://www.sesse.net/ > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgsql-performance-owner@postgresql.org Mon Jan 9 21:44:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B73F99DC892 for ; Mon, 9 Jan 2006 21:44:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65809-01 for ; Mon, 9 Jan 2006 21:44:56 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 6271B9DC82B for ; Mon, 9 Jan 2006 21:44:50 -0400 (AST) Received: from opteron.random (unknown [217.133.42.200]) by svr4.postgresql.org (Postfix) with ESMTP id 19AFB5AF072 for ; Tue, 10 Jan 2006 01:44:53 +0000 (GMT) Received: by opteron.random (Postfix, from userid 500) id CEDC41C1197; Tue, 10 Jan 2006 02:44:47 +0100 (CET) Date: Tue, 10 Jan 2006 02:44:47 +0100 From: Andrea Arcangeli To: pgsql-performance@postgresql.org Subject: NOT LIKE much faster than LIKE? Message-ID: <20060110014447.GB18474@opteron.random> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/72 X-Sequence-Number: 16550 Hello, I've a performance problem with the planner algorithm choosen in a website. See the difference between this: http://klive.cpushare.com/?scheduler=cooperative and this: http://klive.cpushare.com/?scheduler=preemptive (note, there's much less data to show with preemptive, so it's not because of the amount of data to output) The second takes ages to complete and it overloads the server as well at 100% cpu load for several seconds. "cooperative" runs "WHERE kernel_version NOT LIKE '%% PREEMPT %%'", while "preempt" runs "WHERE kernel_version LIKE '%% PREEMPT %%'. The only difference is a NOT before "LIKE". No other differences at all. The planner does apparently a big mistake using the nested loop in the "LIKE" query, it should use the hash join lik in the "NOT LIKE" query instead. I guess I can force it somehow (I found some docs about it here: http://www.postgresql.org/docs/8.1/static/runtime-config-query.html ) but it looks like something could be improved in the default mode too, so I'm reporting the problem since it looks a performance bug to me. It just makes no sense to me that the planner takes a difference decision based on a "not". It can't know if it's more likely or less likely, this is a boolean return, it's *exactly* the same cost to run it. Making assumption without user-provided hints looks a mistake. I never said to the db that "not like" is more or less likely to return data in output than "like". Tried ANALYZE, including VACUUM FULL ANALYZE and it doesn't make a difference. Perhaps it's analyze that suggests to use a different algorithm with "not like" because there's much more data to analyze with "not like" than with "like", but that algorithm works much better even when there's less data to analyze. Indexes don't make any visible difference. postgres is version 8.1.2 self compiled from CVS 8.1 branch of yesterday. psandrea@opteron:~> psql -V psql (PostgreSQL) 8.1.2 contains support for command-line editing andrea@opteron:~> The problem is reproducible on the shell, I only need to remove "explain". Of course explain is wrong about the cost, according to explain the first query is cheaper when infact it's an order of magnitude more costly. klive=> explain SELECT class, vendor, device, revision, COUNT(*) as nr FROM pci NATURAL INNER JOIN klive WHERE kernel_version LIKE '%% PREEMPT %%' GROUP BY class, vendor, device, revision; QUERY PLAN -------------------------------------------------------------------------------------- HashAggregate (cost=1687.82..1687.83 rows=1 width=16) -> Nested Loop (cost=235.86..1687.81 rows=1 width=16) -> Seq Scan on klive (cost=0.00..1405.30 rows=1 width=8) Filter: ((kernel_version)::text ~~ '%% PREEMPT %%'::text) -> Bitmap Heap Scan on pci (cost=235.86..282.32 rows=15 width=24) Recheck Cond: (pci.klive = "outer".klive) -> Bitmap Index Scan on pci_pkey (cost=0.00..235.86 rows=15 width=0) Index Cond: (pci.klive = "outer".klive) (8 rows) klive=> explain SELECT class, vendor, device, revision, COUNT(*) as nr FROM pci NATURAL INNER JOIN klive WHERE kernel_version NOT LIKE '%% PREEMPT %%' GROUP BY class, vendor, device, revision; QUERY PLAN -------------------------------------------------------------------------------- HashAggregate (cost=3577.40..3612.00 rows=2768 width=16) -> Hash Join (cost=1569.96..3231.50 rows=27672 width=16) Hash Cond: ("outer".klive = "inner".klive) -> Seq Scan on pci (cost=0.00..480.73 rows=27673 width=24) -> Hash (cost=1405.30..1405.30 rows=22263 width=8) -> Seq Scan on klive (cost=0.00..1405.30 rows=22263 width=8) Filter: ((kernel_version)::text !~~ '%% PREEMPT %%'::text) (7 rows) klive=> Hints welcome, thanks! PS. All the source code of the website where I'm reproducing the problem is available at the above url under the GPL. From pgsql-performance-owner@postgresql.org Mon Jan 9 22:04:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E4FAD9DC95F for ; Mon, 9 Jan 2006 22:04:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69064-04 for ; Mon, 9 Jan 2006 22:04:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A76E39DC82B for ; Mon, 9 Jan 2006 22:04:46 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0A24mht024022; Mon, 9 Jan 2006 21:04:48 -0500 (EST) To: Andrea Arcangeli cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <20060110014447.GB18474@opteron.random> References: <20060110014447.GB18474@opteron.random> Comments: In-reply-to Andrea Arcangeli message dated "Tue, 10 Jan 2006 02:44:47 +0100" Date: Mon, 09 Jan 2006 21:04:48 -0500 Message-ID: <24021.1136858688@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.077 required=5 tests=[AWL=0.077] X-Spam-Score: 0.077 X-Spam-Level: X-Archive-Number: 200601/73 X-Sequence-Number: 16551 Andrea Arcangeli writes: > It just makes no sense to me that the planner takes a difference > decision based on a "not". Why in the world would you think that? In general a NOT will change the selectivity of the WHERE condition tremendously. If the planner weren't sensitive to that, *that* would be a bug. The only case where it's irrelevant is if the selectivity of the base condition is exactly 50%, which is not a very reasonable default guess for LIKE. It sounds to me that the problem is misestimation of the selectivity of the LIKE pattern --- the planner is going to think that LIKE '%% PREEMPT %%' is fairly selective because of the rather long match text, when in reality it's probably not so selective on your data. But we don't keep any statistics that would allow the actual number of matching rows to be estimated well. You might want to think about changing your data representation so that the pattern-match can be replaced by a boolean column, or some such, so that the existing statistics code can make a more reasonable estimate how many rows are selected. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 9 22:23:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B58CD9DC941 for ; Mon, 9 Jan 2006 22:23:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73773-02 for ; Mon, 9 Jan 2006 22:23:09 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 8AA769DC827 for ; Mon, 9 Jan 2006 22:23:03 -0400 (AST) Received: from opteron.random (unknown [217.133.42.200]) by svr4.postgresql.org (Postfix) with ESMTP id 9A24F5AF04F for ; Tue, 10 Jan 2006 02:23:07 +0000 (GMT) Received: by opteron.random (Postfix, from userid 500) id 42AE41C192F; Tue, 10 Jan 2006 03:23:03 +0100 (CET) Date: Tue, 10 Jan 2006 03:23:03 +0100 From: Andrea Arcangeli To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060110022303.GA20168@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24021.1136858688@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/74 X-Sequence-Number: 16552 On Mon, Jan 09, 2006 at 09:04:48PM -0500, Tom Lane wrote: > Andrea Arcangeli writes: > > It just makes no sense to me that the planner takes a difference > > decision based on a "not". > > Why in the world would you think that? In general a NOT will change the > selectivity of the WHERE condition tremendously. If the planner weren't > sensitive to that, *that* would be a bug. The only case where it's > irrelevant is if the selectivity of the base condition is exactly 50%, > which is not a very reasonable default guess for LIKE. How do you know that "LIKE" will have a selectivity above 50% in the first place? I think 50% should be the default unless the selectively is measured at runtime against the data being queried. If you don't know the data, I think it's a bug that LIKE is assumed to have a selectivity above 50%. You can't know that, only the author of the code can know that and that's why I talked about hints. It'd be fine to give hints like: UNLIKELY string LIKE '%% PREEMPT %%' or: LIKELY string NOT LIKE '%% PREEMPT %%' Then you could assume that very little data will be returned or a lot of data will be returned. If you don't get hints NOT LIKE or LIKE should be assumed to have the same selectivity. > It sounds to me that the problem is misestimation of the selectivity > of the LIKE pattern --- the planner is going to think that > LIKE '%% PREEMPT %%' is fairly selective because of the rather long > match text, when in reality it's probably not so selective on your > data. But we don't keep any statistics that would allow the actual True, there's a lot of data that matches %% PREEMPT %% (even if less than the NOT case). > number of matching rows to be estimated well. You might want to think > about changing your data representation so that the pattern-match can be > replaced by a boolean column, or some such, so that the existing > statistics code can make a more reasonable estimate how many rows are > selected. I see. I can certainly fix it by stopping using LIKE. But IMHO this remains a bug, since until the statistics about the numberof matching rows isn't estimated well, you should not make assumptions on LIKE/NOT LIKE. I think you can change the code in a way that I won't have to touch anything, and this will lead to fewer surprises in the future IMHO. Thanks! From pgsql-performance-owner@postgresql.org Mon Jan 9 22:27:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 94E229DC9BB for ; Mon, 9 Jan 2006 22:27:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70680-07 for ; Mon, 9 Jan 2006 22:27:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com [203.22.197.21]) by postgresql.org (Postfix) with ESMTP id A732A9DC941 for ; Mon, 9 Jan 2006 22:27:46 -0400 (AST) Received: from houston.familyhealth.com.au (localhost [127.0.0.1]) by houston.familyhealth.com.au (Postfix) with ESMTP id B35FE25077; Tue, 10 Jan 2006 10:27:48 +0800 (WST) Received: from [127.0.0.1] (work-40.internal [192.168.0.40]) by houston.familyhealth.com.au (Postfix) with ESMTP id 8D93E2506B; Tue, 10 Jan 2006 10:27:45 +0800 (WST) Message-ID: <43C31BF1.704@familyhealth.com.au> Date: Tue, 10 Jan 2006 10:29:05 +0800 From: Christopher Kings-Lynne User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andrea Arcangeli Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> In-Reply-To: <20060110022303.GA20168@opteron.random> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-familyhealth-MailScanner-Information: Please contact the ISP for more information X-familyhealth-MailScanner: Found to be clean X-familyhealth-MailScanner-From: chriskl@familyhealth.com.au X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.075 required=5 tests=[AWL=0.075, UPPERCASE_25_50=0] X-Spam-Score: 0.075 X-Spam-Level: X-Archive-Number: 200601/75 X-Sequence-Number: 16553 > UNLIKELY string LIKE '%% PREEMPT %%' > > or: > > LIKELY string NOT LIKE '%% PREEMPT %%' You should be using contrib/tsearch2 for an un-anchored text search perhaps? From pgsql-performance-owner@postgresql.org Mon Jan 9 22:45:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4C5EE9DC9C2 for ; Mon, 9 Jan 2006 22:45:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75144-08 for ; Mon, 9 Jan 2006 22:45:37 -0400 (AST) X-Greylist: delayed 00:22:30.61667 by SQLgrey- Received: from opteron.random (unknown [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id EFE4C9DC9AD for ; Mon, 9 Jan 2006 22:45:30 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id 140631C13D2; Tue, 10 Jan 2006 03:45:34 +0100 (CET) Date: Tue, 10 Jan 2006 03:45:34 +0100 From: Andrea Arcangeli To: Christopher Kings-Lynne Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060110024534.GB20168@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <43C31BF1.704@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43C31BF1.704@familyhealth.com.au> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/76 X-Sequence-Number: 16554 On Tue, Jan 10, 2006 at 10:29:05AM +0800, Christopher Kings-Lynne wrote: > > UNLIKELY string LIKE '%% PREEMPT %%' > > > >or: > > > > LIKELY string NOT LIKE '%% PREEMPT %%' > > You should be using contrib/tsearch2 for an un-anchored text search perhaps? If I wanted to get the fastest speed possible, then I think parsing it with python and storing true/false in a boolean like suggested before would be better and simpler as well for this specific case. However I don't need big performance, I need just decent performance, and it annoys me that there heurisics where the LIKE query assumes little data will be selected. There's no way to know that until proper stats are recorded on the results of the query. The default should be good enough to use IMHO, and there's no way to know if NOT LIKE or LIKE will return more data, 50% should be assumed for both if no runtime information is available IMHO. IIRC gcc in a code like if (something) {a} else {b} assumes that a is more likely to be executed then b, but that's because it's forced to choose something. Often one is forced to choose what is more likely between two events, but I don't think the above falls in this case. I guess the heuristic really wanted to speed up the runtime of LIKE, when it actually made it a _lot_ worse. No heuristic is better than an heuristic that falls apart in corner cases like the above "LIKE". From pgsql-performance-owner@postgresql.org Mon Jan 9 22:54:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0308F9DC981 for ; Mon, 9 Jan 2006 22:54:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78663-04 for ; Mon, 9 Jan 2006 22:54:47 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D015E9DC93B for ; Mon, 9 Jan 2006 22:54:40 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0A2siWB024373; Mon, 9 Jan 2006 21:54:44 -0500 (EST) To: Andrea Arcangeli cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <20060110022303.GA20168@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> Comments: In-reply-to Andrea Arcangeli message dated "Tue, 10 Jan 2006 03:23:03 +0100" Date: Mon, 09 Jan 2006 21:54:44 -0500 Message-ID: <24372.1136861684@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.078 required=5 tests=[AWL=0.078] X-Spam-Score: 0.078 X-Spam-Level: X-Archive-Number: 200601/77 X-Sequence-Number: 16555 Andrea Arcangeli writes: > If you don't know the data, I think it's a bug that LIKE is assumed to > have a selectivity above 50%. Extrapolating from the observation that the heuristics don't work well on your data to the conclusion that they don't work for anybody is not good logic. Replacing that code with a flat 50% is not going to happen (or if it does, I'll be sure to send the mob of unhappy users waving torches and pitchforks to your door not mine ;-)). I did just think of something we could improve though. The pattern selectivity code doesn't make any use of the statistics about "most common values". For a constant pattern, we could actually apply the pattern test with each common value and derive answers that are exact for the portion of the population represented by the most-common-values list. If the MCV list covers a large fraction of the population then this would be a big leg up in accuracy. Dunno if that applies to your particular case or not, but it seems worth doing ... regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 9 22:54:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 72E8B9DC981 for ; Mon, 9 Jan 2006 22:54:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77960-04 for ; Mon, 9 Jan 2006 22:54:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 54B549DC9AD for ; Mon, 9 Jan 2006 22:54:53 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id AD51F35161; Mon, 9 Jan 2006 18:54:57 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A89C435125; Mon, 9 Jan 2006 18:54:57 -0800 (PST) Date: Mon, 9 Jan 2006 18:54:57 -0800 (PST) From: Stephan Szabo To: Andrea Arcangeli Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-Reply-To: <20060110022303.GA20168@opteron.random> Message-ID: <20060109185355.S36990@megazone.bigpanda.com> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.073 required=5 tests=[AWL=0.073] X-Spam-Score: 0.073 X-Spam-Level: X-Archive-Number: 200601/78 X-Sequence-Number: 16556 On Tue, 10 Jan 2006, Andrea Arcangeli wrote: > I see. I can certainly fix it by stopping using LIKE. But IMHO this > remains a bug, since until the statistics about the numberof matching > rows isn't estimated well, you should not make assumptions on LIKE/NOT > LIKE. I think you can change the code in a way that I won't have to > touch anything, and this will lead to fewer surprises in the future IMHO. I doubt it, since I would expect that this would be as large a pessimization for a larger fraction of people than it is an optimization for you. From pgsql-performance-owner@postgresql.org Mon Jan 9 23:47:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6DF3D9DC94A for ; Mon, 9 Jan 2006 23:47:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92381-04 for ; Mon, 9 Jan 2006 23:47:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (unknown [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id E5EC49DC93B for ; Mon, 9 Jan 2006 23:47:18 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id 1DF021C17B1; Tue, 10 Jan 2006 04:47:21 +0100 (CET) Date: Tue, 10 Jan 2006 04:47:21 +0100 From: Andrea Arcangeli To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060110034721.GC20168@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24372.1136861684@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/79 X-Sequence-Number: 16557 On Mon, Jan 09, 2006 at 09:54:44PM -0500, Tom Lane wrote: > Extrapolating from the observation that the heuristics don't work well > on your data to the conclusion that they don't work for anybody is not > good logic. Replacing that code with a flat 50% is not going to happen > (or if it does, I'll be sure to send the mob of unhappy users waving > torches and pitchforks to your door not mine ;-)). I'm not convinced but of course I cannot exclude that some people may be depending on this very heuristic. But I consider this being bug-compatible, I've an hard time to be convinced that such heuristic isn't going to bite other people like it did with me. > I did just think of something we could improve though. The pattern > selectivity code doesn't make any use of the statistics about "most > common values". For a constant pattern, we could actually apply the > pattern test with each common value and derive answers that are exact > for the portion of the population represented by the most-common-values > list. If the MCV list covers a large fraction of the population then > this would be a big leg up in accuracy. Dunno if that applies to your > particular case or not, but it seems worth doing ... Fixing this with proper stats would be great indeed. What would be the most common value for the kernel_version? You can see samples of the kernel_version here http://klive.cpushare.com/2.6.15/ . That's the string that is being searched against both PREEMPT and SMP. BTW, I also run a LIKE '%% SMP %%' a NOT LIKE '%% SMP %%' but that runs fine, probably because as you said in the first email PREEMPT is long but SMP is short. Thanks! From pgsql-performance-owner@postgresql.org Tue Jan 10 00:30:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 917159DC880 for ; Tue, 10 Jan 2006 00:30:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01658-04 for ; Tue, 10 Jan 2006 00:30:31 -0400 (AST) X-Greylist: delayed 00:06:40.480594 by SQLgrey- Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) by postgresql.org (Postfix) with ESMTP id D646E9DC87D for ; Tue, 10 Jan 2006 00:30:30 -0400 (AST) Received: (qmail 30906 invoked by uid 1010); 9 Jan 2006 23:23:49 -0500 Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid 1002 with qmail-scanner-1.20 (spamassassin: 3.1.0. Clear:RC:0(63.147.78.66):SA:0(?/?):. Processed in 2.337398 secs); 10 Jan 2006 04:23:49 -0000 Received: from unknown (HELO thunder.logicalchaos.org) (perl?test@logicalchaos.org@63.147.78.66) by rambo.iniquinet.com with AES256-SHA encrypted SMTP; 9 Jan 2006 23:23:46 -0500 Received: from logicalchaos.org (localhost [127.0.0.1]) by thunder.logicalchaos.org (Postfix) with ESMTP id 2231396F9A for ; Mon, 9 Jan 2006 21:23:45 -0700 (MST) Date: Mon, 9 Jan 2006 21:23:38 -0700 From: Robert Creager To: PGPerformance Subject: Index isn't used during a join. Message-ID: <20060109212338.6420af12@thunder.logicalchaos.org> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i586-mandriva-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary=Signature_Mon__9_Jan_2006_21_23_38_-0700_gN17GIHnFOTBJ1wn; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/80 X-Sequence-Number: 16558 --Signature_Mon__9_Jan_2006_21_23_38_-0700_gN17GIHnFOTBJ1wn Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hey folks, I'm working with a query to get more info out with a join. The base query = works great speed wise because of index usage. When the join is tossed in,= the index is no longer used, so the query performance tanks. Can anyone advise on how to get the index usage back? weather=3D# select version(); version = =20 ---------------------------------------------------------------------------= -------------------------------------------- PostgreSQL 8.1.1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.0.1 (4.= 0.1-5mdk for Mandriva Linux release 2006.0) (1 row) The base query is: weather=3D# EXPLAIN ANALYZE weather-# SELECT min_reading, max_reading, avg_reading, -- doy, weather-# unmunge_time( time_group ) AS time weather-# FROM minute."windspeed" weather-# --JOIN readings_doy ON EXTRACT( doy FROM unmunge_time( time_group= ) ) =3D doy weather-# WHERE unmunge_time( time_group ) > ( now() - '24 hour'::interval ) weather-# ORDER BY time_group; QUERY PLAN= =20 ---------------------------------------------------------------------------= ------------------------------------------------------------------ Sort (cost=3D10995.29..11155.58 rows=3D64117 width=3D28) (actual time=3D4= .509..4.574 rows=3D285 loops=3D1) Sort Key: time_group -> Bitmap Heap Scan on windspeed (cost=3D402.42..5876.05 rows=3D64117 = width=3D28) (actual time=3D0.784..3.639 rows=3D285 loops=3D1) Recheck Cond: (unmunge_time(time_group) > (now() - '24:00:00'::int= erval)) -> Bitmap Index Scan on minute_windspeed_index (cost=3D0.00..402= .42 rows=3D64117 width=3D0) (actual time=3D0.675..0.675 rows=3D285 loops=3D= 1) Index Cond: (unmunge_time(time_group) > (now() - '24:00:00':= :interval)) Total runtime: 4.880 ms (7 rows) When I add in the join, the query tosses out the nice quick index in favor = of sequence scans: weather=3D# EXPLAIN ANALYZE weather-# SELECT min_reading, max_reading, avg_reading, -- doy, weather-# unmunge_time( time_group ) AS time weather-# FROM minute."windspeed" weather-# JOIN readings_doy ON EXTRACT( doy FROM unmunge_time( time_group )= ) =3D doy weather-# WHERE unmunge_time( time_group ) > ( now() - '24 hour'::interval ) weather-# ORDER BY time_group; QUERY PLAN = =20 ---------------------------------------------------------------------------= -------------------------------------------------------------- Sort (cost=3D98239590.88..99052623.66 rows=3D325213113 width=3D28) (actua= l time=3D60136.484..61079.845 rows=3D1030656 loops=3D1) Sort Key: windspeed.time_group -> Merge Join (cost=3D265774.21..8396903.54 rows=3D325213113 width=3D2= 8) (actual time=3D34318.334..47113.277 rows=3D1030656 loops=3D1) Merge Cond: ("outer"."?column5?" =3D "inner"."?column2?") -> Sort (cost=3D12997.68..13157.98 rows=3D64120 width=3D28) (act= ual time=3D2286.155..2286.450 rows=3D284 loops=3D1) Sort Key: date_part('doy'::text, unmunge_time(windspeed.time= _group)) -> Seq Scan on windspeed (cost=3D0.00..7878.18 rows=3D6412= 0 width=3D28) (actual time=3D2279.275..2285.271 rows=3D284 loops=3D1) Filter: (unmunge_time(time_group) > (now() - '24:00:00= '::interval)) -> Sort (cost=3D252776.54..255312.51 rows=3D1014389 width=3D8) (= actual time=3D32001.370..33473.407 rows=3D1051395 loops=3D1) Sort Key: date_part('doy'::text, readings."when") -> Seq Scan on readings (cost=3D0.00..142650.89 rows=3D101= 4389 width=3D8) (actual time=3D0.053..13759.015 rows=3D1014448 loops=3D1) Total runtime: 61720.935 ms (12 rows) weather=3D# \d minute.windspeed Table "minute.windspeed" Column | Type | Modifiers=20 -------------+------------------+----------- time_group | integer | not null min_reading | double precision | not null max_reading | double precision | not null avg_reading | double precision | not null Indexes: "windspeed_pkey" PRIMARY KEY, btree (time_group) "minute_windspeed_index" btree (unmunge_time(time_group)) CREATE OR REPLACE FUNCTION unmunge_time( integer ) RETURNS timestamp AS ' DECLARE input ALIAS FOR $1; BEGIN RETURN (''epoch''::timestamptz + input * ''1sec''::interval)::timestamp; END; ' LANGUAGE plpgsql IMMUTABLE STRICT; weather=3D# \d readings Table "public.readings" Column | Type | = Modifiers =20 ----------------------+-----------------------------+----------------------= --------------------------------------- when | timestamp without time zone | not null default (tim= eofday())::timestamp without time zone hour_group | integer |=20 minute_group | integer |=20 day_group | integer |=20 week_group | integer |=20 month_group | integer |=20 year_group | integer |=20 year_group_updated | boolean | default false month_group_updated | boolean | default false week_group_updated | boolean | default false day_group_updated | boolean | default false hour_group_updated | boolean | default false minute_group_updated | boolean | default false Indexes: "readings_pkey" PRIMARY KEY, btree ("when") "day_group_updated_index" btree (day_group_updated, day_group) "hour_group_updated_index" btree (hour_group_updated, hour_group) "month_group_updated_index" btree (month_group_updated, month_group) "readings_doy_index" btree (date_part('doy'::text, "when")) "week_group_updated_index" btree (week_group_updated, week_group) "year_group_updated_index" btree (year_group_updated, year_group) Triggers: munge_time BEFORE INSERT OR UPDATE ON readings FOR EACH ROW EXECUTE PRO= CEDURE munge_time() readings_doy is a view that adds date_part('doy'::text, readings."when") AS= doy to the readings table. Thanks, Rob --=20 21:15:51 up 2 days, 13:42, 9 users, load average: 3.14, 2.63, 2.62 Linux 2.6.12-12-2 #4 SMP Tue Jan 3 19:56:19 MST 2006 --Signature_Mon__9_Jan_2006_21_23_38_-0700_gN17GIHnFOTBJ1wn Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iEYEARECAAYFAkPDNtAACgkQLQ/DKuwDYzno5QCgisAGadWtWJ6KGQlT6nc1SuEE tVsAn0144x8/1a4rYxqcRslobs3pnAjP =6XVQ -----END PGP SIGNATURE----- --Signature_Mon__9_Jan_2006_21_23_38_-0700_gN17GIHnFOTBJ1wn-- From pgsql-performance-owner@postgresql.org Tue Jan 10 01:58:31 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8252B9DC851 for ; Tue, 10 Jan 2006 01:58:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16927-03 for ; Tue, 10 Jan 2006 01:58:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 3E3049DC841 for ; Tue, 10 Jan 2006 01:58:25 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0A5wKc9006502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 Jan 2006 22:58:22 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0A5wJOf055284; Mon, 9 Jan 2006 22:58:19 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0A5wJ74055283; Mon, 9 Jan 2006 22:58:19 -0700 (MST) (envelope-from mfuhr) Date: Mon, 9 Jan 2006 22:58:18 -0700 From: Michael Fuhr To: Robert Creager Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060110055818.GA55076@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060109212338.6420af12@thunder.logicalchaos.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.086 required=5 tests=[AWL=0.086] X-Spam-Score: 0.086 X-Spam-Level: X-Archive-Number: 200601/81 X-Sequence-Number: 16559 On Mon, Jan 09, 2006 at 09:23:38PM -0700, Robert Creager wrote: > I'm working with a query to get more info out with a join. The base > query works great speed wise because of index usage. When the join is > tossed in, the index is no longer used, so the query performance tanks. The first query you posted returns 285 rows and the second returns over one million; index usage aside, that difference surely accounts for a performance penalty. And as is often pointed out, index scans aren't always faster than sequential scans: the more of a table a query has to fetch, the more likely a sequential scan will be faster. Have the tables been vacuumed and analyzed? The planner's estimates for windspeed are pretty far off, which could be affecting the query plan: > -> Sort (cost=12997.68..13157.98 rows=64120 width=28) (actual time=2286.155..2286.450 rows=284 loops=1) > Sort Key: date_part('doy'::text, unmunge_time(windspeed.time_group)) > -> Seq Scan on windspeed (cost=0.00..7878.18 rows=64120 width=28) (actual time=2279.275..2285.271 rows=284 loops=1) > Filter: (unmunge_time(time_group) > (now() - '24:00:00'::interval)) That's a small amount of the total query time, however, so although an index scan might help it probably won't provide the big gain you're looking for. Have you done any tests with enable_seqscan disabled? That'll show whether an index or bitmap scan would be faster. And have you verified that the join condition is correct? Should the query be returning over a million rows? -- Michael Fuhr From pgsql-performance-owner@postgresql.org Tue Jan 10 03:46:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 587A29DC832 for ; Tue, 10 Jan 2006 03:46:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34812-03 for ; Tue, 10 Jan 2006 03:46:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id F35CD9DC851 for ; Tue, 10 Jan 2006 03:46:27 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id ECC5A7CDB24; Tue, 10 Jan 2006 08:50:18 +0100 (CET) Message-ID: <43C3665F.5020106@barettadeit.com> Date: Tue, 10 Jan 2006 08:46:39 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Matteo Beccati , pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong statistics! References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> <43C28DEA.60801@barettadeit.com> <6719.1136832065@sss.pgh.pa.us> <43C2B06B.4050506@barettadeit.com> <6914.1136833010@sss.pgh.pa.us> In-Reply-To: <6914.1136833010@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/82 X-Sequence-Number: 16560 Tom Lane wrote: > Alessandro Baretta writes: > >>Tom Lane wrote: >> >>>I'm curious to see how many rows the planner thinks this will produce, >>>and whether it will use the index or not. >>dmd-freerp-1-alex=# EXPLAIN ANALYZE SELECT * FROM articolo WHERE >>articolo.xdbs_modified > '2006-01-08 18:25:00+01'; >> QUERY PLAN >>------------------------------------------------------------------------------------------------------------------------------------------- >> Index Scan using articolo_modified_index on articolo (cost=0.00..3914.91 >>rows=17697 width=653) (actual time=0.032..0.032 rows=0 loops=1) >> Index Cond: (xdbs_modified > '2006-01-08 18:25:00'::timestamp without time zone) >> Total runtime: 0.150 ms >>(3 rows) > > > Well, there's your problem: 17697 rows estimated vs 0 actual. With a > closer row estimate it would've probably done the right thing for the > join problem. Hmmm, what you are telling me is very interesting, Tom. So, let me see if I got this straight: the first 'rows=... in the result from EXPLAIN ANALYZE gives me estimates, while the second gives the actual cardinality of the selected record set. Correct? If this is true, two questions arise: why is the estimated number of rows completele wrong, and why, given such a large estimated record set does PostgreSQL schedule an Index Scan as opposed to a Seq Scan? > > How many rows are really in the table, anyway? Could we see the > pg_stats row for articolo.xdbs_modified? dmd-freerp-1-alex=# select count(*) from articolo; count ------- 53091 (1 row) dmd-freerp-1-alex=# explain analyze select * from articolo; QUERY PLAN ----------------------------------------------------------------------------------------------------------------- Seq Scan on articolo (cost=0.00..1439.91 rows=53091 width=653) (actual time=0.013..151.189 rows=53091 loops=1) Total runtime: 295.152 ms (2 rows) Now let me get the pg_stats for xdbs_modified. dmd-freerp-1-alex=# select * from pg_stats where tablename = 'articolo' and attname = 'xdbs_modified'; schemaname | tablename | attname | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation ------------+-----------+---------------+-----------+-----------+------------+--------------------------------+-------------------+------------------+------------- public | articolo | xdbs_modified | 0 | 8 | 1 | {"2006-01-10 08:12:58.605327"} | {1} | | 1 (1 row) For sake of simplicity I have re-timestamped all tuples in the table with the current timestamp, as you can see above. Now, obviously, the planner must estimate ~0 rows for queries posing a selection condition on xdbs_modified, for any value other than "2006-01-10 08:12:58.605327". Let me try selecting from articolo first. dmd-freerp-1-alex=# EXPLAIN ANALYZE SELECT * FROM articolo WHERE articolo.xdbs_modified > '2006-01-10 18:25:00+01'; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------ Index Scan using articolo_modified_index on articolo (cost=0.00..2.01 rows=1 width=653) (actual time=0.139..0.139 rows=0 loops=1) Index Cond: (xdbs_modified > '2006-01-10 18:25:00'::timestamp without time zone) Total runtime: 0.257 ms (3 rows) The planner produces a sensible estimate of the number of rows and consequently chooses the appropriate query plan. Now, the join. dmd-freerp-1-alex=# explain analyze SELECT * FROM articolo JOIN ubicazione USING (id_ente, id_produttore, id_articolo) WHERE articolo.id_ente = 'dmd' AND allarme IS NULL AND manutenzione IS NULL AND articolo.xdbs_modified > '2006-01-10 18:25:00+01'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..5.05 rows=1 width=1146) (actual time=0.043..0.043 rows=0 loops=1) -> Index Scan using articolo_modified_index on articolo (cost=0.00..2.02 rows=1 width=653) (actual time=0.035..0.035 rows=0 loops=1) Index Cond: (xdbs_modified > '2006-01-10 18:25:00'::timestamp without time zone) Filter: (id_ente = 'dmd'::text) -> Index Scan using ubicazione_fkey_articolo on ubicazione (cost=0.00..3.02 rows=1 width=536) (never executed) Index Cond: (('dmd'::text = ubicazione.id_ente) AND ("outer".id_produttore = ubicazione.id_produttore) AND ("outer".id_articolo = ubicazione.id_articolo)) Filter: ((allarme IS NULL) AND (manutenzione IS NULL)) Total runtime: 0.382 ms (8 rows) Dear Tom, you're my hero! I have no clue as to how or why the statistics were wrong yesterday--as I vacuum-analyzed continuously out of lack of any better idea--and I was stupid enough to re-timestamp everything before selecting from pg_stats. Supposedly, the timestamps in the table were a random sampling taken from the month of December 2005, so that any date in January would be greater than all the timestamps in xdbs_modified. There must a bug in the my rule/trigger system, which is responsible to maintain these timestamps as appropriate. > regards, tom lane > Thank you very much Tom and Matteo. Your help has been very precious to me. Thanks to your wisdom, my application will now have a 500x speed boost on a very common class of queries. The end result is the following query plan, allowing me to rapidly select only the tuples in a join which have changed since the application last updated its notion of this dataset. dmd-freerp-1-alex=# explain analyze SELECT * FROM articolo JOIN ubicazione USING (id_ente, id_produttore, id_articolo) WHERE articolo.id_ente = 'dmd' AND allarme IS NULL AND manutenzione IS NULL AND articolo.xdbs_modified > '2006-01-10 18:25:00+01' UNION SELECT * FROM articolo JOIN ubicazione USING (id_ente, id_produttore, id_articolo) WHERE articolo.id_ente = 'dmd' AND allarme IS NULL AND manutenzione IS NULL AND ubicazione.xdbs_modified > '2006-01-10 18:25:00+01'; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Unique (cost=11.13..11.39 rows=2 width=1146) (actual time=0.519..0.519 rows=0 loops=1) -> Sort (cost=11.13..11.14 rows=2 width=1146) (actual time=0.512..0.512 rows=0 loops=1) Sort Key: id_ente, id_produttore, id_articolo, bigoid, metadata, finalized, xdbs_created, xdbs_modified, barcode, tipo, venditore_id_ente, id_prodotto, aggregato_id_ente, aggregato_id_produttore, aggregato_id_articolo, descr, url, datasheet, scheda_sicurezza, peso, lunghezza, larghezza, altezza, volume, max_strati, um, bigoid, metadata, finalized, xdbs_created, xdbs_modified, barcode, tipo, id_magazzino, id_settore, id_area, id_ubicazione, flavor, peso_max, lunghezza, larghezza, altezza, volume_max, inventario, allarme, manutenzione, quantita, in_prelievo, in_deposito, lotto, scadenza -> Append (cost=0.00..11.12 rows=2 width=1146) (actual time=0.305..0.305 rows=0 loops=1) -> Subquery Scan "*SELECT* 1" (cost=0.00..5.06 rows=1 width=1146) (actual time=0.157..0.157 rows=0 loops=1) -> Nested Loop (cost=0.00..5.05 rows=1 width=1146) (actual time=0.149..0.149 rows=0 loops=1) -> Index Scan using articolo_modified_index on articolo (cost=0.00..2.02 rows=1 width=653) (actual time=0.142..0.142 rows=0 loops=1) Index Cond: (xdbs_modified > '2006-01-10 18:25:00'::timestamp without time zone) Filter: (id_ente = 'dmd'::text) -> Index Scan using ubicazione_fkey_articolo on ubicazione (cost=0.00..3.02 rows=1 width=536) (never executed) Index Cond: (('dmd'::text = ubicazione.id_ente) AND ("outer".id_produttore = ubicazione.id_produttore) AND ("outer".id_articolo = ubicazione.id_articolo)) Filter: ((allarme IS NULL) AND (manutenzione IS NULL)) -> Subquery Scan "*SELECT* 2" (cost=0.00..6.06 rows=1 width=1146) (actual time=0.137..0.137 rows=0 loops=1) -> Nested Loop (cost=0.00..6.05 rows=1 width=1146) (actual time=0.131..0.131 rows=0 loops=1) -> Index Scan using ubicazione_modified_index on ubicazione (cost=0.00..3.02 rows=1 width=536) (actual time=0.123..0.123 rows=0 loops=1) Index Cond: (xdbs_modified > '2006-01-10 18:25:00'::timestamp without time zone) Filter: ((allarme IS NULL) AND (manutenzione IS NULL) AND ('dmd'::text = id_ente)) -> Index Scan using articolo_pkey on articolo (cost=0.00..3.02 rows=1 width=653) (never executed) Index Cond: ((articolo.id_ente = 'dmd'::text) AND (articolo.id_produttore = "outer".id_produttore) AND (articolo.id_articolo = "outer".id_articolo)) Total runtime: 1.609 ms (20 rows) Since the previous approach used in my application was to select the whole relation every time the user needed to access this data, the above result must be compared with the following naive one. dmd-freerp-1-alex=# explain analyze SELECT * FROM articolo JOIN ubicazione USING (id_ente, id_produttore, id_articolo) WHERE articolo.id_ente = 'dmd' AND allarme IS NULL AND manutenzione IS NULL; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..1014.49 rows=1 width=1146) (actual time=0.210..283.272 rows=3662 loops=1) -> Seq Scan on ubicazione (cost=0.00..1011.45 rows=1 width=536) (actual time=0.070..51.223 rows=12036 loops=1) Filter: ((allarme IS NULL) AND (manutenzione IS NULL) AND ('dmd'::text = id_ente)) -> Index Scan using articolo_pkey on articolo (cost=0.00..3.02 rows=1 width=653) (actual time=0.008..0.009 rows=0 loops=12036) Index Cond: ((articolo.id_ente = 'dmd'::text) AND (articolo.id_produttore = "outer".id_produttore) AND (articolo.id_articolo = "outer".id_articolo)) Total runtime: 292.544 ms (6 rows) This amounts to a ~200x speedup for the end user. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Tue Jan 10 05:08:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D6D6B9DC83C for ; Tue, 10 Jan 2006 05:08:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45643-10 for ; Tue, 10 Jan 2006 05:08:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from roast.hq.mobyt.it (194-185-112-82.f5.ngi.it [194.185.112.82]) by postgresql.org (Postfix) with SMTP id F3A499DC809 for ; Tue, 10 Jan 2006 05:08:26 -0400 (AST) Received: (qmail 26923 invoked from network); 10 Jan 2006 10:05:19 +0100 Received: from webdev.hq.mobyt.it (HELO ?10.20.20.4?) (10.20.20.4) by 0 with SMTP; 10 Jan 2006 10:05:19 +0100 Message-ID: <43C3799D.5030103@beccati.com> Date: Tue, 10 Jan 2006 10:08:45 +0100 From: Matteo Beccati User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Tom Lane CC: Andrea Arcangeli , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> In-Reply-To: <24372.1136861684@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/83 X-Sequence-Number: 16561 Hi, > I did just think of something we could improve though. The pattern > selectivity code doesn't make any use of the statistics about "most > common values". For a constant pattern, we could actually apply the > pattern test with each common value and derive answers that are exact > for the portion of the population represented by the most-common-values > list. If the MCV list covers a large fraction of the population then > this would be a big leg up in accuracy. Dunno if that applies to your > particular case or not, but it seems worth doing ... This reminds me what I did in a patch which is currently on hold for the next release: http://momjian.postgresql.org/cgi-bin/pgpatches_hold http://candle.pha.pa.us/mhonarc/patches_hold/msg00026.html The patch was addressing a similar issue when using ltree <@ and @> operator on an unbalanced tree. Best regards -- Matteo Beccati http://phpadsnew.com http://phppgads.com From pgsql-performance-owner@postgresql.org Tue Jan 10 11:31:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6A7F09DCA69 for ; Tue, 10 Jan 2006 11:31:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26535-01-8 for ; Tue, 10 Jan 2006 11:31:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth07.mail.atl.earthlink.net (smtpauth07.mail.atl.earthlink.net [209.86.89.67]) by postgresql.org (Postfix) with ESMTP id 2DE2A9DCA74 for ; Tue, 10 Jan 2006 10:33:25 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=PXk5ndzaGm8Qmymm7jI6MDS5RLEMzlvVNNULbBRbcKt325zdSjjb7J6ZWtdfkVeh; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.244.95] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth07.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1EwKYy-000511-Is; Tue, 10 Jan 2006 09:33:28 -0500 Message-Id: <7.0.1.0.2.20060110085315.06dadf00@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Tue, 10 Jan 2006 09:33:20 -0500 To: peter royal ,pgsql-performance@postgresql.org From: Ron Subject: Re: help tuning queries on large database In-Reply-To: <414814B8-556C-47DB-B364-A5A681CC3522@pobox.com> References: <414814B8-556C-47DB-B364-A5A681CC3522@pobox.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bcccc28fa40b9ca6051184277e6da68113350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.244.95 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.417 required=5 tests=[AWL=-0.062, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.417 X-Spam-Level: X-Archive-Number: 200601/84 X-Sequence-Number: 16562 At 12:23 PM 1/9/2006, peter royal wrote: >On Jan 8, 2006, at 4:35 PM, Ron wrote: >>>Areca ARC-1220 8-port PCI-E controller >> >>Make sure you have 1GB or 2GB of cache. Get the battery backup and >>set the cache for write back rather than write through. > >The card we've got doesn't have a SODIMM socket, since its only an >8- port card. My understanding was that was cache used when writing? Trade in your 8 port ARC-1220 that doesn't support 1-2GB of cache for a 12, 16, or 24 port Areca one that does. It's that important. Present generation SATA2 HDs should average ~50MBps raw ASTR. The Intel IOP333 DSP on the ARC's is limited to 800MBps, so that's your limit per card. That's 16 SATA2 HD's operating in parallel (16HD RAID 0, 17 HD RAID 5, 32 HD RAID 10). Next generation 2.5" form factor 10Krpm SAS HD's due to retail in 2006 are supposed to average ~90MBps raw ASTR. 8 such HDs in parallel per ARC-12xx will be the limit. Side Note: the PCI-Ex8 bus on the 12xx cards is good for ~1.6GBps RWPB, so I expect Areca is going to be upgrading this controller to at least 2x, if not 4x (would require replacing the x8 bus with a x16 bus), the bandwidth at some point. A PCI-Ex16 bus is good for ~3.2GBps RWPB, so if you have the slots 4 such populated ARC cards will max out a PCI-Ex16 bus. In your shoes, I think I would recommend replacing your 8 port ARC-1220 with a 12 port ARC-1230 with 1-2GB of battery backed cache and planning to get more of them as need arises. >>A 2.6.12 or later based Linux distro should have NO problems using >>more than 4GB or RAM. > >Upgraded the kernel to 2.6.15, then we were able to set the BIOS >option for the 'Memory Hole' to 'Software' and it saw all 4G (under >2.6.11 we got a kernel panic with that set) There are some other kernel tuning params that should help memory and physical IO performance. Talk to a Linux kernel guru to get the correct advice specific to your installation and application. It should be noted that there are indications of some major inefficiencies in pg's IO layer that make it compute bound under some circumstances before it becomes IO bound. These may or may not cause trouble for you as you keep pushing the envelope for maximum IO performance. With the kind of work you are doing and we are describing, I'm sure you can have a _very_ zippy system. Ron From pgsql-performance-owner@postgresql.org Tue Jan 10 11:31:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B7C549DCA81 for ; Tue, 10 Jan 2006 11:31:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27113-02 for ; Tue, 10 Jan 2006 11:31:45 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.193]) by postgresql.org (Postfix) with ESMTP id 62B149DCC1E for ; Tue, 10 Jan 2006 10:41:26 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so2718100wxc for ; Tue, 10 Jan 2006 06:41:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=hRvqfIyq9R3vodXdVhuhFz4dvgWp2zpui1hsEao5foZvleVdGNHeNT6kgB/sg1zaTFc8F6SeC40wDmWAMNDPRoxNDIZn/8Rk5j9dqAjFQaG2DoaRPTKcriNf4O6Dp+b4x8Icc7GNN+piGURVrJhPJoJF/b2BpXrVWTQpy4em/+I= Received: by 10.70.25.16 with SMTP id 16mr6390953wxy; Tue, 10 Jan 2006 06:41:28 -0800 (PST) Received: by 10.70.55.9 with HTTP; Tue, 10 Jan 2006 06:41:27 -0800 (PST) Message-ID: Date: Tue, 10 Jan 2006 12:41:27 -0200 From: "Charles A. Landemaine" To: pgsql-performance@postgresql.org Subject: How to handle a large DB and simultaneous accesses? MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/85 X-Sequence-Number: 16563 Hello, I have to develop a companies search engine (looks like the Yellow pages). We're using PostgreSQL at the company, and the initial DB is 2GB large, as it has companies from the entire world, with a fair amount of information. What reading do you suggest so that we can develop the search engine core, in order that the result pages show up instantly, no matter the heavy load and the DB size. The DB is 2GB but should grow to up to 10GB in 2 years, and there should be 250,000 unique visitors per month by the end of the year. Are there special techniques? Maybe there's a way to sort of cache search results? We're using PHP5 + phpAccelerator. Thanks, -- Charles A. Landemaine. From pgsql-performance-owner@postgresql.org Tue Jan 10 11:33:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 810939DCA73 for ; Tue, 10 Jan 2006 11:32:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26544-02-8 for ; Tue, 10 Jan 2006 11:32:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id D3F599DCE4E for ; Tue, 10 Jan 2006 11:11:20 -0400 (AST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1EwL9a-0000Op-00; Tue, 10 Jan 2006 10:11:19 -0500 To: Andrea Arcangeli Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <20060110034721.GC20168@opteron.random> In-Reply-To: <20060110034721.GC20168@opteron.random> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 10 Jan 2006 10:11:18 -0500 Message-ID: <87y81oyv6x.fsf@stark.xeocode.com> Lines: 21 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.116 required=5 tests=[AWL=0.116] X-Spam-Score: 0.116 X-Spam-Level: X-Archive-Number: 200601/89 X-Sequence-Number: 16567 Andrea Arcangeli writes: > Fixing this with proper stats would be great indeed. What would be the > most common value for the kernel_version? You can see samples of the > kernel_version here http://klive.cpushare.com/2.6.15/ . That's the > string that is being searched against both PREEMPT and SMP. Try something like this where attname is the column name and tablename is, well, the tablename: db=> select most_common_vals from pg_stats where tablename = 'region' and attname = 'province'; most_common_vals ------------------ {ON,NB,QC,BC} Note that there's a second column most_common_freqs and to do this would really require doing a weighted average based on the frequencies. -- greg From pgsql-performance-owner@postgresql.org Tue Jan 10 11:33:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E03DE9DCA8D for ; Tue, 10 Jan 2006 11:32:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27249-01-6 for ; Tue, 10 Jan 2006 11:32:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) by postgresql.org (Postfix) with ESMTP id 97BE99DC87E for ; Tue, 10 Jan 2006 11:17:04 -0400 (AST) Received: (qmail 15429 invoked by uid 1010); 10 Jan 2006 10:17:08 -0500 Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid 1002 with qmail-scanner-1.20 (spamassassin: 3.1.0. Clear:RC:0(63.147.78.66):SA:0(?/?):. Processed in 0.903932 secs); 10 Jan 2006 15:17:08 -0000 Received: from unknown (HELO thunder.logicalchaos.org) (perl?test@logicalchaos.org@63.147.78.66) by rambo.iniquinet.com with AES256-SHA encrypted SMTP; 10 Jan 2006 10:17:07 -0500 Received: from logicalchaos.org (localhost [127.0.0.1]) by thunder.logicalchaos.org (Postfix) with ESMTP id 202C0126054; Tue, 10 Jan 2006 08:17:06 -0700 (MST) Date: Tue, 10 Jan 2006 08:17:05 -0700 From: Robert Creager To: Michael Fuhr Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060110081705.221792f9@thunder.logicalchaos.org> In-Reply-To: <20060110055818.GA55076@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i586-mandriva-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary=Signature_Tue__10_Jan_2006_08_17_05_-0700_h4.0YeYibKxKw2n8; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/88 X-Sequence-Number: 16566 --Signature_Tue__10_Jan_2006_08_17_05_-0700_h4.0YeYibKxKw2n8 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable When grilled further on (Mon, 9 Jan 2006 22:58:18 -0700), Michael Fuhr confessed: > On Mon, Jan 09, 2006 at 09:23:38PM -0700, Robert Creager wrote: > > I'm working with a query to get more info out with a join. The base > > query works great speed wise because of index usage. When the join is > > tossed in, the index is no longer used, so the query performance tanks. >=20 > The first query you posted returns 285 rows and the second returns > over one million; index usage aside, that difference surely accounts > for a performance penalty. And as is often pointed out, index scans > aren't always faster than sequential scans: the more of a table a > query has to fetch, the more likely a sequential scan will be faster. Thanks for pointing out the obvious that I missed. Too much data in the se= cond query. It's supposed to match (row wise) what was returned from the f= irst query. Just ignore me for now... Thanks, Rob --=20 08:15:24 up 3 days, 42 min, 9 users, load average: 2.07, 2.20, 2.25 Linux 2.6.12-12-2 #4 SMP Tue Jan 3 19:56:19 MST 2006 --Signature_Tue__10_Jan_2006_08_17_05_-0700_h4.0YeYibKxKw2n8 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iEYEARECAAYFAkPDz/EACgkQLQ/DKuwDYzkAigCbBvC3b0FyrhF8bSq4ESimD4md QSIAnR/IXEhKexDSJsD7SxwGDiyKsDdA =BoOU -----END PGP SIGNATURE----- --Signature_Tue__10_Jan_2006_08_17_05_-0700_h4.0YeYibKxKw2n8-- From pgsql-performance-owner@postgresql.org Tue Jan 10 11:32:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 447A79DCC12 for ; Tue, 10 Jan 2006 11:32:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23901-06-11 for ; Tue, 10 Jan 2006 11:32:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id ADDF99DD073 for ; Tue, 10 Jan 2006 11:23:03 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0AFMxvM029703; Tue, 10 Jan 2006 10:22:59 -0500 (EST) To: Alessandro Baretta cc: Matteo Beccati , pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong statistics! In-reply-to: <43C3665F.5020106@barettadeit.com> References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> <43C28DEA.60801@barettadeit.com> <6719.1136832065@sss.pgh.pa.us> <43C2B06B.4050506@barettadeit.com> <6914.1136833010@sss.pgh.pa.us> <43C3665F.5020106@barettadeit.com> Comments: In-reply-to Alessandro Baretta message dated "Tue, 10 Jan 2006 08:46:39 +0100" Date: Tue, 10 Jan 2006 10:22:59 -0500 Message-ID: <29702.1136906579@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.077 required=5 tests=[AWL=0.077] X-Spam-Score: 0.077 X-Spam-Level: X-Archive-Number: 200601/87 X-Sequence-Number: 16565 Alessandro Baretta writes: > I have no clue as to how or why the statistics were wrong > yesterday--as I vacuum-analyzed continuously out of lack of any better > idea--and I was stupid enough to re-timestamp everything before > selecting from pg_stats. Too bad. I would be interested to find out how, if the stats were up-to-date, the thing was still getting the row estimate so wrong. If you manage to get the database back into its prior state please do send along the pg_stats info. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 10 11:32:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4CAB19DC9E3 for ; Tue, 10 Jan 2006 11:32:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27451-01-2 for ; Tue, 10 Jan 2006 11:32:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (unknown [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id 066F69DD368 for ; Tue, 10 Jan 2006 11:27:17 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id DCEEB1C1BEC; Tue, 10 Jan 2006 16:27:20 +0100 (CET) Date: Tue, 10 Jan 2006 16:27:20 +0100 From: Andrea Arcangeli To: Greg Stark Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060110152720.GL15897@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <20060110034721.GC20168@opteron.random> <87y81oyv6x.fsf@stark.xeocode.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87y81oyv6x.fsf@stark.xeocode.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/86 X-Sequence-Number: 16564 On Tue, Jan 10, 2006 at 10:11:18AM -0500, Greg Stark wrote: > > Andrea Arcangeli writes: > > > Fixing this with proper stats would be great indeed. What would be the > > most common value for the kernel_version? You can see samples of the > > kernel_version here http://klive.cpushare.com/2.6.15/ . That's the > > string that is being searched against both PREEMPT and SMP. > > Try something like this where attname is the column name and tablename is, > well, the tablename: > > db=> select most_common_vals from pg_stats where tablename = 'region' and attname = 'province'; > most_common_vals > ------------------ > {ON,NB,QC,BC} Thanks for the info! klive=> select most_common_vals from pg_stats where tablename = 'klive' and attname = 'kernel_version'; most_common_vals ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ {"#1 Tue Sep 13 14:56:15 UTC 2005","#1 Fri Aug 19 11:58:59 UTC 2005","#7 SMP Fri Oct 7 15:56:41 CEST 2005","#1 SMP Fri Aug 19 11:58:59 UTC 2005","#2 Thu Sep 22 15:58:44 CEST 2005","#1 Fri Sep 23 15:32:21 GMT 2005","#1 Fri Oct 21 03:46:55 EDT 2005","#1 Sun Sep 4 13:45:32 CEST 2005","#5 PREEMPT Mon Nov 21 17:53:59 EET 2005","#1 Wed Sep 28 19:15:10 EDT 2005"} (1 row) klive=> select most_common_freqs from pg_stats where tablename = 'klive' and attname = 'kernel_version'; most_common_freqs ------------------------------------------------------------------------------------------- {0.0133333,0.0116667,0.011,0.009,0.00733333,0.00666667,0.00633333,0.006,0.006,0.00566667} (1 row) klive=> There's only one preempt near the end, not sure if it would work? From pgsql-performance-owner@postgresql.org Tue Jan 10 11:47:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 741269DC817 for ; Tue, 10 Jan 2006 11:47:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30485-04 for ; Tue, 10 Jan 2006 11:47:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D3F349DC809 for ; Tue, 10 Jan 2006 11:47:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0AFksFu000153; Tue, 10 Jan 2006 10:46:54 -0500 (EST) To: Andrea Arcangeli cc: Greg Stark , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <20060110152720.GL15897@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <20060110034721.GC20168@opteron.random> <87y81oyv6x.fsf@stark.xeocode.com> <20060110152720.GL15897@opteron.random> Comments: In-reply-to Andrea Arcangeli message dated "Tue, 10 Jan 2006 16:27:20 +0100" Date: Tue, 10 Jan 2006 10:46:53 -0500 Message-ID: <152.1136908013@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.078 required=5 tests=[AWL=0.078] X-Spam-Score: 0.078 X-Spam-Level: X-Archive-Number: 200601/90 X-Sequence-Number: 16568 Andrea Arcangeli writes: > There's only one preempt near the end, not sure if it would work? Not with that data, but maybe if you increased the statistics target for the column to 100 or so, you'd catch enough values to get reasonable results. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 10 13:50:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3A1869DC93E for ; Tue, 10 Jan 2006 13:50:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51494-08 for ; Tue, 10 Jan 2006 13:49:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 802AC9DC8E1 for ; Tue, 10 Jan 2006 13:49:57 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0AHnts9001626; Tue, 10 Jan 2006 12:49:55 -0500 (EST) To: Matteo Beccati cc: Andrea Arcangeli , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <43C3799D.5030103@beccati.com> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> Comments: In-reply-to Matteo Beccati message dated "Tue, 10 Jan 2006 10:08:45 +0100" Date: Tue, 10 Jan 2006 12:49:55 -0500 Message-ID: <1625.1136915395@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.078 required=5 tests=[AWL=0.078] X-Spam-Score: 0.078 X-Spam-Level: X-Archive-Number: 200601/91 X-Sequence-Number: 16569 Matteo Beccati writes: >> I did just think of something we could improve though. The pattern >> selectivity code doesn't make any use of the statistics about "most >> common values". For a constant pattern, we could actually apply the >> pattern test with each common value and derive answers that are exact >> for the portion of the population represented by the most-common-values >> list. > This reminds me what I did in a patch which is currently on hold for the > next release: I've applied a patch to make patternsel() compute the exact result for the MCV list, and use its former heuristics only for the portion of the column population not included in the MCV list. After finishing that work it occurred to me that we could go a step further: if the MCV list accounts for a substantial fraction of the population, we could assume that the MCV list is representative of the whole population, and extrapolate the pattern's selectivity over the MCV list to the whole population instead of using the existing heuristics at all. In a situation like Andreas' example this would win big, although you can certainly imagine cases where it would lose too. Any thoughts about this? What would be a reasonable threshold for "substantial fraction"? It would probably make sense to have different thresholds depending on whether the pattern is left-anchored or not, since the range heuristic only works for left-anchored patterns. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 10 18:06:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E6E169DC800 for ; Tue, 10 Jan 2006 18:06:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05757-04 for ; Tue, 10 Jan 2006 18:06:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id 94ADC9DC8E1 for ; Tue, 10 Jan 2006 18:06:34 -0400 (AST) Received: from [192.168.0.3] (unknown [84.12.184.6]) by smtp.nildram.co.uk (Postfix) with ESMTP id B271E268942; Tue, 10 Jan 2006 22:06:32 +0000 (GMT) Subject: Re: NOT LIKE much faster than LIKE? From: Simon Riggs To: Tom Lane Cc: Matteo Beccati , Andrea Arcangeli , pgsql-performance@postgresql.org In-Reply-To: <1625.1136915395@sss.pgh.pa.us> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> Content-Type: text/plain Date: Tue, 10 Jan 2006 22:06:36 +0000 Message-Id: <1136930796.21025.486.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.056 required=5 tests=[AWL=0.056] X-Spam-Score: 0.056 X-Spam-Level: X-Archive-Number: 200601/92 X-Sequence-Number: 16570 On Tue, 2006-01-10 at 12:49 -0500, Tom Lane wrote: > Matteo Beccati writes: > >> I did just think of something we could improve though. The pattern > >> selectivity code doesn't make any use of the statistics about "most > >> common values". For a constant pattern, we could actually apply the > >> pattern test with each common value and derive answers that are exact > >> for the portion of the population represented by the most-common-values > >> list. > > > This reminds me what I did in a patch which is currently on hold for the > > next release: > > I've applied a patch to make patternsel() compute the exact result for > the MCV list, and use its former heuristics only for the portion of the > column population not included in the MCV list. I think its OK to use the MCV, but I have a problem with the current heuristics: they only work for randomly generated strings, since the selectivity goes down geometrically with length. That doesn't match most languages where one and two syllable words are extremely common and longer ones much less so. A syllable can be 1-2 chars long, so any search string of length 1-4 is probably equally likely, rather than reducing in selectivity based upon length. So I think part of the problem is the geometrically reducing selectivity itself. > After finishing that work it occurred to me that we could go a step > further: if the MCV list accounts for a substantial fraction of the > population, we could assume that the MCV list is representative of the > whole population, and extrapolate the pattern's selectivity over the MCV > list to the whole population instead of using the existing heuristics at > all. In a situation like Andreas' example this would win big, although > you can certainly imagine cases where it would lose too. I don't think that can be inferred with any confidence, unless a large proportion of the MCV list were itself selected. Otherwise it might match only a single MCV that just happens to have a high proportion, then we assume all others have the same proportion. The calculation is related to Ndistinct, in some ways. > Any thoughts about this? What would be a reasonable threshold for > "substantial fraction"? It would probably make sense to have different > thresholds depending on whether the pattern is left-anchored or not, > since the range heuristic only works for left-anchored patterns. I don't think you can do this for a low enough substantial fraction to make this interesting. I would favour the idea of dynamic sampling using a block sampling approach; that was a natural extension of improving ANALYZE also. We can use that approach for things such as LIKE, but also use it for multi-column single-table and join selectivity. Best Regards, Simon Riggs From pgsql-performance-owner@postgresql.org Tue Jan 10 18:21:37 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 16A979DC9A5 for ; Tue, 10 Jan 2006 18:21:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10116-02 for ; Tue, 10 Jan 2006 18:21:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id BD8759DC98A for ; Tue, 10 Jan 2006 18:21:31 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0AMLP7O006399; Tue, 10 Jan 2006 17:21:25 -0500 (EST) To: Simon Riggs cc: Matteo Beccati , Andrea Arcangeli , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <1136930796.21025.486.camel@localhost.localdomain> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> <1136930796.21025.486.camel@localhost.localdomain> Comments: In-reply-to Simon Riggs message dated "Tue, 10 Jan 2006 22:06:36 +0000" Date: Tue, 10 Jan 2006 17:21:25 -0500 Message-ID: <6398.1136931685@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/93 X-Sequence-Number: 16571 Simon Riggs writes: > I think its OK to use the MCV, but I have a problem with the current > heuristics: they only work for randomly generated strings, since the > selectivity goes down geometrically with length. We could certainly use a less aggressive curve for that. You got a specific proposal? >> After finishing that work it occurred to me that we could go a step >> further: if the MCV list accounts for a substantial fraction of the >> population, we could assume that the MCV list is representative of the >> whole population, and extrapolate the pattern's selectivity over the MCV >> list to the whole population instead of using the existing heuristics at >> all. In a situation like Andreas' example this would win big, although >> you can certainly imagine cases where it would lose too. > I don't think that can be inferred with any confidence, unless a large > proportion of the MCV list were itself selected. Otherwise it might > match only a single MCV that just happens to have a high proportion, > then we assume all others have the same proportion. Well, of course it can't be inferred "with confidence". Sometimes you'll win and sometimes you'll lose. The question is, is this a better heuristic than what we use otherwise? The current estimate for non-anchored patterns is really pretty crummy, and even with a less aggressive length-vs-selectivity curve it's not going to be great. Another possibility is to merge the two estimates somehow. > I would favour the idea of dynamic sampling using a block sampling > approach; that was a natural extension of improving ANALYZE also. One thing at a time please. Obtaining better statistics is one issue, but the one at hand here is what to do given particular statistics. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 10 19:36:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 007B49DC93E for ; Tue, 10 Jan 2006 19:36:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21658-06 for ; Tue, 10 Jan 2006 19:36:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id D52139DC86A for ; Tue, 10 Jan 2006 19:36:43 -0400 (AST) Received: from [192.168.0.3] (unknown [84.12.184.6]) by smtp.nildram.co.uk (Postfix) with ESMTP id 21296269972; Tue, 10 Jan 2006 23:36:42 +0000 (GMT) Subject: Re: NOT LIKE much faster than LIKE? From: Simon Riggs To: Tom Lane Cc: Matteo Beccati , Andrea Arcangeli , pgsql-performance@postgresql.org In-Reply-To: <6398.1136931685@sss.pgh.pa.us> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> <1136930796.21025.486.camel@localhost.localdomain> <6398.1136931685@sss.pgh.pa.us> Content-Type: text/plain Date: Tue, 10 Jan 2006 23:36:45 +0000 Message-Id: <1136936205.21025.507.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.057 required=5 tests=[AWL=0.057] X-Spam-Score: 0.057 X-Spam-Level: X-Archive-Number: 200601/94 X-Sequence-Number: 16572 On Tue, 2006-01-10 at 17:21 -0500, Tom Lane wrote: > Simon Riggs writes: > > I think its OK to use the MCV, but I have a problem with the current > > heuristics: they only work for randomly generated strings, since the > > selectivity goes down geometrically with length. > > We could certainly use a less aggressive curve for that. You got a > specific proposal? I read some research not too long ago that showed a frequency curve of words by syllable length. I'll dig that out tomorrow. > > I would favour the idea of dynamic sampling using a block sampling > > approach; that was a natural extension of improving ANALYZE also. > > One thing at a time please. Obtaining better statistics is one issue, > but the one at hand here is what to do given particular statistics. I meant use the same sampling approach as I was proposing for ANALYZE, but do this at plan time for the query. That way we can apply the function directly to the sampled rows and estimate selectivity. I specifically didn't mention that in the Ndistinct discussion because I didn't want to confuse the subject further, but the underlying block sampling method would be identical, so the code is already almost there...we just need to eval the RestrictInfo against the sampled tuples. Best Regards, Simon Riggs From pgsql-performance-owner@postgresql.org Tue Jan 10 20:29:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E0B299DC81E for ; Tue, 10 Jan 2006 20:29:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27233-08 for ; Tue, 10 Jan 2006 20:29:23 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 4E9899DC994 for ; Tue, 10 Jan 2006 20:29:18 -0400 (AST) Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by svr4.postgresql.org (Postfix) with ESMTP id EABB75AF031 for ; Wed, 11 Jan 2006 00:29:21 +0000 (GMT) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 10 Jan 2006 16:28:06 -0800 Subject: Re: help tuning queries on large database From: Mark Lewis To: Ron Cc: pgsql-performance@postgresql.org In-Reply-To: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> References: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Tue, 10 Jan 2006 16:28:06 -0800 Message-Id: <1136939286.22590.27.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-22) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/95 X-Sequence-Number: 16573 Ron, A few days back you mentioned: > Upgrade your kernel to at least 2.6.12 > There's a known issue with earlier versions of the 2.6.x kernel and > 64b CPUs like the Opteron. See kernel.org for details. > I did some searching and couldn't find any obvious mention of this issue (I gave up after searching through the first few hundred instances of "64" in the 2.6.12 changelog). Would you mind being a little more specific about which issue you're talking about? We're about to deploy some new 16GB RAM Opteron DB servers and I'd like to check and make sure RH backported whatever the fix was to their current RHEL4 kernel. Thanks, Mark Lewis From pgsql-performance-owner@postgresql.org Tue Jan 10 23:06:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 32E049DC832 for ; Tue, 10 Jan 2006 23:06:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65339-03 for ; Tue, 10 Jan 2006 23:06:13 -0400 (AST) X-Greylist: delayed 00:59:58.586091 by SQLgrey- Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id E07459DC812 for ; Tue, 10 Jan 2006 23:06:05 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [63.226.156.118] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 81113492 for pgsql-performance@postgresql.org; Tue, 10 Jan 2006 18:06:09 -0800 From: "Dave Dutcher" To: Subject: Left Join Performance vs Inner Join Performance Date: Tue, 10 Jan 2006 20:06:08 -0600 Message-ID: <011f01c61653$96c509f0$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0120_01C61621.4C2A99F0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001, UPPERCASE_25_50=0] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/96 X-Sequence-Number: 16574 This is a multi-part message in MIME format. ------=_NextPart_000_0120_01C61621.4C2A99F0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hello, I have an inner join query that runs fast, but I when I change to a left join the query runs 96 times slower. I wish I could always do an inner join, but there are rare times when there isn't data in the right hand table. I could expect a small performance hit, but the difference is so large I figure I must be doing something wrong. What I think is the strangest is how similar the two query plans are. Query (inner join version, just replace inner with left for other version): select p.owner_trader_id, p.strategy_id, m.last, m.bid, m.ask from om_position p inner join om_instrument_mark m on m.instrument_id = p.instrument_id and m.data_source_id = 5 and m.date = '2005-02-03' where p.as_of_date = '2005-02-03' and p.fund_id = 'TRIDE' and p.owner_trader_id = 'tam4' and p.strategy_id = 'BASKET1' Query plan for inner join: Nested Loop (cost=0.00..176.99 rows=4 width=43) (actual time=0.234..14.182 rows=193 loops=1) -> Index Scan using as_of_date_om_position_index on om_position p (cost=0.00..68.26 rows=19 width=20) (actual time=0.171..5.210 rows=193 loops=1) Index Cond: (as_of_date = '2005-02-03'::date)" Filter: (((fund_id)::text = 'TRIDE'::text) AND ((owner_trader_id)::text = 'tam4'::text) AND ((strategy_id)::text = 'BASKET1'::text)) -> Index Scan using om_instrument_mark_pkey on om_instrument_mark m (cost=0.00..5.71 rows=1 width=31) (actual time=0.028..0.032 rows=1 loops=193) Index Cond: ((m.instrument_id = "outer".instrument_id) AND (m.data_source_id = 5) AND (m.date = '2005-02-03'::date)) Total runtime: 14.890 ms Query plan for left join: Nested Loop Left Join (cost=0.00..7763.36 rows=19 width=43) (actual time=3.005..1346.308 rows=193 loops=1) -> Index Scan using as_of_date_om_position_index on om_position p (cost=0.00..68.26 rows=19 width=20) (actual time=0.064..6.654 rows=193 loops=1) Index Cond: (as_of_date = '2005-02-03'::date) Filter: (((fund_id)::text = 'TRIDE'::text) AND ((owner_trader_id)::text = 'tam4'::text) AND ((strategy_id)::text = 'BASKET1'::text)) -> Index Scan using om_instrument_mark_pkey on om_instrument_mark m (cost=0.00..404.99 rows=1 width=31) (actual time=3.589..6.919 rows=1 loops=193) Index Cond: (m.instrument_id = "outer".instrument_id) Filter: ((data_source_id = 5) AND (date = '2005-02-03'::date)) Total runtime: 1347.159 ms Table Definitions: CREATE TABLE om_position ( fund_id varchar(10) NOT NULL DEFAULT ''::character varying, owner_trader_id varchar(10) NOT NULL DEFAULT ''::character varying, strategy_id varchar(30) NOT NULL DEFAULT ''::character varying, instrument_id int4 NOT NULL DEFAULT 0, as_of_date date NOT NULL DEFAULT '0001-01-01'::date, pos numeric(22,9) NOT NULL DEFAULT 0.000000000, cf_account_id int4 NOT NULL DEFAULT 0, cost numeric(22,9) NOT NULL DEFAULT 0.000000000, CONSTRAINT om_position_pkey PRIMARY KEY (fund_id, owner_trader_id, strategy_id, cf_account_id, instrument_id, as_of_date), CONSTRAINT "$1" FOREIGN KEY (strategy_id) REFERENCES om_strategy (strategy_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "$2" FOREIGN KEY (fund_id) REFERENCES om_fund (fund_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "$3" FOREIGN KEY (cf_account_id) REFERENCES om_cf_account (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "$4" FOREIGN KEY (owner_trader_id) REFERENCES om_trader (trader_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) WITH OIDS; CREATE INDEX as_of_date_om_position_index ON om_position USING btree (as_of_date); CREATE TABLE om_instrument_mark ( instrument_id int4 NOT NULL DEFAULT 0, data_source_id int4 NOT NULL DEFAULT 0, date date NOT NULL DEFAULT '0001-01-01'::date, "last" numeric(22,9) NOT NULL DEFAULT 0.000000000, bid numeric(22,9) NOT NULL DEFAULT 0.000000000, ask numeric(22,9) NOT NULL DEFAULT 0.000000000, "comment" varchar(150) NOT NULL DEFAULT ''::character varying, trader_id varchar(10) NOT NULL DEFAULT 'auto'::character varying, CONSTRAINT om_instrument_mark_pkey PRIMARY KEY (instrument_id, data_source_id, date), CONSTRAINT "$1" FOREIGN KEY (instrument_id) REFERENCES om_instrument (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "$2" FOREIGN KEY (data_source_id) REFERENCES om_data_source (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT om_instrument_mark_trader_id_fkey FOREIGN KEY (trader_id) REFERENCES om_trader (trader_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) WITH OIDS; Thanks for any help ------=_NextPart_000_0120_01C61621.4C2A99F0 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

Hello,

 

I have an inner join query that runs fast, but I when = I change to a left join the query runs 96 times = slower.  I wish I could always do an = inner join, but there are rare times when there isn’t data in the right hand table.  I could expect a = small performance hit, but the difference is so large I figure I must be doing something wrong.  What I = think is the strangest is how similar the two query plans = are.

 

Query (inner join version, just replace inner with = left for other version):

select<= font size=3D2 face=3DArial> =

p.owner_trader_id, p.strategy_id, m.last, = m.bid, m.ask

from =

om_position p inner join om_instrument_mark m on m.instrument_id =3D p.instrument_id and m.data_source_id =3D 5 and m.date =3D '2005-02-03' =

where p.as_of_date =3D '2005-02-03' and p.fund_id =3D 'TRIDE' and p.owner_trader_id =3D 'tam4' = and p.strategy_id =3D = 'BASKET1'

 

Query plan for inner = join:

Nested Loop  (cost=3D0.00..176.99 = rows=3D4 width=3D43) (actual time=3D0.234..14.182 rows=3D193 = loops=3D1)

  ->  = Index Scan using as_of_date_om_position_index on om_position p  (cost=3D0.00..68.26 rows=3D19 width=3D20) (actual = time=3D0.171..5.210 rows=3D193 loops=3D1)

        = Index Cond: (as_of_date =3D '2005-02-03'::date)"

        Filter: (((fund_id)::text =3D 'TRIDE'::text) AND ((owner_trader_id)::text =3D 'tam4'::text) AND ((strategy_id)::text = =3D 'BASKET1'::text))

  ->  = Index Scan using om_instrument_mark_pkey on om_instrument_mark m  (cost=3D0.00..5.71 = rows=3D1 width=3D31) (actual time=3D0.028..0.032 rows=3D1 = loops=3D193)

        Index Cond: ((m.instrument_id =3D "outer".instrument_id) AND = (m.data_source_id =3D 5) AND (m.date =3D '2005-02-03'::date))

Total runtime: 14.890 ms

 

Query plan for left = join:

Nested Loop Left Join  (cost=3D0.00..7763.36 = rows=3D19 width=3D43) (actual time=3D3.005..1346.308 rows=3D193 = loops=3D1)

  ->  = Index Scan using as_of_date_om_position_index on om_position p  (cost=3D0.00..68.26 rows=3D19 width=3D20) (actual = time=3D0.064..6.654 rows=3D193 loops=3D1)

        Index Cond: (as_of_date =3D '2005-02-03'::date)

        Filter: (((fund_id)::text =3D 'TRIDE'::text) AND ((owner_trader_id)::text =3D 'tam4'::text) AND ((strategy_id)::text = =3D 'BASKET1'::text))

  ->  = Index Scan using om_instrument_mark_pkey on om_instrument_mark m  (cost=3D0.00..404.99 = rows=3D1 width=3D31) (actual time=3D3.589..6.919 rows=3D1 = loops=3D193)

        Index Cond: (m.instrument_id =3D "outer".instrument_id)=

        Filter: ((data_source_id =3D 5) AND = (date =3D '2005-02-03'::date))

Total runtime: 1347.159 = ms

 

 

Table Definitions:

CREATE TABLE om_position

(

  fund_id varchar(10) NOT NULL DEFAULT ''::character varying,

  owner_trader_id varchar(10) NOT NULL DEFAULT ''::character = varying,

  strategy_id varchar(30) NOT NULL DEFAULT ''::character varying,

  instrument_id int4 NOT NULL DEFAULT = 0,

  as_of_date date NOT = NULL DEFAULT '0001-01-01'::date,

  pos numeric(22,9) NOT NULL DEFAULT = 0.000000000,

  cf_account_id int4 NOT NULL DEFAULT = 0,

  cost numeric(22,9) NOT NULL DEFAULT = 0.000000000,

  = CONSTRAINT om_position_pkey PRIMARY KEY (fund_id, owner_trader_id, strategy_id, cf_account_id, instrument_id, as_of_date),

  = CONSTRAINT "$1" FOREIGN KEY (strategy_id)

      = REFERENCES om_strategy (strategy_id) MATCH SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION,

  = CONSTRAINT "$2" FOREIGN KEY (fund_id)

      = REFERENCES om_fund (fund_id) = MATCH SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION,

  = CONSTRAINT "$3" FOREIGN KEY (cf_account_id)

      = REFERENCES om_cf_account (id) MATCH = SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION,

  = CONSTRAINT "$4" FOREIGN KEY (owner_trader_id)

      = REFERENCES om_trader (trader_id) = MATCH SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION

)

WITH OIDS;

CREATE INDEX as_of_date_om_position_index

  ON = om_position

  USING = btree

  (as_of_date);

 

CREATE TABLE om_instrument_mark

(

  instrument_id int4 NOT NULL DEFAULT = 0,

  data_source_id int4 NOT NULL DEFAULT = 0,

  date date NOT NULL = DEFAULT '0001-01-01'::date,

  = "last" numeric(22,9) NOT NULL DEFAULT = 0.000000000,

  bid numeric(22,9) NOT NULL DEFAULT = 0.000000000,

  ask numeric(22,9) NOT NULL DEFAULT = 0.000000000,

  = "comment" varchar(150) NOT NULL DEFAULT ''::character varying,

  trader_id varchar(10) NOT NULL DEFAULT 'auto'::character = varying,

  = CONSTRAINT om_instrument_mark_pkey PRIMARY KEY (instrument_id, data_source_id, = date),

  = CONSTRAINT "$1" FOREIGN KEY (instrument_id)

      = REFERENCES om_instrument (id) MATCH = SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION,

  = CONSTRAINT "$2" FOREIGN KEY (data_source_id)

      = REFERENCES om_data_source (id) MATCH = SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION,

  = CONSTRAINT om_instrument_mark_trader_id_fkey FOREIGN KEY = (trader_id)

      = REFERENCES om_trader (trader_id) = MATCH SIMPLE

      ON = UPDATE NO ACTION ON DELETE NO ACTION

)

WITH OIDS;

 

Thanks for any help

 

------=_NextPart_000_0120_01C61621.4C2A99F0-- From pgsql-performance-owner@postgresql.org Tue Jan 10 23:40:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1BA4F9DC9E3 for ; Tue, 10 Jan 2006 23:40:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70974-05 for ; Tue, 10 Jan 2006 23:40:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 3B25E9DC9D0 for ; Tue, 10 Jan 2006 23:40:31 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0B3eUgS007925; Tue, 10 Jan 2006 22:40:30 -0500 (EST) To: Simon Riggs cc: Matteo Beccati , Andrea Arcangeli , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <1136936205.21025.507.camel@localhost.localdomain> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> <1136930796.21025.486.camel@localhost.localdomain> <6398.1136931685@sss.pgh.pa.us> <1136936205.21025.507.camel@localhost.localdomain> Comments: In-reply-to Simon Riggs message dated "Tue, 10 Jan 2006 23:36:45 +0000" Date: Tue, 10 Jan 2006 22:40:30 -0500 Message-ID: <7924.1136950830@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/97 X-Sequence-Number: 16575 Simon Riggs writes: > I meant use the same sampling approach as I was proposing for ANALYZE, > but do this at plan time for the query. That way we can apply the > function directly to the sampled rows and estimate selectivity. I think this is so unlikely to be a win as to not even be worth spending any time discussing. The extra planning time across all queries will vastly outweigh the occasional improvement in plan choice for some queries. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 10 23:53:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E02E59DC801 for ; Tue, 10 Jan 2006 23:53:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72776-06 for ; Tue, 10 Jan 2006 23:53:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.invendra.net (sbx-01.invendra.net [66.139.76.16]) by postgresql.org (Postfix) with ESMTP id BD50E9DC810 for ; Tue, 10 Jan 2006 23:52:01 -0400 (AST) Received: from david.lang.hm (dsl081-044-215.lax1.dsl.speakeasy.net [64.81.44.215]) by mail.invendra.net (Postfix) with ESMTP id 01DA71AC3E9; Tue, 10 Jan 2006 19:52:18 -0800 (PST) Date: Tue, 10 Jan 2006 19:50:46 -0800 (PST) From: David Lang X-X-Sender: dlang@david.lang.hm To: "Charles A. Landemaine" Cc: pgsql-performance@postgresql.org Subject: Re: How to handle a large DB and simultaneous accesses? In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200601/98 X-Sequence-Number: 16576 On Tue, 10 Jan 2006, Charles A. Landemaine wrote: > Hello, > > I have to develop a companies search engine (looks like the Yellow > pages). We're using PostgreSQL at the company, and the initial DB is > 2GB large, as it > has companies from the entire world, with a fair amount of information. > > What reading do you suggest so that we can develop the search engine > core, in order that the result pages show up instantly, no matter the > heavy load and > the DB size. The DB is 2GB but should grow to up to 10GB in 2 years, > and there should be 250,000 unique visitors per month by the end of > the year. > > Are there special techniques? Maybe there's a way to sort of cache > search results? We're using PHP5 + phpAccelerator. > Thanks, frankly that is a small enough chunk of data compared to available memory sizes that I think your best bet is to plan to have enough ram that you only do disk I/O to write and on boot. a dual socket Opteron system can hold 16G with 2G memory modules (32G as 4G modules become readily available over the next couple of years). this should be enough to keep your data and indexes in ram at all times. if you find that other system processes push the data out of ram consider loading the data from disk to a ramfs filesystem, just make sure you don't update the ram-only copy (or if you do that you have replication setup to replicate from the ram copy to a copy on real disks somewhere). depending on your load you could go with single core or dual core chips (and the cpu's are a small enough cost compared to this much ram that you may as well go with the dual core cpu's) now even with your data in ram you can slow down if your queries, indexes, and other settings are wrong, but if performance is important you should be able to essentially eliminate disks for databases of this size. David Lang From pgsql-performance-owner@postgresql.org Wed Jan 11 00:38:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B1DD09DC809 for ; Wed, 11 Jan 2006 00:38:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80416-06 for ; Wed, 11 Jan 2006 00:38:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4BEC09DC801 for ; Wed, 11 Jan 2006 00:38:21 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0B4cKnW008322; Tue, 10 Jan 2006 23:38:20 -0500 (EST) To: "Dave Dutcher" cc: pgsql-performance@postgresql.org Subject: Re: Left Join Performance vs Inner Join Performance In-reply-to: <011f01c61653$96c509f0$8300a8c0@tridecap.com> References: <011f01c61653$96c509f0$8300a8c0@tridecap.com> Comments: In-reply-to "Dave Dutcher" message dated "Tue, 10 Jan 2006 20:06:08 -0600" Date: Tue, 10 Jan 2006 23:38:20 -0500 Message-ID: <8321.1136954300@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/99 X-Sequence-Number: 16577 "Dave Dutcher" writes: > I have an inner join query that runs fast, but I when I change to a left > join the query runs 96 times slower. This looks like an issue that is fixed in the latest set of releases, namely that OUTER JOIN ON conditions that reference only the inner side of the join weren't getting pushed down into indexquals. See thread here: http://archives.postgresql.org/pgsql-performance/2005-12/msg00134.php and patches in this and the following messages: http://archives.postgresql.org/pgsql-committers/2005-12/msg00105.php regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 01:11:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8B5129DC887 for ; Wed, 11 Jan 2006 01:11:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84614-07 for ; Wed, 11 Jan 2006 01:11:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) by postgresql.org (Postfix) with ESMTP id AFC329DC899 for ; Wed, 11 Jan 2006 01:11:20 -0400 (AST) Received: (qmail 11085 invoked by uid 1010); 11 Jan 2006 00:11:20 -0500 Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid 1002 with qmail-scanner-1.20 (spamassassin: 3.1.0. Clear:RC:0(63.147.78.66):SA:0(?/?):. Processed in 1.79774 secs); 11 Jan 2006 05:11:20 -0000 Received: from unknown (HELO thunder.logicalchaos.org) (perl?test@logicalchaos.org@63.147.78.66) by rambo.iniquinet.com with AES256-SHA encrypted SMTP; 11 Jan 2006 00:11:18 -0500 Received: from logicalchaos.org (localhost [127.0.0.1]) by thunder.logicalchaos.org (Postfix) with ESMTP id ADBA5F06F8; Tue, 10 Jan 2006 22:11:16 -0700 (MST) Date: Tue, 10 Jan 2006 22:10:55 -0700 From: Robert Creager To: Michael Fuhr Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060110221055.053596ab@thunder.logicalchaos.org> In-Reply-To: <20060110055818.GA55076@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i586-mandriva-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Signature_Tue__10_Jan_2006_22_10_55_-0700_Gs9GVXt/AaVacPA+"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/100 X-Sequence-Number: 16578 --Signature_Tue__10_Jan_2006_22_10_55_-0700_Gs9GVXt/AaVacPA+ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Ok, I'm back, and in a little better shape. The query is now correct, but still is slow because of lack of index usage.= I don't know how to structure the query correctly to use the index. Taken individually: weather=3D# explain analyze select * from doy_agg where doy =3D extract( do= y from now() ); QUERY PLAN = =20 ---------------------------------------------------------------------------= ------------------------------------------------------------- HashAggregate (cost=3D13750.67..13750.71 rows=3D2 width=3D20) (actual tim= e=3D123.134..123.135 rows=3D1 loops=3D1) -> Bitmap Heap Scan on readings (cost=3D25.87..13720.96 rows=3D3962 wi= dth=3D20) (actual time=3D6.384..116.559 rows=3D4175 loops=3D1) Recheck Cond: (date_part('doy'::text, "when") =3D date_part('doy':= :text, now())) -> Bitmap Index Scan on readings_doy_index (cost=3D0.00..25.87 r= ows=3D3962 width=3D0) (actual time=3D5.282..5.282 rows=3D4215 loops=3D1) Index Cond: (date_part('doy'::text, "when") =3D date_part('d= oy'::text, now())) Total runtime: 123.366 ms produces the data: weather=3D# select * from doy_agg where doy =3D extract( doy from now() ); doy | avg_windspeed | max_windspeed=20 -----+------------------+--------------- 10 | 8.53403056583666 | 59 and: weather=3D# EXPLAIN ANALYZE weather-# SELECT *, weather-# unmunge_time( time_group ) AS time weather-# FROM minute."windspeed" weather-# WHERE unmunge_time( time_group ) > ( now() - '24 hour'::interval ) weather-# ORDER BY time_group; QUERY PL= AN =20 ---------------------------------------------------------------------------= ---------------------------------------------------------------------- Sort (cost=3D595.33..595.77 rows=3D176 width=3D28) (actual time=3D4.762..= 4.828 rows=3D283 loops=3D1) Sort Key: time_group -> Bitmap Heap Scan on windspeed (cost=3D2.62..588.76 rows=3D176 width= =3D28) (actual time=3D0.901..3.834 rows=3D283 loops=3D1) Recheck Cond: (unmunge_time(time_group) > (now() - '24:00:00'::int= erval)) -> Bitmap Index Scan on minute_windspeed_unmunge_index (cost=3D0= .00..2.62 rows=3D176 width=3D0) (actual time=3D0.745..0.745 rows=3D284 loop= s=3D1) Index Cond: (unmunge_time(time_group) > (now() - '24:00:00':= :interval)) Total runtime: 5.108 ms produces: time_group | min_reading | max_reading | avg_reading | = time =20 ------------+-------------------+-------------+-------------------+--------= ------------- 1136869500 | 0.8 | 6 | 2.62193548387097 | 2006-01= -09 22:05:00 1136869800 | 0 | 3 | 0.406021505376343 | 2006-01= -09 22:10:00 1136870100 | 0 | 5 | 1.68 | 2006-01= -09 22:15:00 ...=20 But I want the composite of the two queries, and I'm stuck on: weather=3D# EXPLAIN ANALYZE weather-# SELECT *, weather-# unmunge_time( time_group ) AS time weather-# FROM minute."windspeed" weather-# JOIN doy_agg ON( EXTRACT( doy FROM unmunge_time( time_group ) ) = =3D doy ) weather-# WHERE unmunge_time( time_group ) > ( now() - '24 hour'::interval ) weather-# ORDER BY time_group; QU= ERY PLAN = =20 ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------- Sort (cost=3D153627.67..153628.48 rows=3D322 width=3D48) (actual time=3D1= 0637.681..10637.748 rows=3D286 loops=3D1) Sort Key: windspeed.time_group -> Merge Join (cost=3D153604.82..153614.26 rows=3D322 width=3D48) (act= ual time=3D10633.375..10636.728 rows=3D286 loops=3D1) Merge Cond: ("outer"."?column5?" =3D "inner".doy) -> Sort (cost=3D594.89..595.33 rows=3D176 width=3D28) (actual ti= me=3D5.539..5.612 rows=3D286 loops=3D1) Sort Key: date_part('doy'::text, unmunge_time(windspeed.time= _group)) -> Bitmap Heap Scan on windspeed (cost=3D2.62..588.32 rows= =3D176 width=3D28) (actual time=3D0.918..4.637 rows=3D286 loops=3D1) Recheck Cond: (unmunge_time(time_group) > (now() - '24= :00:00'::interval)) -> Bitmap Index Scan on minute_windspeed_unmunge_inde= x (cost=3D0.00..2.62 rows=3D176 width=3D0) (actual time=3D0.739..0.739 row= s=3D287 loops=3D1) Index Cond: (unmunge_time(time_group) > (now() -= '24:00:00'::interval)) -> Sort (cost=3D153009.93..153010.84 rows=3D366 width=3D20) (act= ual time=3D10627.699..10627.788 rows=3D295 loops=3D1) Sort Key: doy_agg.doy -> HashAggregate (cost=3D152984.28..152990.69 rows=3D366 w= idth=3D20) (actual time=3D10625.649..10626.601 rows=3D366 loops=3D1) -> Seq Scan on readings (cost=3D0.00..145364.93 rows= =3D1015914 width=3D20) (actual time=3D0.079..8901.123 rows=3D1015917 loops= =3D1) Total runtime: 10638.298 ms Where: weather=3D# \d doy_agg View "public.doy_agg" Column | Type | Modifiers=20 ---------------+------------------+----------- doy | double precision |=20 avg_windspeed | double precision |=20 max_windspeed | integer |=20 View definition: SELECT doy_readings.doy, avg(doy_readings.windspeedaverage1) AS avg_windsp= eed, max(doy_readings.windspeedmax1) AS max_windspeed FROM ONLY doy_readings GROUP BY doy_readings.doy; which I don't want because of the full scan on readings. I can easily do the two queries seperately in the script utilizing this dat= a, but want to do it in the db itself. I figure I'm just not seeing how to= combine the two queries effectively. Thoughts? Thanks, Rob --=20 22:08:50 up 3 days, 14:35, 9 users, load average: 2.71, 2.48, 2.51 Linux 2.6.12-12-2 #4 SMP Tue Jan 3 19:56:19 MST 2006 --Signature_Tue__10_Jan_2006_22_10_55_-0700_Gs9GVXt/AaVacPA+ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iEYEARECAAYFAkPEk3QACgkQLQ/DKuwDYznPUQCffh1APeMK0jSrKv03dgrm/25K fhgAn0+2id9WEgmP0PfHzX5CVEFNbTyr =kDMv -----END PGP SIGNATURE----- --Signature_Tue__10_Jan_2006_22_10_55_-0700_Gs9GVXt/AaVacPA+-- From pgsql-performance-owner@postgresql.org Wed Jan 11 02:03:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B0DD19DC800 for ; Wed, 11 Jan 2006 02:03:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97787-01 for ; Wed, 11 Jan 2006 02:03:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth07.mail.atl.earthlink.net (smtpauth07.mail.atl.earthlink.net [209.86.89.67]) by postgresql.org (Postfix) with ESMTP id 9197F9DC801 for ; Wed, 11 Jan 2006 02:03:55 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=SK94i2hlZY1X6eqxcidqObTVtBaE6rCA8k7hY4VrVie/4SLprslNbaRtYFb4tTm0; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.244.95] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth07.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1EwZ5N-0007vM-1N; Wed, 11 Jan 2006 01:03:53 -0500 Message-Id: <7.0.1.0.2.20060111005534.0378a630@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Wed, 11 Jan 2006 01:03:48 -0500 To: Mark Lewis ,pgsql-performance@postgresql.org From: Ron Subject: Re: help tuning queries on large database In-Reply-To: <1136939286.22590.27.camel@archimedes> References: <7.0.1.0.2.20060108160633.026bd358@earthlink.net> <1136939286.22590.27.camel@archimedes> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bcfe12da2425cfba20cce11acfa72a174a350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.244.95 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.421 required=5 tests=[AWL=-0.058, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.421 X-Spam-Level: X-Archive-Number: 200601/101 X-Sequence-Number: 16579 At 07:28 PM 1/10/2006, Mark Lewis wrote: >Ron, > >A few days back you mentioned: > > > Upgrade your kernel to at least 2.6.12 > > There's a known issue with earlier versions of the 2.6.x kernel and > > 64b CPUs like the Opteron. See kernel.org for details. > > > >I did some searching and couldn't find any obvious mention of this issue >(I gave up after searching through the first few hundred instances of >"64" in the 2.6.12 changelog). > >Would you mind being a little more specific about which issue you're >talking about? We're about to deploy some new 16GB RAM Opteron DB >servers and I'd like to check and make sure RH backported whatever the >fix was to their current RHEL4 kernel. There are 3 issues I know about in general: 1= As Peter Royal noted on this list, pre 12 versions of 2.6.x have problems with RAM of >= 4GB. 2= Pre 12 versions on 2.6.x when running A64 or Xeon 64b SMP seem to be susceptible to "context switch storms". 3= Physical and memory IO is considerably improved in the later versions of 2.6.x compared to 2.6.11 or earlier. Talk to a real Linux kernel guru (I am not) for details and specifics. Ron From pgsql-performance-owner@postgresql.org Wed Jan 11 03:57:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 00CF89DC809 for ; Wed, 11 Jan 2006 03:57:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10915-07 for ; Wed, 11 Jan 2006 03:57:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 612C79DC847 for ; Wed, 11 Jan 2006 03:57:00 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0B7uuo5007983 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2006 00:56:58 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0B7uu9v051423; Wed, 11 Jan 2006 00:56:56 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0B7utHu051422; Wed, 11 Jan 2006 00:56:55 -0700 (MST) (envelope-from mfuhr) Date: Wed, 11 Jan 2006 00:56:55 -0700 From: Michael Fuhr To: Robert Creager Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060111075655.GA51292@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060110221055.053596ab@thunder.logicalchaos.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.087 required=5 tests=[AWL=0.087] X-Spam-Score: 0.087 X-Spam-Level: X-Archive-Number: 200601/102 X-Sequence-Number: 16580 On Tue, Jan 10, 2006 at 10:10:55PM -0700, Robert Creager wrote: > The query is now correct, but still is slow because of lack of > index usage. I don't know how to structure the query correctly to > use the index. Have you tried adding restrictions on doy in the WHERE clause? Something like this, I think: WHERE ... AND doy >= EXTRACT(doy FROM now() - '24 hour'::interval) AND doy <= EXTRACT(doy FROM now()) Something else occurred to me: do you (or will you) have more than one year of data? If so then matching on doy could be problematic unless you also check for the year, or unless you want to match more than one year. -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 11 04:00:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 33EB69DC809 for ; Wed, 11 Jan 2006 04:00:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13324-10 for ; Wed, 11 Jan 2006 04:00:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (217-133-42-200.b2b.tiscali.it [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id E194C9DC865 for ; Wed, 11 Jan 2006 03:59:57 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id E9C6E1C18DB; Wed, 11 Jan 2006 08:59:56 +0100 (CET) Date: Wed, 11 Jan 2006 08:59:56 +0100 From: Andrea Arcangeli To: Tom Lane Cc: Greg Stark , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111075956.GU15897@opteron.random> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <20060110034721.GC20168@opteron.random> <87y81oyv6x.fsf@stark.xeocode.com> <20060110152720.GL15897@opteron.random> <152.1136908013@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152.1136908013@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/103 X-Sequence-Number: 16581 On Tue, Jan 10, 2006 at 10:46:53AM -0500, Tom Lane wrote: > Not with that data, but maybe if you increased the statistics target for > the column to 100 or so, you'd catch enough values to get reasonable > results. Sorry, I'm not expert with postgresql, could you tell me how to increase the statistic target? In another email you said you applied a patch to CVS, please let me know if you've anything to test for me, and I'll gladly test it immediately (I've a sandbox so it's ok even if it corrupts the db ;). Thanks! From pgsql-performance-owner@postgresql.org Wed Jan 11 05:00:19 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7E5279DC993 for ; Wed, 11 Jan 2006 05:00:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25842-07 for ; Wed, 11 Jan 2006 05:00:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 1A4B59DC981 for ; Wed, 11 Jan 2006 05:00:15 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0B9081c008047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2006 02:00:12 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0B908Dp051768; Wed, 11 Jan 2006 02:00:08 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0B908sw051767; Wed, 11 Jan 2006 02:00:08 -0700 (MST) (envelope-from mfuhr) Date: Wed, 11 Jan 2006 02:00:08 -0700 From: Michael Fuhr To: Robert Creager Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060111090008.GA51672@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> <20060111075655.GA51292@winnie.fuhr.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060111075655.GA51292@winnie.fuhr.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.087 required=5 tests=[AWL=0.087] X-Spam-Score: 0.087 X-Spam-Level: X-Archive-Number: 200601/104 X-Sequence-Number: 16582 On Wed, Jan 11, 2006 at 12:56:55AM -0700, Michael Fuhr wrote: > WHERE ... > AND doy >= EXTRACT(doy FROM now() - '24 hour'::interval) > AND doy <= EXTRACT(doy FROM now()) To work on 1 Jan this should be more like WHERE ... AND (doy = EXTRACT(doy FROM now() - '24 hour'::interval) OR doy = EXTRACT(doy FROM now())) In any case the point is to add conditions to the WHERE clause that will use an index on the table for which you're currently getting a sequential scan. -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 11 05:07:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3268D9DC865 for ; Wed, 11 Jan 2006 05:07:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27220-03 for ; Wed, 11 Jan 2006 05:07:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id EF9209DC813 for ; Wed, 11 Jan 2006 05:07:46 -0400 (AST) Received: from [192.168.0.3] (unknown [84.12.184.6]) by smtp.nildram.co.uk (Postfix) with ESMTP id 22DA626A8DC; Wed, 11 Jan 2006 09:07:44 +0000 (GMT) Subject: Re: NOT LIKE much faster than LIKE? From: Simon Riggs To: Tom Lane Cc: Matteo Beccati , Andrea Arcangeli , pgsql-performance@postgresql.org In-Reply-To: <7924.1136950830@sss.pgh.pa.us> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> <1136930796.21025.486.camel@localhost.localdomain> <6398.1136931685@sss.pgh.pa.us> <1136936205.21025.507.camel@localhost.localdomain> <7924.1136950830@sss.pgh.pa.us> Content-Type: text/plain Date: Wed, 11 Jan 2006 09:07:45 +0000 Message-Id: <1136970465.21025.527.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.058 required=5 tests=[AWL=0.058] X-Spam-Score: 0.058 X-Spam-Level: X-Archive-Number: 200601/105 X-Sequence-Number: 16583 On Tue, 2006-01-10 at 22:40 -0500, Tom Lane wrote: > Simon Riggs writes: > > I meant use the same sampling approach as I was proposing for ANALYZE, > > but do this at plan time for the query. That way we can apply the > > function directly to the sampled rows and estimate selectivity. > > I think this is so unlikely to be a win as to not even be worth spending > any time discussing. The extra planning time across all queries will > vastly outweigh the occasional improvement in plan choice for some > queries. Extra planning time would be bad, so clearly we wouldn't do this when we already have relevant ANALYZE statistics. I would suggest we do this only when all of these are true - when accessing more than one table, so the selectivity could effect a join result - when we have either no ANALYZE statistics, or ANALYZE statistics are not relevant to estimating selectivity, e.g. LIKE - when access against the single table in question cannot find an index to use from other RestrictInfo predicates I imagined that this would also be controlled by a GUC, dynamic_sampling which would be set to zero by default, and give a measure of sample size to use. (Or just a bool enable_sampling = off (default)). This is mentioned now because the plan under consideration in this thread would be improved by this action. It also isn't a huge amount of code to get it to work. Best Regards, Simon Riggs From pgsql-performance-owner@postgresql.org Wed Jan 11 05:18:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6444B9DC9A5 for ; Wed, 11 Jan 2006 05:18:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31791-01 for ; Wed, 11 Jan 2006 05:18:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (217-133-42-200.b2b.tiscali.it [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id 599AE9DC9A4 for ; Wed, 11 Jan 2006 05:18:40 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id 687871C18DD; Wed, 11 Jan 2006 10:18:41 +0100 (CET) Date: Wed, 11 Jan 2006 10:18:41 +0100 From: Andrea Arcangeli To: Simon Riggs Cc: Tom Lane , Matteo Beccati , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111091841.GA15897@opteron.random> References: <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> <1136930796.21025.486.camel@localhost.localdomain> <6398.1136931685@sss.pgh.pa.us> <1136936205.21025.507.camel@localhost.localdomain> <7924.1136950830@sss.pgh.pa.us> <1136970465.21025.527.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1136970465.21025.527.camel@localhost.localdomain> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/106 X-Sequence-Number: 16584 On Wed, Jan 11, 2006 at 09:07:45AM +0000, Simon Riggs wrote: > I would suggest we do this only when all of these are true > - when accessing more than one table, so the selectivity could effect a > join result FWIW my problem only happens if I join: on the main table where the kernel_version string is stored (without joins), everything is always blazing fast. So this requirement certainly sounds fine to me. From pgsql-performance-owner@postgresql.org Wed Jan 11 05:42:37 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3B8A29DC802 for ; Wed, 11 Jan 2006 05:42:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31851-07 for ; Wed, 11 Jan 2006 05:42:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 430BA9DC813 for ; Wed, 11 Jan 2006 05:42:33 -0400 (AST) Received: from [10.1.0.20] (unknown [10.1.0.20]) by mail.barettadeit.com (Postfix) with ESMTP id 40F957D258E; Wed, 11 Jan 2006 10:46:30 +0100 (CET) Message-ID: <43C4D315.8010505@barettadeit.com> Date: Wed, 11 Jan 2006 10:42:45 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: 500x speed-down: Wrong statistics! References: <43C26A5F.7040702@barettadeit.com> <43C27AFA.7060604@beccati.com> <43C28DEA.60801@barettadeit.com> <6719.1136832065@sss.pgh.pa.us> <43C2B06B.4050506@barettadeit.com> <6914.1136833010@sss.pgh.pa.us> <43C3665F.5020106@barettadeit.com> <29702.1136906579@sss.pgh.pa.us> In-Reply-To: <29702.1136906579@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/107 X-Sequence-Number: 16585 Tom Lane wrote: > Alessandro Baretta writes: > >>I have no clue as to how or why the statistics were wrong >>yesterday--as I vacuum-analyzed continuously out of lack of any better >>idea--and I was stupid enough to re-timestamp everything before >>selecting from pg_stats. > > > Too bad. I would be interested to find out how, if the stats were > up-to-date, the thing was still getting the row estimate so wrong. > If you manage to get the database back into its prior state please > do send along the pg_stats info. I have some more information on this issue, which clears PostgreSQL's planner of all suspects. I am observing severe corruption of the bookkeeping fields managed by the xdbs rule/trigger "complex". I am unable to pinpoint the cause, right now, but the effect is that after running a few hours' test on the end-user application (which never interacts directly with xdbs_* fields, and thus cannot possibly mangle them) most tuples (the older ones, apparently) get thei timestamps set to NULL. Before vacuum-analyzing the table, yesterday's statistics were in effect, and the planner used the appropriate indexes. Now, after vacuum-analyzing the table, the pg_stats row for the xdbs_modified field no longer exists (!), and the planner has reverted to the Nested Loop Seq Scan join strategy. Hence, all the vacuum-analyzing I was doing when complaining against the planner was actually collecting completely screwed statistics, and this is why the ALTER TABLE ... SET STATISTICS 1000 did not help at all! Ok. I plead guilty and ask for the clemency of the court. I'll pay my debt with society with a long term of pl/pgsql code debugging... Alex From pgsql-performance-owner@postgresql.org Wed Jan 11 06:59:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6D4899DC9D6 for ; Wed, 11 Jan 2006 06:59:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47539-03 for ; Wed, 11 Jan 2006 06:59:55 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.203]) by postgresql.org (Postfix) with ESMTP id 649C79DC9CE for ; Wed, 11 Jan 2006 06:59:50 -0400 (AST) Received: by zproxy.gmail.com with SMTP id z31so121753nzd for ; Wed, 11 Jan 2006 02:59:53 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=eDZ/UrOeWupUtg4x8ymAwSfINYlrv8T8URkgsn+NHvOpd91vzgbnoWYNKunronbsbOHkHI17zh1+vsHudnp3F1DnvJ4ql/yrbjcChYKt6sbcA12eqJVKGXzQoh9bJMhzZNvN5IyQg/EHlVObrCVoXOAnjO60D/z97TI857AaItI= Received: by 10.65.239.15 with SMTP id q15mr169429qbr; Wed, 11 Jan 2006 02:59:53 -0800 (PST) Received: from ?10.80.1.43? ( [194.248.208.94]) by mx.gmail.com with ESMTP id q13sm115173qbq.2006.01.11.02.59.52; Wed, 11 Jan 2006 02:59:52 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v746.2) Content-Transfer-Encoding: 7bit Message-Id: Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: pgsql-performance@postgresql.org From: Bendik Rognlien Johansen Subject: Slow query with joins Date: Wed, 11 Jan 2006 11:59:39 +0100 X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/108 X-Sequence-Number: 16586 Hello! Has anyone got any tips for speeding up this query? It currently takes hours to start. PostgreSQL v8.x on (SuSe Linux) Thanks! no_people=# explain SELECT r.id AS r_id, r.firstname || ' ' || r.lastname AS r_name, ad.id AS ad_id, ad.type AS ad_type, ad.address AS ad_address, ad.postalcode AS ad_postalcode, ad.postalsite AS ad_postalsite, ad.priority AS ad_priority, ad.position[0] AS ad_lat, ad.position[1] AS ad_lon, ad.uncertainty AS ad_uncertainty, ad.extra AS ad_extra, co.id AS co_id, co.type AS co_type, co.value AS co_value, co.description AS co_description, co.priority AS co_priority, co.visible AS co_visible, co.searchable AS co_searchable FROM people r LEFT OUTER JOIN addresses ad ON(r.id = ad.record) LEFT OUTER JOIN contacts co ON(r.id = co.record) WHERE r.deleted = false AND r.original IS NULL AND co.deleted = false AND NOT ad.deleted ORDER BY r.id; QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------- Sort (cost=1152540.74..1152988.20 rows=178983 width=585) Sort Key: r.id -> Hash Join (cost=313757.11..1005334.96 rows=178983 width=585) Hash Cond: ("outer".record = "inner".id) -> Seq Scan on addresses ad (cost=0.00..428541.29 rows=4952580 width=136) Filter: (NOT deleted) -> Hash (cost=312039.95..312039.95 rows=27664 width=457) -> Hash Join (cost=94815.24..312039.95 rows=27664 width=457) Hash Cond: ("outer".record = "inner".id) -> Seq Scan on contacts co (cost=0.00..147791.54 rows=5532523 width=430) Filter: (deleted = false) -> Hash (cost=94755.85..94755.85 rows=23755 width=27) -> Index Scan using people_original_is_null on people r (cost=0.00..94755.85 rows=23755 width=27) Filter: ((deleted = false) AND (original IS NULL)) (14 rows) no_people=# \d contacts Table "public.contacts" Column | Type | Modifiers -------------+------------------------ +---------------------------------------------------------- id | integer | not null default nextval ('public.contacts_id_seq'::text) record | integer | type | integer | value | character varying(128) | description | character varying(255) | priority | integer | itescotype | integer | original | integer | source | integer | reference | character varying(32) | deleted | boolean | not null default false quality | integer | visible | boolean | not null default true searchable | boolean | not null default true Indexes: "contacts_pkey" PRIMARY KEY, btree (id) "contacts_deleted_idx" btree (deleted) "contacts_record_idx" btree (record) CLUSTER "contacts_source_reference_idx" btree (source, reference) no_people=# \d addresses Table "public.addresses" Column | Type | Modifiers -------------+------------------------ +----------------------------------------------------------- id | integer | not null default nextval ('public.addresses_id_seq'::text) record | integer | address | character varying(128) | extra | character varying(32) | postalcode | character varying(16) | postalsite | character varying(64) | description | character varying(255) | position | point | uncertainty | integer | default 99999999 priority | integer | type | integer | place | character varying(64) | floor | integer | side | character varying(8) | housename | character varying(64) | original | integer | source | integer | reference | character varying(32) | deleted | boolean | not null default false quality | integer | visible | boolean | not null default true searchable | boolean | not null default true Indexes: "addresses_pkey" PRIMARY KEY, btree (id) "addresses_deleted_idx" btree (deleted) "addresses_record_idx" btree (record) CLUSTER "addresses_source_reference_idx" btree (source, reference) no_people=# \d people Table "public.people" Column | Type | Modifiers ------------+-------------------------- +-------------------------------------------------------- id | integer | not null default nextval ('public.people_id_seq'::text) origid | integer | firstname | character varying(128) | default ''::character varying middlename | character varying(128) | default ''::character varying lastname | character varying(128) | default ''::character varying updated | timestamp with time zone | default ('now'::text)::timestamp(6) with time zone updater | integer | relevance | real | not null default 0 phonetic | text | indexed | boolean | default false record | text | original | integer | active | boolean | default true title | character varying(128) | deleted | boolean | not null default false Indexes: "people_pkey" PRIMARY KEY, btree (id) "people_indexed_idx" btree (indexed) "people_lower_lastname_firstname_idx" btree (lower (lastname::text), lower(firstname::text)) "people_original_is_null" btree (original) WHERE original IS NULL "people_relevance_idx" btree (relevance) "person_updated_idx" btree (updated) no_people=# From pgsql-performance-owner@postgresql.org Wed Jan 11 10:27:04 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3BADA9DC85E for ; Wed, 11 Jan 2006 10:27:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86977-08 for ; Wed, 11 Jan 2006 10:27:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) by postgresql.org (Postfix) with ESMTP id 405E19DC833 for ; Wed, 11 Jan 2006 10:27:00 -0400 (AST) Received: (qmail 8702 invoked by uid 1010); 11 Jan 2006 09:27:05 -0500 Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid 1002 with qmail-scanner-1.20 (spamassassin: 3.1.0. Clear:RC:0(63.147.78.66):SA:0(?/?):. Processed in 1.021922 secs); 11 Jan 2006 14:27:05 -0000 Received: from unknown (HELO thunder.logicalchaos.org) (perl?test@logicalchaos.org@63.147.78.66) by rambo.iniquinet.com with AES256-SHA encrypted SMTP; 11 Jan 2006 09:27:04 -0500 Received: from logicalchaos.org (localhost [127.0.0.1]) by thunder.logicalchaos.org (Postfix) with ESMTP id 9FF47F0EE7; Wed, 11 Jan 2006 07:26:59 -0700 (MST) Date: Wed, 11 Jan 2006 07:26:59 -0700 From: Robert Creager To: Michael Fuhr Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060111072659.7c1772ad@thunder.logicalchaos.org> In-Reply-To: <20060111075655.GA51292@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> <20060111075655.GA51292@winnie.fuhr.org> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i586-mandriva-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary=Signature_Wed__11_Jan_2006_07_26_59_-0700_P8qE46FONw9_i6Xw; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/110 X-Sequence-Number: 16588 --Signature_Wed__11_Jan_2006_07_26_59_-0700_P8qE46FONw9_i6Xw Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable When grilled further on (Wed, 11 Jan 2006 00:56:55 -0700), Michael Fuhr confessed: > On Tue, Jan 10, 2006 at 10:10:55PM -0700, Robert Creager wrote: > > The query is now correct, but still is slow because of lack of > > index usage. I don't know how to structure the query correctly to > > use the index. >=20 > Have you tried adding restrictions on doy in the WHERE clause? > Something like this, I think: I cannot. That's what I thought I would get from the join. The query show= n will always have two days involved, and only grows from there. The data = is graphed at http://www.logicalchaos.org/weather/index.html, and I'm looki= ng at adding historical data to the graphs. Opps, never mind. You hit the nail on the head: weather-# SELECT *, unmunge_time( time_group ) AS time, weather-# EXTRACT( doy FROM unmunge_time( time_group ) ) weather-# FROM minute."windspeed" weather-# JOIN doy_agg ON( EXTRACT( doy FROM unmunge_time( time_group ) ) = =3D doy ) weather-# WHERE unmunge_time( time_group ) > ( now() - '24 hour'::interval = )=20 weather-# AND doy BETWEEN EXTRACT( doy FROM now() - '24 hour'::interval)=20 weather-# AND EXTRACT( doy FROM now() ) weather-# ORDER BY time_group; = QUERY PLAN = =20 ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------- Sort (cost=3D21914.09..21914.10 rows=3D1 width=3D48) (actual time=3D76.59= 5..76.662 rows=3D286 loops=3D1) Sort Key: windspeed.time_group -> Hash Join (cost=3D21648.19..21914.08 rows=3D1 width=3D48) (actual t= ime=3D64.656..75.562 rows=3D286 loops=3D1) Hash Cond: (date_part('doy'::text, unmunge_time("outer".time_group= )) =3D "inner".doy) -> Bitmap Heap Scan on windspeed (cost=3D2.27..267.40 rows=3D74 = width=3D28) (actual time=3D0.585..1.111 rows=3D286 loops=3D1) Recheck Cond: (unmunge_time(time_group) > (now() - '24:00:00= '::interval)) -> Bitmap Index Scan on minute_windspeed_unmunge_index (co= st=3D0.00..2.27 rows=3D74 width=3D0) (actual time=3D0.566..0.566 rows=3D287= loops=3D1) Index Cond: (unmunge_time(time_group) > (now() - '24:0= 0:00'::interval)) -> Hash (cost=3D21645.92..21645.92 rows=3D3 width=3D20) (actual = time=3D63.849..63.849 rows=3D2 loops=3D1) -> HashAggregate (cost=3D21645.84..21645.89 rows=3D3 width= =3D20) (actual time=3D63.832..63.834 rows=3D2 loops=3D1) -> Bitmap Heap Scan on readings (cost=3D59.21..21596= .85 rows=3D6532 width=3D20) (actual time=3D15.174..53.249 rows=3D7613 loops= =3D1) Recheck Cond: ((date_part('doy'::text, "when") >= =3D date_part('doy'::text, (now() - '24:00:00'::interval))) AND (date_part(= 'doy'::text, "when") <=3D date_part('doy'::text, now()))) -> Bitmap Index Scan on readings_doy_index (co= st=3D0.00..59.21 rows=3D6532 width=3D0) (actual time=3D12.509..12.509 rows= =3D10530 loops=3D1) Index Cond: ((date_part('doy'::text, "when= ") >=3D date_part('doy'::text, (now() - '24:00:00'::interval))) AND (date_p= art('doy'::text, "when") <=3D date_part('doy'::text, now()))) Total runtime: 77.177 ms What I had thought is that PG would (could?) be smart enough to realize tha= t one query was restricted, and apply that restriction to the other based o= n the join. I know it works in other cases (using indexes on both tables u= sing the join)... >=20 > Something else occurred to me: do you (or will you) have more than > one year of data? If so then matching on doy could be problematic > unless you also check for the year, or unless you want to match > more than one year. Yes and yes. I'm doing both aggregate by day of the year for all data, and= aggregate by day of year within each year. The examples are: weather=3D# select * from doy_agg where doy =3D extract( doy from now() ); doy | avg_windspeed | max_windspeed=20 -----+------------------+--------------- 11 | 6.14058239764748 | 69 (1 row) weather=3D# select * from doy_day_agg where extract( doy from day ) =3D ext= ract( doy from now() ); day | avg_windspeed | max_windspeed=20 ---------------------+------------------+--------------- 2004-01-11 00:00:00 | 5.03991313397539 | 17 2006-01-11 00:00:00 | 18.532050716667 | 69 2005-01-11 00:00:00 | 3.6106763448041 | 13 Thanks for your help Michael. Cheers, Rob --=20 07:07:30 up 3 days, 23:34, 9 users, load average: 2.29, 2.44, 2.43 Linux 2.6.12-12-2 #4 SMP Tue Jan 3 19:56:19 MST 2006 --Signature_Wed__11_Jan_2006_07_26_59_-0700_P8qE46FONw9_i6Xw Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iEYEARECAAYFAkPFFbMACgkQLQ/DKuwDYzk7EACfenPC//X9+XTTW4KD2cTWmysA r18AoJBs9KI0bOW0HikfbPucsF79Wjut =ogeI -----END PGP SIGNATURE----- --Signature_Wed__11_Jan_2006_07_26_59_-0700_P8qE46FONw9_i6Xw-- From pgsql-performance-owner@postgresql.org Wed Jan 11 11:02:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B17E49DC845 for ; Wed, 11 Jan 2006 11:02:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94782-05 for ; Wed, 11 Jan 2006 11:02:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) by postgresql.org (Postfix) with ESMTP id 099889DC833 for ; Wed, 11 Jan 2006 11:02:35 -0400 (AST) Received: (qmail 6101 invoked by uid 1010); 11 Jan 2006 10:02:40 -0500 Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid 1002 with qmail-scanner-1.20 (spamassassin: 3.1.0. Clear:RC:0(63.147.78.66):SA:0(?/?):. Processed in 0.747927 secs); 11 Jan 2006 15:02:40 -0000 Received: from unknown (HELO thunder.logicalchaos.org) (perl?test@logicalchaos.org@63.147.78.66) by rambo.iniquinet.com with AES256-SHA encrypted SMTP; 11 Jan 2006 10:02:40 -0500 Received: from logicalchaos.org (localhost [127.0.0.1]) by thunder.logicalchaos.org (Postfix) with ESMTP id 0377C333F1; Wed, 11 Jan 2006 08:02:37 -0700 (MST) Date: Wed, 11 Jan 2006 08:02:37 -0700 From: Robert Creager Cc: Michael Fuhr , PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060111080237.66040a61@thunder.logicalchaos.org> In-Reply-To: <20060111072659.7c1772ad@thunder.logicalchaos.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> <20060111075655.GA51292@winnie.fuhr.org> <20060111072659.7c1772ad@thunder.logicalchaos.org> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i586-mandriva-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Signature_Wed__11_Jan_2006_08_02_37_-0700_RiKYkfFcX0Sf=Pvx"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.184 required=5 tests=[AWL=-0.005, MISSING_HEADERS=0.189] X-Spam-Score: 0.184 X-Spam-Level: X-Archive-Number: 200601/111 X-Sequence-Number: 16589 --Signature_Wed__11_Jan_2006_08_02_37_-0700_RiKYkfFcX0Sf=Pvx Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable When grilled further on (Wed, 11 Jan 2006 07:26:59 -0700), Robert Creager confessed: >=20 > weather-# SELECT *, unmunge_time( time_group ) AS time, > weather-# EXTRACT( doy FROM unmunge_time( time_group ) ) > weather-# FROM minute."windspeed" > weather-# JOIN doy_agg ON( EXTRACT( doy FROM unmunge_time( time_group ) )= =3D doy ) > weather-# WHERE unmunge_time( time_group ) > ( now() - '24 hour'::interva= l )=20 > weather-# AND doy BETWEEN EXTRACT( doy FROM now() - '24 hour'::interval)= =20 > weather-# AND EXTRACT( doy FROM now() ) > weather-# ORDER BY time_group; The more I think about it, the more I believe PG is missing an opportunity.= The query is adequately constrained without the BETWEEN clause. Why does= n't PG see that? I realize I'm a hack and by db organization shows that... The query is wrong as stated, as it won't work when the interval crosses a = year boundary, but it's a stop gap for now. Cheers, Rob --=20 07:58:30 up 4 days, 25 min, 9 users, load average: 2.13, 2.15, 2.22 Linux 2.6.12-12-2 #4 SMP Tue Jan 3 19:56:19 MST 2006 --Signature_Wed__11_Jan_2006_08_02_37_-0700_RiKYkfFcX0Sf=Pvx Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iEYEARECAAYFAkPFHg0ACgkQLQ/DKuwDYzkn0gCglCZYhYZDuIuf7pjSpF6booRy sRcAnilZXRfJtmchUxcoZkZogXmGawc4 =QodM -----END PGP SIGNATURE----- --Signature_Wed__11_Jan_2006_08_02_37_-0700_RiKYkfFcX0Sf=Pvx-- From pgsql-performance-owner@postgresql.org Sat Jan 14 01:50:26 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F26FA9DC9D6 for ; Wed, 11 Jan 2006 11:20:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97774-06 for ; Wed, 11 Jan 2006 11:20:04 -0400 (AST) X-Greylist: delayed 00:16:23.558436 by SQLgrey- Received: from mail.livedatagroup.com (mail.deg.cc [64.139.134.201]) by postgresql.org (Postfix) with ESMTP id 83CE59DC9D1 for ; Wed, 11 Jan 2006 11:19:57 -0400 (AST) Received: from [192.168.2.145] (gw.livedatagroup.com [205.242.255.66]) by mail.livedatagroup.com (Postfix) with ESMTP id 5AEE755F89 for ; Wed, 11 Jan 2006 10:03:36 -0500 (EST) Message-ID: <43C51E48.70407@livedatagroup.com> Date: Wed, 11 Jan 2006 10:03:36 -0500 From: Pallav Kalva MIME-Version: 1.0 To: PGPerformance Subject: Postgres8.0 Planner chooses WRONG plan. Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/180 X-Sequence-Number: 16658 Hi , I am having problem optimizing this query, Postgres optimizer uses a plan which invloves seq-scan on a table. And when I choose a option to disable seq-scan it uses index-scan and obviously the query is much faster. All tables are daily vacummed and analyzed as per docs. Why cant postgres use index-scan ? Postgres Version:8.0.2 Platform : Fedora Here is the explain analyze output. Let me know if any more information is needed. Can we make postgres use index scan for this query ? Thanks! Pallav. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- explain analyze select * from provisioning.alerts where countystate = 'FL' and countyno = '099' and status = 'ACTIVE' ; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=3.45..15842.17 rows=1 width=125) (actual time=913.491..18992.009 rows=110 loops=1) -> Nested Loop (cost=3.45..15838.88 rows=1 width=86) (actual time=913.127..18958.482 rows=110 loops=1) -> Hash Join (cost=3.45..15835.05 rows=1 width=82) (actual time=913.093..18954.951 rows=110 loops=1) Hash Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) -> Hash Join (cost=2.38..15833.96 rows=2 width=74) (actual time=175.139..18952.830 rows=358 loops=1) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Seq Scan on serviceinstance si (cost=0.00..15831.52 rows=7 width=78) (actual time=174.430..18948.210 rows=358 loops=1) Filter: (((subplan) = 'FL'::text) AND ((subplan) = '099'::text)) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.090..0.093 rows=1 loops=3923) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.058..0.061 rows=1 loops=265617) -> Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.444..0.444 rows=0 loops=1) -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual time=0.312..0.428 rows=1 loops=1) Hash Cond: ("outer".fkserviceid = "inner".serviceid) -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18 width=8) (actual time=0.005..0.068 rows=18 loops=1) -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.036..0.036 rows=0 loops=1) -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual time=0.014..0.019 rows=1 loops=1) Filter: (servicename = 'alert'::text) -> Hash (cost=1.06..1.06 rows=1 width=16) (actual time=0.044..0.044 rows=0 loops=1) -> Seq Scan on serviceinstancestatus sis (cost=0.00..1.06 rows=1 width=16) (actual time=0.017..0.024 rows=1 loops=1) Filter: (status = 'ACTIVE'::text) -> Index Scan using pk_account_accountid on account a (cost=0.00..3.82 rows=1 width=8) (actual time=0.012..0.016 rows=1 loops=110) Index Cond: ("outer".fkaccountid = a.accountid) -> Index Scan using pk_contact_contactid on contact c (cost=0.00..3.24 rows=1 width=47) (actual time=0.014..0.018 rows=1 loops=110) Index Cond: ("outer".fkcontactid = c.contactid) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.072..0.075 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.079..0.082 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.086..0.089 rows=1 loops=110) Total runtime: 18992.694 ms (30 rows) Time: 18996.203 ms --> As you can see the -> Seq Scan on serviceinstance si (cost=0.00..15831.52 rows=7 width=78) (actual time=174.430..18948.210 rows=358 loops=1) was taking too long . same query when i disable the seq-scan it uses index-scan and its much faster now set enable_seqscan=false; SET Time: 0.508 ms explain analyze select * from provisioning.alerts where countystate = 'FL' and countyno = '099' and status = 'ACTIVE' ; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=9.10..16676.10 rows=1 width=125) (actual time=24.792..3898.939 rows=110 loops=1) -> Nested Loop (cost=9.10..16672.81 rows=1 width=86) (actual time=24.383..3862.025 rows=110 loops=1) -> Hash Join (cost=9.10..16668.97 rows=1 width=82) (actual time=24.351..3858.351 rows=110 loops=1) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Nested Loop (cost=0.00..16659.85 rows=2 width=86) (actual time=8.449..3841.260 rows=110 loops=1) -> Index Scan using pk_serviceinstancestatus_serviceinstancestatusid on serviceinstancestatus sis (cost=0.00..3.07 rows=1 width=16) (actual time=3.673..3.684 rows=1 loops=1) Filter: (status = 'ACTIVE'::text) -> Index Scan using idx_serviceinstance_fkserviceinstancestatusid on serviceinstance si (cost=0.00..16656.76 rows=2 width=78) (actual time=4.755..3836.399 rows=110 loops=1) Index Cond: (si.fkserviceinstancestatusid = "outer".serviceinstancestatusid) Filter: (((subplan) = 'FL'::text) AND ((subplan) = '099'::text)) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.125..0.128 rows=1 loops=1283) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.083..0.086 rows=1 loops=26146) -> Hash (cost=9.09..9.09 rows=3 width=4) (actual time=15.661..15.661 rows=0 loops=1) -> Nested Loop (cost=0.00..9.09 rows=3 width=4) (actual time=15.617..15.637 rows=1 loops=1) -> Index Scan using uk_service_servicename on service s (cost=0.00..3.96 rows=1 width=4) (actual time=11.231..11.236 rows=1 loops=1) Index Cond: (servicename = 'alert'::text) -> Index Scan using idx_serviceoffering_fkserviceid on serviceoffering so (cost=0.00..5.09 rows=3 width=8) (actual time=4.366..4.371 rows=1 loops=1) Index Cond: ("outer".serviceid = so.fkserviceid) -> Index Scan using pk_account_accountid on account a (cost=0.00..3.82 rows=1 width=8) (actual time=0.013..0.017 rows=1 loops=110) Index Cond: ("outer".fkaccountid = a.accountid) -> Index Scan using pk_contact_contactid on contact c (cost=0.00..3.24 rows=1 width=47) (actual time=0.013..0.017 rows=1 loops=110) Index Cond: ("outer".fkcontactid = c.contactid) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.081..0.084 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.088..0.091 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.098..0.101 rows=1 loops=110) Total runtime: 3899.589 ms (28 rows) Here is the view definition ------------------------------- View "provisioning.alerts" Column | Type | Modifiers -------------------+---------+----------- serviceinstanceid | integer | accountid | integer | firstname | text | lastname | text | email | text | status | text | affiliate | text | affiliatesub | text | domain | text | countyno | text | countystate | text | listingtype | text | View definition: SELECT si.serviceinstanceid, a.accountid, c.firstname, c.lastname, c.email, sis.status, si.affiliate, si.affiliatesub, si."domain", ( SELECT get_parametervalue(si.serviceinstanceid, 'countyNo'::text) AS get_parametervalue) AS countyno, ( SELECT get_parametervalue(si.serviceinstanceid, 'countyState'::text) AS get_parametervalue) AS countystate, ( SELECT get_parametervalue(si.serviceinstanceid, 'listingType'::text) AS get_parametervalue) AS listingtype FROM provisioning.account a, common.contact c, provisioning.service s, provisioning.serviceoffering so, provisioning.serviceinstance si, provisioning.serviceinstancestatus sis WHERE si.fkserviceofferingid = so.serviceofferingid AND si.fkserviceinstancestatusid = sis.serviceinstancestatusid AND s.serviceid = so.fkserviceid AND a.fkcontactid = c.contactid AND si.fkaccountid = a.accountid AND s.servicename = 'alert'::text; Function Definition ---------------------- CREATE OR REPLACE FUNCTION get_parametervalue(v_fkserviceinstanceid integer, v_name text) RETURNS TEXT AS $$ DECLARE v_value text; BEGIN SELECT p.value INTO v_value FROM provisioning.serviceinstanceparameter sip, common.parameter p WHERE fkserviceinstanceid = v_fkserviceinstanceid AND sip.fkparameterid = p.parameterid AND p.name = v_name; RETURN v_value; END Serviceinstance table stats ----------------------------- select relname, relpages, reltuples from pg_class where relname = 'serviceinstance'; relname | relpages | reltuples -----------------+----------+----------- serviceinstance | 5207 | 265613 $$ language plpgsql From pgsql-performance-owner@postgresql.org Wed Jan 11 11:27:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1D9AB9DC802 for ; Wed, 11 Jan 2006 11:27:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00667-02 for ; Wed, 11 Jan 2006 11:27:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.livedatagroup.com (mail.deg.cc [64.139.134.201]) by postgresql.org (Postfix) with ESMTP id 16AB89DC833 for ; Wed, 11 Jan 2006 11:27:35 -0400 (AST) Received: from [192.168.2.145] (gw.livedatagroup.com [205.242.255.66]) by mail.livedatagroup.com (Postfix) with ESMTP id CB9CE55F89 for ; Wed, 11 Jan 2006 10:27:39 -0500 (EST) Message-ID: <43C523EB.3000201@livedatagroup.com> Date: Wed, 11 Jan 2006 10:27:39 -0500 From: Pallav Kalva MIME-Version: 1.0 To: PGPerformance Subject: Postgres8.0 planner chooses WRONG plan Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/112 X-Sequence-Number: 16590 Hi , I am having problem optimizing this query, Postgres optimizer uses a plan which invloves seq-scan on a table. And when I choose a option to disable seq-scan it uses index-scan and obviously the query is much faster. All tables are daily vacummed and analyzed as per docs. Why cant postgres use index-scan ? Postgres Version:8.0.2 Platform : Fedora Here is the explain analyze output. Let me know if any more information is needed. Can we make postgres use index scan for this query ? Thanks! Pallav. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- explain analyze select * from provisioning.alerts where countystate = 'FL' and countyno = '099' and status = 'ACTIVE' ; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=3.45..15842.17 rows=1 width=125) (actual time=913.491..18992.009 rows=110 loops=1) -> Nested Loop (cost=3.45..15838.88 rows=1 width=86) (actual time=913.127..18958.482 rows=110 loops=1) -> Hash Join (cost=3.45..15835.05 rows=1 width=82) (actual time=913.093..18954.951 rows=110 loops=1) Hash Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) -> Hash Join (cost=2.38..15833.96 rows=2 width=74) (actual time=175.139..18952.830 rows=358 loops=1) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Seq Scan on serviceinstance si (cost=0.00..15831.52 rows=7 width=78) (actual time=174.430..18948.210 rows=358 loops=1) Filter: (((subplan) = 'FL'::text) AND ((subplan) = '099'::text)) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.090..0.093 rows=1 loops=3923) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.058..0.061 rows=1 loops=265617) -> Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.444..0.444 rows=0 loops=1) -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual time=0.312..0.428 rows=1 loops=1) Hash Cond: ("outer".fkserviceid = "inner".serviceid) -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18 width=8) (actual time=0.005..0.068 rows=18 loops=1) -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.036..0.036 rows=0 loops=1) -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual time=0.014..0.019 rows=1 loops=1) Filter: (servicename = 'alert'::text) -> Hash (cost=1.06..1.06 rows=1 width=16) (actual time=0.044..0.044 rows=0 loops=1) -> Seq Scan on serviceinstancestatus sis (cost=0.00..1.06 rows=1 width=16) (actual time=0.017..0.024 rows=1 loops=1) Filter: (status = 'ACTIVE'::text) -> Index Scan using pk_account_accountid on account a (cost=0.00..3.82 rows=1 width=8) (actual time=0.012..0.016 rows=1 loops=110) Index Cond: ("outer".fkaccountid = a.accountid) -> Index Scan using pk_contact_contactid on contact c (cost=0.00..3.24 rows=1 width=47) (actual time=0.014..0.018 rows=1 loops=110) Index Cond: ("outer".fkcontactid = c.contactid) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.072..0.075 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.079..0.082 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.086..0.089 rows=1 loops=110) Total runtime: 18992.694 ms (30 rows) Time: 18996.203 ms --> As you can see the -> Seq Scan on serviceinstance si (cost=0.00..15831.52 rows=7 width=78) (actual time=174.430..18948.210 rows=358 loops=1) was taking too long . same query when i disable the seq-scan it uses index-scan and its much faster now set enable_seqscan=false; SET Time: 0.508 ms explain analyze select * from provisioning.alerts where countystate = 'FL' and countyno = '099' and status = 'ACTIVE' ; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=9.10..16676.10 rows=1 width=125) (actual time=24.792..3898.939 rows=110 loops=1) -> Nested Loop (cost=9.10..16672.81 rows=1 width=86) (actual time=24.383..3862.025 rows=110 loops=1) -> Hash Join (cost=9.10..16668.97 rows=1 width=82) (actual time=24.351..3858.351 rows=110 loops=1) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Nested Loop (cost=0.00..16659.85 rows=2 width=86) (actual time=8.449..3841.260 rows=110 loops=1) -> Index Scan using pk_serviceinstancestatus_serviceinstancestatusid on serviceinstancestatus sis (cost=0.00..3.07 rows=1 width=16) (actual time=3.673..3.684 rows=1 loops=1) Filter: (status = 'ACTIVE'::text) -> Index Scan using idx_serviceinstance_fkserviceinstancestatusid on serviceinstance si (cost=0.00..16656.76 rows=2 width=78) (actual time=4.755..3836.399 rows=110 loops=1) Index Cond: (si.fkserviceinstancestatusid = "outer".serviceinstancestatusid) Filter: (((subplan) = 'FL'::text) AND ((subplan) = '099'::text)) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.125..0.128 rows=1 loops=1283) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.083..0.086 rows=1 loops=26146) -> Hash (cost=9.09..9.09 rows=3 width=4) (actual time=15.661..15.661 rows=0 loops=1) -> Nested Loop (cost=0.00..9.09 rows=3 width=4) (actual time=15.617..15.637 rows=1 loops=1) -> Index Scan using uk_service_servicename on service s (cost=0.00..3.96 rows=1 width=4) (actual time=11.231..11.236 rows=1 loops=1) Index Cond: (servicename = 'alert'::text) -> Index Scan using idx_serviceoffering_fkserviceid on serviceoffering so (cost=0.00..5.09 rows=3 width=8) (actual time=4.366..4.371 rows=1 loops=1) Index Cond: ("outer".serviceid = so.fkserviceid) -> Index Scan using pk_account_accountid on account a (cost=0.00..3.82 rows=1 width=8) (actual time=0.013..0.017 rows=1 loops=110) Index Cond: ("outer".fkaccountid = a.accountid) -> Index Scan using pk_contact_contactid on contact c (cost=0.00..3.24 rows=1 width=47) (actual time=0.013..0.017 rows=1 loops=110) Index Cond: ("outer".fkcontactid = c.contactid) SubPlan -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.081..0.084 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.088..0.091 rows=1 loops=110) -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.098..0.101 rows=1 loops=110) Total runtime: 3899.589 ms (28 rows) Here is the view definition ------------------------------- View "provisioning.alerts" Column | Type | Modifiers -------------------+---------+----------- serviceinstanceid | integer | accountid | integer | firstname | text | lastname | text | email | text | status | text | affiliate | text | affiliatesub | text | domain | text | countyno | text | countystate | text | listingtype | text | View definition: SELECT si.serviceinstanceid, a.accountid, c.firstname, c.lastname, c.email, sis.status, si.affiliate, si.affiliatesub, si."domain", ( SELECT get_parametervalue(si.serviceinstanceid, 'countyNo'::text) AS get_parametervalue) AS countyno, ( SELECT get_parametervalue(si.serviceinstanceid, 'countyState'::text) AS get_parametervalue) AS countystate, ( SELECT get_parametervalue(si.serviceinstanceid, 'listingType'::text) AS get_parametervalue) AS listingtype FROM provisioning.account a, common.contact c, provisioning.service s, provisioning.serviceoffering so, provisioning.serviceinstance si, provisioning.serviceinstancestatus sis WHERE si.fkserviceofferingid = so.serviceofferingid AND si.fkserviceinstancestatusid = sis.serviceinstancestatusid AND s.serviceid = so.fkserviceid AND a.fkcontactid = c.contactid AND si.fkaccountid = a.accountid AND s.servicename = 'alert'::text; Function Definition ---------------------- CREATE OR REPLACE FUNCTION get_parametervalue(v_fkserviceinstanceid integer, v_name text) RETURNS TEXT AS $$ DECLARE v_value text; BEGIN SELECT p.value INTO v_value FROM provisioning.serviceinstanceparameter sip, common.parameter p WHERE fkserviceinstanceid = v_fkserviceinstanceid AND sip.fkparameterid = p.parameterid AND p.name = v_name; RETURN v_value; END Serviceinstance table stats ----------------------------- select relname, relpages, reltuples from pg_class where relname = 'serviceinstance'; relname | relpages | reltuples -----------------+----------+----------- serviceinstance | 5207 | 265613 $$ language plpgsql From pgsql-performance-owner@postgresql.org Wed Jan 11 11:33:08 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 455339DC9EB for ; Wed, 11 Jan 2006 11:33:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99763-08 for ; Wed, 11 Jan 2006 11:33:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 05FE89DC9F0 for ; Wed, 11 Jan 2006 11:33:05 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BFX3Y6012878; Wed, 11 Jan 2006 10:33:03 -0500 (EST) To: Robert Creager cc: Michael Fuhr , PGPerformance Subject: Re: Index isn't used during a join. In-reply-to: <20060111072659.7c1772ad@thunder.logicalchaos.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> <20060111075655.GA51292@winnie.fuhr.org> <20060111072659.7c1772ad@thunder.logicalchaos.org> Comments: In-reply-to Robert Creager message dated "Wed, 11 Jan 2006 07:26:59 -0700" Date: Wed, 11 Jan 2006 10:33:03 -0500 Message-ID: <12877.1136993583@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/113 X-Sequence-Number: 16591 Robert Creager writes: > What I had thought is that PG would (could?) be smart enough to realize tha= > t one query was restricted, and apply that restriction to the other based o= > n the join. I know it works in other cases (using indexes on both tables u= > sing the join)... The planner understands about transitivity of equality, ie given a = b and b = c it can infer a = c. It doesn't do any such thing for inequalities though, nor does it deduce f(a) = f(b) for arbitrary functions f. The addition Michael suggested requires much more understanding of the properties of the functions in your query than I think would be reasonable to put into the planner. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 11:45:48 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8931E9DC98A for ; Wed, 11 Jan 2006 11:45:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00885-10 for ; Wed, 11 Jan 2006 11:45:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id AE5AB9DC9D6 for ; Wed, 11 Jan 2006 11:45:43 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BFjlSC013029; Wed, 11 Jan 2006 10:45:47 -0500 (EST) To: Bendik Rognlien Johansen cc: pgsql-performance@postgresql.org Subject: Re: Slow query with joins In-reply-to: References: Comments: In-reply-to Bendik Rognlien Johansen message dated "Wed, 11 Jan 2006 11:59:39 +0100" Date: Wed, 11 Jan 2006 10:45:47 -0500 Message-ID: <13028.1136994347@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/114 X-Sequence-Number: 16592 Bendik Rognlien Johansen writes: > Has anyone got any tips for speeding up this query? It currently > takes hours to start. Are the rowcount estimates close to reality? The plan doesn't look unreasonable to me if they are. It might help to increase work_mem to ensure that the hash tables don't spill to disk. Indexes: "people_original_is_null" btree (original) WHERE original IS NULL This index seems poorly designed: the actual index entries are dead weight since all of them are necessarily NULL. You might as well make the index carry something that you frequently test in conjunction with "original IS NULL". For instance, if this particular query is a common case, you could replace this index with CREATE INDEX people_deleted_original_is_null ON people(deleted) WHERE original IS NULL; This index is still perfectly usable for queries that only say "original IS NULL", but it can also filter out rows with the wrong value of deleted. Now, if there are hardly any rows with deleted = true, maybe this won't help much for your problem. But in any case you ought to consider whether you can make the index entries do something useful. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 12:07:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ED0FD9DC803 for ; Wed, 11 Jan 2006 12:07:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08850-01 for ; Wed, 11 Jan 2006 12:07:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 60BE49DC802 for ; Wed, 11 Jan 2006 12:07:26 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BG7Igv013188; Wed, 11 Jan 2006 11:07:18 -0500 (EST) To: Pallav Kalva cc: PGPerformance Subject: Re: Postgres8.0 planner chooses WRONG plan In-reply-to: <43C523EB.3000201@livedatagroup.com> References: <43C523EB.3000201@livedatagroup.com> Comments: In-reply-to Pallav Kalva message dated "Wed, 11 Jan 2006 10:27:39 -0500" Date: Wed, 11 Jan 2006 11:07:18 -0500 Message-ID: <13187.1136995638@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/115 X-Sequence-Number: 16593 Pallav Kalva writes: > I am having problem optimizing this query, Get rid of the un-optimizable function inside the view. You've converted something that should be a join into an unreasonably large number of function calls. > -> Seq Scan on serviceinstance si > (cost=0.00..15831.52 rows=7 width=78) (actual time=174.430..18948.210 > rows=358 loops=1) > Filter: (((subplan) = 'FL'::text) AND > ((subplan) = '099'::text)) > SubPlan > -> Result (cost=0.00..0.01 rows=1 width=0) > (actual time=0.090..0.093 rows=1 loops=3923) > -> Result (cost=0.00..0.01 rows=1 width=0) > (actual time=0.058..0.061 rows=1 loops=265617) The bulk of the cost here is in the second subplan (0.061 * 265617 = 16202.637 msec total runtime), and there's not a darn thing Postgres can do to improve this because the work is all down inside a "black box" function. In fact the planner does not even know that the function call is expensive, else it would have preferred a plan that requires fewer evaluations of the function. The alternative plan you show is *not* faster "because it's an indexscan"; it's faster because get_parametervalue is evaluated fewer times. The useless sub-SELECTs atop the function calls are adding their own little increment of wasted time, too. I'm not sure how bad that is relative to the function calls, but it's certainly not helping. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 12:45:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 116A69DC845 for ; Wed, 11 Jan 2006 12:45:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16667-01 for ; Wed, 11 Jan 2006 12:45:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.livedatagroup.com (mail.deg.cc [64.139.134.201]) by postgresql.org (Postfix) with ESMTP id 1E6369DC859 for ; Wed, 11 Jan 2006 12:44:59 -0400 (AST) Received: from [192.168.2.145] (gw.livedatagroup.com [205.242.255.66]) by mail.livedatagroup.com (Postfix) with ESMTP id F3CD955F8B; Wed, 11 Jan 2006 11:44:58 -0500 (EST) Message-ID: <43C5360A.4010409@livedatagroup.com> Date: Wed, 11 Jan 2006 11:44:58 -0500 From: Pallav Kalva MIME-Version: 1.0 To: Tom Lane Cc: PGPerformance Subject: Re: Postgres8.0 planner chooses WRONG plan References: <43C523EB.3000201@livedatagroup.com> <13187.1136995638@sss.pgh.pa.us> In-Reply-To: <13187.1136995638@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/116 X-Sequence-Number: 16594 Hi Tom, Thanks! for your input, the view was written first without using the function but its an ugly big with all the joins and its much slower that way. Below is the view without the function and its explain analzye output , as you can see the it takes almost 2 min to run this query with this view . Is there any way to optimize or make changes to this view ? Thanks! Pallav. View Definition ------------------- create or replace view provisioning.alertserviceinstanceold as SELECT services.serviceinstanceid, a.accountid, c.firstname, c.lastname, c.email, services.countyno, services.countystate, services.listingtype AS listingtypename, services.status, services.affiliate, services.affiliatesub, services."domain" FROM provisioning.account a JOIN common.contact c ON a.fkcontactid = c.contactid JOIN ( SELECT p1.serviceinstanceid, p1.accountid, p1.countyno, p2.countystate, p3.listingtype, p1.status, p1.affiliate, p1.affiliatesub, p1."domain" FROM ( SELECT si.serviceinstanceid, si.affiliate, si.affiliatesub, si."domain", si.fkaccountid AS accountid, p.value AS countyno, sis.status FROM provisioning.service s JOIN provisioning.serviceoffering so ON s.serviceid = so.fkserviceid JOIN provisioning.serviceinstance si ON so.serviceofferingid = si.fkserviceofferingid JOIN provisioning.serviceinstancestatus sis ON si.fkserviceinstancestatusid = sis.serviceinstancestatusid JOIN provisioning.serviceinstanceparameter sip ON si.serviceinstanceid = sip.fkserviceinstanceid JOIN common.parameter p ON sip.fkparameterid = p.parameterid WHERE s.servicename = 'alert'::text AND p.name = 'countyNo'::text) p1 JOIN ( SELECT si.serviceinstanceid, si.affiliate, si.affiliatesub, si."domain", si.fkaccountid AS accountid, p.value AS countystate, sis.status FROM provisioning.service s JOIN provisioning.serviceoffering so ON s.serviceid = so.fkserviceid JOIN provisioning.serviceinstance si ON so.serviceofferingid = si.fkserviceofferingid JOIN provisioning.serviceinstancestatus sis ON si.fkserviceinstancestatusid = sis.serviceinstancestatusid JOIN provisioning.serviceinstanceparameter sip ON si.serviceinstanceid = sip.fkserviceinstanceid JOIN common.parameter p ON sip.fkparameterid = p.parameterid WHERE s.servicename = 'alert'::text AND p.name = 'countyState'::text) p2 ON p1.accountid = p2.accountid AND p1.serviceinstanceid = p2.serviceinstanceid JOIN ( SELECT si.serviceinstanceid, si.affiliate, si.affiliatesub, si."domain", si.fkaccountid AS accountid, p.value AS listingtype, sis.status FROM provisioning.service s JOIN provisioning.serviceoffering so ON s.serviceid = so.fkserviceid JOIN provisioning.serviceinstance si ON so.serviceofferingid = si.fkserviceofferingid JOIN provisioning.serviceinstancestatus sis ON si.fkserviceinstancestatusid = sis.serviceinstancestatusid JOIN provisioning.serviceinstanceparameter sip ON si.serviceinstanceid = sip.fkserviceinstanceid JOIN common.parameter p ON sip.fkparameterid = p.parameterid WHERE s.servicename = 'alert'::text AND p.name = 'listingType'::text) p3 ON p2.accountid = p3.accountid AND p2.serviceinstanceid = p3.serviceinstanceid) services ON a.accountid = services.accountid ORDER BY services.serviceinstanceid; Explain Analyze ------------------ explain analyze select * from provisioning.alertserviceinstanceold where countystate = 'FL' and countyno = '099' and status = 'ACTIVE' ; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------- Subquery Scan alertserviceinstanceold (cost=31954.24..31954.25 rows=1 width=328) (actual time=113485.801..113487.024 rows=110 loops=1) -> Sort (cost=31954.24..31954.24 rows=1 width=152) (actual time=113485.787..113486.123 rows=110 loops=1) Sort Key: si.serviceinstanceid -> Hash Join (cost=20636.38..31954.23 rows=1 width=152) (actual time=109721.688..113485.311 rows=110 loops=1) Hash Cond: ("outer".accountid = "inner".fkaccountid) -> Hash Join (cost=6595.89..16770.25 rows=228696 width=47) (actual time=1742.592..4828.396 rows=229855 loops=1) Hash Cond: ("outer".contactid = "inner".fkcontactid) -> Seq Scan on contact c (cost=0.00..4456.96 rows=228696 width=47) (actual time=0.006..1106.459 rows=229868 loops=1) -> Hash (cost=6024.11..6024.11 rows=228711 width=8) (actual time=1742.373..1742.373 rows=0 loops=1) -> Seq Scan on account a (cost=0.00..6024.11 rows=228711 width=8) (actual time=0.010..990.597 rows=229855 loops=1) -> Hash (cost=14040.49..14040.49 rows=1 width=117) (actual time=107911.397..107911.397 rows=0 loops=1) -> Nested Loop (cost=10.34..14040.49 rows=1 width=117) (actual time=1185.383..107910.738 rows=110 loops=1) -> Nested Loop (cost=10.34..14037.45 rows=1 width=112) (actual time=1185.278..107898.885 rows=550 loops=1) -> Hash Join (cost=10.34..14033.98 rows=1 width=124) (actual time=1185.224..107888.542 rows=110 loops=1) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Hash Join (cost=7.96..14031.58 rows=1 width=128) (actual time=1184.490..107886.329 rows=110 loops=1) Hash Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) -> Nested Loop (cost=6.90..14030.50 rows=1 width=132) (actual time=1184.151..107884.302 rows=110 loops=1) Join Filter: ("outer".fkaccountid = "inner".fkaccountid) -> Nested Loop (cost=6.90..14025.09 rows=1 width=116) (actual time=1184.123..107880.635 rows=110 loops=1) Join Filter: (("outer".fkaccountid = "inner".fkaccountid) AND ("outer".serviceinstanceid = "inner".serviceinstanceid)) -> Hash Join (cost=3.45..636.39 rows=1 width=95) (actual time=85.524..293.387 rows=226 loops=1) Hash Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) -> Hash Join (cost=2.38..635.29 rows=4 width=87) (actual time=6.894..289.000 rows=663 loops=1) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Nested Loop (cost=0.00..632.75 rows=23 width=91) (actual time=6.176..281.620 rows=663 loops=1) -> Nested Loop (cost=0.00..508.26 rows=23 width=13) (actual time=6.138..221.590 rows=663 loops=1) -> Index Scan using idx_parameter_value on parameter p (cost=0.00..437.42 rows=23 width=13) (actual time=6.091..20.656 rows=663 loops=1) Index Cond: (value = '099'::text) Filter: (name = 'countyNo'::text) -> Index Scan using idx_serviceinstanceparameter_fkparameterid on serviceinstanceparameter sip (cost=0.00..3.07 rows=1 width=8) (actual time=0.278..0.288 rows=1 loops=663) Index Cond: (sip.fkparameterid = "outer".parameterid) -> Index Scan using pk_serviceinstance_serviceinstanceid on serviceinstance si (cost=0.00..5.40 rows=1 width=78) (actual time=0.041..0.073 rows=1 loops=663) Index Cond: (si.serviceinstanceid = "outer".fkserviceinstanceid) -> Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.445..0.445 rows=0 loops=1) -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual time=0.314..0.426 rows=1 loops=1) Hash Cond: ("outer".fkserviceid = "inner".serviceid) -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18width=8) (actual time=0.005..0.065 rows=18 loops=1) -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.033..0.033 rows=0 loops=1) -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual time=0.011..0.016 rows=1 loops=1) Filter: (servicename = 'alert'::text) -> Hash (cost=1.06..1.06 rows=1 width=16) (actual time=0.031..0.031 rows=0 loops=1) -> Seq Scan on serviceinstancestatus sis (cost=0.00..1.06 rows=1 width=16) (actual time=0.008..0.014 rows=1 loops=1) Filter: (status = 'ACTIVE'::text) -> Hash Join (cost=3.45..13386.23 rows=165 width=21) (actual time=0.119..461.891 rows=3935 loops=226) Hash Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) -> Hash Join (cost=2.38..13382.69 rows=165 width=25) (actual time=0.110..432.555 rows=3935 loops=226) Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) -> Nested Loop (cost=0.00..13373.71 rows=990 width=29) (actual time=0.098..400.805 rows=3935 loops=226) -> Nested Loop (cost=0.00..8015.16 rows=990 width=13) (actual time=0.035..267.634 rows=3935 loops=226) -> Seq Scan on parameter p (cost=0.00..4968.81 rows=989 width=13) (actual time=0.008..131.735 rows=3935 loops=226) Filter: ((name = 'countyState'::text) AND (value = 'FL'::text)) -> Index Scan using idx_serviceinstanceparameter_fkparameterid on serviceinstanceparameter sip (cost=0.00..3.07 rows=1 width=8) (actual time=0.015..0.020 rows=1 loops=889310) Index Cond: (sip.fkparameterid = "outer".parameterid) -> Index Scan using pk_serviceinstance_serviceinstanceid on serviceinstance si (cost=0.00..5.40 rows=1 width=16) (actual time=0.012..0.019 rows=1 loops=889310) Index Cond: (si.serviceinstanceid = "outer".fkserviceinstanceid) -> Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.439..0.439 rows=0 loops=1) -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual time=0.310..0.423 rows=1 loops=1) Hash Cond: ("outer".fkserviceid = "inner".serviceid) -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18 width=8) (actual time=0.006..0.065 rows=18 loops=1) -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.035..0.035 rows=0 loops=1) -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual time=0.013..0.018 rows=1 loops=1) Filter: (servicename = 'alert'::text) -> Hash (cost=1.05..1.05 rows=5 width=4) (actual time=0.059..0.059 rows=0 loops=1) -> Seq Scan on serviceinstancestatus sis (cost=0.00..1.05 rows=5 width=4) (actual time=0.010..0.029 rows=5 loops=1) -> Index Scan using pk_serviceinstance_serviceinstanceid on serviceinstance si (cost=0.00..5.40 rows=1 width=16) (actual time=0.009..0.012 rows=1 loops=110) Index Cond: (si.serviceinstanceid = "outer".fkserviceinstanceid) -> Hash (cost=1.05..1.05 rows=5 width=4) (actual time=0.055..0.055 rows=0 loops=1) -> Seq Scan on serviceinstancestatus sis (cost=0.00..1.05 rows=5 width=4) (actual time=0.008..0.025 rows=5 loops=1) -> Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.461..0.461 rows=0 loops=1) -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual time=0.325..0.445 rows=1 loops=1) Hash Cond: ("outer".fkserviceid = "inner".serviceid) -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18 width=8) (actual time=0.006..0.074 rows=18 loops=1) -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.044..0.044 rows=0 loops=1) -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual time=0.022..0.027 rows=1 loops=1) Filter: (servicename = 'alert'::text) -> Index Scan using idx_serviceinstanceparameter_fkserviceinstanceid on serviceinstanceparameter sip (cost=0.00..3.41 rows=5 width=8) (actual time=0.018..0.038 rows=5 loops=110) Index Cond: (sip.fkserviceinstanceid = "outer".fkserviceinstanceid) -> Index Scan using pk_parameter_parameterid on parameter p (cost=0.00..3.02 rows=1 width=13) (actual time=0.011..0.012 rows=0 loops=550) Index Cond: ("outer".fkparameterid = p.parameterid) Filter: (name = 'listingType'::text) Total runtime: 113490.582 ms (82 rows) Tom Lane wrote: >Pallav Kalva writes: > >> I am having problem optimizing this query, >> > >Get rid of the un-optimizable function inside the view. You've >converted something that should be a join into an unreasonably large >number of function calls. > > >> -> Seq Scan on serviceinstance si >>(cost=0.00..15831.52 rows=7 width=78) (actual time=174.430..18948.210 >>rows=358 loops=1) >> Filter: (((subplan) = 'FL'::text) AND >>((subplan) = '099'::text)) >> SubPlan >> -> Result (cost=0.00..0.01 rows=1 width=0) >>(actual time=0.090..0.093 rows=1 loops=3923) >> -> Result (cost=0.00..0.01 rows=1 width=0) >>(actual time=0.058..0.061 rows=1 loops=265617) >> > >The bulk of the cost here is in the second subplan (0.061 * 265617 = >16202.637 msec total runtime), and there's not a darn thing Postgres >can do to improve this because the work is all down inside a "black box" >function. In fact the planner does not even know that the function call >is expensive, else it would have preferred a plan that requires fewer >evaluations of the function. The alternative plan you show is *not* >faster "because it's an indexscan"; it's faster because get_parametervalue >is evaluated fewer times. > >The useless sub-SELECTs atop the function calls are adding their own >little increment of wasted time, too. I'm not sure how bad that is >relative to the function calls, but it's certainly not helping. > > regards, tom lane > > From pgsql-performance-owner@postgresql.org Wed Jan 11 13:06:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 00EDB9DC833 for ; Wed, 11 Jan 2006 13:06:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19519-03 for ; Wed, 11 Jan 2006 13:06:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id A34B99DC803 for ; Wed, 11 Jan 2006 13:06:51 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0BH6jOd008691 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2006 10:06:48 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0BH6jSE058097; Wed, 11 Jan 2006 10:06:45 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0BH6jnN058096; Wed, 11 Jan 2006 10:06:45 -0700 (MST) (envelope-from mfuhr) Date: Wed, 11 Jan 2006 10:06:45 -0700 From: Michael Fuhr To: Robert Creager Cc: PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060111170645.GA58041@winnie.fuhr.org> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> <20060111075655.GA51292@winnie.fuhr.org> <20060111072659.7c1772ad@thunder.logicalchaos.org> <20060111080237.66040a61@thunder.logicalchaos.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060111080237.66040a61@thunder.logicalchaos.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/117 X-Sequence-Number: 16595 On Wed, Jan 11, 2006 at 08:02:37AM -0700, Robert Creager wrote: > The query is wrong as stated, as it won't work when the interval > crosses a year boundary, but it's a stop gap for now. Yeah, I realized that shortly after I posted the original and posted a correction. http://archives.postgresql.org/pgsql-performance/2006-01/msg00104.php -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 11 14:25:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 320849DCA22 for ; Wed, 11 Jan 2006 14:25:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35672-07 for ; Wed, 11 Jan 2006 14:25:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 0A1C19DCA1F for ; Wed, 11 Jan 2006 14:25:45 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id E81073984B; Wed, 11 Jan 2006 12:25:45 -0600 (CST) Date: Wed, 11 Jan 2006 12:25:45 -0600 From: "Jim C. Nasby" To: Andy Cc: Frank Wiles , pgsql-performance@postgresql.org Subject: Re: Improving Inner Join Performance Message-ID: <20060111182545.GR3902@pervasive.com> References: <20060106111231.28cdcb72.frank@wiles.org> <009301c614f2$41d55920$0b00a8c0@forge> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <009301c614f2$41d55920$0b00a8c0@forge> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.087 required=5 tests=[AWL=0.087] X-Spam-Score: 0.087 X-Spam-Level: X-Archive-Number: 200601/118 X-Sequence-Number: 16596 Did you originally post some problem queries? The settings look OK, though 1G of memory isn't very much now-a-days. On Mon, Jan 09, 2006 at 09:56:52AM +0200, Andy wrote: > shared_buffers = 10240 > effective_cache_size = 64000 > RAM on server: 1Gb. > > Andy. > > ----- Original Message ----- > > From: "Frank Wiles" > To: "Andy" > Sent: Friday, January 06, 2006 7:12 PM > Subject: Re: [PERFORM] Improving Inner Join Performance > > > > On Fri, 6 Jan 2006 09:59:30 +0200 > > "Andy" wrote: > > > >> Yes I have indexes an all join fields. > >> The tables have around 30 columns each and around 100k rows. > >> The database is vacuumed every hour. > > > > What are you settings for: > > > > shared_buffers > > effective_cache_size > > > > And how much RAM do you have in the server? > > > > --------------------------------- > > Frank Wiles > > http://www.wiles.org > > --------------------------------- > > > > > > -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 11 14:40:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3F2159DC833 for ; Wed, 11 Jan 2006 14:40:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41139-02 for ; Wed, 11 Jan 2006 14:40:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 6ABF29DC94D for ; Wed, 11 Jan 2006 14:40:32 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id D4F303982E; Wed, 11 Jan 2006 12:40:32 -0600 (CST) Date: Wed, 11 Jan 2006 12:40:32 -0600 From: "Jim C. Nasby" To: Andrea Arcangeli Cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111184032.GS3902@pervasive.com> References: <20060110014447.GB18474@opteron.random> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060110014447.GB18474@opteron.random> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.087 required=5 tests=[AWL=0.087] X-Spam-Score: 0.087 X-Spam-Level: X-Archive-Number: 200601/119 X-Sequence-Number: 16597 On Tue, Jan 10, 2006 at 02:44:47AM +0100, Andrea Arcangeli wrote: > "cooperative" runs "WHERE kernel_version NOT LIKE '%% PREEMPT %%'", while > "preempt" runs "WHERE kernel_version LIKE '%% PREEMPT %%'. The only difference One thing you could do is change the like to: WHERE position(' PREEMPT ' in kernel_version) != 0 And then create a functional index on that: CREATE INDEX indexname ON tablename ( position(' PREEMPT ' in kernel_version) ); -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 11 15:02:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AD31A9DC802 for ; Wed, 11 Jan 2006 15:02:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52824-01 for ; Wed, 11 Jan 2006 15:02:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 4D9D49DC863 for ; Wed, 11 Jan 2006 15:02:08 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 3B3943983E; Wed, 11 Jan 2006 13:02:09 -0600 (CST) Date: Wed, 11 Jan 2006 13:02:09 -0600 From: "Jim C. Nasby" To: Pallav Kalva Cc: Tom Lane , PGPerformance Subject: Re: Postgres8.0 planner chooses WRONG plan Message-ID: <20060111190209.GT3902@pervasive.com> References: <43C523EB.3000201@livedatagroup.com> <13187.1136995638@sss.pgh.pa.us> <43C5360A.4010409@livedatagroup.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43C5360A.4010409@livedatagroup.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.087 required=5 tests=[AWL=0.087] X-Spam-Score: 0.087 X-Spam-Level: X-Archive-Number: 200601/120 X-Sequence-Number: 16598 On Wed, Jan 11, 2006 at 11:44:58AM -0500, Pallav Kalva wrote: Some view you've got there... you might want to break that apart into multiple views that are a bit easier to manage. service_instance_with_status is a likely candidate, for example. > View Definition > ------------------- > > create or replace view provisioning.alertserviceinstanceold as > SELECT services.serviceinstanceid, a.accountid, c.firstname, c.lastname, > c.email, services.countyno, services.countystate, services.listingtype > AS listingtypename, services.status, services.affiliate, > services.affiliatesub, services."domain" > FROM provisioning.account a > JOIN common.contact c ON a.fkcontactid = c.contactid > JOIN ( SELECT p1.serviceinstanceid, p1.accountid, p1.countyno, > p2.countystate, p3.listingtype, p1.status, p1.affiliate, > p1.affiliatesub, p1."domain" > FROM ( SELECT si.serviceinstanceid, si.affiliate, si.affiliatesub, > si."domain", si.fkaccountid AS accountid, p.value AS countyno, sis.status > FROM provisioning.service s > JOIN provisioning.serviceoffering so ON s.serviceid = > so.fkserviceid > JOIN provisioning.serviceinstance si ON so.serviceofferingid = > si.fkserviceofferingid > JOIN provisioning.serviceinstancestatus sis ON > si.fkserviceinstancestatusid = sis.serviceinstancestatusid > JOIN provisioning.serviceinstanceparameter sip ON > si.serviceinstanceid = sip.fkserviceinstanceid > JOIN common.parameter p ON sip.fkparameterid = p.parameterid > WHERE s.servicename = 'alert'::text AND p.name = 'countyNo'::text) p1 > JOIN ( SELECT si.serviceinstanceid, si.affiliate, si.affiliatesub, > si."domain", si.fkaccountid AS accountid, p.value AS countystate, sis.status > FROM provisioning.service s > JOIN provisioning.serviceoffering so ON s.serviceid = > so.fkserviceid > JOIN provisioning.serviceinstance si ON so.serviceofferingid = > si.fkserviceofferingid > JOIN provisioning.serviceinstancestatus sis ON > si.fkserviceinstancestatusid = sis.serviceinstancestatusid > JOIN provisioning.serviceinstanceparameter sip ON > si.serviceinstanceid = sip.fkserviceinstanceid > JOIN common.parameter p ON sip.fkparameterid = p.parameterid > WHERE s.servicename = 'alert'::text AND p.name = 'countyState'::text) > p2 ON p1.accountid = p2.accountid AND p1.serviceinstanceid = > p2.serviceinstanceid > JOIN ( SELECT si.serviceinstanceid, si.affiliate, si.affiliatesub, > si."domain", si.fkaccountid AS accountid, p.value AS listingtype, sis.status > FROM provisioning.service s > JOIN provisioning.serviceoffering so ON s.serviceid = so.fkserviceid > JOIN provisioning.serviceinstance si ON so.serviceofferingid = > si.fkserviceofferingid > JOIN provisioning.serviceinstancestatus sis ON > si.fkserviceinstancestatusid = sis.serviceinstancestatusid > JOIN provisioning.serviceinstanceparameter sip ON > si.serviceinstanceid = sip.fkserviceinstanceid > JOIN common.parameter p ON sip.fkparameterid = p.parameterid > WHERE s.servicename = 'alert'::text AND p.name = 'listingType'::text) > p3 ON p2.accountid = p3.accountid AND p2.serviceinstanceid = > p3.serviceinstanceid) services > ON a.accountid = services.accountid > ORDER BY services.serviceinstanceid; > > Explain Analyze > ------------------ > explain analyze > select * from provisioning.alertserviceinstanceold where countystate = > 'FL' and countyno = '099' and status = 'ACTIVE' ; > > > QUERY PLAN > > ---------------------------------------------------------------------------------------------------------------------------------------------- > -------------------------------------------------------------------------------------------------------------------- > Subquery Scan alertserviceinstanceold (cost=31954.24..31954.25 rows=1 > width=328) (actual time=113485.801..113487.024 rows=110 loops=1) > -> Sort (cost=31954.24..31954.24 rows=1 width=152) (actual > time=113485.787..113486.123 rows=110 loops=1) > Sort Key: si.serviceinstanceid > -> Hash Join (cost=20636.38..31954.23 rows=1 width=152) > (actual time=109721.688..113485.311 rows=110 loops=1) > Hash Cond: ("outer".accountid = "inner".fkaccountid) > -> Hash Join (cost=6595.89..16770.25 rows=228696 > width=47) (actual time=1742.592..4828.396 rows=229855 loops=1) > Hash Cond: ("outer".contactid = "inner".fkcontactid) > -> Seq Scan on contact c (cost=0.00..4456.96 > rows=228696 width=47) (actual time=0.006..1106.459 rows=229868 loops=1) > -> Hash (cost=6024.11..6024.11 rows=228711 > width=8) (actual time=1742.373..1742.373 rows=0 loops=1) > -> Seq Scan on account a > (cost=0.00..6024.11 rows=228711 width=8) (actual time=0.010..990.597 > rows=229855 loops=1) > -> Hash (cost=14040.49..14040.49 rows=1 width=117) > (actual time=107911.397..107911.397 rows=0 loops=1) > -> Nested Loop (cost=10.34..14040.49 rows=1 > width=117) (actual time=1185.383..107910.738 rows=110 loops=1) > -> Nested Loop (cost=10.34..14037.45 rows=1 > width=112) (actual time=1185.278..107898.885 rows=550 loops=1) > -> Hash Join (cost=10.34..14033.98 > rows=1 width=124) (actual time=1185.224..107888.542 rows=110 loops=1) > Hash Cond: > ("outer".fkserviceofferingid = "inner".serviceofferingid) > -> Hash Join > (cost=7.96..14031.58 rows=1 width=128) (actual time=1184.490..107886.329 > rows=110 loops=1) > Hash Cond: > ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) > -> Nested Loop > (cost=6.90..14030.50 rows=1 width=132) (actual time=1184.151..107884.302 > rows=110 loops=1) > Join Filter: > ("outer".fkaccountid = "inner".fkaccountid) Well, here's the step that's killing you: > -> Nested Loop > (cost=6.90..14025.09 rows=1 width=116) (actual time=1184.123..107880.635 > rows=110 loops=1) > Join Filter: > (("outer".fkaccountid = "inner".fkaccountid) AND > ("outer".serviceinstanceid = "inner".serviceinstanceid)) > -> Hash Join > (cost=3.45..636.39 rows=1 width=95) (actual time=85.524..293.387 > rows=226 loops=1) > Hash > Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) Unfortunately, the way this query plan came out it's difficult to figure out what the other input to that nested loop is. But before we get to that, what do you have join_collapse_limit set to? If it's the default of 8 then the optimizer is essentially going to follow the join order you specified when you wrote the view, which could be far from optimal. It would be worth setting join_collapse_limit high enough so that this query will get flattened and see what kind of plan it comes up with then. Note that this could result in an unreasonably-large plan time, but if it results in a fast query execution we know it's just a matter of re-ordering things in the query. Also, it would be best if you could send the results of explain as an attachement that hasn't been word-wrapped. > -> Hash > Join (cost=2.38..635.29 rows=4 width=87) (actual time=6.894..289.000 > rows=663 loops=1) > > Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) > -> > Nested Loop (cost=0.00..632.75 rows=23 width=91) (actual > time=6.176..281.620 rows=663 loops=1) > > -> Nested Loop (cost=0.00..508.26 rows=23 width=13) (actual > time=6.138..221.590 rows=663 loops=1) > > -> Index Scan using idx_parameter_value on parameter p > (cost=0.00..437.42 rows=23 width=13) (actual time=6.091..20.656 rows=663 > loops=1) > > Index Cond: (value = '099'::text) > > Filter: (name = 'countyNo'::text) > > -> Index Scan using idx_serviceinstanceparameter_fkparameterid on > serviceinstanceparameter sip (cost=0.00..3.07 rows=1 width=8) (actual > time=0.278..0.288 rows=1 loops=663) > > Index Cond: (sip.fkparameterid = "outer".parameterid) > > -> Index Scan using pk_serviceinstance_serviceinstanceid on > serviceinstance si (cost=0.00..5.40 rows=1 width=78) (actual > time=0.041..0.073 rows=1 loops=663) > > Index Cond: (si.serviceinstanceid = "outer".fkserviceinstanceid) > -> > Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.445..0.445 rows=0 > loops=1) > > -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual > time=0.314..0.426 rows=1 loops=1) > > Hash Cond: ("outer".fkserviceid = "inner".serviceid) > > -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18width=8) > (actual time=0.005..0.065 rows=18 loops=1) > > -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.033..0.033 > rows=0 loops=1) > > -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual > time=0.011..0.016 rows=1 loops=1) > > Filter: (servicename = 'alert'::text) > -> Hash > (cost=1.06..1.06 rows=1 width=16) (actual time=0.031..0.031 rows=0 loops=1) > -> > Seq Scan on serviceinstancestatus sis (cost=0.00..1.06 rows=1 width=16) > (actual time=0.008..0.014 rows=1 loops=1) > > Filter: (status = 'ACTIVE'::text) > -> Hash Join > (cost=3.45..13386.23 rows=165 width=21) (actual time=0.119..461.891 > rows=3935 loops=226) > Hash > Cond: ("outer".fkserviceinstancestatusid = "inner".serviceinstancestatusid) > -> Hash > Join (cost=2.38..13382.69 rows=165 width=25) (actual > time=0.110..432.555 rows=3935 loops=226) > > Hash Cond: ("outer".fkserviceofferingid = "inner".serviceofferingid) > -> > Nested Loop (cost=0.00..13373.71 rows=990 width=29) (actual > time=0.098..400.805 rows=3935 loops=226) > > -> Nested Loop (cost=0.00..8015.16 rows=990 width=13) (actual > time=0.035..267.634 rows=3935 loops=226) > > -> Seq Scan on parameter p (cost=0.00..4968.81 rows=989 width=13) > (actual time=0.008..131.735 rows=3935 loops=226) > > Filter: ((name = 'countyState'::text) AND (value = 'FL'::text)) > > -> Index Scan using idx_serviceinstanceparameter_fkparameterid on > serviceinstanceparameter sip (cost=0.00..3.07 rows=1 width=8) (actual > time=0.015..0.020 rows=1 loops=889310) > > Index Cond: (sip.fkparameterid = "outer".parameterid) > > -> Index Scan using pk_serviceinstance_serviceinstanceid on > serviceinstance si (cost=0.00..5.40 rows=1 width=16) (actual > time=0.012..0.019 rows=1 loops=889310) > > Index Cond: (si.serviceinstanceid = "outer".fkserviceinstanceid) > -> > Hash (cost=2.38..2.38 rows=3 width=4) (actual time=0.439..0.439 rows=0 > loops=1) > > -> Hash Join (cost=1.08..2.38 rows=3 width=4) (actual > time=0.310..0.423 rows=1 loops=1) > > Hash Cond: ("outer".fkserviceid = "inner".serviceid) > > -> Seq Scan on serviceoffering so (cost=0.00..1.18 rows=18 width=8) > (actual time=0.006..0.065 rows=18 loops=1) > > -> Hash (cost=1.07..1.07 rows=1 width=4) (actual time=0.035..0.035 > rows=0 loops=1) > > -> Seq Scan on service s (cost=0.00..1.07 rows=1 width=4) (actual > time=0.013..0.018 rows=1 loops=1) > > Filter: (servicename = 'alert'::text) > -> Hash > (cost=1.05..1.05 rows=5 width=4) (actual time=0.059..0.059 rows=0 loops=1) > -> > Seq Scan on serviceinstancestatus sis (cost=0.00..1.05 rows=5 width=4) > (actual time=0.010..0.029 rows=5 loops=1) > -> Index Scan using > pk_serviceinstance_serviceinstanceid on serviceinstance si > (cost=0.00..5.40 rows=1 width=16) (actual time=0.009..0.012 rows=1 > loops=110) > Index Cond: > (si.serviceinstanceid = "outer".fkserviceinstanceid) > -> Hash (cost=1.05..1.05 > rows=5 width=4) (actual time=0.055..0.055 rows=0 loops=1) > -> Seq Scan on > serviceinstancestatus sis (cost=0.00..1.05 rows=5 width=4) (actual > time=0.008..0.025 rows=5 loops=1) > -> Hash (cost=2.38..2.38 rows=3 > width=4) (actual time=0.461..0.461 rows=0 loops=1) > -> Hash Join > (cost=1.08..2.38 rows=3 width=4) (actual time=0.325..0.445 rows=1 loops=1) > Hash Cond: > ("outer".fkserviceid = "inner".serviceid) > -> Seq Scan on > serviceoffering so (cost=0.00..1.18 rows=18 width=8) (actual > time=0.006..0.074 rows=18 loops=1) > -> Hash > (cost=1.07..1.07 rows=1 width=4) (actual time=0.044..0.044 rows=0 loops=1) > -> Seq Scan on > service s (cost=0.00..1.07 rows=1 width=4) (actual time=0.022..0.027 > rows=1 loops=1) > Filter: > (servicename = 'alert'::text) > -> Index Scan using > idx_serviceinstanceparameter_fkserviceinstanceid on > serviceinstanceparameter sip (cost=0.00..3.41 rows=5 width=8) (actual > time=0.018..0.038 rows=5 loops=110) > Index Cond: > (sip.fkserviceinstanceid = "outer".fkserviceinstanceid) > -> Index Scan using pk_parameter_parameterid > on parameter p (cost=0.00..3.02 rows=1 width=13) (actual > time=0.011..0.012 rows=0 loops=550) > Index Cond: ("outer".fkparameterid = > p.parameterid) > Filter: (name = 'listingType'::text) > > Total runtime: 113490.582 ms > (82 rows) -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Sat Jan 14 01:50:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8BDC79DC802 for ; Wed, 11 Jan 2006 15:48:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62958-08 for ; Wed, 11 Jan 2006 15:48:08 -0400 (AST) X-Greylist: delayed 00:27:26.743693 by SQLgrey- Received: from crt0.crt.umontreal.ca (crt0.CRT.UMontreal.CA [132.204.100.27]) by postgresql.org (Postfix) with ESMTP id 712709DC833 for ; Wed, 11 Jan 2006 15:48:06 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 95D57384150 for ; Wed, 11 Jan 2006 14:20:40 -0500 (EST) Received: from crt0.crt.umontreal.ca ([127.0.0.1]) by localhost (crt0.crt.umontreal.ca [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 17688-01-75 for ; Wed, 11 Jan 2006 14:20:39 -0500 (EST) Received: from Spoke01 (unknown [10.100.3.7]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 12341384122 for ; Wed, 11 Jan 2006 14:20:39 -0500 (EST) From: =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= To: Subject: Extremely irregular query performance Date: Wed, 11 Jan 2006 14:29:03 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcYW5UeV8bUde1TSRGeDJp/e9FicfQ== Message-Id: <20060111192039.12341384122@crt0.crt.umontreal.ca> X-Virus-Scanned: amavisd-new at crt.umontreal.ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/179 X-Sequence-Number: 16657 Hi, I'm running version 8.1 on a dedicated Sun v20 server (2 AMD x64's) with 4Gb of RAM. I have recently noticed that the performance of some more complex queries is extremely variable and irregular. For example, I currently have a query that returns a small number of rows (5) by joining a dozen of tables. Below are the running times obtained by repeatedly lauching this query in psql: Time: 424.848 ms Time: 1615.143 ms Time: 15036.475 ms Time: 83471.683 ms Time: 163.224 ms Time: 2454.939 ms Time: 188.093 ms Time: 158.071 ms Time: 192.431 ms Time: 195.076 ms Time: 635.739 ms Time: 164549.902 ms As you can see, the performance is most of the time pretty good (less than 1 second), but every fourth of fifth time I launch the query the server seems to go into orbit. For the longer running times, I can see from top that the server process uses almost 100% of a CPU. This is rather worrisome, as I cannot be confident of the overall performance of my application with so much variance in query response times. I suspect a configuration problem related to the cache mechanism (shared_buffers? effective_cache_size?), but to be honest I do not know where to start to diagnose it. Any help would be greatly appreciated. Thanks in advance, J-P From pgsql-performance-owner@postgresql.org Wed Jan 11 15:55:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 719279DCA17 for ; Wed, 11 Jan 2006 15:55:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68491-08-2 for ; Wed, 11 Jan 2006 15:55:40 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.204]) by postgresql.org (Postfix) with ESMTP id 357EC9DC9B6 for ; Wed, 11 Jan 2006 15:55:35 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so65356uge for ; Wed, 11 Jan 2006 11:55:36 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-mailer; b=YbPeVHT/1HokW++0IfEkCu4ASSQgiIH9g9Hbjy557IH6GhkJZ1OFETAQgsbHHlBaUV2hB0Mh1I6s0vquTIR0HtgwFjrtrJ462jNcg4AN4xd6s1b3SdRWo5+ojJSbANYlrkSIjU9YtMyMd7Bs3uslQGxlnb45y3kq0H7nvLlzdwY= Received: by 10.66.220.3 with SMTP id s3mr412412ugg; Wed, 11 Jan 2006 11:55:36 -0800 (PST) Received: from ?10.80.1.43? ( [194.248.208.94]) by mx.gmail.com with ESMTP id q1sm463867uge.2006.01.11.11.55.35; Wed, 11 Jan 2006 11:55:35 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <13028.1136994347@sss.pgh.pa.us> References: <13028.1136994347@sss.pgh.pa.us> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <65451320-7D72-4544-A8E8-CD93212E4A5D@gmail.com> Content-Transfer-Encoding: 7bit From: Bendik Rognlien Johansen Subject: Re: Slow query with joins Date: Wed, 11 Jan 2006 20:55:32 +0100 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/121 X-Sequence-Number: 16599 Yes, the rowcount estimates are real, however, it has been a long time since the last VACUUM FULL (there is never a good time). I have clustered the tables, reindexed, analyzed, vacuumed and the plan now looks like this: no_people=# explain SELECT r.id AS r_id, r.firstname || ' ' || r.lastname AS r_name, ad.id AS ad_id, ad.type AS ad_type, ad.address AS ad_address, ad.postalcode AS ad_postalcode, ad.postalsite AS ad_postalsite, ad.priority AS ad_priority, ad.position[0] AS ad_lat, ad.position[1] AS ad_lon, ad.uncertainty AS ad_uncertainty, ad.extra AS ad_extra, ad.deleted AS ad_deleted, co.id AS co_id, co.type AS co_type, co.value AS co_value, co.description AS co_description, co.priority AS co_priority, co.visible AS co_visible, co.searchable AS co_searchable, co.deleted AS co_deleted FROM people r LEFT OUTER JOIN addresses ad ON(r.id = ad.record) LEFT OUTER JOIN contacts co ON (r.id = co.record) WHERE NOT r.deleted AND r.original IS NULL ORDER BY r.id; QUERY PLAN ------------------------------------------------------------------------ -------------------------------------------------- Sort (cost=182866.49..182943.12 rows=30655 width=587) Sort Key: r.id -> Nested Loop Left Join (cost=0.00..170552.10 rows=30655 width=587) -> Nested Loop Left Join (cost=0.00..75054.96 rows=26325 width=160) -> Index Scan using people_deleted_original_is_null on people r (cost=0.00..1045.47 rows=23861 width=27) Filter: ((NOT deleted) AND (original IS NULL)) -> Index Scan using addresses_record_idx on addresses ad (cost=0.00..3.05 rows=4 width=137) Index Cond: ("outer".id = ad.record) -> Index Scan using contacts_record_idx on contacts co (cost=0.00..3.32 rows=24 width=431) Index Cond: ("outer".id = co.record) (10 rows) Looks faster, but still very slow. I added limit 1000 and it has been running for about 25 minutes now with no output. top shows: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 29994 postgres 18 0 95768 78m 68m R 17.0 7.7 0:53.27 postmaster which is unusual, I usually get 99.9 %cpu for just about any query, which leads me to believe this is disk related. postgresql.conf: shared_buffers = 8192 work_mem = 8192 maintenance_work_mem = 524288 Hardware 2x2.8GHz cpu 1GB ram Could this be an issue related to lack of VACUUM FULL? The tables get a lot of updates. Thank you very much so far! On Jan 11, 2006, at 4:45 PM, Tom Lane wrote: > Bendik Rognlien Johansen writes: >> Has anyone got any tips for speeding up this query? It currently >> takes hours to start. > > Are the rowcount estimates close to reality? The plan doesn't look > unreasonable to me if they are. It might help to increase work_mem > to ensure that the hash tables don't spill to disk. > > Indexes: > "people_original_is_null" btree (original) WHERE original IS NULL > > This index seems poorly designed: the actual index entries are dead > weight since all of them are necessarily NULL. You might as well make > the index carry something that you frequently test in conjunction with > "original IS NULL". For instance, if this particular query is a > common > case, you could replace this index with > > CREATE INDEX people_deleted_original_is_null ON people(deleted) > WHERE original IS NULL; > > This index is still perfectly usable for queries that only say > "original > IS NULL", but it can also filter out rows with the wrong value of > deleted. Now, if there are hardly any rows with deleted = true, maybe > this won't help much for your problem. But in any case you ought to > consider whether you can make the index entries do something useful. > > regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 16:24:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 321909DC874 for ; Wed, 11 Jan 2006 16:24:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75253-07 for ; Wed, 11 Jan 2006 16:24:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 58ADD9DC845 for ; Wed, 11 Jan 2006 16:24:00 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 549AB3984A; Wed, 11 Jan 2006 14:23:45 -0600 (CST) Date: Wed, 11 Jan 2006 14:23:45 -0600 From: "Jim C. Nasby" To: Bendik Rognlien Johansen Cc: pgsql-performance@postgresql.org Subject: Re: Slow query with joins Message-ID: <20060111202345.GC63175@pervasive.com> References: <13028.1136994347@sss.pgh.pa.us> <65451320-7D72-4544-A8E8-CD93212E4A5D@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <65451320-7D72-4544-A8E8-CD93212E4A5D@gmail.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/122 X-Sequence-Number: 16600 I'd try figuring out if the join is the culprit or the sort is (by dropping the ORDER BY). work_mem is probably forcing the sort to spill to disk, and if your drives are rather busy... You might also get a win if you re-order the joins to people, contacts, addresses, if you know it will have the same result. In this case LIMIT won't have any real effect, because you have to go all the way through with the ORDER BY anyway. On Wed, Jan 11, 2006 at 08:55:32PM +0100, Bendik Rognlien Johansen wrote: > Yes, the rowcount estimates are real, however, it has been a long > time since the last VACUUM FULL (there is never a good time). > > I have clustered the tables, reindexed, analyzed, vacuumed and the > plan now looks like this: > > > no_people=# explain SELECT r.id AS r_id, r.firstname || ' ' || > r.lastname AS r_name, ad.id AS ad_id, ad.type AS ad_type, ad.address > AS ad_address, ad.postalcode AS ad_postalcode, ad.postalsite AS > ad_postalsite, ad.priority AS ad_priority, ad.position[0] AS ad_lat, > ad.position[1] AS ad_lon, ad.uncertainty AS ad_uncertainty, ad.extra > AS ad_extra, ad.deleted AS ad_deleted, co.id AS co_id, co.type AS > co_type, co.value AS co_value, co.description AS co_description, > co.priority AS co_priority, co.visible AS co_visible, co.searchable > AS co_searchable, co.deleted AS co_deleted FROM people r LEFT OUTER > JOIN addresses ad ON(r.id = ad.record) LEFT OUTER JOIN contacts co ON > (r.id = co.record) WHERE NOT r.deleted AND r.original IS NULL ORDER > BY r.id; > QUERY PLAN > ------------------------------------------------------------------------ > -------------------------------------------------- > Sort (cost=182866.49..182943.12 rows=30655 width=587) > Sort Key: r.id > -> Nested Loop Left Join (cost=0.00..170552.10 rows=30655 > width=587) > -> Nested Loop Left Join (cost=0.00..75054.96 rows=26325 > width=160) > -> Index Scan using people_deleted_original_is_null > on people r (cost=0.00..1045.47 rows=23861 width=27) > Filter: ((NOT deleted) AND (original IS NULL)) > -> Index Scan using addresses_record_idx on > addresses ad (cost=0.00..3.05 rows=4 width=137) > Index Cond: ("outer".id = ad.record) > -> Index Scan using contacts_record_idx on contacts co > (cost=0.00..3.32 rows=24 width=431) > Index Cond: ("outer".id = co.record) > (10 rows) > > > > > > > Looks faster, but still very slow. I added limit 1000 and it has been > running for about 25 minutes now with no output. top shows: > > > PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND > 29994 postgres 18 0 95768 78m 68m R 17.0 7.7 0:53.27 postmaster > > > > which is unusual, I usually get 99.9 %cpu for just about any query, > which leads me to believe this is disk related. > > > > postgresql.conf: > shared_buffers = 8192 > work_mem = 8192 > maintenance_work_mem = 524288 > > > > > Hardware 2x2.8GHz cpu > 1GB ram > > Could this be an issue related to lack of VACUUM FULL? The tables get > a lot of updates. > > > Thank you very much so far! > > > > > On Jan 11, 2006, at 4:45 PM, Tom Lane wrote: > > >Bendik Rognlien Johansen writes: > >>Has anyone got any tips for speeding up this query? It currently > >>takes hours to start. > > > >Are the rowcount estimates close to reality? The plan doesn't look > >unreasonable to me if they are. It might help to increase work_mem > >to ensure that the hash tables don't spill to disk. > > > >Indexes: > > "people_original_is_null" btree (original) WHERE original IS NULL > > > >This index seems poorly designed: the actual index entries are dead > >weight since all of them are necessarily NULL. You might as well make > >the index carry something that you frequently test in conjunction with > >"original IS NULL". For instance, if this particular query is a > >common > >case, you could replace this index with > > > >CREATE INDEX people_deleted_original_is_null ON people(deleted) > > WHERE original IS NULL; > > > >This index is still perfectly usable for queries that only say > >"original > >IS NULL", but it can also filter out rows with the wrong value of > >deleted. Now, if there are hardly any rows with deleted = true, maybe > >this won't help much for your problem. But in any case you ought to > >consider whether you can make the index entries do something useful. > > > > regards, tom lane > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 11 16:39:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 92A839DC833 for ; Wed, 11 Jan 2006 16:39:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79930-05 for ; Wed, 11 Jan 2006 16:39:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (217-133-42-200.b2b.tiscali.it [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id 1BC999DC804 for ; Wed, 11 Jan 2006 16:39:47 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id C2C9C1C1421; Wed, 11 Jan 2006 21:39:47 +0100 (CET) Date: Wed, 11 Jan 2006 21:39:47 +0100 From: Andrea Arcangeli To: "Jim C. Nasby" Cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111203947.GL15897@opteron.random> References: <20060110014447.GB18474@opteron.random> <20060111184032.GS3902@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060111184032.GS3902@pervasive.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/123 X-Sequence-Number: 16601 On Wed, Jan 11, 2006 at 12:40:32PM -0600, Jim C. Nasby wrote: > On Tue, Jan 10, 2006 at 02:44:47AM +0100, Andrea Arcangeli wrote: > > "cooperative" runs "WHERE kernel_version NOT LIKE '%% PREEMPT %%'", while > > "preempt" runs "WHERE kernel_version LIKE '%% PREEMPT %%'. The only difference > > One thing you could do is change the like to: > > WHERE position(' PREEMPT ' in kernel_version) != 0 That alone fixed it, with this I don't even need the index (yet). Thanks a lot. > And then create a functional index on that: > > CREATE INDEX indexname ON tablename ( position(' PREEMPT ' in kernel_version) ); The index only helps the above query with = 0 and not the one with != 0, but it seems not needed in practice. From pgsql-performance-owner@postgresql.org Wed Jan 11 16:46:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 362469DC89B for ; Wed, 11 Jan 2006 16:46:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80641-07 for ; Wed, 11 Jan 2006 16:46:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (217-133-42-200.b2b.tiscali.it [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id 83B1E9DC8A9 for ; Wed, 11 Jan 2006 16:46:39 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id 02D061C16A7; Wed, 11 Jan 2006 21:46:39 +0100 (CET) Date: Wed, 11 Jan 2006 21:46:39 +0100 From: Andrea Arcangeli Cc: "Jim C. Nasby" , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111204639.GM15897@opteron.random> References: <20060110014447.GB18474@opteron.random> <20060111184032.GS3902@pervasive.com> <20060111203947.GL15897@opteron.random> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060111203947.GL15897@opteron.random> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.214 required=5 tests=[AWL=0.025, MISSING_HEADERS=0.189] X-Spam-Score: 0.214 X-Spam-Level: X-Archive-Number: 200601/124 X-Sequence-Number: 16602 On Wed, Jan 11, 2006 at 09:39:47PM +0100, Andrea Arcangeli wrote: > On Wed, Jan 11, 2006 at 12:40:32PM -0600, Jim C. Nasby wrote: > > On Tue, Jan 10, 2006 at 02:44:47AM +0100, Andrea Arcangeli wrote: > > > "cooperative" runs "WHERE kernel_version NOT LIKE '%% PREEMPT %%'", while > > > "preempt" runs "WHERE kernel_version LIKE '%% PREEMPT %%'. The only difference > > > > One thing you could do is change the like to: > > > > WHERE position(' PREEMPT ' in kernel_version) != 0 > > That alone fixed it, with this I don't even need the index (yet). Thanks > a lot. The fix is online already w/o index: http://klive.cpushare.com/?branch=all&scheduler=preemptive Of course I'm still fully available to test any fix for the previous LIKE query if there's interest. From pgsql-performance-owner@postgresql.org Wed Jan 11 17:02:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8D9E99DC845 for ; Wed, 11 Jan 2006 17:02:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86977-06 for ; Wed, 11 Jan 2006 17:02:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 51E8A9DC98E for ; Wed, 11 Jan 2006 17:02:20 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id D64EC39849; Wed, 11 Jan 2006 15:02:21 -0600 (CST) Date: Wed, 11 Jan 2006 15:02:21 -0600 From: "Jim C. Nasby" To: Andrea Arcangeli Cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111210221.GD63175@pervasive.com> References: <20060110014447.GB18474@opteron.random> <20060111184032.GS3902@pervasive.com> <20060111203947.GL15897@opteron.random> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060111203947.GL15897@opteron.random> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/125 X-Sequence-Number: 16603 On Wed, Jan 11, 2006 at 09:39:47PM +0100, Andrea Arcangeli wrote: > > CREATE INDEX indexname ON tablename ( position(' PREEMPT ' in kernel_version) ); > > The index only helps the above query with = 0 and not the one with != 0, > but it seems not needed in practice. Hrm. If you need indexing then, you'll probably have to do 2 indexes with a WHERE clause... CREATE INDEX ... WHERE position(...) = 0; CREATE INDEX ... WHERE position(...) != 0; I suspect this is because of a lack of stats for functional indexes. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 11 17:13:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2497E9DC845 for ; Wed, 11 Jan 2006 17:13:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89840-03 for ; Wed, 11 Jan 2006 17:13:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A964E9DC839 for ; Wed, 11 Jan 2006 17:13:21 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BLDKgq028233; Wed, 11 Jan 2006 16:13:20 -0500 (EST) To: "Jim C. Nasby" cc: Andrea Arcangeli , pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? In-reply-to: <20060111210221.GD63175@pervasive.com> References: <20060110014447.GB18474@opteron.random> <20060111184032.GS3902@pervasive.com> <20060111203947.GL15897@opteron.random> <20060111210221.GD63175@pervasive.com> Comments: In-reply-to "Jim C. Nasby" message dated "Wed, 11 Jan 2006 15:02:21 -0600" Date: Wed, 11 Jan 2006 16:13:20 -0500 Message-ID: <28232.1137014000@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.084 required=5 tests=[AWL=0.084] X-Spam-Score: 0.084 X-Spam-Level: X-Archive-Number: 200601/126 X-Sequence-Number: 16604 "Jim C. Nasby" writes: > On Wed, Jan 11, 2006 at 09:39:47PM +0100, Andrea Arcangeli wrote: >> The index only helps the above query with = 0 and not the one with != 0, >> but it seems not needed in practice. > I suspect this is because of a lack of stats for functional indexes. No, it's because != isn't an indexable operator. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 17:31:04 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 424339DC9CB for ; Wed, 11 Jan 2006 17:31:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93076-09 for ; Wed, 11 Jan 2006 17:31:04 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.206]) by postgresql.org (Postfix) with ESMTP id 931BE9DC9AC for ; Wed, 11 Jan 2006 17:31:00 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so71494uge for ; Wed, 11 Jan 2006 13:31:02 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:in-reply-to:references:mime-version:content-type:message-id:cc:content-transfer-encoding:from:subject:date:to:x-mailer; b=txZvS7vpHeSZxQyHPPsLS1MEtIbaA8PqLNtq2qs8SEJc/t+89UQh9Wd4jpLx1S8kNaJCiwgJz8G5H9YOy+hIJ7BVAAFQPhriUE1AwQ1XKp5cTufxOxHxCvXNkrVrbJIQlwRavGZAc+C2TiqppbsALTliAEZulY4aDyNm0jhcoz4= Received: by 10.67.31.12 with SMTP id i12mr451394ugj; Wed, 11 Jan 2006 13:31:01 -0800 (PST) Received: from ?192.168.1.238? ( [80.203.240.195]) by mx.gmail.com with ESMTP id h1sm459774ugf.2006.01.11.13.31.00; Wed, 11 Jan 2006 13:31:01 -0800 (PST) In-Reply-To: <20060111202345.GC63175@pervasive.com> References: <13028.1136994347@sss.pgh.pa.us> <65451320-7D72-4544-A8E8-CD93212E4A5D@gmail.com> <20060111202345.GC63175@pervasive.com> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <850AD6F9-08BD-4EF2-A549-407FD87C7974@gmail.com> Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit From: Bendik Rognlien Johansen Subject: Re: Slow query with joins Date: Wed, 11 Jan 2006 22:30:58 +0100 To: "Jim C. Nasby" X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/127 X-Sequence-Number: 16605 The sort is definitively the culprit. When I removed it the query was instant. I tried setting work_mem = 131072 but it did not seem to help. I really don't understand this :-( Any other ideas? Thanks! On Jan 11, 2006, at 9:23 PM, Jim C. Nasby wrote: > I'd try figuring out if the join is the culprit or the sort is (by > dropping the ORDER BY). work_mem is probably forcing the sort to spill > to disk, and if your drives are rather busy... > > You might also get a win if you re-order the joins to people, > contacts, > addresses, if you know it will have the same result. > > In this case LIMIT won't have any real effect, because you have to go > all the way through with the ORDER BY anyway. > > On Wed, Jan 11, 2006 at 08:55:32PM +0100, Bendik Rognlien Johansen > wrote: >> Yes, the rowcount estimates are real, however, it has been a long >> time since the last VACUUM FULL (there is never a good time). >> >> I have clustered the tables, reindexed, analyzed, vacuumed and the >> plan now looks like this: >> >> >> no_people=# explain SELECT r.id AS r_id, r.firstname || ' ' || >> r.lastname AS r_name, ad.id AS ad_id, ad.type AS ad_type, ad.address >> AS ad_address, ad.postalcode AS ad_postalcode, ad.postalsite AS >> ad_postalsite, ad.priority AS ad_priority, ad.position[0] AS ad_lat, >> ad.position[1] AS ad_lon, ad.uncertainty AS ad_uncertainty, ad.extra >> AS ad_extra, ad.deleted AS ad_deleted, co.id AS co_id, co.type AS >> co_type, co.value AS co_value, co.description AS co_description, >> co.priority AS co_priority, co.visible AS co_visible, co.searchable >> AS co_searchable, co.deleted AS co_deleted FROM people r LEFT OUTER >> JOIN addresses ad ON(r.id = ad.record) LEFT OUTER JOIN contacts co ON >> (r.id = co.record) WHERE NOT r.deleted AND r.original IS NULL ORDER >> BY r.id; >> QUERY PLAN >> --------------------------------------------------------------------- >> --- >> -------------------------------------------------- >> Sort (cost=182866.49..182943.12 rows=30655 width=587) >> Sort Key: r.id >> -> Nested Loop Left Join (cost=0.00..170552.10 rows=30655 >> width=587) >> -> Nested Loop Left Join (cost=0.00..75054.96 rows=26325 >> width=160) >> -> Index Scan using people_deleted_original_is_null >> on people r (cost=0.00..1045.47 rows=23861 width=27) >> Filter: ((NOT deleted) AND (original IS NULL)) >> -> Index Scan using addresses_record_idx on >> addresses ad (cost=0.00..3.05 rows=4 width=137) >> Index Cond: ("outer".id = ad.record) >> -> Index Scan using contacts_record_idx on contacts co >> (cost=0.00..3.32 rows=24 width=431) >> Index Cond: ("outer".id = co.record) >> (10 rows) >> >> >> >> >> >> >> Looks faster, but still very slow. I added limit 1000 and it has been >> running for about 25 minutes now with no output. top shows: >> >> >> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND >> 29994 postgres 18 0 95768 78m 68m R 17.0 7.7 0:53.27 >> postmaster >> >> >> >> which is unusual, I usually get 99.9 %cpu for just about any query, >> which leads me to believe this is disk related. >> >> >> >> postgresql.conf: >> shared_buffers = 8192 >> work_mem = 8192 >> maintenance_work_mem = 524288 >> >> >> >> >> Hardware 2x2.8GHz cpu >> 1GB ram >> >> Could this be an issue related to lack of VACUUM FULL? The tables get >> a lot of updates. >> >> >> Thank you very much so far! >> >> >> >> >> On Jan 11, 2006, at 4:45 PM, Tom Lane wrote: >> >>> Bendik Rognlien Johansen writes: >>>> Has anyone got any tips for speeding up this query? It currently >>>> takes hours to start. >>> >>> Are the rowcount estimates close to reality? The plan doesn't look >>> unreasonable to me if they are. It might help to increase work_mem >>> to ensure that the hash tables don't spill to disk. >>> >>> Indexes: >>> "people_original_is_null" btree (original) WHERE original IS >>> NULL >>> >>> This index seems poorly designed: the actual index entries are dead >>> weight since all of them are necessarily NULL. You might as well >>> make >>> the index carry something that you frequently test in conjunction >>> with >>> "original IS NULL". For instance, if this particular query is a >>> common >>> case, you could replace this index with >>> >>> CREATE INDEX people_deleted_original_is_null ON people(deleted) >>> WHERE original IS NULL; >>> >>> This index is still perfectly usable for queries that only say >>> "original >>> IS NULL", but it can also filter out rows with the wrong value of >>> deleted. Now, if there are hardly any rows with deleted = true, >>> maybe >>> this won't help much for your problem. But in any case you ought to >>> consider whether you can make the index entries do something useful. >>> >>> regards, tom lane >> >> >> ---------------------------(end of >> broadcast)--------------------------- >> TIP 5: don't forget to increase your free space map settings >> > > -- > Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com > Pervasive Software http://pervasive.com work: 512-231-6117 > vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 11 18:05:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3CD949DC898 for ; Wed, 11 Jan 2006 18:05:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97772-10 for ; Wed, 11 Jan 2006 18:05:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id 884A19DC863 for ; Wed, 11 Jan 2006 18:05:17 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [63.226.156.118] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 81167295 for pgsql-performance@postgresql.org; Wed, 11 Jan 2006 14:05:19 -0800 From: "Dave Dutcher" To: Subject: Showing Column Statistics Number Date: Wed, 11 Jan 2006 16:05:18 -0600 Message-ID: <020101c616fb$1c4f9de0$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0202_01C616C8.D1B52DE0" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/128 X-Sequence-Number: 16606 This is a multi-part message in MIME format. ------=_NextPart_000_0202_01C616C8.D1B52DE0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, I've looked around through the docs, but can't seem to find an answer to this. If I change a column's statistics with "Alter table alter column set statistics n", is there a way I can later go back and see what the number is for that column? I want to be able to tell which columns I've changed the statistics on, and which ones I haven't. Thanks, Dave ------=_NextPart_000_0202_01C616C8.D1B52DE0 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

Hi,

 

I’ve looked around through the docs, but = can’t seem to find an answer to this.  = If I change a column’s statistics with “Alter table alter = column set statistics n”, is there a way I can later go back and see what the = number is for that column?  I want = to be able to tell which columns I’ve changed the statistics on, and = which ones I haven’t.

 

Thanks,

 

Dave

------=_NextPart_000_0202_01C616C8.D1B52DE0-- From pgsql-performance-owner@postgresql.org Wed Jan 11 18:21:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DA3EF9DCA26 for ; Wed, 11 Jan 2006 18:21:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02648-04 for ; Wed, 11 Jan 2006 18:21:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id ACAE69DCA25 for ; Wed, 11 Jan 2006 18:21:40 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0BMLdww008935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2006 15:21:41 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0BMLd3U088391; Wed, 11 Jan 2006 15:21:39 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0BMLcEF088390; Wed, 11 Jan 2006 15:21:38 -0700 (MST) (envelope-from mfuhr) Date: Wed, 11 Jan 2006 15:21:38 -0700 From: Michael Fuhr To: Dave Dutcher Cc: pgsql-performance@postgresql.org Subject: Re: Showing Column Statistics Number Message-ID: <20060111222138.GA88301@winnie.fuhr.org> References: <020101c616fb$1c4f9de0$8300a8c0@tridecap.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <020101c616fb$1c4f9de0$8300a8c0@tridecap.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/129 X-Sequence-Number: 16607 On Wed, Jan 11, 2006 at 04:05:18PM -0600, Dave Dutcher wrote: > I've looked around through the docs, but can't seem to find an answer to > this. If I change a column's statistics with "Alter table alter column > set statistics n", is there a way I can later go back and see what the > number is for that column? I want to be able to tell which columns I've > changed the statistics on, and which ones I haven't. pg_attribute.attstattarget http://www.postgresql.org/docs/8.1/interactive/catalog-pg-attribute.html -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 11 18:29:02 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5857F9DC94D for ; Wed, 11 Jan 2006 18:29:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01323-09 for ; Wed, 11 Jan 2006 18:29:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from crt0.crt.umontreal.ca (crt0.CRT.UMontreal.CA [132.204.100.27]) by postgresql.org (Postfix) with ESMTP id E18029DC863 for ; Wed, 11 Jan 2006 18:28:59 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 40A5D38409F for ; Wed, 11 Jan 2006 17:29:02 -0500 (EST) Received: from crt0.crt.umontreal.ca ([127.0.0.1]) by localhost (crt0.crt.umontreal.ca [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 18760-01-84 for ; Wed, 11 Jan 2006 17:29:01 -0500 (EST) Received: from Spoke01 (unknown [10.100.3.7]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id EA357384020 for ; Wed, 11 Jan 2006 17:29:00 -0500 (EST) From: =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= To: Subject: Extremely irregular query performance Date: Wed, 11 Jan 2006 17:37:24 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcYW5UeV8bUde1TSRGeDJp/e9FicfQABHBQAAAAjrSAABS2ZoA== Message-Id: <20060111222900.EA357384020@crt0.crt.umontreal.ca> X-Virus-Scanned: amavisd-new at crt.umontreal.ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/130 X-Sequence-Number: 16608 Hi, I'm running version 8.1 on a dedicated Sun v20 server (2 AMD x64's) with 4Gb of RAM. I have recently noticed that the performance of some more complex queries is extremely variable and irregular. For example, I currently have a query that returns a small number of rows (5) by joining a dozen of tables. Below are the running times obtained by repeatedly lauching this query in psql (nothing else was running on the server at that time): Time: 424.848 ms Time: 1615.143 ms Time: 15036.475 ms Time: 83471.683 ms Time: 163.224 ms Time: 2454.939 ms Time: 188.093 ms Time: 158.071 ms Time: 192.431 ms Time: 195.076 ms Time: 635.739 ms Time: 164549.902 ms As you can see, the performance is most of the time pretty good (less than 1 second), but every fourth of fifth time I launch the query the server seems to go into orbit. For the longer running times, I can see from 'top' that the server process uses almost 100% of a CPU. This is rather worrisome, as I cannot be confident of the overall performance of my application with so much variance in query response times. I suspect a configuration problem related to the cache mechanism (shared_buffers? effective_cache_size?), but to be honest I do not know where to start to diagnose it. I also noticed that the query plan can vary when the same query is launched two times in a row (with no other changes to the DB in between). Is there a random aspect to the query optimizer that could explain some of the observed variance in performance ? Any help would be greatly appreciated. Thanks in advance, J-P From pgsql-performance-owner@postgresql.org Wed Jan 11 18:38:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DA0219DC863 for ; Wed, 11 Jan 2006 18:38:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03991-10 for ; Wed, 11 Jan 2006 18:38:45 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.197]) by postgresql.org (Postfix) with ESMTP id 790AF9DC839 for ; Wed, 11 Jan 2006 18:38:41 -0400 (AST) Received: by zproxy.gmail.com with SMTP id i11so260334nzh for ; Wed, 11 Jan 2006 14:38:44 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=JCU0onSkWjodDjUrTKgEqL9FTHL0cYBiOdfjXlqVu55QFXsd4eha/oNsWWShFnFzEhxs3rWpSKp6KDMhK19w1NS91EWjwAAivfklUnApQ/8FoY4O+KuspOsEP60RmC9ldgz/C9m2ij/gN6iSFveUJdPd6E2WEQXJ/4Bqgup845k= Received: by 10.65.194.17 with SMTP id w17mr467230qbp; Wed, 11 Jan 2006 14:38:43 -0800 (PST) Received: by 10.65.156.18 with HTTP; Wed, 11 Jan 2006 14:38:42 -0800 (PST) Message-ID: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> Date: Wed, 11 Jan 2006 14:38:42 -0800 From: Burak Seydioglu To: pgsql-performance@postgresql.org Subject: indexes on primary and foreign keys MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11166_32945758.1137019122582" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.946 required=5 tests=[HTML_10_20=0.945, HTML_MESSAGE=0.001] X-Spam-Score: 0.946 X-Spam-Level: X-Archive-Number: 200601/131 X-Sequence-Number: 16609 ------=_Part_11166_32945758.1137019122582 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I do a load of sql joins using primary and foreign keys. What i would like to know if PostgreSQL creates indexes on these columns automatically (in addition to using them to maintain referential integrity) or do I have to create an index manually on these columns as indicated below? CREATE TABLE cities ( city_id integer primary key, city_name varchar(50) ); CREATE INDEX city_id_index ON cities(city_id); Thanks for any insight. Burak ------=_Part_11166_32945758.1137019122582 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I do a load of sql joins using primary and foreign keys. What i would like to know if PostgreSQL creates indexes on these columns automatically (in addition to using them to maintain referential integrity) or do I have to create an index manually on these columns as indicated below?

CREATE TABLE cities (
ci= ty_id integer primary key,
city_name varchar(50)
);

CREATE I= NDEX city_id_index ON cities(city_id);

Thanks for any insight.

Burak

------=_Part_11166_32945758.1137019122582-- From pgsql-performance-owner@postgresql.org Wed Jan 11 19:03:08 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4F9A29DC89B for ; Wed, 11 Jan 2006 19:03:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10039-07 for ; Wed, 11 Jan 2006 19:03:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id B02979DC898 for ; Wed, 11 Jan 2006 19:03:03 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BN35AE029000; Wed, 11 Jan 2006 18:03:05 -0500 (EST) To: =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= cc: pgsql-performance@postgresql.org Subject: Re: Extremely irregular query performance In-reply-to: <20060111222900.EA357384020@crt0.crt.umontreal.ca> References: <20060111222900.EA357384020@crt0.crt.umontreal.ca> Comments: In-reply-to =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= message dated "Wed, 11 Jan 2006 17:37:24 -0500" Date: Wed, 11 Jan 2006 18:03:05 -0500 Message-ID: <28999.1137020585@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.084 required=5 tests=[AWL=0.084] X-Spam-Score: 0.084 X-Spam-Level: X-Archive-Number: 200601/132 X-Sequence-Number: 16610 =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= writes: > I'm running version 8.1 on a dedicated Sun v20 server (2 AMD x64's) > with 4Gb of RAM. I have recently noticed that the performance of > some more complex queries is extremely variable and irregular. > For example, I currently have a query that returns a small number > of rows (5) by joining a dozen of tables. A dozen tables? You're exceeding the geqo_threshold and getting a plan that has some randomness in it. You could either increase geqo_threshold if you can stand the extra planning time, or try increasing geqo_effort to get it to search a little harder and hopefully find a passable plan more often. See http://www.postgresql.org/docs/8.1/static/geqo.html http://www.postgresql.org/docs/8.1/static/runtime-config-query.html#RUNTIME-CONFIG-QUERY-GEQO I'm kinda surprised that you don't get better results with the default settings. We could tinker some more with the defaults, if you can provide evidence about better values ... regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 19:06:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1C6DA9DC833 for ; Wed, 11 Jan 2006 19:06:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10138-10 for ; Wed, 11 Jan 2006 19:06:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 00D639DC804 for ; Wed, 11 Jan 2006 19:06:31 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0BN6XSH029043; Wed, 11 Jan 2006 18:06:33 -0500 (EST) To: Burak Seydioglu cc: pgsql-performance@postgresql.org Subject: Re: indexes on primary and foreign keys In-reply-to: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> Comments: In-reply-to Burak Seydioglu message dated "Wed, 11 Jan 2006 14:38:42 -0800" Date: Wed, 11 Jan 2006 18:06:33 -0500 Message-ID: <29042.1137020793@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.222 required=5 tests=[AWL=-0.054, MAILTO_TO_SPAM_ADDR=0.276] X-Spam-Score: 0.222 X-Spam-Level: X-Archive-Number: 200601/133 X-Sequence-Number: 16611 Burak Seydioglu writes: > I do a load of sql joins using primary and foreign keys. What i would like > to know if PostgreSQL creates indexes on these columns automatically (in > addition to using them to maintain referential integrity) or do I have to > create an index manually on these columns as indicated below? Indexes are only automatically created where needed to enforce a UNIQUE constraint. That includes primary keys, but not foreign keys. Note that you only really need an index on the referencing (non-unique) side of a foreign key if you are worried about performance of DELETEs or key changes on the referenced table. If you seldom or never do that, you might want to dispense with the index. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 19:22:02 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2718E9DCA1C for ; Wed, 11 Jan 2006 19:22:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15356-04 for ; Wed, 11 Jan 2006 19:22:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 81A669DCA10 for ; Wed, 11 Jan 2006 19:21:59 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0BNLwYj008987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2006 16:22:00 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0BNLvra088936; Wed, 11 Jan 2006 16:21:57 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0BNLvx7088935; Wed, 11 Jan 2006 16:21:57 -0700 (MST) (envelope-from mfuhr) Date: Wed, 11 Jan 2006 16:21:57 -0700 From: Michael Fuhr To: Burak Seydioglu Cc: pgsql-performance@postgresql.org Subject: Re: indexes on primary and foreign keys Message-ID: <20060111232157.GA88829@winnie.fuhr.org> References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.091 required=5 tests=[AWL=0.091] X-Spam-Score: 0.091 X-Spam-Level: X-Archive-Number: 200601/134 X-Sequence-Number: 16612 On Wed, Jan 11, 2006 at 02:38:42PM -0800, Burak Seydioglu wrote: > I do a load of sql joins using primary and foreign keys. What i would like > to know if PostgreSQL creates indexes on these columns automatically (in > addition to using them to maintain referential integrity) or do I have to > create an index manually on these columns as indicated below? > > CREATE TABLE cities ( > city_id integer primary key, > city_name varchar(50) > ); > > CREATE INDEX city_id_index ON cities(city_id); PostgreSQL automatically creates indexes on primary keys. If you run the above CREATE TABLE statement in psql you should see a message to that effect: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "cities_pkey" for table "cities" If you look at the table definition you should see the primary key's index: test=> \d cities Table "public.cities" Column | Type | Modifiers -----------+-----------------------+----------- city_id | integer | not null city_name | character varying(50) | Indexes: "cities_pkey" PRIMARY KEY, btree (city_id) So you don't need to create another index on cities.city_id. However, PostgreSQL doesn't automatically create an index on the referring column of a foreign key constraint, so if you have another table like CREATE TABLE districts ( district_id integer PRIMARY KEY, district_name varchar(50), city_id integer REFERENCES cities ); then you won't automatically get an index on districts.city_id. It's generally a good idea to create one; failure to do so can cause deletes and updates on the referred-to table (cities) to be slow because referential integrity checks would have to do sequential scans on the referring table (districts). Indeed, performance problems for exactly this reason occasionally come up in the mailing lists. -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 11 19:29:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7F4FD9DCA17 for ; Wed, 11 Jan 2006 19:29:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15932-05 for ; Wed, 11 Jan 2006 19:29:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 4D7739DC985 for ; Wed, 11 Jan 2006 19:29:12 -0400 (AST) Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP with MS-WebStorage 6.5.6944 Received: from state.g2switchworks.com by mail.g2switchworks.com; 11 Jan 2006 17:29:14 -0600 Subject: Re: Extremely irregular query performance From: Scott Marlowe To: Jean-Philippe =?ISO-8859-1?Q?C=F4t=E9?= Cc: pgsql-performance@postgresql.org In-Reply-To: <20060111222900.EA357384020@crt0.crt.umontreal.ca> References: <20060111222900.EA357384020@crt0.crt.umontreal.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-Id: <1137022154.3959.1.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Wed, 11 Jan 2006 17:29:14 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.114 required=5 tests=[AWL=0.113, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.114 X-Spam-Level: X-Archive-Number: 200601/135 X-Sequence-Number: 16613 On Wed, 2006-01-11 at 16:37, Jean-Philippe C=C3=B4t=C3=A9 wrote: > Hi, >=20 > I'm running version 8.1 on a dedicated Sun v20 server (2 AMD x64's) > with 4Gb of RAM. I have recently noticed that the performance of > some more complex queries is extremely variable and irregular. > For example, I currently have a query that returns a small number=20 > of rows (5) by joining a dozen of tables. Below are the running times > obtained by repeatedly lauching this query in psql (nothing else > was running on the server at that time): >=20 > Time: 424.848 ms > Time: 1615.143 ms > Time: 15036.475 ms > Time: 83471.683 ms > Time: 163.224 ms > Time: 2454.939 ms > Time: 188.093 ms > Time: 158.071 ms > Time: 192.431 ms > Time: 195.076 ms > Time: 635.739 ms > Time: 164549.902 ms >=20 > As you can see, the performance is most of the time pretty good (less > than 1 second), but every fourth of fifth time I launch the query > the server seems to go into orbit. For the longer running times, > I can see from 'top' that the server process uses almost 100% of > a CPU. As mentioned earlier, it could be you're exceeding the GEQO threshold. It could also be that you are doing just enough else at the time, and have your shared buffers or sort mem high enough that you're initiating a swap storm. Mind posting all the parts of your postgresql.conf file you've changed from the default? From pgsql-performance-owner@postgresql.org Wed Jan 11 19:41:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D31779DC89B for ; Wed, 11 Jan 2006 19:41:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16696-08 for ; Wed, 11 Jan 2006 19:41:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from crt0.crt.umontreal.ca (crt0.CRT.UMontreal.CA [132.204.100.27]) by postgresql.org (Postfix) with ESMTP id B0FF79DC899 for ; Wed, 11 Jan 2006 19:41:47 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 83B6838409F; Wed, 11 Jan 2006 18:41:50 -0500 (EST) Received: from crt0.crt.umontreal.ca ([127.0.0.1]) by localhost (crt0.crt.umontreal.ca [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 03284-01; Wed, 11 Jan 2006 18:41:49 -0500 (EST) Received: from Spoke01 (unknown [10.100.3.7]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 05DEA384099; Wed, 11 Jan 2006 18:41:49 -0500 (EST) From: =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= To: "'Tom Lane'" Cc: Subject: Re: Extremely irregular query performance Date: Wed, 11 Jan 2006 18:50:12 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcYXA0QCFr2+pmGVQ5mQC+gy3cNE8QABfZlA In-reply-to: <28999.1137020585@sss.pgh.pa.us> Message-Id: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> X-Virus-Scanned: amavisd-new at crt.umontreal.ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.048 required=5 tests=[AWL=0.048] X-Spam-Score: 0.048 X-Spam-Level: X-Archive-Number: 200601/136 X-Sequence-Number: 16614 Thanks a lot for this info, I was indeed exceeding the genetic optimizer's threshold. Now that it is turned off, I get a very stable response time of 435ms (more or less 5ms) for the same query. It is about three times slower than the best I got with the genetic optimizer on, but the overall average is much lower. I'll also try to play with the geqo parameters and see if things improve. Thanks again, J-P -----Original Message----- From: pgsql-performance-owner@postgresql.org = [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Tom Lane Sent: January 11, 2006 6:03 PM To: Jean-Philippe C=F4t=E9 Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] Extremely irregular query performance=20 =3D?iso-8859-1?Q?Jean-Philippe_C=3DF4t=3DE9?=3D = writes: > I'm running version 8.1 on a dedicated Sun v20 server (2 AMD x64's) > with 4Gb of RAM. I have recently noticed that the performance of > some more complex queries is extremely variable and irregular. > For example, I currently have a query that returns a small number=20 > of rows (5) by joining a dozen of tables. A dozen tables? You're exceeding the geqo_threshold and getting a plan that has some randomness in it. You could either increase geqo_threshold if you can stand the extra planning time, or try increasing geqo_effort to get it to search a little harder and hopefully find a passable plan more often. See http://www.postgresql.org/docs/8.1/static/geqo.html http://www.postgresql.org/docs/8.1/static/runtime-config-query.html#RUNTI= ME-CONFIG-QUERY-GEQO I'm kinda surprised that you don't get better results with the default settings. We could tinker some more with the defaults, if you can provide evidence about better values ... regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match From pgsql-performance-owner@postgresql.org Wed Jan 11 19:51:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 223989DC899 for ; Wed, 11 Jan 2006 19:51:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19724-04 for ; Wed, 11 Jan 2006 19:51:26 -0400 (AST) X-Greylist: delayed 23:22:04.34182 by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id 373699DCA43 for ; Wed, 11 Jan 2006 19:51:20 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 11 Jan 2006 15:50:44 -0800 Subject: Re: Extremely irregular query performance From: Mark Lewis To: Jean-Philippe =?ISO-8859-1?Q?C=F4t=E9?= Cc: pgsql-performance@postgresql.org In-Reply-To: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> References: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Organization: MIR3, Inc. Date: Wed, 11 Jan 2006 15:50:43 -0800 Message-Id: <1137023443.30926.2.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-22) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.120, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/137 X-Sequence-Number: 16615 If this is a query that will be executed more than once, you can also avoid incurring the planning overhead multiple times by using PREPARE. -- Mark Lewis On Wed, 2006-01-11 at 18:50 -0500, Jean-Philippe C=C3=B4t=C3=A9 wrote: > Thanks a lot for this info, I was indeed exceeding the genetic > optimizer's threshold. Now that it is turned off, I get > a very stable response time of 435ms (more or less 5ms) for > the same query. It is about three times slower than the best > I got with the genetic optimizer on, but the overall average > is much lower. >=20 > I'll also try to play with the geqo parameters and see if things > improve. >=20 > Thanks again, >=20 > J-P From pgsql-performance-owner@postgresql.org Wed Jan 11 19:52:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5F7239DCA25 for ; Wed, 11 Jan 2006 19:52:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21156-03 for ; Wed, 11 Jan 2006 19:52:42 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.194]) by postgresql.org (Postfix) with ESMTP id 290099DCA17 for ; Wed, 11 Jan 2006 19:52:36 -0400 (AST) Received: by zproxy.gmail.com with SMTP id i11so270787nzh for ; Wed, 11 Jan 2006 15:52:40 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=j6eY+gI6xI+YASJhDBITeOfXkSTBrMdoGYLB7bY1AXqIQi0E//MqZ18Hcy9/tgpu8jLyQgq5Dv1fgGoDLvZfNOF2b4Xe7ywduPYpwsbzrjKJ/OEmv/ApUN9cBqNzMzQeeiSJha/QkHrsZ5Ic5+xKFRG+U2NCCUqjz/FxiIWNyZ4= Received: by 10.65.107.11 with SMTP id j11mr460577qbm; Wed, 11 Jan 2006 15:52:40 -0800 (PST) Received: by 10.65.156.18 with HTTP; Wed, 11 Jan 2006 15:52:40 -0800 (PST) Message-ID: <1b8a973c0601111552w31fab815kfac989e1782de98d@mail.gmail.com> Date: Wed, 11 Jan 2006 15:52:40 -0800 From: Burak Seydioglu To: Michael Fuhr Subject: Re: indexes on primary and foreign keys Cc: pgsql-performance@postgresql.org In-Reply-To: <20060111232157.GA88829@winnie.fuhr.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11920_17810882.1137023560071" References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> <20060111232157.GA88829@winnie.fuhr.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.473 required=5 tests=[AWL=0.472, HTML_MESSAGE=0.001] X-Spam-Score: 0.473 X-Spam-Level: X-Archive-Number: 200601/138 X-Sequence-Number: 16616 ------=_Part_11920_17810882.1137023560071 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline How about the performance effect on SELECT statements joining multiple tables (LEFT JOINS)? I have been reading all day and here is an excerpt from one article that is located at http://pgsql.designmagick.com/tutorial.php?id=3D19&pid=3D28 [quote] The best reason to use an index is for joining multiple tables together in a single query. When two tables are joined, a record that exists in both tables needs to be used to link them together. If possible, the column in both tables should be indexed. [/quote] Regarding similar posts, I tried to search the archives but for some reason the search utility is not functioning. http://search.postgresql.org/archives.search?cs=3Dutf-8&fm=3Don&st=3D20&dt= =3Dback&q=3Dindex Thank you very much for your help. Burak On 1/11/06, Michael Fuhr wrote: > > On Wed, Jan 11, 2006 at 02:38:42PM -0800, Burak Seydioglu wrote: > > I do a load of sql joins using primary and foreign keys. What i would > like > > to know if PostgreSQL creates indexes on these columns automatically (i= n > > addition to using them to maintain referential integrity) or do I have > to > > create an index manually on these columns as indicated below? > > > > CREATE TABLE cities ( > > city_id integer primary key, > > city_name varchar(50) > > ); > > > > CREATE INDEX city_id_index ON cities(city_id); > > PostgreSQL automatically creates indexes on primary keys. If you run > the above CREATE TABLE statement in psql you should see a message to > that effect: > > NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index > "cities_pkey" for table "cities" > > If you look at the table definition you should see the primary > key's index: > > test=3D> \d cities > Table "public.cities" > Column | Type | Modifiers > -----------+-----------------------+----------- > city_id | integer | not null > city_name | character varying(50) | > Indexes: > "cities_pkey" PRIMARY KEY, btree (city_id) > > So you don't need to create another index on cities.city_id. However, > PostgreSQL doesn't automatically create an index on the referring > column of a foreign key constraint, so if you have another table like > > CREATE TABLE districts ( > district_id integer PRIMARY KEY, > district_name varchar(50), > city_id integer REFERENCES cities > ); > > then you won't automatically get an index on districts.city_id. > It's generally a good idea to create one; failure to do so can cause > deletes and updates on the referred-to table (cities) to be slow > because referential integrity checks would have to do sequential > scans on the referring table (districts). Indeed, performance > problems for exactly this reason occasionally come up in the mailing > lists. > > -- > Michael Fuhr > ------=_Part_11920_17810882.1137023560071 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline How about the performance effect on SELECT statements joining multiple tabl= es (LEFT JOINS)?

I have been reading all day and here is an excerpt from one article that is located at http://pgsql.designmagick.com/tutorial.php?id=3D19&pid=3D28

[quote]
The best reason to use an ind=
ex is for joining multiple tables together in a single query. When two tabl=
es are joined, a record
that exists in both tables needs to be used to l= ink them together. If possible, the column in both tables should be indexed= .
[/quote]

Regarding similar posts, I tried to search the archives but for some reason= the search utility is not functioning.
http://search.postgresql.org= /archives.search?cs=3Dutf-8&fm=3Don&st=3D20&dt=3Dback&q=3Di= ndex

Thank you very much for your help.

Burak


On 1/11/06, Michael Fuhr <mike@fuhr.org= > wrote:
On Wed, Jan 11, 2006 at 02:38:42PM -0800, Burak Seydioglu wrote:
> I = do a load of sql joins using primary and foreign keys. What i would like> to know if PostgreSQL creates indexes on these columns automatically = (in
> addition to using them to maintain referential integrity) or do I = have to
> create an index manually on these columns as indicated belo= w?
>
> CREATE TABLE cities (
>   city_id intege= r primary key,
>   city_name varchar(50)
> );
>
> CREAT= E INDEX city_id_index ON cities(city_id);

PostgreSQL automatically c= reates indexes on primary keys.  If you run
the above CREATE T= ABLE statement in psql you should see a message to
that effect:

NOTICE:  CREATE TABLE / PRIMARY KEY will = create implicit index "cities_pkey" for table "cities"<= br>
If you look at the table definition you should see the primary
ke= y's index:

test=3D> \d cities
       =       Table "public.cities"
 &nb= sp;Column   |         Type          | Modifiers
-----------+-----------------------+-----------
city_id&nb= sp;  | integer         &n= bsp;     | not null
city_name | character varying(5= 0) |
Indexes:
    "cities_pkey" PRIMARY= KEY, btree (city_id)

So you don't need to create another index on cities.city_id. &= nbsp;However,
PostgreSQL doesn't automatically create an index on the re= ferring
column of a foreign key constraint, so if you have another table= like

CREATE TABLE districts (
  district_id   &n= bsp;integer PRIMARY KEY,
  district_name  varchar(50= ),
  city_id        in= teger REFERENCES cities
);

then you won't automatically get an in= dex on districts.city_id .
It's generally a good idea to create one; failure to do so can causedeletes and updates on the referred-to table (cities) to be slow
becau= se referential integrity checks would have to do sequential
scans on the= referring table (districts).  Indeed, performance
problems for exactly this reason occasionally come up in the mailinglists.

--
Michael Fuhr

------=_Part_11920_17810882.1137023560071-- From pgsql-performance-owner@postgresql.org Wed Jan 11 20:32:31 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BCEC29DCA2E for ; Wed, 11 Jan 2006 20:32:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27709-06 for ; Wed, 11 Jan 2006 20:32:33 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 9F2E49DCA26 for ; Wed, 11 Jan 2006 20:32:28 -0400 (AST) Received: from smtp6.clb.oleane.net (smtp6.clb.oleane.net [213.56.31.26]) by svr4.postgresql.org (Postfix) with ESMTP id 62E635AF09D for ; Thu, 12 Jan 2006 00:32:31 +0000 (GMT) Received: from smtp6.clb.oleane.net (localhost [127.0.0.1]) by smtp6.clb.oleane.net (antivirus) with ESMTP id k0C0WSTY010743; Thu, 12 Jan 2006 01:32:28 +0100 Received: from [127.0.0.1] (pat35-1-82-231-148-216.fbx.proxad.net [82.231.148.216]) (authenticated) by smtp6.clb.oleane.net with ESMTP id k0C0WB90010453; Thu, 12 Jan 2006 01:32:28 +0100 Message-ID: <43C5A38A.8090208@elios-informatique.fr> Date: Thu, 12 Jan 2006 01:32:10 +0100 From: Jamal Ghaffour User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: fr, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Please Help: PostgreSQL performance Optimization Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.947 required=5 tests=[HTML_10_20=0.945, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.001] X-Spam-Score: 0.947 X-Spam-Level: X-Archive-Number: 200601/139 X-Sequence-Number: 16617
Hi,

I'm working on a project, whose implementation deals with PostgreSQL. A brief description of our application is given  below.

I'm running version 8.0 on a dedicated  server 1Gb of RAM. 
my database isn't complex, it contains just 2 simple tables.

CREATE TABLE cookies (
    domain varchar(50) NOT NULL,
    path varchar(50) NOT NULL,
    name varchar(50) NOT NULL,
    principalid varchar(50) NOT NULL,
    host text NOT NULL,
    value text NOT NULL,
    secure bool NOT NULL,
    timestamp timestamp with time zone NOT NULL DEFAULT 
CURRENT_TIMESTAMP+TIME '04:00:00',
    PRIMARY KEY  (domain,path,name,principalid)
)

CREATE TABLE liberty (
    principalid varchar(50) NOT NULL,
    requestid varchar(50) NOT NULL,
    spassertionurl text NOT NULL,
    libertyversion  varchar(50) NOT NULL,
    relaystate  varchar(50) NOT NULL,
    PRIMARY KEY  (principalid)
)

I'm developping an application that uses the libpqxx to execute 
psql queries on the database and have to execute 500 requests at the same time.


UPDATE cookies SET host='ping.icap-elios.com', value= '54E5B5491F27C0177083795F2E09162D', secure=FALSE, 
timestamp=CURRENT_TIMESTAMP+INTERVAL '14400 SECOND' WHERE 
domain='ping.icap-elios.com' AND path='/tfs' AND principalid='192.168.8.219' AND 
name='jsessionid'

SELECT path, upper(name) AS name, value FROM cookies  WHERE timestamp<CURRENT_TIMESTAMP AND principalid='192.168.8.219' AND 
secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com')

I have to notify that the performance of is extremely variable and irregular.
I can also see that the server process uses almost 100% of
a CPU.

I'm using the default configuration file, and i m asking if i have to change some paramters to have a good performance.

Any help would be greatly appreciated.

Thanks,
From pgsql-performance-owner@postgresql.org Wed Jan 11 21:00:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 20CBB9DC882 for ; Wed, 11 Jan 2006 21:00:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32647-06 for ; Wed, 11 Jan 2006 21:00:58 -0400 (AST) X-Greylist: delayed 00:23:45.74358 by SQLgrey- Received: from imsm058dat.netvigator.com (imsm058.netvigator.com [218.102.48.211]) by postgresql.org (Postfix) with ESMTP id 5E80E9DC839 for ; Wed, 11 Jan 2006 21:00:52 -0400 (AST) Received: from n2.netvigator.com ([218.103.176.100]) by imsm057dat.netvigator.com (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20060112003708.MPBW14795.imsm057dat.netvigator.com@n2.netvigator.com> for ; Thu, 12 Jan 2006 08:37:08 +0800 Received: from n2.netvigator.com ([127.0.0.1]) by [127.0.0.1] with ESMTP (SpamPal v1.591) sender ; 12 Jan 2006 08:37:08 +???? Message-Id: <6.2.1.2.0.20060112083033.02bb74c8@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2 Date: Thu, 12 Jan 2006 08:36:19 +0800 To: pgsql-performance@postgresql.org From: K C Lau Subject: Re: indexes on primary and foreign keys In-Reply-To: <20060111232157.GA88829@winnie.fuhr.org> References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> <20060111232157.GA88829@winnie.fuhr.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.44 required=5 tests=[DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.44 X-Spam-Level: * X-Archive-Number: 200601/142 X-Sequence-Number: 16620 At 07:21 06/01/12, Michael Fuhr wrote: >On Wed, Jan 11, 2006 at 02:38:42PM -0800, Burak Seydioglu wrote: > > I do a load of sql joins using primary and foreign keys. What i would like > > to know if PostgreSQL creates indexes on these columns automatically (in > > addition to using them to maintain referential integrity) or do I have to > > create an index manually on these columns as indicated below? > > > > CREATE TABLE cities ( > > city_id integer primary key, > > city_name varchar(50) > > ); > > > > CREATE INDEX city_id_index ON cities(city_id); > >PostgreSQL automatically creates indexes on primary keys. If you run >the above CREATE TABLE statement in psql you should see a message to >that effect: > >NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index >"cities_pkey" for table "cities" Is there a way to suppress this notice when I create tables in a script? Best regards, KC. From pgsql-performance-owner@postgresql.org Wed Jan 11 20:41:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 384C49DCA10 for ; Wed, 11 Jan 2006 20:41:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28681-08 for ; Wed, 11 Jan 2006 20:41:32 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id BFF229DCA14 for ; Wed, 11 Jan 2006 20:41:26 -0400 (AST) Received: from mail.goldpocket.com (mail1.goldpocket.com [38.101.116.14]) by svr4.postgresql.org (Postfix) with ESMTP id DB0D75AF0A9 for ; Thu, 12 Jan 2006 00:41:30 +0000 (GMT) Received: from localhost (unknown [127.0.0.1]) by mail.goldpocket.com (Postfix) with ESMTP id 82AC8E048F23 for ; Thu, 12 Jan 2006 00:41:28 +0000 (UTC) Received: from mail.goldpocket.com ([127.0.0.1]) by localhost (mail.goldpocket.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05506-11 for ; Wed, 11 Jan 2006 16:41:24 -0800 (PST) Received: from mail1.goldpocket.com (srvgpimail1.gpi.local [10.10.0.13]) by mail.goldpocket.com (Postfix) with ESMTP id A5B74E048F1E for ; Wed, 11 Jan 2006 16:41:21 -0800 (PST) Received: from mliberman.gpi.local ([10.10.0.158]) by mail1.goldpocket.com with Microsoft SMTPSVC(6.0.3790.211); Wed, 11 Jan 2006 16:41:20 -0800 From: Mark Liberman Organization: Mixed Signals, Inc. To: pgsql-performance@postgresql.org Subject: Stable function being evaluated more than once in a single query Date: Wed, 11 Jan 2006 16:41:20 -0800 User-Agent: KMail/1.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601111641.20627.mliberman@mixedsignals.com> X-OriginalArrivalTime: 12 Jan 2006 00:41:20.0781 (UTC) FILETIME=[E81DA3D0:01C61710] X-Virus-Scanned: amavisd-new at goldpocket.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/140 X-Sequence-Number: 16618 Hi, I've got a set-returning function, defined as STABLE, that I reference twice within a single query, yet appears to be evaluated via two seperate function scans. I created a simple query that calls the function below and joins the results to itself (Note: in case you wonder why I'd do such a query, it's not my actual query, which is much more complex. I just created this simple query to try to test out the 'stable' behavior). select proname,provolatile from pg_proc where proname = 'get_tran_filesize'; proname | provolatile ----------------------------+------------- get_tran_filesize | s (1 row) explain analyze select * from get_tran_filesize('2005-12-11 00:00:00-08','2006-01-11 15:58:33-08','{228226,228222,228210}'); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- Function Scan on get_tran_filesize (cost=0.00..12.50 rows=1000 width=40) (actual time=49.522..49.524 rows=3 loops=1) Total runtime: 49.550 ms (2 rows) explain analyze select * from get_tran_filesize('2005-12-11 00:00:00-08','2006-01-11 15:58:33-08','{228226,228222,228210}') gt, get_tran_filesize('2005-12-11 00:00:00-08','2006-01-11 15:58:33-08','{228226,228222,228210}') gt2 where gt.tran_id = gt2.tran_id; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------ Merge Join (cost=124.66..204.66 rows=5000 width=80) (actual time=83.027..83.040 rows=3 loops=1) Merge Cond: ("outer".tran_id = "inner".tran_id) -> Sort (cost=62.33..64.83 rows=1000 width=40) (actual time=40.250..40.251 rows=3 loops=1) Sort Key: gt.tran_id -> Function Scan on get_tran_filesize gt (cost=0.00..12.50 rows=1000 width=40) (actual time=40.237..40.237 rows=3 loops=1) -> Sort (cost=62.33..64.83 rows=1000 width=40) (actual time=42.765..42.767 rows=3 loops=1) Sort Key: gt2.tran_id -> Function Scan on get_tran_filesize gt2 (cost=0.00..12.50 rows=1000 width=40) (actual time=42.748..42.751 rows=3 loops=1) Total runtime: 83.112 ms (9 rows) If I do get this working, then my question is, if I reference this function within a single query, but within seperate subqueries within the query, will it be re-evaluated each time, or just once. Basically, I'm not clear on the definition of "surrounding query" in the following exerpt from the Postgreql documentation: A STABLE function cannot modify the database and is guaranteed to return the same results given the same arguments for all calls within a single surrounding query. Thanks, Mark From pgsql-performance-owner@postgresql.org Wed Jan 11 20:48:37 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7BCCC9DC833 for ; Wed, 11 Jan 2006 20:48:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32647-01 for ; Wed, 11 Jan 2006 20:48:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id D22649DC804 for ; Wed, 11 Jan 2006 20:48:33 -0400 (AST) Received: from [192.168.0.3] (195-112-29-105.dyn.gotadsl.co.uk [195.112.29.105]) by smtp.nildram.co.uk (Postfix) with ESMTP id 78933252624; Thu, 12 Jan 2006 00:48:36 +0000 (GMT) Subject: Re: NOT LIKE much faster than LIKE? From: Simon Riggs To: Tom Lane Cc: Matteo Beccati , Andrea Arcangeli , pgsql-performance@postgresql.org In-Reply-To: <6398.1136931685@sss.pgh.pa.us> References: <20060110014447.GB18474@opteron.random> <24021.1136858688@sss.pgh.pa.us> <20060110022303.GA20168@opteron.random> <24372.1136861684@sss.pgh.pa.us> <43C3799D.5030103@beccati.com> <1625.1136915395@sss.pgh.pa.us> <1136930796.21025.486.camel@localhost.localdomain> <6398.1136931685@sss.pgh.pa.us> Content-Type: text/plain Date: Thu, 12 Jan 2006 00:48:36 +0000 Message-Id: <1137026916.21025.585.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.113 required=5 tests=[AWL=0.113] X-Spam-Score: 0.113 X-Spam-Level: X-Archive-Number: 200601/141 X-Sequence-Number: 16619 On Tue, 2006-01-10 at 17:21 -0500, Tom Lane wrote: > Simon Riggs writes: > > I think its OK to use the MCV, but I have a problem with the current > > heuristics: they only work for randomly generated strings, since the > > selectivity goes down geometrically with length. > > We could certainly use a less aggressive curve for that. You got a > specific proposal? non-left anchored LIKE is most likely going to be used with unstructured, variable length data - else we might use SUBSTRING instead. My proposal would be to assume that LIKE is acting on human language text data. I considered this a while back, but wrote it off in favour of dynamic sampling - but it's worth discussing this to see whether we can improve on things without that. Here's one of the links I reviewed previously: http://www.ling.lu.se/persons/Joost/Texts/studling.pdf Sigurd et al [2004] This shows word frequency distribution peaks at 3 letter/2 phoneme words, then tails off exponentially after that. Clearly when search string > 3 then the selectivity must tail off exponentially also, since we couldn't find words shorter than the search string itself. The search string might be a phrase, but it seems reasonable to assume that phrases also drop off in frequency according to length. It is difficult to decide what to do at len=2 or len=3, and I would be open to various thoughts, but would default to keeping like_selectivity as it is now. Sigurd et al show that word length tails off at 0.7^Len beyond Len=3, so selectivity FIXED_CHAR_SEL should not be more than 0.7, but I see no evidence for it being as low as 0.2 (from the published results). For simplicity, where Len > 3, I would make the tail off occur with factor 0.5, rather than 0.2. We could see a few more changes from those results, but curbing the aggressive tail off would be a simple and easy act. Best Regards, Simon Riggs From pgsql-performance-owner@postgresql.org Wed Jan 11 21:27:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E3EA79DCA19 for ; Wed, 11 Jan 2006 21:27:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36339-10 for ; Wed, 11 Jan 2006 21:27:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [151.155.5.143]) by postgresql.org (Postfix) with ESMTP id 68DBA9DC9A5 for ; Wed, 11 Jan 2006 21:27:03 -0400 (AST) Received: from [172.16.1.181] grzm [61.197.227.146] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 1.6 $ on Linux; Wed, 11 Jan 2006 18:27:00 -0700 In-Reply-To: <6.2.1.2.0.20060112083033.02bb74c8@localhost> References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> <20060111232157.GA88829@winnie.fuhr.org> <6.2.1.2.0.20060112083033.02bb74c8@localhost> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: indexes on primary and foreign keys Date: Thu, 12 Jan 2006 10:26:58 +0900 To: K C Lau X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.089 required=5 tests=[AWL=-0.243, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.089 X-Spam-Level: * X-Archive-Number: 200601/143 X-Sequence-Number: 16621 On Jan 12, 2006, at 9:36 , K C Lau wrote: >> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index >> "cities_pkey" for table "cities" > > Is there a way to suppress this notice when I create tables in a > script? Set[1] your log_min_messages to WARNING or higher[2]. [1](http://www.postgresql.org/docs/current/interactive/sql-set.html) [2](http://www.postgresql.org/docs/current/interactive/runtime-config- logging.html#RUNTIME-CONFIG-LOGGING-WHEN) Michael Glaesemann grzm myrealbox com From pgsql-performance-owner@postgresql.org Wed Jan 11 21:41:08 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CA47D9DCA1C for ; Wed, 11 Jan 2006 21:41:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40136-04 for ; Wed, 11 Jan 2006 21:41:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 974E09DCA25 for ; Wed, 11 Jan 2006 21:41:05 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0C1ewIw009097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2006 18:41:02 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0C1evhO089652; Wed, 11 Jan 2006 18:40:57 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0C1evro089651; Wed, 11 Jan 2006 18:40:57 -0700 (MST) (envelope-from mfuhr) Date: Wed, 11 Jan 2006 18:40:57 -0700 From: Michael Fuhr To: Michael Glaesemann Cc: K C Lau , pgsql-performance@postgresql.org Subject: Re: indexes on primary and foreign keys Message-ID: <20060112014057.GA89601@winnie.fuhr.org> References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> <20060111232157.GA88829@winnie.fuhr.org> <6.2.1.2.0.20060112083033.02bb74c8@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.092 required=5 tests=[AWL=0.092] X-Spam-Score: 0.092 X-Spam-Level: X-Archive-Number: 200601/144 X-Sequence-Number: 16622 On Thu, Jan 12, 2006 at 10:26:58AM +0900, Michael Glaesemann wrote: > On Jan 12, 2006, at 9:36 , K C Lau wrote: > >>NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index > >>"cities_pkey" for table "cities" > > > >Is there a way to suppress this notice when I create tables in a > >script? > > Set[1] your log_min_messages to WARNING or higher[2]. Or client_min_messages, depending on where you don't want to see the notice. -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 11 23:23:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9DFAB9DCA2E for ; Wed, 11 Jan 2006 23:23:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65049-04 for ; Wed, 11 Jan 2006 23:23:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 81E419DCA50 for ; Wed, 11 Jan 2006 23:23:51 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0C3NtXw000482; Wed, 11 Jan 2006 22:23:56 -0500 (EST) To: =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= cc: pgsql-performance@postgresql.org Subject: Re: Extremely irregular query performance In-reply-to: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> References: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> Comments: In-reply-to =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= message dated "Wed, 11 Jan 2006 18:50:12 -0500" Date: Wed, 11 Jan 2006 22:23:55 -0500 Message-ID: <480.1137036235@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.085 required=5 tests=[AWL=0.085] X-Spam-Score: 0.085 X-Spam-Level: X-Archive-Number: 200601/145 X-Sequence-Number: 16623 =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= writes: > Thanks a lot for this info, I was indeed exceeding the genetic > optimizer's threshold. Now that it is turned off, I get > a very stable response time of 435ms (more or less 5ms) for > the same query. It is about three times slower than the best > I got with the genetic optimizer on, but the overall average > is much lower. Hmm. It would be interesting to use EXPLAIN ANALYZE to confirm that the plan found this way is the same as the best plan found by GEQO, and the extra couple hundred msec is the price you pay for the exhaustive plan search. If GEQO is managing to find a plan better than the regular planner then we need to look into why ... regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 11 23:49:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1F4EE9DCA75 for ; Wed, 11 Jan 2006 23:49:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70472-05 for ; Wed, 11 Jan 2006 23:49:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from imsm057dat.netvigator.com (imsm057.netvigator.com [218.102.48.210]) by postgresql.org (Postfix) with ESMTP id 178129DCA77 for ; Wed, 11 Jan 2006 23:49:19 -0400 (AST) Received: from n2.netvigator.com ([218.103.176.100]) by imsm057dat.netvigator.com (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20060112034923.NIKX14795.imsm057dat.netvigator.com@n2.netvigator.com> for ; Thu, 12 Jan 2006 11:49:23 +0800 Received: from n2.netvigator.com ([127.0.0.1]) by [127.0.0.1] with ESMTP (SpamPal v1.591) sender ; 12 Jan 2006 11:49:23 +???? Message-Id: <6.2.1.2.0.20060112103712.0529cdd0@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2 Date: Thu, 12 Jan 2006 11:49:16 +0800 To: pgsql-performance@postgresql.org From: K C Lau Subject: Re: indexes on primary and foreign keys In-Reply-To: References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> <20060111232157.GA88829@winnie.fuhr.org> <6.2.1.2.0.20060112083033.02bb74c8@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.2 required=5 tests=[AWL=-0.240, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.2 X-Spam-Level: * X-Archive-Number: 200601/146 X-Sequence-Number: 16624 At 09:26 06/01/12, you wrote: >On Jan 12, 2006, at 9:36 , K C Lau wrote: > >>>NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index >>>"cities_pkey" for table "cities" >> >>Is there a way to suppress this notice when I create tables in a >>script? > >Set[1] your log_min_messages to WARNING or higher[2]. > >[1](http://www.postgresql.org/docs/current/interactive/sql-set.html) >[2](http://www.postgresql.org/docs/current/interactive/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN) > >Michael Glaesemann >grzm myrealbox com Thanks. The side effect is that it would suppress other notices which might be useful. I was looking for a way to suppress the notice within the CREATE TABLE statement but could not. I noticed that when I specify a constraint name for the primary key, it would create an implicit index with the constraint name. So may be if the optional constraint name is specified by the user, then the notice can be suppressed. Indeed the manual already says that the index will be automatically created. BTW, there's an extra space in link[2] above which I have removed. Best regards, KC. From pgsql-performance-owner@postgresql.org Thu Jan 12 00:21:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0D7479DCAAF for ; Thu, 12 Jan 2006 00:21:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76677-04 for ; Thu, 12 Jan 2006 00:20:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rambo.iniquinet.com (rambo.iniquinet.com [69.39.89.10]) by postgresql.org (Postfix) with ESMTP id 94FF69DCAAE for ; Thu, 12 Jan 2006 00:20:57 -0400 (AST) Received: (qmail 17488 invoked by uid 1010); 11 Jan 2006 23:20:56 -0500 Received: from Robert_Creager@LogicalChaos.org by rambo.iniquinet.com by uid 1002 with qmail-scanner-1.20 (spamassassin: 3.1.0. Clear:RC:0(63.147.78.66):SA:0(?/?):. Processed in 0.899434 secs); 12 Jan 2006 04:20:56 -0000 Received: from unknown (HELO thunder.logicalchaos.org) (perl?test@logicalchaos.org@63.147.78.66) by rambo.iniquinet.com with AES256-SHA encrypted SMTP; 11 Jan 2006 23:20:55 -0500 Received: from logicalchaos.org (localhost [127.0.0.1]) by thunder.logicalchaos.org (Postfix) with ESMTP id 978C7650AC; Wed, 11 Jan 2006 21:20:52 -0700 (MST) Date: Wed, 11 Jan 2006 21:20:46 -0700 From: Robert Creager To: Tom Lane Cc: Michael Fuhr , PGPerformance Subject: Re: Index isn't used during a join. Message-ID: <20060111212046.200f3e55@thunder.logicalchaos.org> In-Reply-To: <12877.1136993583@sss.pgh.pa.us> References: <20060109212338.6420af12@thunder.logicalchaos.org> <20060110055818.GA55076@winnie.fuhr.org> <20060110221055.053596ab@thunder.logicalchaos.org> <20060111075655.GA51292@winnie.fuhr.org> <20060111072659.7c1772ad@thunder.logicalchaos.org> <12877.1136993583@sss.pgh.pa.us> Organization: Starlight Vision, LLC. X-Mailer: Sylpheed-Claws 1.0.4 (GTK+ 1.2.10; i586-mandriva-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Signature_Wed__11_Jan_2006_21_20_46_-0700_9l/As_kpQKQi1.HU"; protocol="application/pgp-signature"; micalg=pgp-sha1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.115 required=5 tests=[AWL=0.115] X-Spam-Score: 0.115 X-Spam-Level: X-Archive-Number: 200601/147 X-Sequence-Number: 16625 --Signature_Wed__11_Jan_2006_21_20_46_-0700_9l/As_kpQKQi1.HU Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable When grilled further on (Wed, 11 Jan 2006 10:33:03 -0500), Tom Lane confessed: > The planner understands about transitivity of equality, ie given a =3D b > and b =3D c it can infer a =3D c. It doesn't do any such thing for > inequalities though, nor does it deduce f(a) =3D f(b) for arbitrary > functions f. The addition Michael suggested requires much more > understanding of the properties of the functions in your query than > I think would be reasonable to put into the planner. >=20 OK. I think reached a point that I need to re-organize how the data is sto= red, maybe ridding myself of the schema and switching entirely to views. At that point, I likely could rid myself of the function (unmunge_time) I'm using, = and work with times and doy fields. Thanks, Rob --=20 21:17:00 up 4 days, 13:43, 9 users, load average: 2.02, 2.18, 2.23 Linux 2.6.12-12-2 #4 SMP Tue Jan 3 19:56:19 MST 2006 --Signature_Wed__11_Jan_2006_21_20_46_-0700_9l/As_kpQKQi1.HU Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iEYEARECAAYFAkPF2SQACgkQLQ/DKuwDYzk6+gCggGVDiEZrn9Vk4Qm2B9SkhFmT EUYAoJBEOf54PYvuSSmKFc+gJwtm2g1A =yOpl -----END PGP SIGNATURE----- --Signature_Wed__11_Jan_2006_21_20_46_-0700_9l/As_kpQKQi1.HU-- From pgsql-performance-owner@postgresql.org Thu Jan 12 00:33:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5495E9DCABC for ; Thu, 12 Jan 2006 00:33:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79692-05 for ; Thu, 12 Jan 2006 00:33:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 0209E9DCA65 for ; Thu, 12 Jan 2006 00:33:25 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0C4XNxn000936; Wed, 11 Jan 2006 23:33:23 -0500 (EST) To: Mark Liberman cc: pgsql-performance@postgresql.org Subject: Re: Stable function being evaluated more than once in a single query In-reply-to: <200601111641.20627.mliberman@mixedsignals.com> References: <200601111641.20627.mliberman@mixedsignals.com> Comments: In-reply-to Mark Liberman message dated "Wed, 11 Jan 2006 16:41:20 -0800" Date: Wed, 11 Jan 2006 23:33:23 -0500 Message-ID: <935.1137040403@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.085 required=5 tests=[AWL=0.085] X-Spam-Score: 0.085 X-Spam-Level: X-Archive-Number: 200601/148 X-Sequence-Number: 16626 Mark Liberman writes: > I've got a set-returning function, defined as STABLE, that I reference twice > within a single query, yet appears to be evaluated via two seperate function > scans. There is no guarantee, express or implied, that this won't be the case. (Seems like we just discussed this a couple days ago...) regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jan 12 00:48:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3FF4F9DD61C for ; Thu, 12 Jan 2006 00:48:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86807-02-9 for ; Thu, 12 Jan 2006 00:48:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 0F5AD9DCE04 for ; Thu, 12 Jan 2006 00:45:54 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0C4jnYZ001093; Wed, 11 Jan 2006 23:45:49 -0500 (EST) To: K C Lau cc: pgsql-performance@postgresql.org Subject: Re: indexes on primary and foreign keys In-reply-to: <6.2.1.2.0.20060112103712.0529cdd0@localhost> References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com> <20060111232157.GA88829@winnie.fuhr.org> <6.2.1.2.0.20060112083033.02bb74c8@localhost> <6.2.1.2.0.20060112103712.0529cdd0@localhost> Comments: In-reply-to K C Lau message dated "Thu, 12 Jan 2006 11:49:16 +0800" Date: Wed, 11 Jan 2006 23:45:49 -0500 Message-ID: <1092.1137041149@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.223 required=5 tests=[AWL=-0.053, MAILTO_TO_SPAM_ADDR=0.276] X-Spam-Score: 0.223 X-Spam-Level: X-Archive-Number: 200601/149 X-Sequence-Number: 16627 K C Lau writes: > Thanks. The side effect is that it would suppress other notices which might > be useful. There's been some discussion of subdividing the present "notice" category into two subclasses, roughly defined as "only novices wouldn't know this" and "maybe this is interesting". What's missing at this point is a concrete proposal as to which existing NOTICE messages should go into each category. If you feel like tackling the project, go for it... regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jan 12 05:49:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 27FAA9DC8A2 for ; Thu, 12 Jan 2006 05:49:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86671-03 for ; Thu, 12 Jan 2006 05:49:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by postgresql.org (Postfix) with ESMTP id EF8099DC888 for ; Thu, 12 Jan 2006 05:48:57 -0400 (AST) Received: from [192.168.0.3] (unknown [84.12.152.182]) by smtp.nildram.co.uk (Postfix) with ESMTP id D56162531ED; Thu, 12 Jan 2006 09:48:39 +0000 (GMT) Subject: Re: Extremely irregular query performance From: Simon Riggs To: Tom Lane Cc: Jean-Philippe =?ISO-8859-1?Q?C=F4t=E9?= , pgsql-performance@postgresql.org In-Reply-To: <480.1137036235@sss.pgh.pa.us> References: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> <480.1137036235@sss.pgh.pa.us> Content-Type: text/plain Date: Thu, 12 Jan 2006 09:48:41 +0000 Message-Id: <1137059321.3180.34.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/150 X-Sequence-Number: 16628 On Wed, 2006-01-11 at 22:23 -0500, Tom Lane wrote: > =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= writes: > > Thanks a lot for this info, I was indeed exceeding the genetic > > optimizer's threshold. Now that it is turned off, I get > > a very stable response time of 435ms (more or less 5ms) for > > the same query. It is about three times slower than the best > > I got with the genetic optimizer on, but the overall average > > is much lower. > > Hmm. It would be interesting to use EXPLAIN ANALYZE to confirm that the > plan found this way is the same as the best plan found by GEQO, and > the extra couple hundred msec is the price you pay for the exhaustive > plan search. If GEQO is managing to find a plan better than the regular > planner then we need to look into why ... It seems worth noting in the EXPLAIN whether GEQO has been used to find the plan, possibly along with other factors influencing the plan such as enable_* settings. Best Regards, Simon Riggs From pgsql-performance-owner@postgresql.org Thu Jan 12 08:19:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2DF719DCD7F for ; Thu, 12 Jan 2006 08:18:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23301-05 for ; Thu, 12 Jan 2006 08:19:01 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204]) by postgresql.org (Postfix) with ESMTP id 99C009DCD7A for ; Thu, 12 Jan 2006 08:18:56 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so290986wxc for ; Thu, 12 Jan 2006 04:19:00 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=gvBR2AuHCdRov/uBnv5hTjdFA/3qQkhap9/0BmXlbvQk+8YMXiRhNFpN6pEQL1LP0bxDETIyJ1l6dmSwBl0wgWKlYSMEtBNxaR1EbBecRhRzG6UlTp5pErduXzP7MfMnb9CFWGT5dxkVWLQG59v3a5R06OFCLkAK6IrfWtojOkg= Received: by 10.70.47.17 with SMTP id u17mr2247768wxu; Thu, 12 Jan 2006 04:18:58 -0800 (PST) Received: by 10.70.44.7 with HTTP; Thu, 12 Jan 2006 04:18:58 -0800 (PST) Message-ID: <34608c0c0601120418n1af567b9n@mail.gmail.com> Date: Thu, 12 Jan 2006 13:18:58 +0100 From: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= To: pgsql-performance@postgresql.org Subject: Throwing unnecessary joins away MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11612_32089099.1137068338744" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.473 required=5 tests=[AWL=-0.472, HTML_10_20=0.945, HTML_MESSAGE=0.001] X-Spam-Score: 0.473 X-Spam-Level: X-Archive-Number: 200601/151 X-Sequence-Number: 16629 ------=_Part_11612_32089099.1137068338744 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi all, Is PostgreSQL able to throw unnecessary joins? For example I have two tables, and I join then with their primary keys, say type of bigint . In this case if I don't reference to one of the tables anywhere except the join condition, then the join can be eliminated. Or if I do a "table1 left join table2 (table1.referer=3Dtable2.id)" (N : 1 relationship), and I don't reference table2 anywhere else, then it is unnecessary. Primary key - primary key joins are often generated by O/R mappers. These generated queries could be optimized even more by not joining if not necessary. You may say that I should not write such queries. The truth is that the O/R mapper is generating queries on views, and it does not use every field ever= y time, but even so the query of the view is executed with the same plan by PostgreSQL, although some joins are unnecessary. So basically this all is relevant only with views. Best Regards, Otto ------=_Part_11612_32089099.1137068338744 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi all,
 
Is PostgreSQL able to throw unnecessary joins?
For example I have two tables, and I join then with their primary keys= , say type of bigint . In this case if I don't reference to one of the= tables anywhere except the join condition, then the join can be = eliminated.=20
Or if I do a "table1 left join table2 (table1.referer=3Dtable2.id= )"  (N : 1 relationship), and I don't reference table2 anywhere e= lse, then it is unnecessary.
Primary key - primary key joins are often generated by O/R mappers. Th= ese generated queries could be optimized even more by not joining if not ne= cessary.
 
You may say that I should not write such queries. The truth is that th= e O/R mapper is generating queries on views, and it does not use every fiel= d every time, but even so the query of the view is executed with the s= ame plan by PostgreSQL, although some joins are unnecessary.
 
So basically this all is relevant only with views.
 
Best Regards,
Otto
------=_Part_11612_32089099.1137068338744-- From pgsql-performance-owner@postgresql.org Thu Jan 12 08:34:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ECEE19DCDA0 for ; Thu, 12 Jan 2006 08:34:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25055-10 for ; Thu, 12 Jan 2006 08:34:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 296989DCA35 for ; Thu, 12 Jan 2006 08:34:53 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id 6F5C4112E1F; Thu, 12 Jan 2006 13:38:56 +0100 (CET) Message-ID: <43C64CFB.9030504@barettadeit.com> Date: Thu, 12 Jan 2006 13:35:07 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= Cc: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away References: <34608c0c0601120418n1af567b9n@mail.gmail.com> In-Reply-To: <34608c0c0601120418n1af567b9n@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/152 X-Sequence-Number: 16630 Ott� Havasv�lgyi wrote: > Hi all, > > Is PostgreSQL able to throw unnecessary joins? > For example I have two tables, and I join then with their primary keys, > say type of bigint . In this case if I don't reference to one of the > tables anywhere except the join condition, then the join can be eliminated. > Or if I do a "table1 left join table2 (table1.referer=table2.id)" (N : > 1 relationship), and I don't reference table2 anywhere else, then it is > unnecessary. It cannot possibly remove "unnecessary joins", simply because the join influences whether a tuple in the referenced table gets selected and how many times. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Thu Jan 12 09:41:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C3F009DCDB5 for ; Thu, 12 Jan 2006 09:41:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41197-01 for ; Thu, 12 Jan 2006 09:41:31 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.201]) by postgresql.org (Postfix) with ESMTP id 443269DCD9A for ; Thu, 12 Jan 2006 09:41:26 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so304131wxc for ; Thu, 12 Jan 2006 05:41:30 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sLb3991V6GBSTEXE5L4V8KYu8YA2nXkySGGD0hmidzEnbclN38KJgfdOsA9neGT8GjKlYJLfvJbdNBkI475GsrIJf1RTf7BcIgucLbOt61Pd32cfJ6OpWUBXeQistYiliixzkLZP+pE/UnVMguIN/x5LcZj/Yu7c2n0Z35O9I2Q= Received: by 10.70.68.5 with SMTP id q5mr2355930wxa; Thu, 12 Jan 2006 05:41:30 -0800 (PST) Received: by 10.70.44.7 with HTTP; Thu, 12 Jan 2006 05:41:30 -0800 (PST) Message-ID: <34608c0c0601120541wd910da3s@mail.gmail.com> Date: Thu, 12 Jan 2006 14:41:30 +0100 From: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= To: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away In-Reply-To: <43C64CFB.9030504@barettadeit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.395 required=5 tests=[AWL=0.395] X-Spam-Score: 0.395 X-Spam-Level: X-Archive-Number: 200601/153 X-Sequence-Number: 16631 Hi, As far as I know SQL Server has some similar feature. It does not join if not necessary, more exactly: if the result would be the same if it joined the table. Here is another example: http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0902/en/html= /dbugen9/00000468.htm This would be a fantastic feature. Best Regards, Otto 2006/1/12, Alessandro Baretta : > Ott=F3 Havasv=F6lgyi wrote: > > Hi all, > > > > Is PostgreSQL able to throw unnecessary joins? > > For example I have two tables, and I join then with their primary keys, > > say type of bigint . In this case if I don't reference to one of the > > tables anywhere except the join condition, then the join can be elimina= ted. > > Or if I do a "table1 left join table2 (table1.referer=3Dtable2.id)" (N= : > > 1 relationship), and I don't reference table2 anywhere else, then it is > > unnecessary. > > It cannot possibly remove "unnecessary joins", simply because the join > influences whether a tuple in the referenced table gets selected and how = many times. > > Alex > > > -- > ********************************************************************* > http://www.barettadeit.com/ > Baretta DE&IT > A division of Baretta SRL > > tel. +39 02 370 111 55 > fax. +39 02 370 111 54 > > Our technology: > > The Application System/Xcaml (AS/Xcaml) > > > The FreerP Project > > From pgsql-performance-owner@postgresql.org Thu Jan 12 10:48:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A4A7D9DCA35 for ; Thu, 12 Jan 2006 10:48:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52255-05 for ; Thu, 12 Jan 2006 10:48:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bramble.mmrd.com (bramble.mmrd.com [65.217.53.66]) by postgresql.org (Postfix) with ESMTP id AD98B9DCA2B for ; Thu, 12 Jan 2006 10:48:31 -0400 (AST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by bramble.mmrd.com (8.12.8/8.12.8) with ESMTP id k0CFYfkB021707 for ; Thu, 12 Jan 2006 10:34:41 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [10.225.10.110]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id k0CEmsC16322 for ; Thu, 12 Jan 2006 09:48:55 -0500 Received: from [10.225.105.30] (10.225.105.30 [10.225.105.30]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id TWDAXTCL; Thu, 12 Jan 2006 09:48:51 -0500 Subject: query slower on 8.1 than 7.3 From: Robert Treat To: pgsql-performance@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 12 Jan 2006 09:48:25 -0500 Message-Id: <1137077315.28013.444.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.138 required=5 tests=[AWL=0.138] X-Spam-Score: 0.138 X-Spam-Level: X-Archive-Number: 200601/154 X-Sequence-Number: 16632 Porting app from 7.3 to 8.1, have hit a query that is slower. Everything is analyzed / vacuumed appropriately. I've managed to pare the query down into something manageable that still gives me a problem, it looks like this: SELECT * FROM ( SELECT software_download.* FROM ( SELECT host_id, max(mtime) as mtime FROM software_download JOIN software_binary USING (software_binary_id) WHERE binary_type_id IN (3,5,6) AND bds_status_id not in (6,17,18) GROUP BY host_id, software_binary_id ) latest_download JOIN software_download using (host_id,mtime) ) ld LEFT JOIN ( SELECT entityid, rmsbinaryid, rmsbinaryid as software_binary_id, timestamp as downloaded, ia.host_id FROM ( SELECT entityid, rmsbinaryid,max(msgid) as msgid FROM msg306u WHERE downloadstatus=1 GROUP BY entityid,rmsbinaryid ) a1 JOIN myapp_app ia on (entityid=myapp_app_id) JOIN ( SELECT * FROM msg306u WHERE downloadstatus != 0 ) a2 USING(entityid,rmsbinaryid,msgid) ) aa USING (host_id,software_binary_id) The problem seems to stem from 8.1's thinking that using a nested loop left join is a good idea. The 7.3 explain plan looks like this: Hash Join (cost=10703.38..11791.64 rows=1 width=150) (actual time=2550.23..2713.26 rows=475 loops=1) Hash Cond: ("outer".host_id = "inner".host_id) Join Filter: ("outer".software_binary_id = "inner".rmsbinaryid) -> Merge Join (cost=1071.80..2160.07 rows=1 width=110) (actual time=93.16..252.12 rows=475 loops=1) Merge Cond: ("outer".host_id = "inner".host_id) Join Filter: ("inner".mtime = "outer".mtime) -> Index Scan using software_download_host_id on software_download (cost=0.00..973.16 rows=18513 width=98) (actual time=0.05..119.89 rows=15587 loops=1) -> Sort (cost=1071.80..1072.81 rows=403 width=20) (actual time=90.82..94.97 rows=7328 loops=1) Sort Key: latest_download.host_id -> Subquery Scan latest_download (cost=1014.00..1054.34 rows=403 width=20) (actual time=85.60..90.12 rows=475 loops=1) -> Aggregate (cost=1014.00..1054.34 rows=403 width=20) (actual time=85.59..89.27 rows=475 loops=1) -> Group (cost=1014.00..1044.26 rows=4034 width=20) (actual time=85.55..87.61 rows=626 loops=1) -> Sort (cost=1014.00..1024.09 rows=4034 width=20) (actual time=85.54..85.86 rows=626 loops=1) Sort Key: software_download.host_id, software_download.software_binary_id -> Hash Join (cost=21.64..772.38 rows=4034 width=20) (actual time=1.06..84.14 rows=626 loops=1) Hash Cond: ("outer".software_binary_id = "inner".software_binary_id) -> Seq Scan on software_download (cost=0.00..565.98 rows=17911 width=16) (actual time=0.06..67.26 rows=15364 loops=1) Filter: ((bds_status_id <> 6) AND (bds_status_id <> 17) AND (bds_status_id <> 18)) -> Hash (cost=21.59..21.59 rows=20 width=4) (actual time=0.94..0.94 rows=0 loops=1) -> Seq Scan on software_binary (cost=0.00..21.59 rows=20 width=4) (actual time=0.32..0.91 rows=23 loops=1) Filter: ((binary_type_id = 3) OR (binary_type_id = 5) OR (binary_type_id = 6)) -> Hash (cost=9631.57..9631.57 rows=1 width=40) (actual time=2457.04..2457.04 rows=0 loops=1) -> Merge Join (cost=9495.38..9631.57 rows=1 width=40) (actual time=2345.77..2456.74 rows=240 loops=1) Merge Cond: (("outer".rmsbinaryid = "inner".rmsbinaryid) AND ("outer".msgid = "inner".msgid) AND ("outer".entityid = "inner".entityid)) -> Sort (cost=4629.24..4691.15 rows=24761 width=20) (actual time=514.19..539.04 rows=25544 loops=1) Sort Key: msg306u.rmsbinaryid, msg306u.msgid, msg306u.entityid -> Seq Scan on msg306u (cost=0.00..2556.22 rows=24761 width=20) (actual time=0.08..228.09 rows=25544 loops=1) Filter: (downloadstatus <> '0'::text) -> Sort (cost=4866.14..4872.33 rows=2476 width=20) (actual time=1831.55..1831.68 rows=241 loops=1) Sort Key: a1.rmsbinaryid, a1.msgid, a1.entityid -> Hash Join (cost=4429.43..4726.56 rows=2476 width=20) (actual time=1724.39..1830.63 rows=325 loops=1) Hash Cond: ("outer".entityid = "inner".myapp_app_id) -> Subquery Scan a1 (cost=4363.24..4610.85 rows=2476 width=12) (actual time=1714.04..1818.66 rows=325 loops=1) -> Aggregate (cost=4363.24..4610.85 rows=2476 width=12) (actual time=1714.03..1818.08 rows=325 loops=1) -> Group (cost=4363.24..4548.95 rows=24761 width=12) (actual time=1714.01..1796.43 rows=25544 loops=1) -> Sort (cost=4363.24..4425.15 rows=24761 width=12) (actual time=1714.00..1739.34 rows=25544 loops=1) Sort Key: entityid, rmsbinaryid -> Seq Scan on msg306u (cost=0.00..2556.22 rows=24761 width=12) (actual time=0.03..152.94 rows=25544 loops=1) Filter: (downloadstatus = '1'::text) -> Hash (cost=61.95..61.95 rows=1695 width=8) (actual time=10.25..10.25 rows=0 loops=1) -> Seq Scan on myapp_app ia (cost=0.00..61.95 rows=1695 width=8) (actual time=0.09..5.48 rows=1698 loops=1) Total runtime: 2716.84 msec Compared to the 8.1 plan: Nested Loop Left Join (cost=2610.56..6491.82 rows=1 width=112) (actual time=166.411..4468.322 rows=472 loops=1) Join Filter: (("outer".host_id = "inner".host_id) AND ("outer".software_binary_id = "inner".rmsbinaryid)) -> Merge Join (cost=616.56..1495.06 rows=1 width=96) (actual time=47.004..120.085 rows=472 loops=1) Merge Cond: ("outer".host_id = "inner".host_id) Join Filter: ("inner".mtime = "outer".mtime) -> Index Scan using software_download_host_id on software_download (cost=0.00..615.92 rows=13416 width=96) (actual time=0.017..35.243 rows=13372 loops=1) -> Sort (cost=616.56..620.45 rows=1555 width=12) (actual time=46.034..53.978 rows=6407 loops=1) Sort Key: latest_download.host_id -> Subquery Scan latest_download (cost=499.13..534.12 rows=1555 width=12) (actual time=43.137..45.058 rows=472 loops=1) -> HashAggregate (cost=499.13..518.57 rows=1555 width=16) (actual time=43.132..43.887 rows=472 loops=1) -> Hash Join (cost=5.64..477.57 rows=2875 width=16) (actual time=0.206..41.782 rows=623 loops=1) Hash Cond: ("outer".software_binary_id = "inner".software_binary_id) -> Seq Scan on software_download (cost=0.00..377.78 rows=13080 width=16) (actual time=0.007..23.679 rows=13167 loops=1) Filter: ((bds_status_id <> 6) AND (bds_status_id <> 17) AND (bds_status_id <> 18)) -> Hash (cost=5.59..5.59 rows=20 width=4) (actual time=0.155..0.155 rows=22 loops=1) -> Seq Scan on software_binary (cost=0.00..5.59 rows=20 width=4) (actual time=0.011..0.111 rows=22 loops=1) Filter: ((binary_type_id = 3) OR (binary_type_id = 5) OR (binary_type_id = 6)) -> Nested Loop (cost=1994.00..4996.74 rows=1 width=20) (actual time=0.259..8.870 rows=238 loops=472) -> Nested Loop (cost=1994.00..4992.28 rows=1 width=16) (actual time=0.249..5.851 rows=238 loops=472) Join Filter: ("outer".rmsbinaryid = "inner".rmsbinaryid) -> HashAggregate (cost=1994.00..2001.41 rows=593 width=12) (actual time=0.236..0.942 rows=323 loops=472) -> Seq Scan on msg306u (cost=0.00..1797.28 rows=26230 width=12) (actual time=0.009..69.590 rows=25542 loops=1) Filter: (downloadstatus = '1'::text) -> Index Scan using msg306u_entityid_msgid_idx on msg306u (cost=0.00..5.02 rows=1 width=20) (actual time=0.008..0.010 rows=1 loops=152456) Index Cond: (("outer".entityid = msg306u.entityid) AND ("outer"."?column3?" = msg306u.msgid)) Filter: (downloadstatus <> '0'::text) -> Index Scan using myapp_app_pkey on myapp_app ia (cost=0.00..4.44 rows=1 width=8) (actual time=0.006..0.007 rows=1 loops=112336) Index Cond: ("outer".entityid = ia.myapp_app_id) Total runtime: 4469.506 ms What is really tossing me here is I set enable_nestloop = off and got this plan: Hash Left Join (cost=7034.77..7913.29 rows=1 width=112) (actual time=483.840..551.136 rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND ("outer".software_binary_id = "inner".rmsbinaryid)) -> Merge Join (cost=616.56..1495.06 rows=1 width=96) (actual time=46.696..112.434 rows=472 loops=1) Merge Cond: ("outer".host_id = "inner".host_id) Join Filter: ("inner".mtime = "outer".mtime) -> Index Scan using software_download_host_id on software_download (cost=0.00..615.92 rows=13416 width=96) (actual time=0.019..30.345 rows=13372 loops=1) -> Sort (cost=616.56..620.45 rows=1555 width=12) (actual time=45.720..53.265 rows=6407 loops=1) Sort Key: latest_download.host_id -> Subquery Scan latest_download (cost=499.13..534.12 rows=1555 width=12) (actual time=42.867..44.763 rows=472 loops=1) -> HashAggregate (cost=499.13..518.57 rows=1555 width=16) (actual time=42.862..43.628 rows=472 loops=1) -> Hash Join (cost=5.64..477.57 rows=2875 width=16) (actual time=0.206..41.503 rows=623 loops=1) Hash Cond: ("outer".software_binary_id = "inner".software_binary_id) -> Seq Scan on software_download (cost=0.00..377.78 rows=13080 width=16) (actual time=0.007..23.494 rows=13167 loops=1) Filter: ((bds_status_id <> 6) AND (bds_status_id <> 17) AND (bds_status_id <> 18)) -> Hash (cost=5.59..5.59 rows=20 width=4) (actual time=0.155..0.155 rows=22 loops=1) -> Seq Scan on software_binary (cost=0.00..5.59 rows=20 width=4) (actual time=0.011..0.112 rows=22 loops=1) Filter: ((binary_type_id = 3) OR (binary_type_id = 5) OR (binary_type_id = 6)) -> Hash (cost=6418.20..6418.20 rows=1 width=20) (actual time=437.111..437.111 rows=238 loops=1) -> Merge Join (cost=6149.96..6418.20 rows=1 width=20) (actual time=367.555..436.667 rows=238 loops=1) Merge Cond: (("outer".rmsbinaryid = "inner".rmsbinaryid) AND ("outer".msgid = "inner".msgid) AND ("outer".entityid = "inner".entityid)) -> Sort (cost=2119.55..2121.03 rows=593 width=16) (actual time=117.104..117.476 rows=323 loops=1) Sort Key: a1.rmsbinaryid, a1.msgid, a1.entityid -> Hash Join (cost=2054.19..2092.23 rows=593 width=16) (actual time=114.671..116.280 rows=323 loops=1) Hash Cond: ("outer".entityid = "inner".myapp_app_id) -> HashAggregate (cost=1994.00..2001.41 rows=593 width=12) (actual time=108.909..109.486 rows=323 loops=1) -> Seq Scan on msg306u (cost=0.00..1797.28 rows=26230 width=12) (actual time=0.009..68.861 rows=25542 loops=1) Filter: (downloadstatus = '1'::text) -> Hash (cost=55.95..55.95 rows=1695 width=8) (actual time=5.736..5.736 rows=1695 loops=1) -> Seq Scan on myapp_app ia (cost=0.00..55.95 rows=1695 width=8) (actual time=0.005..2.850 rows=1695 loops=1) -> Sort (cost=4030.42..4095.99 rows=26230 width=20) (actual time=250.434..286.311 rows=25542 loops=1) Sort Key: public.msg306u.rmsbinaryid, public.msg306u.msgid, public.msg306u.entityid -> Seq Scan on msg306u (cost=0.00..1797.28 rows=26230 width=20) (actual time=0.009..80.478 rows=25542 loops=1) Filter: (downloadstatus <> '0'::text) Total runtime: 553.409 ms Ah, a beautiful scheme! So given I can't run with enable_nestloop off, anyone have a suggestion on how to get this thing moving in the right direction? I tried raising statistics estimates on some of the columns but that didn't help, though maybe I was raising it on the right columns.. any suggestions there? Or perhaps a better way to write the query... I'm open to suggestions. TIA, Robert Treat -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL From pgsql-performance-owner@postgresql.org Thu Jan 12 10:50:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 760D99DCDB5 for ; Thu, 12 Jan 2006 10:50:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53874-04 for ; Thu, 12 Jan 2006 10:50:51 -0400 (AST) X-Greylist: delayed 14:18:20.375081 by SQLgrey- Received: from smtp2.clb.oleane.net (smtp2.clb.oleane.net [213.56.31.18]) by postgresql.org (Postfix) with ESMTP id 4E9669DCDB7 for ; Thu, 12 Jan 2006 10:50:44 -0400 (AST) Received: from smtp2.clb.oleane.net (localhost [127.0.0.1]) by smtp2.clb.oleane.net (antivirus) with ESMTP id k0CEomhq026762; Thu, 12 Jan 2006 15:50:48 +0100 Received: from [192.168.8.219] ([62.160.127.238]) (authenticated) by smtp2.clb.oleane.net with ESMTP id k0CEollV026748; Thu, 12 Jan 2006 15:50:48 +0100 Message-ID: <43C66D67.1000502@elios-informatique.fr> Date: Thu, 12 Jan 2006 15:53:27 +0100 From: Jamal Ghaffour User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: fr, en MIME-Version: 1.0 To: Jamal Ghaffour , pgsql-performance@postgresql.org Subject: Re: Please Help: PostgreSQL performance Optimization References: <43C66742.9060104@elios-informatique.fr> In-Reply-To: <43C66742.9060104@elios-informatique.fr> Content-Type: multipart/mixed; boundary="------------060805020108060506070404" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[AWL=-0.001, HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/155 X-Sequence-Number: 16633 This is a multi-part message in MIME format. --------------060805020108060506070404 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Jamal Ghaffour a écrit :
Hi,

I'm working on a project, whose implementation deals with PostgreSQL. A brief description of our application is given  below.

I'm running version 8.0 on a dedicated  server 1Gb of RAM. 
my database isn't complex, it contains just 2 simple tables.

CREATE TABLE cookies (
    domain varchar(50) NOT NULL,
    path varchar(50) NOT NULL,
    name varchar(50) NOT NULL,
    principalid varchar(50) NOT NULL,
    host text NOT NULL,
    value text NOT NULL,
    secure bool NOT NULL,
    timestamp timestamp with time zone NOT NULL DEFAULT 
CURRENT_TIMESTAMP+TIME '04:00:00',
    PRIMARY KEY  (domain,path,name,principalid)
)

CREATE TABLE liberty (
    principalid varchar(50) NOT NULL,
    requestid varchar(50) NOT NULL,
    spassertionurl text NOT NULL,
    libertyversion  varchar(50) NOT NULL,
    relaystate  varchar(50) NOT NULL,
    PRIMARY KEY  (principalid)
)

I'm developping an application that uses the libpqxx to execute 
psql queries on the database and have to execute 500 requests at the same time.


UPDATE cookies SET host='ping.icap-elios.com', value= '54E5B5491F27C0177083795F2E09162D', secure=FALSE, 
timestamp=CURRENT_TIMESTAMP+INTERVAL '14400 SECOND' WHERE 
domain='ping.icap-elios.com' AND path='/tfs' AND principalid='192.168.8.219' AND 
name='jsessionid'

SELECT path, upper(name) AS name, value FROM cookies  WHERE timestamp<CURRENT_TIMESTAMP AND principalid='192.168.8.219' AND 
secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com')

I have to notify that the performance of is extremely variable and irregular.
I can also see that the server process uses almost 100% of
a CPU.

I'm using the default configuration file, and i m asking if i have to change some paramters to have a good performance.

Any help would be greatly appreciated.

Thanks,
Hi,

There are some results that can give you concrete  idea about my problem:
when i 'm launching my test that executes in loop manner the  SELECT and UPDATE queries described above, i'm obtaining this results:

UPDATE Time execution :0s: 5225 us
SELECT Time execution  :0s: 6908 us

5 minutes Later:

UPDATE Time execution :0s: 6125 us
SELECT Time execution  :0s: 10928 us

5 minutes Later:

UPDATE Time execution :0s: 5825 us
SELECT Time execution  :0s: 14978 us

As you can see , the time execution of the SELECT request is growing relatively to time and not the UPDATE time execution.
 I note that to stop the explosion of the Select time execution, i m using frequently the vaccum query on the cookies table.
Set  the  autovacuum parmaeter in the configuation file to on wasn't able to remplace the use of the vaccum command, and i don't know if this behaivour is normal?

Thanks,
Jamal
--------------060805020108060506070404 Content-Type: text/x-vcard; charset=utf-8; name="Jamal.Ghaffour.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Jamal.Ghaffour.vcf" begin:vcard fn:Jamal Ghaffour n:Ghaffour;Jamal org:ELIOS Informatique adr;quoted-printable:;;1, sq de ch=C3=AAne Germain,;CESSON SEVIGNE;;35510;FRANCE email;internet:Jamal.Ghaffour@elios-informatique.fr tel;work:(+33) 2.99.63.85.30 tel;fax:(+33) 2.99.63.85.93 tel;home:(+33) 2 99 36 73 96 tel;cell:(+33) 6.21.85.15.91 url:http://www.elios-informatique.fr version:2.1 end:vcard --------------060805020108060506070404-- From pgsql-performance-owner@postgresql.org Thu Jan 12 11:53:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1867C9DC803 for ; Thu, 12 Jan 2006 11:53:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65050-08 for ; Thu, 12 Jan 2006 11:53:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 0AA7C9DC81D for ; Thu, 12 Jan 2006 11:53:50 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0CFrrt4005270; Thu, 12 Jan 2006 10:53:53 -0500 (EST) To: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= cc: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away In-reply-to: <34608c0c0601120541wd910da3s@mail.gmail.com> References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> <34608c0c0601120541wd910da3s@mail.gmail.com> Comments: In-reply-to =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= message dated "Thu, 12 Jan 2006 14:41:30 +0100" Date: Thu, 12 Jan 2006 10:53:53 -0500 Message-ID: <5269.1137081233@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.086 required=5 tests=[AWL=0.086] X-Spam-Score: 0.086 X-Spam-Level: X-Archive-Number: 200601/156 X-Sequence-Number: 16634 =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= writes: > As far as I know SQL Server has some similar feature. It does not join > if not necessary, more exactly: if the result would be the same if it > joined the table. I find it really really hard to believe that such cases arise often enough to justify having the planner spend cycles checking for them. regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jan 12 12:25:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5FD579DCDC5 for ; Thu, 12 Jan 2006 12:25:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78485-03-2 for ; Thu, 12 Jan 2006 12:25:50 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.193]) by postgresql.org (Postfix) with ESMTP id 7A9569DCDBF for ; Thu, 12 Jan 2006 12:25:49 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so129123uge for ; Thu, 12 Jan 2006 08:25:48 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=Q8mJooaVSVzv74bMm1EylBp/n+knXQzKHwh4jtoIPbHXIIOverpUWBJjACAYSCk0Muzd3S0XADdtLy0CTryJIKaHd0Lm/K47qR17rJUHszH4QJI6ALDY79RJ6zmIOjRgtmj8m0R1TOtM27BwcJn5I6krZLJDz7r358Cran5vjbs= Received: by 10.66.255.3 with SMTP id c3mr289363ugi; Thu, 12 Jan 2006 08:25:48 -0800 (PST) Received: from ?192.168.3.4? ( [81.182.248.121]) by mx.gmail.com with ESMTP id k2sm1034082ugf.2006.01.12.08.25.47; Thu, 12 Jan 2006 08:25:48 -0800 (PST) Message-ID: <43C682F5.4000001@gmail.com> Date: Thu, 12 Jan 2006 17:25:25 +0100 From: =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> <34608c0c0601120541wd910da3s@mail.gmail.com> <5269.1137081233@sss.pgh.pa.us> In-Reply-To: <5269.1137081233@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.786 required=5 tests=[AWL=-0.546, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 0.786 X-Spam-Level: X-Archive-Number: 200601/157 X-Sequence-Number: 16635 Dear Tom, Not sure about Otto's exact problem, but he did mention views, and I'd feel more comfortable if you told me that view-based queries are re-planned based on actual conditions etc. Are they? Also, if you find it unlikely (or very rare) then it might be a configurable parameter. If someone finds it drastically improving (some of) their queries, it'd be possible to enable this feature in expense of extra planner cycles (on all queries). What I'd be concerned about, is whether the developers' time spent on this feature would worth it. :) -- G. On 2006.01.12. 16:53, Tom Lane wrote: > =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= writes: >> As far as I know SQL Server has some similar feature. It does not join >> if not necessary, more exactly: if the result would be the same if it >> joined the table. > > I find it really really hard to believe that such cases arise often > enough to justify having the planner spend cycles checking for them. > > regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jan 12 13:00:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B5A939DCB34 for ; Thu, 12 Jan 2006 13:00:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 88307-08 for ; Thu, 12 Jan 2006 13:00:09 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.198]) by postgresql.org (Postfix) with ESMTP id A965B9DCA31 for ; Thu, 12 Jan 2006 13:00:08 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so336533wxc for ; Thu, 12 Jan 2006 09:00:08 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Oj/VMfpnJs3eIRrWUZdv2VmPbm3MOwouXujyUK2Uh5GVh7PcLDm24vk55gPdatdyB8rzJYtYMdqqr2jRJ6q7IhMi0lB/WQF63YjXD/PAP9vqMnFx54ZxjTL94KUJEzw3U4LRw+Os+3s9zfljco8GZSTCcfTMZKYGT899QT4exqU= Received: by 10.70.12.6 with SMTP id 6mr2585527wxl; Thu, 12 Jan 2006 09:00:07 -0800 (PST) Received: by 10.70.44.7 with HTTP; Thu, 12 Jan 2006 09:00:07 -0800 (PST) Message-ID: <34608c0c0601120900l7d26073dp@mail.gmail.com> Date: Thu, 12 Jan 2006 18:00:07 +0100 From: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= To: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away In-Reply-To: <5269.1137081233@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> <34608c0c0601120541wd910da3s@mail.gmail.com> <5269.1137081233@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.285 required=5 tests=[AWL=0.285] X-Spam-Score: 0.285 X-Spam-Level: X-Archive-Number: 200601/158 X-Sequence-Number: 16636 Hi, I think it would be sufficient only for views. In other cases the programmer can optimize himself. But a view can be a join of other tables, and it is not sure that all of them are always needed. It all depends on what I select from the view. This information could even be calculted at view creation time. Of cource this requires that views are handled in a bit more special way, not just a view definition that is substituted into the original query (as far as I know the current implementation is similar to this. Sorry if not). What do you think about this idea? Of course it is not trivial to implement, but the result is really great. Postgres could determine at creation time, if this kind of optimization is possible at all or not. It can happan though that not all information is available (I mean unique index or foreign key) at that time. So this optimiztaion info could be refreshed later by a command, "ALTER VIEW ANALYZE" or "ANALYZE " simply. Postgres could also establish at creation time that for a given column in the selection list which source table(s) are required. This is probably not sufficient, but I haven't thought is through thouroughly yet. And I am not that familiar with the current optimizer internals. And one should be able to turn off this optimization, so that view creation takes not longer than now. If the optimizer finds no optimization info in the catalog, it behaves like now. I hope you see this worth. This all is analogue to statistics collection. Thanks for reading, Otto 2006/1/12, Tom Lane : > =3D?ISO-8859-1?Q?Ott=3DF3_Havasv=3DF6lgyi?=3D writes: > > As far as I know SQL Server has some similar feature. It does not join > > if not necessary, more exactly: if the result would be the same if it > > joined the table. > > I find it really really hard to believe that such cases arise often > enough to justify having the planner spend cycles checking for them. > > regards, tom lane > From pgsql-performance-owner@postgresql.org Thu Jan 12 13:03:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C3EB19DCDCA for ; Thu, 12 Jan 2006 13:03:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97927-03 for ; Thu, 12 Jan 2006 13:03:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from koolancexeon.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 87CB19DCDC5 for ; Thu, 12 Jan 2006 13:03:04 -0400 (AST) Received: mail.g2switchworks.com 10.10.1.8 from 10.10.1.37 10.10.1.37 via HTTP with MS-WebStorage 6.5.6944 Received: from state.g2switchworks.com by mail.g2switchworks.com; 12 Jan 2006 11:03:02 -0600 Subject: Re: Throwing unnecessary joins away From: Scott Marlowe To: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= Cc: pgsql-performance@postgresql.org In-Reply-To: <34608c0c0601120900l7d26073dp@mail.gmail.com> References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> <34608c0c0601120541wd910da3s@mail.gmail.com> <5269.1137081233@sss.pgh.pa.us> <34608c0c0601120900l7d26073dp@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-Id: <1137085382.3959.16.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 12 Jan 2006 11:03:02 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.116 required=5 tests=[AWL=0.115, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.116 X-Spam-Level: X-Archive-Number: 200601/159 X-Sequence-Number: 16637 On Thu, 2006-01-12 at 11:00, Ott=C3=B3 Havasv=C3=B6lgyi wrote: > Hi, >=20 > I think it would be sufficient only for views. In other cases the > programmer can optimize himself. But a view can be a join of other > tables, and it is not sure that all of them are always needed. It all > depends on what I select from the view. The idea that you could throw away joins only works for outer joins.=20 I.e. if you did: select a.x, a.y, a.z from a left join b (on a.id=3Db.aid)=20 then you could throw away the join to b. But if it was a regular inner join then you couldn't know whether or not you needed to join to b without actually joining to b... From pgsql-performance-owner@postgresql.org Thu Jan 12 14:34:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0D6869DC803 for ; Thu, 12 Jan 2006 14:34:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67388-03 for ; Thu, 12 Jan 2006 14:34:15 -0400 (AST) X-Greylist: delayed 00:05:12.206106 by SQLgrey- Received: from pillette.com (adsl-67-119-5-202.dsl.snfc21.pacbell.net [67.119.5.202]) by postgresql.org (Postfix) with ESMTP id 6A3E39DC83A for ; Thu, 12 Jan 2006 14:34:12 -0400 (AST) Received: from [192.168.1.234] ([192.168.1.234]) by pillette.com (8.11.6/8.11.6) with ESMTP id k0CIStJ03177; Thu, 12 Jan 2006 10:28:55 -0800 Message-ID: <43C6A31F.3010007@pillette.com> Date: Thu, 12 Jan 2006 10:42:39 -0800 From: Andrew Lazarus Reply-To: andrew@pillette.com Organization: Pillette Investment Management User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jamal Ghaffour CC: pgsql-performance@postgresql.org Subject: Re: Please Help: PostgreSQL performance Optimization References: <43C66742.9060104@elios-informatique.fr> <43C66D67.1000502@elios-informatique.fr> In-Reply-To: <43C66D67.1000502@elios-informatique.fr> Content-Type: multipart/mixed; boundary="------------010002000102050508090103" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/160 X-Sequence-Number: 16638 This is a multi-part message in MIME format. --------------010002000102050508090103 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Jamal Ghaffour wrote: >>CREATE TABLE cookies ( >> domain varchar(50) NOT NULL, >> path varchar(50) NOT NULL, >> name varchar(50) NOT NULL, >> principalid varchar(50) NOT NULL, >> host text NOT NULL, >> value text NOT NULL, >> secure bool NOT NULL, >> timestamp timestamp with time zone NOT NULL DEFAULT >>CURRENT_TIMESTAMP+TIME '04:00:00', >> PRIMARY KEY (domain,path,name,principalid) >>) [snip] >>SELECT path, upper(name) AS name, value FROM cookies WHERE timestamp>secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com') I think the problem here is that the column order in the index doesn't match the columns used in the WHERE clause criteria. Try adding an index on (domain,principalid) or (domain,principalid,timestamp). If these are your only queries, you can get the same effect by re-ordering the columns in the table so that this is the column order used by the primary key and its implicit index. You should check up on EXPLAIN and EXPLAIN ANALYZE to help you debug slow queries. --------------010002000102050508090103 Content-Type: text/x-vcard; charset=utf-8; name="andrew.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="andrew.vcf" begin:vcard fn:Andrew Lazarus n:Lazarus;Andrew org:Pillette Investment Management;Research and Development adr;dom:;;3028 Fillmore;San Francisco;CA;94123 email;internet:andrew@pillette.com title:Director tel;work:800-366-0688 tel;fax:415-440-4093 url:http://www.pillette.com version:2.1 end:vcard --------------010002000102050508090103-- From pgsql-performance-owner@postgresql.org Thu Jan 12 14:51:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 436349DCDCA for ; Thu, 12 Jan 2006 14:51:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 88883-03 for ; Thu, 12 Jan 2006 14:51:24 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.207]) by postgresql.org (Postfix) with ESMTP id 299449DCDBC for ; Thu, 12 Jan 2006 14:51:21 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so354595wxc for ; Thu, 12 Jan 2006 10:51:22 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ejRdLdNbV1WHiwdrf3LmFt+Ic2HBrm9RUOHpHx/HXS3n8nEiaA7wuuheczwxbOuJ4vyjea/RK3jo8+oj8x8pqnYEjuQBnbKG+BMZMQbjs8Kde+kbYPRhYFJw5QCapk1dwCsELvbyWL7MkQaRRNuRi2dZYXh/cK9AicEsPL97vTs= Received: by 10.70.45.12 with SMTP id s12mr2698009wxs; Thu, 12 Jan 2006 10:51:22 -0800 (PST) Received: by 10.70.44.7 with HTTP; Thu, 12 Jan 2006 10:51:22 -0800 (PST) Message-ID: <34608c0c0601121051r52c707f6l@mail.gmail.com> Date: Thu, 12 Jan 2006 19:51:22 +0100 From: =?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?= To: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away In-Reply-To: <1137085382.3959.16.camel@state.g2switchworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> <34608c0c0601120541wd910da3s@mail.gmail.com> <5269.1137081233@sss.pgh.pa.us> <34608c0c0601120900l7d26073dp@mail.gmail.com> <1137085382.3959.16.camel@state.g2switchworks.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.238 required=5 tests=[AWL=0.238] X-Spam-Score: 0.238 X-Spam-Level: X-Archive-Number: 200601/161 X-Sequence-Number: 16639 Hi, If the join is to a primary key or notnull unique column(s), then inner join is also ok. But of course left join is the simpler case. An example: create table person (id serial primary key, name varchar not null); create table pet (id serial primary key, name varchar not null, person_id int not null references person(id)); create view v_pet_person as select pet.id as pet_id, pet.name as pet_name, person_id as person_id, person.name as person_name from pet join person (pet.person_id=3Dperson.id); At this point we know that optimization may be possible because of the primary key on person. The optimization depends on the primary key constraint. Kindof internal dependency. We can find out that which "from-element" is a given field's source as far they are simple references. This can be stored. Then query the view: select pet_name, person_id from v_pet_person where person_id=3D2; In this case we don't need the join. These queries are usually dynamically generated, the selection list and the where condition is the dynamic part. Best Regards, Otto 2006/1/12, Scott Marlowe : > On Thu, 2006-01-12 at 11:00, Ott=F3 Havasv=F6lgyi wrote: > > Hi, > > > > I think it would be sufficient only for views. In other cases the > > programmer can optimize himself. But a view can be a join of other > > tables, and it is not sure that all of them are always needed. It all > > depends on what I select from the view. > > The idea that you could throw away joins only works for outer joins. > I.e. if you did: > > select a.x, a.y, a.z from a left join b (on a.id=3Db.aid) > > then you could throw away the join to b. But if it was a regular inner > join then you couldn't know whether or not you needed to join to b > without actually joining to b... > From pgsql-performance-owner@postgresql.org Sat Jan 14 01:50:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7A5559DC829 for ; Thu, 12 Jan 2006 15:16:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15514-01 for ; Thu, 12 Jan 2006 15:16:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from is.rice.edu (is.rice.edu [128.42.42.24]) by postgresql.org (Postfix) with ESMTP id 3331B9DC847 for ; Thu, 12 Jan 2006 15:16:19 -0400 (AST) Received: from scan2.mail.rice.edu (scan2.mail.rice.edu [128.42.59.161]) by is.rice.edu (Postfix) with ESMTP id E09F241878; Thu, 12 Jan 2006 13:16:19 -0600 (CST) Received: from is.rice.edu ([128.42.42.24]) by scan2.mail.rice.edu (scan2.mail.rice.edu [128.42.59.161]) (amavisd-new, port 10024) with ESMTP id 25072-03; Thu, 12 Jan 2006 13:16:19 -0600 (CST) Received: by is.rice.edu (Postfix, from userid 18612) id 2B079418DC; Thu, 12 Jan 2006 13:16:19 -0600 (CST) Date: Thu, 12 Jan 2006 13:16:18 -0600 From: Kenneth Marshall To: Simon Riggs Cc: Tom Lane , Jean-Philippe C?t? , pgsql-performance@postgresql.org Subject: Re: Extremely irregular query performance Message-ID: <20060112191618.GB81@it.is.rice.edu> References: <20060111234149.05DEA384099@crt0.crt.umontreal.ca> <480.1137036235@sss.pgh.pa.us> <1137059321.3180.34.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1137059321.3180.34.camel@localhost.localdomain> User-Agent: Mutt/1.4.2i X-Virus-Scanned: by amavis-2.2.1 at scan2.mail.rice.edu X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.03 required=5 tests=[AWL=0.030] X-Spam-Score: 0.03 X-Spam-Level: X-Archive-Number: 200601/181 X-Sequence-Number: 16659 On Thu, Jan 12, 2006 at 09:48:41AM +0000, Simon Riggs wrote: > On Wed, 2006-01-11 at 22:23 -0500, Tom Lane wrote: > > =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= writes: > > > Thanks a lot for this info, I was indeed exceeding the genetic > > > optimizer's threshold. Now that it is turned off, I get > > > a very stable response time of 435ms (more or less 5ms) for > > > the same query. It is about three times slower than the best > > > I got with the genetic optimizer on, but the overall average > > > is much lower. > > > > Hmm. It would be interesting to use EXPLAIN ANALYZE to confirm that the > > plan found this way is the same as the best plan found by GEQO, and > > the extra couple hundred msec is the price you pay for the exhaustive > > plan search. If GEQO is managing to find a plan better than the regular > > planner then we need to look into why ... > > It seems worth noting in the EXPLAIN whether GEQO has been used to find > the plan, possibly along with other factors influencing the plan such as > enable_* settings. > Is it the plan that is different in the fastest case with GEQO or is it the time needed to plan that is causing the GEQO to beat the exhaustive search? Ken From pgsql-performance-owner@postgresql.org Thu Jan 12 16:16:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5D0D29DCE0C for ; Thu, 12 Jan 2006 16:16:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62699-08 for ; Thu, 12 Jan 2006 16:16:04 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.197]) by postgresql.org (Postfix) with ESMTP id DA90D9DCE09 for ; Thu, 12 Jan 2006 16:16:01 -0400 (AST) Received: by wproxy.gmail.com with SMTP id i28so529754wra for ; Thu, 12 Jan 2006 12:16:03 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=AkLG99mw+iVMlqg7lDjPv22IN7QJpK1uzb4itQY5Hokkmt8DZqWDltdSF+Osa9Vo4GUz2VzxpcIn+KDieTDbOXbLQB0WZbVdbif19om7PH4TzCAMQZ2njA3TftlPB5/oGgqHBdP1yFpKyjNnEzxjPCK5I2Z55kdyJpNNzO/q4N4= Received: by 10.54.112.5 with SMTP id k5mr2901659wrc; Thu, 12 Jan 2006 12:16:00 -0800 (PST) Received: by 10.54.93.8 with HTTP; Thu, 12 Jan 2006 12:16:00 -0800 (PST) Message-ID: Date: Thu, 12 Jan 2006 15:16:00 -0500 From: Jaime Casanova To: Jamal Ghaffour Subject: Re: Please Help: PostgreSQL performance Optimization Cc: pgsql-performance@postgresql.org In-Reply-To: <43C66D67.1000502@elios-informatique.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <43C66742.9060104@elios-informatique.fr> <43C66D67.1000502@elios-informatique.fr> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.086 required=5 tests=[AWL=0.086] X-Spam-Score: 0.086 X-Spam-Level: X-Archive-Number: 200601/163 X-Sequence-Number: 16641 On 1/12/06, Jamal Ghaffour wrote: > Jamal Ghaffour a =E9crit : > Hi, I'm working on a project, whose implementation deals with PostgreSQL. A > brief description of our application is given below. I'm running version > 8.0 on a dedicated server 1Gb of RAM. my database isn't complex, it > contains just 2 simple tables. CREATE TABLE cookies ( domain varchar(50) > NOT NULL, path varchar(50) NOT NULL, name varchar(50) NOT NULL, > principalid varchar(50) NOT NULL, host text NOT NULL, value text NOT > NULL, secure bool NOT NULL, timestamp timestamp with time zone NOT NULL > DEFAULT CURRENT_TIMESTAMP+TIME '04:00:00', PRIMARY KEY > (domain,path,name,principalid) ) CREATE TABLE liberty ( principalid > varchar(50) NOT NULL, requestid varchar(50) NOT NULL, spassertionurl text > NOT NULL, libertyversion varchar(50) NOT NULL, relaystate varchar(50) NOT > NULL, PRIMARY KEY (principalid) ) I'm developping an application that uses > the libpqxx to execute psql queries on the database and have to execute 500 > requests at the same time. UPDATE cookies SET host=3D'ping.icap-elios.com', > value=3D '54E5B5491F27C0177083795F2E09162D', secure=3DFALSE, > timestamp=3DCURRENT_TIMESTAMP+INTERVAL '14400 SECOND' WHERE > domain=3D'ping.icap-elios.com' AND path=3D'/tfs' AND > principalid=3D'192.168.8.219' AND name=3D'jsessionid' SELECT path, upper(name) > AS name, value FROM cookies WHERE timestamp principalid=3D'192.168.8.219' AND secure=3DFALSE AND > (domain=3D'ping.icap-elios.com' OR domain=3D'.icap-elios.com') I have to notify > that the performance of is extremely variable and irregular. I can also see > that the server process uses almost 100% of a CPU. I'm using the default > configuration file, and i m asking if i have to change some paramters to > have a good performance. Any help would be greatly appreciated. Thanks, > Hi, > > There are some results that can give you concrete idea about my problem: > when i 'm launching my test that executes in loop manner the SELECT and > UPDATE queries described above, i'm obtaining this results: > > UPDATE Time execution :0s: 5225 us > SELECT Time execution :0s: 6908 us > > 5 minutes Later: > > UPDATE Time execution :0s: 6125 us > SELECT Time execution :0s: 10928 us > > 5 minutes Later: > > UPDATE Time execution :0s: 5825 us > SELECT Time execution :0s: 14978 us > > As you can see , the time execution of the SELECT request is growing > relatively to time and not the UPDATE time execution. > I note that to stop the explosion of the Select time execution, i m usin= g > frequently the vaccum query on the cookies table. > Set the autovacuum parmaeter in the configuation file to on wasn't able= to > remplace the use of the vaccum command, and i don't know if this behaivou= r > is normal? > > Thanks, > Jamal > > please execute EXPLAIN ANALYZE and show the results, is the only way to know what's happening -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;) From pgsql-performance-owner@postgresql.org Thu Jan 12 16:14:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 467D49DCDE6 for ; Thu, 12 Jan 2006 16:13:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81464-02 for ; Thu, 12 Jan 2006 16:13:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from crt0.crt.umontreal.ca (crt0.CRT.UMontreal.CA [132.204.100.27]) by postgresql.org (Postfix) with ESMTP id B60269DCB90 for ; Thu, 12 Jan 2006 16:13:54 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 50C42384067; Thu, 12 Jan 2006 15:13:55 -0500 (EST) Received: from crt0.crt.umontreal.ca ([127.0.0.1]) by localhost (crt0.crt.umontreal.ca [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 20526-02-43; Thu, 12 Jan 2006 15:13:53 -0500 (EST) Received: from Spoke01 (unknown [10.100.3.7]) by crt0.crt.umontreal.ca (Postfix) with ESMTP id 5C39138409A; Thu, 12 Jan 2006 15:13:53 -0500 (EST) From: =?us-ascii?Q?Jean-Philippe_Cote?= To: "'Kenneth Marshall'" , "'Simon Riggs'" Cc: Subject: Re: Extremely irregular query performance Date: Thu, 12 Jan 2006 15:23:14 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 In-Reply-To: <20060112191618.GB81@it.is.rice.edu> Thread-Index: AcYXrKvAExiJhZ6tRsmWsPX/79zinQACIKKQ Message-Id: <20060112201353.5C39138409A@crt0.crt.umontreal.ca> X-Virus-Scanned: amavisd-new at crt.umontreal.ca X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068, FROM_EXCESS_QP=0] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/162 X-Sequence-Number: 16640 Can I actully know whether a given plan is excuted with GEQO on ? In other words, if I launch 'explain ', I'll get a given plan, but if I re-launch the (withtout the 'explain' keyword), could I get a different plan given that GEQO induces some randomness ? >Is it the plan that is different in the fastest case with GEQO or is it >the time needed to plan that is causing the GEQO to beat the exhaustive >search? From pgsql-performance-owner@postgresql.org Sat Jan 14 01:50:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7852A9DC995 for ; Thu, 12 Jan 2006 17:05:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12010-04 for ; Thu, 12 Jan 2006 17:05:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from is.rice.edu (is.rice.edu [128.42.42.24]) by postgresql.org (Postfix) with ESMTP id 056E49DC81A for ; Thu, 12 Jan 2006 17:05:53 -0400 (AST) Received: from scan2.mail.rice.edu (scan2.mail.rice.edu [128.42.59.161]) by is.rice.edu (Postfix) with ESMTP id 0ABD3418B0; Thu, 12 Jan 2006 15:05:55 -0600 (CST) Received: from is.rice.edu ([128.42.42.24]) by scan2.mail.rice.edu (scan2.mail.rice.edu [128.42.59.161]) (amavisd-new, port 10024) with ESMTP id 26620-06; Thu, 12 Jan 2006 15:05:54 -0600 (CST) Received: by is.rice.edu (Postfix, from userid 18612) id 555D741878; Thu, 12 Jan 2006 15:05:50 -0600 (CST) Date: Thu, 12 Jan 2006 15:05:50 -0600 From: Kenneth Marshall To: Jean-Philippe Cote Cc: 'Simon Riggs' , pgsql-performance@postgresql.org Subject: Re: Extremely irregular query performance Message-ID: <20060112210550.GI81@it.is.rice.edu> References: <20060112191618.GB81@it.is.rice.edu> <20060112201353.5C39138409A@crt0.crt.umontreal.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060112201353.5C39138409A@crt0.crt.umontreal.ca> User-Agent: Mutt/1.4.2i X-Virus-Scanned: by amavis-2.2.1 at scan2.mail.rice.edu X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.027 required=5 tests=[AWL=0.027] X-Spam-Score: 0.027 X-Spam-Level: X-Archive-Number: 200601/182 X-Sequence-Number: 16660 On Thu, Jan 12, 2006 at 03:23:14PM -0500, Jean-Philippe Cote wrote: > > > Can I actully know whether a given plan is excuted with GEQO on ? > In other words, if I launch 'explain ', I'll get a given plan, but if I re-launch > the (withtout the 'explain' keyword), could I get a different > plan given that GEQO induces some randomness ? > > >Is it the plan that is different in the fastest case with GEQO or is it > >the time needed to plan that is causing the GEQO to beat the exhaustive > >search? > GEQO will be used if the number of joins is over the GEQO limit in the configuration file. The GEQO process is an iterative random process to find an query plan. The EXPLAIN results are the plan for that query, but not neccessarily for subsequent runs. GEQO's advantage is a much faster plan time than the exhaustive search method normally used. If the resulting plan time is less than the exhaustive search plan time, for short queries you can have the GECO run more quickly than the exhaustive search result. Of course, if you PREPARE the query the plan time drops out. Ken From pgsql-performance-owner@postgresql.org Fri Jan 13 05:10:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F173A9DD624 for ; Fri, 13 Jan 2006 05:10:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54472-07 for ; Fri, 13 Jan 2006 05:10:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp10.clb.oleane.net (smtp10.clb.oleane.net [213.56.31.32]) by postgresql.org (Postfix) with ESMTP id 0111A9DD5F2 for ; Fri, 13 Jan 2006 05:10:48 -0400 (AST) Received: from smtp10.clb.oleane.net (localhost [127.0.0.1]) by smtp10.clb.oleane.net (antivirus) with ESMTP id k0D9AkN9007244; Fri, 13 Jan 2006 10:10:46 +0100 Received: from [192.168.8.219] ([62.160.127.238]) (authenticated) by smtp10.clb.oleane.net with ESMTP id k0D9Aj6S007141; Fri, 13 Jan 2006 10:10:45 +0100 Message-ID: <43C76F41.1030902@elios-informatique.fr> Date: Fri, 13 Jan 2006 10:13:37 +0100 From: Jamal Ghaffour User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: fr, en MIME-Version: 1.0 To: andrew@pillette.com CC: pgsql-performance@postgresql.org, systemguards@gmail.com Subject: Re: Please Help: PostgreSQL performance Optimization References: <43C66742.9060104@elios-informatique.fr> <43C66D67.1000502@elios-informatique.fr> <43C6A31F.3010007@pillette.com> In-Reply-To: <43C6A31F.3010007@pillette.com> Content-Type: multipart/mixed; boundary="------------080302050007030004030709" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/164 X-Sequence-Number: 16642 This is a multi-part message in MIME format. --------------080302050007030004030709 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Andrew Lazarus a �crit : > Jamal Ghaffour wrote: > >>> CREATE TABLE cookies ( >>> domain varchar(50) NOT NULL, >>> path varchar(50) NOT NULL, >>> name varchar(50) NOT NULL, >>> principalid varchar(50) NOT NULL, >>> host text NOT NULL, >>> value text NOT NULL, >>> secure bool NOT NULL, >>> timestamp timestamp with time zone NOT NULL DEFAULT >>> CURRENT_TIMESTAMP+TIME '04:00:00', >>> PRIMARY KEY (domain,path,name,principalid) >>> ) >> > [snip] > >>> SELECT path, upper(name) AS name, value FROM cookies WHERE >>> timestamp>> secure=FALSE AND (domain='ping.icap-elios.com' OR >>> domain='.icap-elios.com') >> > > I think the problem here is that the column order in the index doesn't > match the columns used in the WHERE clause criteria. Try adding an > index on (domain,principalid) or (domain,principalid,timestamp). If > these are your only queries, you can get the same effect by > re-ordering the columns in the table so that this is the column order > used by the primary key and its implicit index. > > You should check up on EXPLAIN and EXPLAIN ANALYZE to help you debug > slow queries. Hi, I created an index into the cookies table CREATE INDEX index_cookies_select ON cookies (domain, principalid, timestamp); and execute my UPDATE and select queries: 1 - The first select quey give the following results: icap=# EXPLAIN ANALYZE SELECT path, upper(name) AS name, value FROM cookies WHERE timestamp>CURRENT_TIMESTAMP AND principalid='192.168.8.219' AND secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com'); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Bitmap Heap Scan on cookies (cost=4.02..8.04 rows=1 width=268) (actual time=0.107..0.108 rows=1 loops=1) Recheck Cond: (((("domain")::text = 'ping.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) OR ((("domain")::text = '.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now()))) Filter: (("timestamp" > now()) AND (NOT secure)) -> BitmapOr (cost=4.02..4.02 rows=1 width=0) (actual time=0.091..0.091 rows=0 loops=1) -> Bitmap Index Scan on index_cookies_select (cost=0.00..2.01 rows=1 width=0) (actual time=0.077..0.077 rows=1 loops=1) Index Cond: ((("domain")::text = 'ping.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) -> Bitmap Index Scan on index_cookies_select (cost=0.00..2.01 rows=1 width=0) (actual time=0.012..0.012 rows=0 loops=1) Index Cond: ((("domain")::text = '.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) Total runtime: 0.155 ms (9 rows) 2- After that, i launch my test code that execute continuely the UPDATE and select queries (in loop manner), after 1 minute of continuous execution, i obtain the following result: icap=# EXPLAIN ANALYZE SELECT path, upper(name) AS name, value FROM cookies WHERE timestamp>CURRENT_TIMESTAMP AND principalid='192.168.8.219' AND secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com'); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Bitmap Heap Scan on cookies (cost=4.02..8.04 rows=1 width=268) (actual time=39.545..39.549 rows=1 loops=1) Recheck Cond: (((("domain")::text = 'ping.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) OR ((("domain")::text = '.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now()))) Filter: (("timestamp" > now()) AND (NOT secure)) -> BitmapOr (cost=4.02..4.02 rows=1 width=0) (actual time=39.512..39.512 rows=0 loops=1) -> Bitmap Index Scan on index_cookies_select (cost=0.00..2.01 rows=1 width=0) (actual time=39.471..39.471 rows=2 loops=1) Index Cond: ((("domain")::text = 'ping.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) -> Bitmap Index Scan on index_cookies_select (cost=0.00..2.01 rows=1 width=0) (actual time=0.036..0.036 rows=0 loops=1) Index Cond: ((("domain")::text = '.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) Total runtime: 39.616 ms (9 rows) I notice that the time execution increases significantly. and i need the vacuum query to obtain normal time execution: 3- After vacuum execution: icap=# vacuum cookies; VACUUM icap=# EXPLAIN ANALYZE SELECT path, upper(name) AS name, value FROM cookies WHERE timestamp>CURRENT_TIMESTAMP AND principalid='192.168.8.219' AND secure=FALSE AND (domain='ping.icap-elios.com' OR domain='.icap-elios.com'); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Bitmap Heap Scan on cookies (cost=4.02..8.04 rows=1 width=268) (actual time=0.111..0.112 rows=1 loops=1) Recheck Cond: (((("domain")::text = 'ping.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) OR ((("domain")::text = '.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now()))) Filter: (("timestamp" > now()) AND (NOT secure)) -> BitmapOr (cost=4.02..4.02 rows=1 width=0) (actual time=0.095..0.095 rows=0 loops=1) -> Bitmap Index Scan on index_cookies_select (cost=0.00..2.01 rows=1 width=0) (actual time=0.081..0.081 rows=1 loops=1) Index Cond: ((("domain")::text = 'ping.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) -> Bitmap Index Scan on index_cookies_select (cost=0.00..2.01 rows=1 width=0) (actual time=0.012..0.012 rows=0 loops=1) Index Cond: ((("domain")::text = '.icap-elios.com'::text) AND ((principalid)::text = '192.168.8.219'::text) AND ("timestamp" > now())) Total runtime: 0.159 ms (9 rows) Thanks, Jamal --------------080302050007030004030709 Content-Type: text/x-vcard; charset=utf-8; name="Jamal.Ghaffour.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Jamal.Ghaffour.vcf" begin:vcard fn:Jamal Ghaffour n:Ghaffour;Jamal org:ELIOS Informatique adr;quoted-printable:;;1, sq de ch=C3=AAne Germain,;CESSON SEVIGNE;;35510;FRANCE email;internet:Jamal.Ghaffour@elios-informatique.fr tel;work:(+33) 2.99.63.85.30 tel;fax:(+33) 2.99.63.85.93 tel;home:(+33) 2 99 36 73 96 tel;cell:(+33) 6.21.85.15.91 url:http://www.elios-informatique.fr version:2.1 end:vcard --------------080302050007030004030709-- From pgsql-performance-owner@postgresql.org Fri Jan 13 13:41:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7A7F99DD737 for ; Fri, 13 Jan 2006 13:41:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52362-03 for ; Fri, 13 Jan 2006 13:41:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from frank.wiles.org (frank.wiles.org [24.124.39.75]) by postgresql.org (Postfix) with ESMTP id A38EE9DCC30 for ; Fri, 13 Jan 2006 13:40:57 -0400 (AST) Received: from kungfu (frank.wiles.org [127.0.0.1]) by frank.wiles.org (8.13.1/8.13.1) with SMTP id k0DHeowg001745; Fri, 13 Jan 2006 11:40:50 -0600 Date: Fri, 13 Jan 2006 11:41:26 -0600 From: Frank Wiles To: Jamal Ghaffour Cc: pgsql-performance@postgresql.org Subject: Re: Please Help: PostgreSQL performance Optimization Message-Id: <20060113114126.747383fb.frank@wiles.org> In-Reply-To: <43C5A38A.8090208@elios-informatique.fr> References: <43C5A38A.8090208@elios-informatique.fr> X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.051 required=5 tests=[AWL=0.051] X-Spam-Score: 0.051 X-Spam-Level: X-Archive-Number: 200601/165 X-Sequence-Number: 16643 On Thu, 12 Jan 2006 01:32:10 +0100 Jamal Ghaffour wrote: > I'm using the default configuration file, and i m asking if i have to > change some paramters to have a good performance. In general the answer is yes. The default is a pretty good best guess at what sorts of values work for your "typical system", but if you run into performance problems the config file is where you should look first, provided you've done the simple things like adding good indexes, vacumm analyze, etc. You'll want to consult the following various documentation out there to help your properly tune your configuration: http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html http://www.powerpostgresql.com/Docs http://www.powerpostgresql.com/PerfList http://www.revsys.com/writings/postgresql-performance.html Hopefully these will help you understand how to set your configuration values. --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From pgsql-performance-owner@postgresql.org Fri Jan 13 16:10:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 64AB19DD738 for ; Fri, 13 Jan 2006 16:10:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78666-10-2 for ; Fri, 13 Jan 2006 16:10:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms040pub.verizon.net (vms040pub.verizon.net [206.46.252.40]) by postgresql.org (Postfix) with ESMTP id 69F9E9DD732 for ; Fri, 13 Jan 2006 16:10:27 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms040.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IT10085HS11QDO4@vms040.mailsrvcs.net> for pgsql-performance@postgresql.org; Fri, 13 Jan 2006 14:10:14 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id 987CD6061604 for ; Fri, 13 Jan 2006 15:10:12 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 13563-02-2 for ; Fri, 13 Jan 2006 15:10:11 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id E58BC6061601; Fri, 13 Jan 2006 15:10:11 -0500 (EST) Date: Fri, 13 Jan 2006 15:10:11 -0500 From: Michael Stone Subject: insert without oids To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060113201011.GI1408@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.103 required=5 tests=[AWL=0.103] X-Spam-Score: 0.103 X-Spam-Level: X-Archive-Number: 200601/166 X-Sequence-Number: 16644 OIDs seem to be on their way out, and most of the time you can get a more helpful result by using a serial primary key anyway, but I wonder if there's any extension to INSERT to help identify what unique id a newly-inserted key will get? Using OIDs the insert would return the OID of the inserted row, which could be useful if you then want to refer to that row in a subsequent operation. You could get the same result by manually retrieving the next number in the sequence and using that value in the insert, but at the cost of additional DB operations. Are there plans on updating the insert API for the post-OID world? Mike Stone From pgsql-performance-owner@postgresql.org Fri Jan 13 16:20:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 90ABD9DC84B for ; Fri, 13 Jan 2006 16:20:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78677-08 for ; Fri, 13 Jan 2006 16:20:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id B889B9DD74F for ; Fri, 13 Jan 2006 16:20:02 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0DKJx6a011767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Jan 2006 13:20:01 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0DKJxkA099123 for ; Fri, 13 Jan 2006 13:19:59 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0DKJxKs099122 for pgsql-performance@postgresql.org; Fri, 13 Jan 2006 13:19:59 -0700 (MST) (envelope-from mfuhr) Date: Fri, 13 Jan 2006 13:19:59 -0700 From: Michael Fuhr To: pgsql-performance@postgresql.org Subject: Re: insert without oids Message-ID: <20060113201958.GA99082@winnie.fuhr.org> References: <20060113201011.GI1408@mathom.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060113201011.GI1408@mathom.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.097 required=5 tests=[AWL=0.097] X-Spam-Score: 0.097 X-Spam-Level: X-Archive-Number: 200601/167 X-Sequence-Number: 16645 On Fri, Jan 13, 2006 at 03:10:11PM -0500, Michael Stone wrote: > Are there plans on updating the insert API for the post-OID world? Are you looking for this TODO item? * Allow INSERT/UPDATE ... RETURNING new.col or old.col This is useful for returning the auto-generated key for an INSERT. One complication is how to handle rules that run as part of the insert. http://www.postgresql.org/docs/faqs.TODO.html -- Michael Fuhr From pgsql-performance-owner@postgresql.org Fri Jan 13 17:28:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8A28C9DD717 for ; Fri, 13 Jan 2006 17:28:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91921-08 for ; Fri, 13 Jan 2006 17:28:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mailbox.samurai.com (mailbox.samurai.com [205.207.28.82]) by postgresql.org (Postfix) with ESMTP id 004499DD75C for ; Fri, 13 Jan 2006 17:28:27 -0400 (AST) Received: from localhost (mailbox.samurai.com [205.207.28.82]) by mailbox.samurai.com (Postfix) with ESMTP id 9A9A223945B; Fri, 13 Jan 2006 16:28:29 -0500 (EST) Received: from mailbox.samurai.com ([205.207.28.82]) by localhost (mailbox.samurai.com [205.207.28.82]) (amavisd-new, port 10024) with LMTP id 52186-01-4; Fri, 13 Jan 2006 16:28:28 -0500 (EST) Received: from [192.168.1.104] (d38-160-188.home1.cgocable.net [72.38.160.188]) by mailbox.samurai.com (Postfix) with ESMTP id 304B7239457; Fri, 13 Jan 2006 16:28:28 -0500 (EST) Subject: Re: insert without oids From: Neil Conway To: Michael Stone Cc: pgsql-performance@postgresql.org In-Reply-To: <20060113201011.GI1408@mathom.us> References: <20060113201011.GI1408@mathom.us> Content-Type: text/plain Date: Fri, 13 Jan 2006 16:29:15 -0500 Message-Id: <1137187755.2509.6.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailbox.samurai.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.124 required=5 tests=[AWL=0.124] X-Spam-Score: 0.124 X-Spam-Level: X-Archive-Number: 200601/168 X-Sequence-Number: 16646 On Fri, 2006-01-13 at 15:10 -0500, Michael Stone wrote: > OIDs seem to be on their way out, and most of the time you can get a > more helpful result by using a serial primary key anyway, but I wonder > if there's any extension to INSERT to help identify what unique id a > newly-inserted key will get? Using OIDs the insert would return the OID > of the inserted row, which could be useful if you then want to refer to > that row in a subsequent operation. You could get the same result by > manually retrieving the next number in the sequence and using that value > in the insert, but at the cost of additional DB operations. There's really no additional operations required: INSERT INTO t1 VALUES (...); INSERT INTO t2 VALUES (currval('t1_id_seq'), ...); You need a separate SELECT if you want to use the generated sequence value outside the database, although the INSERT ... RETURNING extension will avoid that (there's a patch implementing this, although it is not yet in CVS). -Neil From pgsql-performance-owner@postgresql.org Fri Jan 13 18:48:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A33509DC942 for ; Fri, 13 Jan 2006 18:48:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06973-06 for ; Fri, 13 Jan 2006 18:48:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by postgresql.org (Postfix) with ESMTP id 2F8DA9DC862 for ; Fri, 13 Jan 2006 18:48:04 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IT1003IQZC5MHDC@vms046.mailsrvcs.net> for pgsql-performance@postgresql.org; Fri, 13 Jan 2006 16:48:05 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id 45E646061604 for ; Fri, 13 Jan 2006 17:48:04 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 14228-01 for ; Fri, 13 Jan 2006 17:48:02 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 917926061601; Fri, 13 Jan 2006 17:48:01 -0500 (EST) Date: Fri, 13 Jan 2006 17:48:01 -0500 From: Michael Stone Subject: Re: insert without oids In-reply-to: <1137187755.2509.6.camel@localhost.localdomain> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060113224800.GJ1408@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us References: <20060113201011.GI1408@mathom.us> <1137187755.2509.6.camel@localhost.localdomain> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.105 required=5 tests=[AWL=0.105] X-Spam-Score: 0.105 X-Spam-Level: X-Archive-Number: 200601/169 X-Sequence-Number: 16647 On Fri, Jan 13, 2006 at 04:29:15PM -0500, Neil Conway wrote: >There's really no additional operations required: >INSERT INTO t2 VALUES (currval('t1_id_seq'), ...); >You need a separate SELECT if you want to use the generated sequence >value outside the database, That would, of course, be the goal. IOW, if you have a table which has data which is unique only for the serial column, the old syntax provided a way to refer to the newly inserted row uniquely without any additional operations. >although the INSERT ... RETURNING extension will avoid that That sounds promising. I'll have to put the TODO list on my todo list. :) Mike Stone From pgsql-performance-owner@postgresql.org Fri Jan 13 19:34:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CC2A89DCBDF for ; Fri, 13 Jan 2006 19:34:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20995-03 for ; Fri, 13 Jan 2006 19:34:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 224DB9DCB75 for ; Fri, 13 Jan 2006 19:34:51 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id D295D3983F; Fri, 13 Jan 2006 17:34:54 -0600 (CST) Date: Fri, 13 Jan 2006 17:34:54 -0600 From: "Jim C. Nasby" To: Bendik Rognlien Johansen Cc: pgsql-performance@postgresql.org Subject: Re: Slow query with joins Message-ID: <20060113233454.GM9017@pervasive.com> References: <13028.1136994347@sss.pgh.pa.us> <65451320-7D72-4544-A8E8-CD93212E4A5D@gmail.com> <20060111202345.GC63175@pervasive.com> <850AD6F9-08BD-4EF2-A549-407FD87C7974@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <850AD6F9-08BD-4EF2-A549-407FD87C7974@gmail.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/170 X-Sequence-Number: 16648 On Wed, Jan 11, 2006 at 10:30:58PM +0100, Bendik Rognlien Johansen wrote: > The sort is definitively the culprit. When I removed it the query was > instant. I tried setting work_mem = 131072 but it did not seem to > help. I really don't understand this :-( Any other ideas? What's explain analyze show with the sort in? -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 13 20:06:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3B3299DC81B for ; Fri, 13 Jan 2006 20:06:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26349-07 for ; Fri, 13 Jan 2006 20:06:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id D87BE9DC80C for ; Fri, 13 Jan 2006 20:06:52 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id A1F5A3983E; Fri, 13 Jan 2006 18:06:40 -0600 (CST) Date: Fri, 13 Jan 2006 18:06:40 -0600 From: "Jim C. Nasby" To: Tom Lane Cc: Mark Liberman , pgsql-performance@postgresql.org Subject: Re: Stable function being evaluated more than once in a single query Message-ID: <20060114000640.GN9017@pervasive.com> References: <200601111641.20627.mliberman@mixedsignals.com> <935.1137040403@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <935.1137040403@sss.pgh.pa.us> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/171 X-Sequence-Number: 16649 On Wed, Jan 11, 2006 at 11:33:23PM -0500, Tom Lane wrote: > Mark Liberman writes: > > I've got a set-returning function, defined as STABLE, that I reference twice > > within a single query, yet appears to be evaluated via two seperate function > > scans. > > There is no guarantee, express or implied, that this won't be the case. > > (Seems like we just discussed this a couple days ago...) Well, from 32.6: "This category allows the optimizer to optimize away multiple calls of the function within a single query." That could certainly be read as indicating that if the function is used twice in one query it could be optimized to one call. Is the issue that the optimizer won't combine two function calls (ie: SELECT foo(..) ... WHERE foo(..)), or is it that sometimes it won't make the optimization (maybe depending on the query plan, for example)? -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 13 20:18:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 02A979DC862 for ; Fri, 13 Jan 2006 20:18:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29218-02 for ; Fri, 13 Jan 2006 20:17:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id F09389DC80C for ; Fri, 13 Jan 2006 20:17:54 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 1C2203983E; Fri, 13 Jan 2006 18:17:58 -0600 (CST) Date: Fri, 13 Jan 2006 18:17:58 -0600 From: "Jim C. Nasby" To: Alessandro Baretta Cc: Ott? Havasv?lgyi , pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away Message-ID: <20060114001758.GO9017@pervasive.com> References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43C64CFB.9030504@barettadeit.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/172 X-Sequence-Number: 16650 On Thu, Jan 12, 2006 at 01:35:07PM +0100, Alessandro Baretta wrote: > Ott? Havasv?lgyi wrote: > >Hi all, > > > >Is PostgreSQL able to throw unnecessary joins? > >For example I have two tables, and I join then with their primary keys, > >say type of bigint . In this case if I don't reference to one of the > >tables anywhere except the join condition, then the join can be eliminated. > >Or if I do a "table1 left join table2 (table1.referer=table2.id)" (N : > >1 relationship), and I don't reference table2 anywhere else, then it is > >unnecessary. > > It cannot possibly remove "unnecessary joins", simply because the join > influences whether a tuple in the referenced table gets selected and how > many times. It can remove them if it's an appropriate outer join, or if there is appropriate RI that proves that the join won't change what data is selected. A really common example of this is creating views that pull in tables that have text names to go with id's, ie: CREATE TABLE bug_status( bug_status_id serial PRIMARY KEY , bug_status_name text NOT NULL UNIQUE ); CREATE TABLE bug( ... , bug_status_id int REFERENCES bug_status(bug_status_id) ); CREATE VIEW bug_v AS SELECT b.*, bs.bug_status_name FROM bug b JOIN bug_status NATURAL ; If you have a bunch of cases like that and start building views on views it's very easy to end up in situations where you don't have any need of bug_status_name at all. And because of the RI, you know that removing the join can't possibly change the bug.* portion of that view. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 13 20:22:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2E3F19DC842 for ; Fri, 13 Jan 2006 20:22:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29851-03 for ; Fri, 13 Jan 2006 20:22:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id C5A5D9DC838 for ; Fri, 13 Jan 2006 20:22:02 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id A89D23983D; Fri, 13 Jan 2006 18:22:05 -0600 (CST) Date: Fri, 13 Jan 2006 18:22:05 -0600 From: "Jim C. Nasby" To: Ott? Havasv?lgyi Cc: pgsql-performance@postgresql.org Subject: Re: Throwing unnecessary joins away Message-ID: <20060114002205.GP9017@pervasive.com> References: <34608c0c0601120418n1af567b9n@mail.gmail.com> <43C64CFB.9030504@barettadeit.com> <34608c0c0601120541wd910da3s@mail.gmail.com> <5269.1137081233@sss.pgh.pa.us> <34608c0c0601120900l7d26073dp@mail.gmail.com> <1137085382.3959.16.camel@state.g2switchworks.com> <34608c0c0601121051r52c707f6l@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34608c0c0601121051r52c707f6l@mail.gmail.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/173 X-Sequence-Number: 16651 On Thu, Jan 12, 2006 at 07:51:22PM +0100, Ott? Havasv?lgyi wrote: > Hi, > > If the join is to a primary key or notnull unique column(s), then > inner join is also ok. But of course left join is the simpler case. > An example: Actually, you need both the unique/pk constraint, and RI (a fact I missed in the email I just sent). Nullability is another consideration as well. But there certainly are some pretty common cases that can be optimized for. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 13 20:27:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2B20E9DC838 for ; Fri, 13 Jan 2006 20:27:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28073-09 for ; Fri, 13 Jan 2006 20:27:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8F0859DC80C for ; Fri, 13 Jan 2006 20:27:27 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0E0RSv0016008; Fri, 13 Jan 2006 19:27:28 -0500 (EST) To: "Jim C. Nasby" cc: Mark Liberman , pgsql-performance@postgresql.org Subject: Re: Stable function being evaluated more than once in a single query In-reply-to: <20060114000640.GN9017@pervasive.com> References: <200601111641.20627.mliberman@mixedsignals.com> <935.1137040403@sss.pgh.pa.us> <20060114000640.GN9017@pervasive.com> Comments: In-reply-to "Jim C. Nasby" message dated "Fri, 13 Jan 2006 18:06:40 -0600" Date: Fri, 13 Jan 2006 19:27:28 -0500 Message-ID: <16007.1137198448@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/174 X-Sequence-Number: 16652 "Jim C. Nasby" writes: > Is the issue that the optimizer won't combine two function calls (ie: > SELECT foo(..) ... WHERE foo(..)), or is it that sometimes it won't make > the optimization (maybe depending on the query plan, for example)? What the STABLE category actually does is give the planner permission to use the function within an indexscan qualification, eg, WHERE indexed_column = f(42) Since an indexscan involves evaluating the comparison expression just once and using its value to search the index, this would be incorrect if the expression's value might change from row to row. (For VOLATILE functions, we assume that the correct behavior is the naive SQL semantics of actually computing the WHERE clause at each candidate row.) There is no function cache and no checking for duplicate expressions. I think we do check for duplicate aggregate expressions, but not anything else. regards, tom lane From pgsql-docs-owner@postgresql.org Fri Jan 13 20:56:28 2006 X-Original-To: pgsql-docs-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DAFC19DD775 for ; Fri, 13 Jan 2006 20:56:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34681-05 for ; Fri, 13 Jan 2006 20:56:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 15B929DD756 for ; Fri, 13 Jan 2006 20:56:21 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 5C7F83983D; Fri, 13 Jan 2006 18:56:24 -0600 (CST) Resent-From: jnasby@pervasive.com Resent-Date: Fri, 13 Jan 2006 18:56:24 -0600 Resent-Message-ID: <20060114005624.GV9017@pervasive.com> Resent-To: pgsql-docs@postgresql.org X-Original-To: decibel@decibel.org Received: from mx2.hub.org (mx2.hub.org [200.46.204.254]) by noel.decibel.org (Postfix) with ESMTP id DCBE439834 for ; Fri, 13 Jan 2006 18:44:24 -0600 (CST) Received: from postgresql.org (postgresql.org [200.46.204.71]) by mx2.hub.org (Postfix) with ESMTP id 2C6AE513079; Fri, 13 Jan 2006 20:44:19 -0400 (AST) X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 396D29DC838 for ; Fri, 13 Jan 2006 20:43:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32213-04 for ; Fri, 13 Jan 2006 20:43:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id B8ED09DC80C for ; Fri, 13 Jan 2006 20:43:44 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 0BC5E3983D; Fri, 13 Jan 2006 18:43:48 -0600 (CST) Date: Fri, 13 Jan 2006 18:43:48 -0600 From: "Jim C. Nasby" To: Tom Lane Cc: Mark Liberman , pgsql-performance@postgresql.org Subject: Re: [PERFORM] Stable function being evaluated more than once in a single query Message-ID: <20060114004348.GT9017@pervasive.com> References: <200601111641.20627.mliberman@mixedsignals.com> <935.1137040403@sss.pgh.pa.us> <20060114000640.GN9017@pervasive.com> <16007.1137198448@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16007.1137198448@sss.pgh.pa.us> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Mailing-List: pgsql-performance Precedence: bulk X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/22 X-Sequence-Number: 3412 Adding -docs... On Fri, Jan 13, 2006 at 07:27:28PM -0500, Tom Lane wrote: > "Jim C. Nasby" writes: > > Is the issue that the optimizer won't combine two function calls (ie: > > SELECT foo(..) ... WHERE foo(..)), or is it that sometimes it won't make > > the optimization (maybe depending on the query plan, for example)? > > What the STABLE category actually does is give the planner permission to > use the function within an indexscan qualification, eg, > WHERE indexed_column = f(42) > Since an indexscan involves evaluating the comparison expression just > once and using its value to search the index, this would be incorrect > if the expression's value might change from row to row. (For VOLATILE > functions, we assume that the correct behavior is the naive SQL > semantics of actually computing the WHERE clause at each candidate row.) > > There is no function cache and no checking for duplicate expressions. > I think we do check for duplicate aggregate expressions, but not > anything else. In that case I'd say that the sSTABLE section of 32.6 should be changed to read: A STABLE function cannot modify the database and is guaranteed to return the same results given the same arguments for all calls within a single surrounding query. This category gives the planner permission to use the function within an indexscan qualification. (Since an indexscan involves evaluating the comparison expression just once and using its value to search the index, this would be incorrect if the expression's value might change from row to row.) There is no function cache and no checking for duplicate expressions. I can provide a patch to that effect if it's easier... On a related note, would it be difficult to recognize multiple calls of the same function in one query? ISTM that would be a win for all but the most trivial of functions... -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 ---------------------------(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 From pgsql-performance-owner@postgresql.org Sat Jan 14 00:23:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BBC449DCAA3 for ; Sat, 14 Jan 2006 00:23:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76273-02 for ; Sat, 14 Jan 2006 00:23:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 2C3E89DC836 for ; Sat, 14 Jan 2006 00:23:38 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k0E4NX019385; Fri, 13 Jan 2006 23:23:33 -0500 (EST) From: Bruce Momjian Message-Id: <200601140423.k0E4NX019385@candle.pha.pa.us> Subject: Re: Extremely irregular query performance In-Reply-To: <20060112201353.5C39138409A@crt0.crt.umontreal.ca> To: Jean-Philippe Cote Date: Fri, 13 Jan 2006 23:23:33 -0500 (EST) CC: "'Kenneth Marshall'" , "'Simon Riggs'" , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/176 X-Sequence-Number: 16654 Jean-Philippe Cote wrote: > > > Can I actully know whether a given plan is excuted with GEQO on ? > In other words, if I launch 'explain ', I'll get a given plan, but if I re-launch > the (withtout the 'explain' keyword), could I get a different > plan given that GEQO induces some randomness ? > > >Is it the plan that is different in the fastest case with GEQO or is it > >the time needed to plan that is causing the GEQO to beat the exhaustive > >search? Yes, is it likely that when using GEQO you would get a different plan each time, so running it with and without EXPLAIN would produce different plans. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgsql-performance-owner@postgresql.org Sat Jan 14 08:13:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7F3DF9DCBDA for ; Sat, 14 Jan 2006 08:13:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55733-07 for ; Sat, 14 Jan 2006 08:13:10 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 76CC49DD7CA for ; Sat, 14 Jan 2006 08:13:05 -0400 (AST) Received: from gate.gau.hu (gate.gau.hu [192.188.242.65]) by svr4.postgresql.org (Postfix) with ESMTP id 428EA5AF094 for ; Sat, 14 Jan 2006 12:13:09 +0000 (GMT) Received: from gate.gau.hu (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id 24FAC380A748 for ; Sat, 14 Jan 2006 13:13:03 +0100 (CET) Received: from zeus.gau.hu (zeus.gau.hu [192.188.242.66]) by gate.gau.hu (Postfix) with ESMTP id 19791380A6D7 for ; Sat, 14 Jan 2006 13:13:02 +0100 (CET) Received: by zeus.gau.hu (Postfix, from userid 1004) id 4D34F43652A; Sat, 14 Jan 2006 13:13:02 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zeus.gau.hu (Postfix) with ESMTP id 3E10E400133 for ; Sat, 14 Jan 2006 13:13:02 +0100 (CET) Date: Sat, 14 Jan 2006 13:13:02 +0100 (CET) From: Tomka Gergely To: psql performance list Subject: big databases & hospitals Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-2 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/183 X-Sequence-Number: 16661 Hi! I need to write a few pages about Postgresql, to convince some suits. They have a few millions of records, on a few site, but they want to know the practical limits of Postgresql. So i need some information about the biggest (in storage space, in record number, in field number, and maybe table number) postgresql databases. Additionally, because this company develops hospital information systems, if someone knows about a medical institute, which uses Postgresql, and happy, please send me infomation. I only now subscribed to the advocacy list, and only started to browse the archives. Thanks. -- Tomka Gergely Tudom, anyu. Sapka, s�l, doksi. From pgsql-performance-owner@postgresql.org Sat Jan 14 10:54:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8C02D9DC994 for ; Sat, 14 Jan 2006 10:54:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84027-03 for ; Sat, 14 Jan 2006 10:54:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from segundonodo.nodo5.com (segundonodo.nodo5.com [66.98.170.56]) by postgresql.org (Postfix) with ESMTP id 3A6EB9DC884 for ; Sat, 14 Jan 2006 10:54:40 -0400 (AST) Received: from nediam.com.mx (localhost.localdomain [127.0.0.1]) by segundonodo.nodo5.com (8.12.11/8.12.11) with ESMTP id k0EEpkBp020361; Sat, 14 Jan 2006 08:51:46 -0600 From: "Javier Carlos" To: Tomka Gergely , psql performance list Subject: Re: big databases & hospitals Date: Sat, 14 Jan 2006 08:51:46 -0600 Message-Id: <20060114144855.M28832@nediam.com.mx> In-Reply-To: References: X-Mailer: nediam 1.81 20040914 X-OriginatingIP: 201.160.4.201 (nediam) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 X-Virus-Scanned: ClamAV 0.87.1/1241/Sat Jan 14 04:00:03 2006 on segundonodo.nodo5.com X-Virus-Status: Clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.048 required=5 tests=[AWL=0.048] X-Spam-Score: 0.048 X-Spam-Level: X-Archive-Number: 200601/184 X-Sequence-Number: 16662 This is the homepage of a Hospital/Healthservice Information System, I'm not so sure but I think it can use various DBMS, including PostgreSQL: http://www.care2x.org/ Regards, Javier On Sat, 14 Jan 2006 13:13:02 +0100 (CET), Tomka Gergely wrote > Hi! > > I need to write a few pages about Postgresql, to convince some > suits. They have a few millions of records, on a few site, but they > want to know the practical limits of Postgresql. So i need some > information about the biggest (in storage space, in record number, > in field number, and maybe table number) postgresql databases. > > Additionally, because this company develops hospital information > systems, if someone knows about a medical institute, which uses > Postgresql, and happy, please send me infomation. I only now > subscribed to the advocacy list, and only started to browse the archives. > > Thanks. > > -- > Tomka Gergely > Tudom, anyu. Sapka, s�l, doksi. > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match -- nediam.com.mx From pgsql-performance-owner@postgresql.org Sat Jan 14 14:38:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A28D29DD8D4 for ; Sat, 14 Jan 2006 14:38:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24232-02 for ; Sat, 14 Jan 2006 14:38:10 -0400 (AST) X-Greylist: delayed 01:00:28.317809 by SQLgrey- Received: from 1006.org (unknown [62.146.87.34]) by postgresql.org (Postfix) with ESMTP id 1B2119DCA38 for ; Sat, 14 Jan 2006 14:38:07 -0400 (AST) Received: from dell.home.lan (host73-55.pool8248.interbusiness.it [82.48.55.73]) (authenticated (0 bits)) by my.endian.it (8.11.6/8.11.6) with ESMTP id k0EIaQa16087; Sat, 14 Jan 2006 19:36:26 +0100 Subject: Re: big databases & hospitals From: Chris Mair To: Tomka Gergely Cc: psql performance list In-Reply-To: References: Content-Type: text/plain Date: Sat, 14 Jan 2006 18:37:32 +0100 Message-Id: <1137260252.3769.1.camel@dell.home.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-22) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/189 X-Sequence-Number: 16667 > Additionally, because this company develops hospital information systems, > if someone knows about a medical institute, which uses Postgresql, and > happy, please send me infomation. I only now subscribed to the advocacy > list, and only started to browse the archives. Hi, have you seen this case study: http://www.postgresql.org/about/casestudies/shannonmedical Bye, Chris. From pgsql-performance-owner@postgresql.org Sat Jan 14 13:55:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 564DF9DD8A9 for ; Sat, 14 Jan 2006 13:55:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15455-06 for ; Sat, 14 Jan 2006 13:55:52 -0400 (AST) X-Greylist: delayed 05:42:46.399518 by SQLgrey- Received: from gate.gau.hu (gate.gau.hu [192.188.242.65]) by postgresql.org (Postfix) with ESMTP id CE5DD9DD8B3 for ; Sat, 14 Jan 2006 13:55:50 -0400 (AST) Received: from gate.gau.hu (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id 765B6380A651; Sat, 14 Jan 2006 18:55:50 +0100 (CET) Received: from zeus.gau.hu (zeus.gau.hu [192.188.242.66]) by gate.gau.hu (Postfix) with ESMTP id 678B1380A632; Sat, 14 Jan 2006 18:55:50 +0100 (CET) Received: by zeus.gau.hu (Postfix, from userid 1004) id D2FD043652A; Sat, 14 Jan 2006 18:55:49 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zeus.gau.hu (Postfix) with ESMTP id C1FFE400133; Sat, 14 Jan 2006 18:55:49 +0100 (CET) Date: Sat, 14 Jan 2006 18:55:49 +0100 (CET) From: Tomka Gergely To: Chris Mair Cc: psql performance list Subject: Re: big databases & hospitals In-Reply-To: <1137260252.3769.1.camel@dell.home.lan> Message-ID: References: <1137260252.3769.1.camel@dell.home.lan> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-2 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/185 X-Sequence-Number: 16663 2006-01-14 ragyog� napj�n Chris Mair ezt �zente: > > > Additionally, because this company develops hospital information systems, > > if someone knows about a medical institute, which uses Postgresql, and > > happy, please send me infomation. I only now subscribed to the advocacy > > list, and only started to browse the archives. > > Hi, > > have you seen this case study: > http://www.postgresql.org/about/casestudies/shannonmedical Yes, and i found this page: http://advocacy.daemonnews.org/viewtopic.php?t=82 which is better than this small something on the postgres page. Quotes like this: "The FreeBSD/PostgreSQL combination is extremely flexible and robust." the sweetest music for us. But two example better than one, and i can't find technical details, the size of the data, by example. I can only guess the architecture (single node, single cpu, no HA or expensive RAID, because AFAIK FreeBSD in 2000 was not to good in this areas). Thanks, of course! -- Tomka Gergely Tudom, anyu. Sapka, s�l, doksi. From pgsql-performance-owner@postgresql.org Sat Jan 14 14:05:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7F7929DCA38 for ; Sat, 14 Jan 2006 14:05:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18215-04 for ; Sat, 14 Jan 2006 14:05:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 50DCE9DC9FA for ; Sat, 14 Jan 2006 14:05:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0EI5Zuf020666; Sat, 14 Jan 2006 13:05:35 -0500 (EST) To: vimal.gupta@gmail.com cc: pgsql-performance@postgresql.org Subject: Re: Hanging Query In-reply-to: <1136741670.479720.284080@f14g2000cwb.googlegroups.com> References: <1136741670.479720.284080@f14g2000cwb.googlegroups.com> Comments: In-reply-to vimal.gupta@gmail.com message dated "08 Jan 2006 09:34:30 -0800" Date: Sat, 14 Jan 2006 13:05:35 -0500 Message-ID: <20665.1137261935@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/186 X-Sequence-Number: 16664 vimal.gupta@gmail.com writes: > We have to inserts a records(15000- 20000) into a table which also > contains (15000-20000) records, then after insertion, we have to delete > the records according to a business rule. > Above process is taking place in a transaction and we are using batches > of 128 to insert records. > Everything works fine on QA environment but somehow after inserts, > delete query hangs in production environment. Delete query has some > joins with other table and a self join. There is no exception as we > have done enough exception handling. It simply hangs with no trace in > application logs. > When I do "ps aux" , I see > postgres 5294 41.3 2.4 270120 38092 pts/4 R 10:41 52:56 > postgres: nuuser nm 127.0.0.1 DELETE That doesn't look to me like it's "hanging"; it's trying to process some unreasonably long-running query. If I were you I'd be taking a closer look at that DELETE command. It may contain an unconstrained join (cross-product) or some such. Try EXPLAINing the command and look for unexpected table scans. > Postgres 7.3.4 on Linux.. That's mighty ancient and has many known bugs. Do yourself a favor and update to some newer version --- at the very least, use the latest 7.3 branch release (we're up to 7.3.13 now). regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 14 14:10:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6C5EC9DCA38 for ; Sat, 14 Jan 2006 14:10:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20682-01 for ; Sat, 14 Jan 2006 14:10:30 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5D4AA9DC9FA for ; Sat, 14 Jan 2006 14:10:28 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0EIASCa020703; Sat, 14 Jan 2006 13:10:28 -0500 (EST) To: "Bernard Dhooghe" cc: pgsql-performance@postgresql.org Subject: Re: >= forces row compare and not index elements compare when possible In-reply-to: <1136826602.613297.42010@f14g2000cwb.googlegroups.com> References: <1136826602.613297.42010@f14g2000cwb.googlegroups.com> Comments: In-reply-to "Bernard Dhooghe" message dated "09 Jan 2006 09:10:02 -0800" Date: Sat, 14 Jan 2006 13:10:28 -0500 Message-ID: <20702.1137262228@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/187 X-Sequence-Number: 16665 "Bernard Dhooghe" writes: > So >= (or <=) is not optimized against an index where it could be. Work in progress... regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 14 14:13:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D89939DCA38 for ; Sat, 14 Jan 2006 14:13:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17226-08 for ; Sat, 14 Jan 2006 14:13:41 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 71A269DC9FA for ; Sat, 14 Jan 2006 14:13:39 -0400 (AST) Received: from mailrelay.t-mobile.com (m6f095e42.tmodns.net [66.94.9.111]) by svr4.postgresql.org (Postfix) with ESMTP id 1976A5AF0BA for ; Sat, 14 Jan 2006 18:13:40 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mailrelay.t-mobile.com (Postfix) with ESMTP id 8AF2499DF for ; Sat, 14 Jan 2006 10:13:35 -0800 (PST) Received: from mailrelay.t-mobile.com ([127.0.0.1]) by localhost (mailrelay.t-mobile.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01237-06 for ; Sat, 14 Jan 2006 10:13:34 -0800 (PST) Received: from uni (250.72.253.10.in-addr.arpa [10.253.72.250]) by mailrelay.t-mobile.com (Postfix) with ESMTP for ; Sat, 14 Jan 2006 10:13:34 -0800 (PST) From: "Benjamin Arai" To: Subject: Ensuring data integrity with fsync=off Date: Sat, 14 Jan 2006 10:13:27 -0800 Message-ID: <000601c61936$38548770$fa48fd0a@uni> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0007_01C618F3.2A314770" X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcYZNjdPT1qBlKsyRba3b2Qw0tKXbA== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.333 required=5 tests=[HTML_MESSAGE=0.001, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.333 X-Spam-Level: * X-Archive-Number: 200601/188 X-Sequence-Number: 16666 This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C618F3.2A314770 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I have been working on optimizing a PostgreSQL server for weekly updates where data is only updated once a week then for the remaining portion of the week the data is static. So far I have set fsync to off and increased the segment size among other things. I need to ensure that at the end of the update each week the data is in state where a crash will not kill the database. Right now I run "sync" afte the updates have finished to ensure that the data is synced to disk but I am concerned about the segment data and anything else I am missing that PostgreSQL explicitly handles. Is there something I can do in addition to sync to tell PostgreSQL exlplicitly that it is time to ensure everything is stored in its final destionation and etc? Benjamin ------=_NextPart_000_0007_01C618F3.2A314770 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
I have = been working=20 on optimizing a PostgreSQL server for weekly updates where data is only = updated=20 once a week then for the remaining portion of the week the data is = static. =20 So far I have set fsync to off and increased the segment size among = other=20 things.  I need to ensure that at the end of the update each = week the=20 data is in state where a crash will not kill the = database. =20
 
Right = now I run=20 "sync" afte the updates have finished to ensure that the data is = synced to=20 disk but I am concerned about the segment data and anything else I am = missing=20 that PostgreSQL explicitly handles.  Is there something I can do in = addition to sync to tell PostgreSQL exlplicitly that it is time to = ensure=20 everything is stored in its final destionation and = etc?
 
Benjamin
------=_NextPart_000_0007_01C618F3.2A314770-- From pgsql-performance-owner@postgresql.org Sat Jan 14 14:41:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E7AD99DD8D4 for ; Sat, 14 Jan 2006 14:41:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23262-06 for ; Sat, 14 Jan 2006 14:41:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id AB31A9DD8D9 for ; Sat, 14 Jan 2006 14:41:44 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0EIfhaX020898; Sat, 14 Jan 2006 13:41:43 -0500 (EST) To: "Benjamin Arai" cc: pgsql-performance@postgresql.org Subject: Re: Ensuring data integrity with fsync=off In-reply-to: <000601c61936$38548770$fa48fd0a@uni> References: <000601c61936$38548770$fa48fd0a@uni> Comments: In-reply-to "Benjamin Arai" message dated "Sat, 14 Jan 2006 10:13:27 -0800" Date: Sat, 14 Jan 2006 13:41:43 -0500 Message-ID: <20897.1137264103@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.088 required=5 tests=[AWL=0.088] X-Spam-Score: 0.088 X-Spam-Level: X-Archive-Number: 200601/190 X-Sequence-Number: 16668 "Benjamin Arai" writes: > Right now I run "sync" afte the updates have finished to ensure that the > data is synced to disk but I am concerned about the segment data and > anything else I am missing that PostgreSQL explicitly handles. Is there > something I can do in addition to sync to tell PostgreSQL exlplicitly that > it is time to ensure everything is stored in its final destionation and etc? You need to give PG a CHECKPOINT command to flush stuff out of its internal buffers. After that finishes, a manual "sync" commnd will push everything down to disk. You realize, of course, that a system failure while the updates are running might leave your database corrupt? As long as you are prepared to restore from scratch, this might be a good tradeoff ... but don't let yourself get caught without an up-to-date backup ... regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 14 16:31:45 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 957739DD914 for ; Sat, 14 Jan 2006 16:31:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39383-10 for ; Sat, 14 Jan 2006 16:31:45 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203]) by postgresql.org (Postfix) with ESMTP id 8B1819DD90C for ; Sat, 14 Jan 2006 16:31:42 -0400 (AST) Received: by wproxy.gmail.com with SMTP id i28so968167wra for ; Sat, 14 Jan 2006 12:31:44 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UOPkr4rO0UOYD9NQhYeW0MNeOy0r3YWhCAdP0JVSo+HpgqV+Dk9hjj9J9WPjDQEYRUZ9oR4cEkCp7u83lCo4YhUlwS4FziKPUfu2ZF6v4vj6rkIFyKdNyoR5mJ+8nB32Pxnwr8o6vVJpzMOMtdlZQVtrJSSPV5rsoMDwnSAJTsU= Received: by 10.54.83.7 with SMTP id g7mr5845009wrb; Sat, 14 Jan 2006 12:31:43 -0800 (PST) Received: by 10.54.93.8 with HTTP; Sat, 14 Jan 2006 12:31:43 -0800 (PST) Message-ID: Date: Sat, 14 Jan 2006 15:31:43 -0500 From: Jaime Casanova To: Tomka Gergely Subject: Re: big databases & hospitals Cc: psql performance list In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.087 required=5 tests=[AWL=0.087] X-Spam-Score: 0.087 X-Spam-Level: X-Archive-Number: 200601/191 X-Sequence-Number: 16669 On 1/14/06, Tomka Gergely wrote: > Hi! > > I need to write a few pages about Postgresql, to convince some suits. The= y > have a few millions of records, on a few site, but they want to know the > practical limits of Postgresql. So i need some information about the > biggest (in storage space, in record number, in field number, and maybe > table number) postgresql databases. > here you can see some limits of postgresql: http://www.postgresql.org/about/ -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;) From pgsql-performance-owner@postgresql.org Sat Jan 14 22:37:02 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 07DCD9DC88A for ; Sat, 14 Jan 2006 22:37:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96680-10 for ; Sat, 14 Jan 2006 22:37:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.bway.net (xena.bway.net [216.220.96.26]) by postgresql.org (Postfix) with ESMTP id 61F209DC8DB for ; Sat, 14 Jan 2006 22:36:58 -0400 (AST) Received: (qmail 82968 invoked by uid 0); 15 Jan 2006 02:37:02 -0000 Received: from unknown (HELO ?192.168.0.40?) (216.220.116.154) by smtp.bway.net with (DHE-RSA-AES256-SHA encrypted) SMTP; 15 Jan 2006 02:37:02 -0000 Date: Sat, 14 Jan 2006 21:37:01 -0500 (EST) From: Charles Sprickman X-X-Sender: spork@gee5.local To: pgsql-performance@postgresql.org Subject: Re: SAN/NAS options In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/192 X-Sequence-Number: 16670 Following up to myself again... On Wed, 14 Dec 2005, Charles Sprickman wrote: > Hello all, > > Supermicro 1U w/SCA backplane and 4 bays > 2x2.8 GHz Xeons > Adaptec 2015S "zero channel" RAID card I don't want to throw away the four machines like that that we have. I do want to throw away the ZCR cards... :) If I ditch those I still have a 1U box with a U320 scsi plug on the back. I'm vaguely considering pairing these two devices: http://www.areca.us/products/html/products.htm That's an Areca 16 channel SATA II (I haven't even read up on what's new in SATA II) RAID controller with an optional U320 SCSI daughter card to connect to the host(s). http://www.chenbro.com.tw/Chenbro_Special/RM321.php How can I turn that box down? Those people in the picture look very excited about it? Seriously though, it looks like an interesting and economical pairing that gives me most of what I'm looking for: -a modern RAID engine -small form factor -remote management of the array -ability to reuse my current db hosts that are disk-bound Disadvantages: -only 1 or 2 hosts per box -more difficult to move storage from host to host (compared to a SAN or NAS system) -no fancy NetApp features like snapshots -I have no experience with Areca SATA->SCSI RAID controllers Any thoughts on this? The controller looks to be about $1500, the enclosure about $400, and the drives are no great mystery, cost would depend on what total capacity I'm looking for. Our initial plan is to set one up for storage for a mail archive project, and to also have a host use this storage to host replicated copies of all Postgres databases. If things look good, we'd start moving our main PG hosts to use a similar RAID box. Thanks, Charles From pgsql-performance-owner@postgresql.org Sat Jan 14 23:34:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DB0979DC88A for ; Sat, 14 Jan 2006 23:34:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09546-08 for ; Sat, 14 Jan 2006 23:34:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id 22CE29DD9D0 for ; Sat, 14 Jan 2006 23:02:08 -0400 (AST) Received: from 172.16.1.26 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Sat, 14 Jan 2006 22:02:06 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST01.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Sat, 14 Jan 2006 22:02:06 -0500 Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Sun, 15 Jan 2006 03:02:06 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Sat, 14 Jan 2006 19:02:07 -0800 Subject: Re: SAN/NAS options From: "Luke Lonergan" To: "Charles Sprickman" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] SAN/NAS options Thread-Index: AcYZfK45m+CVs5plQe6rcnPdwV/j7gAA2N78 In-Reply-To: MIME-Version: 1.0 X-OriginalArrivalTime: 15 Jan 2006 03:02:06.0687 (UTC) FILETIME=[1181DEF0:01C61980] X-WSS-ID: 6FD764A432K13836119-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.32 required=5 tests=[AWL=0.067, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.32 X-Spam-Level: * X-Archive-Number: 200601/194 X-Sequence-Number: 16672 Charles, On 1/14/06 6:37 PM, "Charles Sprickman" wrote: > I'm vaguely considering pairing these two devices: > > http://www.areca.us/products/html/products.htm > > That's an Areca 16 channel SATA II (I haven't even read up on what's new > in SATA II) RAID controller with an optional U320 SCSI daughter card to > connect to the host(s). I'm confused - SATA with a SCSI daughter card? Where does the SCSI go? The Areca has a number (8,12,16) of single drive attach SATA ports coming out of it, each of which will go to a disk drive connection on the backplane. > http://www.chenbro.com.tw/Chenbro_Special/RM321.php > > How can I turn that box down? Those people in the picture look very > excited about it? Seriously though, it looks like an interesting and > economical pairing that gives me most of what I'm looking for: What a picture! I'm totally enthusiastic all of a sudden! I'm putting !!! at the end of every sentence! We just bought 4 very similar systems that use the chassis from California Design - our latest favorite source: http://www.asacomputers.com/ They did an excellent job of setting the systems up, with proper labeling and Quality Control. They also installed Fedora Core 4 and set up the filesystems, the only mistake they made was that they didn't enable 2TB clipping so that we had to rebuild the RAIDs (and install CentOS with the xfs filesystem). We paid $10.4K each for 16x 400GB WD RE2 SATA II drives, 16GB RAM and two Opteron 250s. We also put a single 200GB SATA system drive into each. RAID card is the 3Ware 9550SX. Performance has been stunning - we're getting 800MB/s sustained I/O throughput using the two 9550SX controllers in parallel. > Any thoughts on this? The controller looks to be about $1500, the > enclosure about $400, and the drives are no great mystery, cost would > depend on what total capacity I'm looking for. I'd get ASA to build it for you - use the Tyan 2882 series motherboard for greatest stablity. They may try to sell you hard on the SuperMicro boards, we've had less luck with them. > Our initial plan is to set one up for storage for a mail archive project, > and to also have a host use this storage to host replicated copies of all > Postgres databases. If things look good, we'd start moving our main PG > hosts to use a similar RAID box. Good approach. I'm personally spending as much time using these machines as I can - they are the fastest I've been on in a *long* time. - Luke From pgsql-performance-owner@postgresql.org Sat Jan 14 23:23:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 439039DC94D for ; Sat, 14 Jan 2006 23:23:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11173-05 for ; Sat, 14 Jan 2006 23:23:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.bway.net (xena.bway.net [216.220.96.26]) by postgresql.org (Postfix) with ESMTP id 179259DC88A for ; Sat, 14 Jan 2006 23:23:00 -0400 (AST) Received: (qmail 44796 invoked by uid 0); 15 Jan 2006 03:23:05 -0000 Received: from unknown (HELO ?192.168.0.40?) (216.220.116.154) by smtp.bway.net with (DHE-RSA-AES256-SHA encrypted) SMTP; 15 Jan 2006 03:23:05 -0000 Date: Sat, 14 Jan 2006 22:23:05 -0500 (EST) From: Charles Sprickman X-X-Sender: spork@gee5.local To: Luke Lonergan cc: pgsql-performance@postgresql.org Subject: Re: SAN/NAS options In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/193 X-Sequence-Number: 16671 On Sat, 14 Jan 2006, Luke Lonergan wrote: > Charles, > > On 1/14/06 6:37 PM, "Charles Sprickman" wrote: > >> I'm vaguely considering pairing these two devices: >> >> http://www.areca.us/products/html/products.htm >> >> That's an Areca 16 channel SATA II (I haven't even read up on what's new >> in SATA II) RAID controller with an optional U320 SCSI daughter card to >> connect to the host(s). > > I'm confused - SATA with a SCSI daughter card? Where does the SCSI go? Bad ASCII diagram follows (D=disk, C=controller H=host): SATA ____ D -------| | SCSI ________ D -------| C |--------| H | D -------| | |________| D -------|____| (etc. up to 16 drives) The drives and the controller go in the Chenbro case. U320 SCSI from the RAID controller in the Chenbro case to the 1U server. C From pgsql-performance-owner@postgresql.org Sun Jan 15 00:05:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E07069DC88A for ; Sun, 15 Jan 2006 00:05:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16022-09 for ; Sun, 15 Jan 2006 00:05:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id B19929DC89C for ; Sun, 15 Jan 2006 00:04:59 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id D9B543093C; Sun, 15 Jan 2006 05:04:58 +0100 (MET) From: Christopher Browne X-Newsgroups: pgsql.performance Subject: Re: SAN/NAS options Date: Sat, 14 Jan 2006 23:04:52 -0500 Organization: cbbrowne Computing Inc Lines: 59 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, berkeley-unix) Cancel-Lock: sha1:imHhvU6cfaVtk6TboJ95EU3V94g= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.638 required=5 tests=[AWL=-0.175, INFO_TLD=0.813] X-Spam-Score: 0.638 X-Spam-Level: X-Archive-Number: 200601/195 X-Sequence-Number: 16673 > Following up to myself again... > > On Wed, 14 Dec 2005, Charles Sprickman wrote: > >> Hello all, >> >> Supermicro 1U w/SCA backplane and 4 bays >> 2x2.8 GHz Xeons >> Adaptec 2015S "zero channel" RAID card > > I don't want to throw away the four machines like that that we have. > I do want to throw away the ZCR cards... :) If I ditch those I still > have a 1U box with a U320 scsi plug on the back. > > I'm vaguely considering pairing these two devices: > http://www.areca.us/products/html/products.htm > http://www.chenbro.com.tw/Chenbro_Special/RM321.php > How can I turn that box down? Those people in the picture look very > excited about it? Seriously though, it looks like an interesting and > economical pairing that gives me most of what I'm looking for: The combination definitely looks attractive. I have only been hearing positive things about the Areca cards; the overall combination sounds pretty attractive. > Disadvantages: > > -only 1 or 2 hosts per box > -more difficult to move storage from host to host (compared to a SAN > or NAS system) > -no fancy NetApp features like snapshots > -I have no experience with Areca SATA->SCSI RAID controllers > > Any thoughts on this? The controller looks to be about $1500, the > enclosure about $400, and the drives are no great mystery, cost would > depend on what total capacity I'm looking for. Another "usage model" that could be appropriate would be ATA-over-Ethernet... > Our initial plan is to set one up for storage for a mail archive > project, and to also have a host use this storage to host replicated > copies of all Postgres databases. If things look good, we'd start > moving our main PG hosts to use a similar RAID box. We're thinking about some stuff like this to host things that require bulky amounts of disk that are otherwise "not high TPC" sorts of apps. This is definitely not a "gold plated" answer, compared to the NetApp and EMC boxes of the world, but can be useful in contexts where they are too expensive. -- let name="cbbrowne" and tld="gmail.com" in String.concat "@" [name;tld];; http://linuxdatabases.info/info/x.html It is usually a good idea to put a capacitor of a few microfarads across the output, as shown. From pgsql-performance-owner@postgresql.org Sun Jan 15 13:21:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DDE0F9DC883 for ; Sun, 15 Jan 2006 13:21:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17093-06 for ; Sun, 15 Jan 2006 13:21:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id 746469DC879 for ; Sun, 15 Jan 2006 13:21:08 -0400 (AST) Received: from 172.16.1.148 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Sun, 15 Jan 2006 12:20:59 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST02.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Sun, 15 Jan 2006 12:20:59 -0500 Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Sun, 15 Jan 2006 17:20:59 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Sun, 15 Jan 2006 09:21:00 -0800 Subject: Re: SAN/NAS options From: "Luke Lonergan" To: "Charles Sprickman" cc: pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] SAN/NAS options Thread-Index: AcYZgwZqNPbr7Y0KRf29uIqWcR1mmgAdQdV3 In-Reply-To: MIME-Version: 1.0 X-OriginalArrivalTime: 15 Jan 2006 17:20:59.0881 (UTC) FILETIME=[0DAF3D90:01C619F8] X-WSS-ID: 6FD45BF132K14143153-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.322 required=5 tests=[AWL=0.069, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.322 X-Spam-Level: * X-Archive-Number: 200601/196 X-Sequence-Number: 16674 Charles, On 1/14/06 7:23 PM, "Charles Sprickman" wrote: > The drives and the controller go in the Chenbro case. U320 SCSI from the > RAID controller in the Chenbro case to the 1U server. Thanks for the explanation - I didn't click on your Areca link until now, thinking it was a generic link to their products page. Looks great - I think this might do better than the SATA -> FC products because of the use of faster processors, but I'd keep my expectations low until we see some performance data on it. We've had some very poor experiences with Fibre Channel attach SATA disk controllers. A large vendor of same ultimately concluded that they will no longer recommend them for database use because of the terrible performance of their unit. We ended up with a 110MB/s bottleneck on the controller when using 200MB/s FC connections. With the dual U320 attach and 16 drives, you should be able to saturate the SCSI busses at about 600MB/s. It would be great if you could post your I/O results here! - Luke From pgsql-performance-owner@postgresql.org Mon Jan 16 06:12:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6A2109DC808 for ; Mon, 16 Jan 2006 06:12:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12520-07 for ; Mon, 16 Jan 2006 06:12:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id D9DA99DC801 for ; Mon, 16 Jan 2006 06:12:46 -0400 (AST) Received: from [10.1.0.20] (unknown [10.1.0.20]) by mail.barettadeit.com (Postfix) with ESMTP id 777A57D3264 for ; Mon, 16 Jan 2006 11:17:06 +0100 (CET) Message-ID: <43CB71AC.20203@barettadeit.com> Date: Mon, 16 Jan 2006 11:13:00 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Suspending SELECTs Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/197 X-Sequence-Number: 16675 I am aware that what I am dreaming of is already available through cursors, but in a web application, cursors are bad boys, and should be avoided. What I would like to be able to do is to plan a query and run the plan to retreive a limited number of rows as well as the executor's state. This way, the burden of maintaining the cursor "on hold", between activations of the web resource which uses it, is transferred from the DBMS to the web application server, and, most importantly, the responsibility for garbage-collecting stale cursors is implicitely delegated to the garbage-collector of active user sessions. Without this mechanism, we are left with two equally unpleasant solutions: first, any time a user instantiates a new session, a new cursor would have to be declared for all relevant queries, and an ad-hoc garbage collection daemon would have to be written to periodically scan the database for stale cursors to be closed; otherwise, instead of using cursors, the web application could resort to OFFSET-LIMIT queries--no garbage collection issues but pathetic performance and server-load. Do we have any way out? Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Mon Jan 16 10:36:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C14419DC847 for ; Mon, 16 Jan 2006 10:36:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61964-09 for ; Mon, 16 Jan 2006 10:36:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 8ED029DC839 for ; Mon, 16 Jan 2006 10:36:49 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id CDAE93093D; Mon, 16 Jan 2006 15:36:53 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Materialized Views Date: Mon, 16 Jan 2006 15:36:53 +0100 Organization: Hub.Org Networking Services Lines: 12 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.017 required=5 tests=[AWL=0.017] X-Spam-Score: 0.017 X-Spam-Level: X-Archive-Number: 200601/198 X-Sequence-Number: 16676 Hi, I've been reading an interesting article which compared different database systems, focusing on materialized views. I was wondering how the postgresql developers feel about this feature ... is it planned to implement materialized views any time soon? They would greatly improve both performance and readability (and thus maintainability) of my code. In particular I'm interested in a view which materializes whenever queried, and is invalidated as soon as underlying data is changed. Mike From pgsql-performance-owner@postgresql.org Mon Jan 16 12:54:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ED8B59DC82A for ; Mon, 16 Jan 2006 12:54:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85766-09 for ; Mon, 16 Jan 2006 12:54:10 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by postgresql.org (Postfix) with SMTP id A91549DC807 for ; Mon, 16 Jan 2006 12:54:07 -0400 (AST) Received: (qmail invoked by alias); 16 Jan 2006 16:54:05 -0000 Received: from 201-24-229-237.ctame704.dsl.brasiltelecom.net.br (EHLO servidor) [201.24.229.237] by mail.gmx.net (mp029) with SMTP; 16 Jan 2006 17:54:05 +0100 X-Authenticated: #15924888 Subject: Use of * affect the performance From: Marcos To: pgsql-performance@postgresql.org Content-Type: text/plain Date: Mon, 16 Jan 2006 14:49:28 +0000 Message-Id: <1137422968.1085.25.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.137 required=5 tests=[AWL=0.137] X-Spam-Score: 0.137 X-Spam-Level: X-Archive-Number: 200601/202 X-Sequence-Number: 16680 Hi, I always think that use of * in SELECT affected in the performance, becoming the search slowest. But I read in the a Postgres book's that it increases the speed of search. And now???? What the more fast? Thanks From pgsql-performance-owner@postgresql.org Mon Jan 16 11:40:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EC8229DC862 for ; Mon, 16 Jan 2006 11:40:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77116-01 for ; Mon, 16 Jan 2006 11:40:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from frank.wiles.org (frank.wiles.org [24.124.39.75]) by postgresql.org (Postfix) with ESMTP id BC9FA9DC85E for ; Mon, 16 Jan 2006 11:39:55 -0400 (AST) Received: from kungfu (frank.wiles.org [127.0.0.1]) by frank.wiles.org (8.13.1/8.13.1) with SMTP id k0GFduwf011920; Mon, 16 Jan 2006 09:39:56 -0600 Date: Mon, 16 Jan 2006 09:40:36 -0600 From: Frank Wiles To: Michael Riess Cc: pgsql-performance@postgresql.org Subject: Re: Materialized Views Message-Id: <20060116094036.12a05a8c.frank@wiles.org> In-Reply-To: References: X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.053 required=5 tests=[AWL=0.053] X-Spam-Score: 0.053 X-Spam-Level: X-Archive-Number: 200601/199 X-Sequence-Number: 16677 On Mon, 16 Jan 2006 15:36:53 +0100 Michael Riess wrote: > Hi, > > I've been reading an interesting article which compared different > database systems, focusing on materialized views. I was wondering how > the postgresql developers feel about this feature ... is it planned > to implement materialized views any time soon? They would greatly > improve both performance and readability (and thus maintainability) > of my code. > > In particular I'm interested in a view which materializes whenever > queried, and is invalidated as soon as underlying data is changed. You can already build materialized views in PostgreSQL, but you end up doing the "heavy lifting" yourself with triggers. You put insert/update/delete triggers on the underlying tables of your view that "do the right thing" in your materialized view table. I wrote a blog entry about this recently, http://revsys.com/blog/archive/9, where I used a very simple materialized view to achieve the performance I needed. It has links to the relevant documentation you'll need however to build triggers for a more complex situation. Hope this helps! --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From pgsql-performance-owner@postgresql.org Mon Jan 16 12:18:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8DA539DC84E for ; Mon, 16 Jan 2006 12:18:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82811-02 for ; Mon, 16 Jan 2006 12:18:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.refusion.com (mail.refusion.com [213.144.155.20]) by postgresql.org (Postfix) with ESMTP id 617F89DC807 for ; Mon, 16 Jan 2006 12:18:01 -0400 (AST) Received: from iwing by mail.refusion.com (MDaemon.PRO.v8.1.4.R) with ESMTP id md50000478927.msg for ; Mon, 16 Jan 2006 17:16:39 +0100 Message-ID: <056a01c61ab8$63b70040$6402a8c0@iwing> From: To: "Michael Riess" , References: Subject: Re: Materialized Views Date: Mon, 16 Jan 2006 17:17:47 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="ISO-8859-15"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.1830 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 X-Authenticated-Sender: info@alternize.com X-Spam-Processed: mail.refusion.com, Mon, 16 Jan 2006 17:16:39 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 80.238.235.198 X-Return-Path: me@alternize.com X-MDaemon-Deliver-To: pgsql-performance@postgresql.org X-ClamAV: Pass X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.71 required=5 tests=[AWL=-0.713, DNS_FROM_RFC_DSN=2.872, NO_REAL_NAME=0.55, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 2.71 X-Spam-Level: ** X-Archive-Number: 200601/200 X-Sequence-Number: 16678 hi mike > In particular I'm interested in a view which materializes whenever > queried, and is invalidated as soon as underlying data is changed. from the german pgsql list earlier last week: http://jonathangardner.net/PostgreSQL/materialized_views/matviews.html this seems to be pretty much what you want (except you'll have to update everything yourself). would be really nice if pgsql supports this "in-house" cheers, thomas From pgsql-performance-owner@postgresql.org Mon Jan 16 12:27:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D3AB89DC84E for ; Mon, 16 Jan 2006 12:27:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83239-07 for ; Mon, 16 Jan 2006 12:27:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id B86649DC82D for ; Mon, 16 Jan 2006 12:27:00 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id EC7CD308DA; Mon, 16 Jan 2006 17:26:59 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Materialized Views Date: Mon, 16 Jan 2006 17:26:59 +0100 Organization: Hub.Org Networking Services Lines: 49 Message-ID: References: <20060116094036.12a05a8c.frank@wiles.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <20060116094036.12a05a8c.frank@wiles.org> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.03 required=5 tests=[AWL=0.030] X-Spam-Score: 0.03 X-Spam-Level: X-Archive-Number: 200601/201 X-Sequence-Number: 16679 Thanks! Of course I know that I can build materialized views with triggers, but so far I've avoided using triggers altogether ... I would really appreciate something like "create view foo (select * from b) materialize on query". But I'll look into your blog entry, thanks again! Mike > On Mon, 16 Jan 2006 15:36:53 +0100 > Michael Riess wrote: > >> Hi, >> >> I've been reading an interesting article which compared different >> database systems, focusing on materialized views. I was wondering how >> the postgresql developers feel about this feature ... is it planned >> to implement materialized views any time soon? They would greatly >> improve both performance and readability (and thus maintainability) >> of my code. >> >> In particular I'm interested in a view which materializes whenever >> queried, and is invalidated as soon as underlying data is changed. > > You can already build materialized views in PostgreSQL, but you > end up doing the "heavy lifting" yourself with triggers. You put > insert/update/delete triggers on the underlying tables of your > view that "do the right thing" in your materialized view table. > > I wrote a blog entry about this recently, > http://revsys.com/blog/archive/9, where I used a very simple > materialized view to achieve the performance I needed. It has links > to the relevant documentation you'll need however to build triggers > for a more complex situation. > > Hope this helps! > > --------------------------------- > Frank Wiles > http://www.wiles.org > --------------------------------- > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > From pgsql-performance-owner@postgresql.org Mon Jan 16 13:51:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BACFC9DC85B for ; Mon, 16 Jan 2006 13:51:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99536-06 for ; Mon, 16 Jan 2006 13:51:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 989A59DC82A for ; Mon, 16 Jan 2006 13:51:50 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0GHplxc009767; Mon, 16 Jan 2006 12:51:47 -0500 (EST) To: Alessandro Baretta cc: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs In-reply-to: <43CB71AC.20203@barettadeit.com> References: <43CB71AC.20203@barettadeit.com> Comments: In-reply-to Alessandro Baretta message dated "Mon, 16 Jan 2006 11:13:00 +0100" Date: Mon, 16 Jan 2006 12:51:47 -0500 Message-ID: <9766.1137433907@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/203 X-Sequence-Number: 16681 Alessandro Baretta writes: > I am aware that what I am dreaming of is already available through > cursors, but in a web application, cursors are bad boys, and should be > avoided. What I would like to be able to do is to plan a query and run > the plan to retreive a limited number of rows as well as the > executor's state. This way, the burden of maintaining the cursor "on > hold", between activations of the web resource which uses it, is > transferred from the DBMS to the web application server, This is a pipe dream, I'm afraid, as the state of a cursor does not consist exclusively of bits that can be sent somewhere else and then retrieved. There are also locks to worry about, as well as the open transaction itself, and these must stay alive inside the DBMS because they affect the behavior of other transactions. As an example, once the cursor's originating transaction closes, there is nothing to stop other transactions from modifying or removing rows it would have read. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 16 13:55:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9EB9F9DC807 for ; Mon, 16 Jan 2006 13:55:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00612-05 for ; Mon, 16 Jan 2006 13:55:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from alvh.no-ip.org (201-220-123-7.bk10-dsl.surnet.cl [201.220.123.7]) by postgresql.org (Postfix) with ESMTP id 3A0889DC82A for ; Mon, 16 Jan 2006 13:55:34 -0400 (AST) Received: by alvh.no-ip.org (Postfix, from userid 1000) id DC34DC2DC59; Mon, 16 Jan 2006 14:57:38 -0300 (CLST) Date: Mon, 16 Jan 2006 14:57:38 -0300 From: Alvaro Herrera To: Tom Lane Cc: Alessandro Baretta , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Message-ID: <20060116175738.GB32100@surnet.cl> Mail-Followup-To: Tom Lane , Alessandro Baretta , pgsql-performance@postgresql.org References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9766.1137433907@sss.pgh.pa.us> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.984 required=5 tests=[AWL=0.065, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.984 X-Spam-Level: * X-Archive-Number: 200601/204 X-Sequence-Number: 16682 Tom Lane wrote: > Alessandro Baretta writes: > > I am aware that what I am dreaming of is already available through > > cursors, but in a web application, cursors are bad boys, and should be > > avoided. What I would like to be able to do is to plan a query and run > > the plan to retreive a limited number of rows as well as the > > executor's state. This way, the burden of maintaining the cursor "on > > hold", between activations of the web resource which uses it, is > > transferred from the DBMS to the web application server, > > This is a pipe dream, I'm afraid, as the state of a cursor does not > consist exclusively of bits that can be sent somewhere else and then > retrieved. I wonder if we could have a way to "suspend" a transaction and restart it later in another backend. I think we could do something like this using the 2PC machinery. Not that I'm up for coding it; just an idea that crossed my mind. -- Alvaro Herrera Developer, http://www.PostgreSQL.org Oh, oh, las chicas galacianas, lo har�n por las perlas, �Y las de Arrakis por el agua! Pero si buscas damas Que se consuman como llamas, �Prueba una hija de Caladan! (Gurney Halleck) From pgsql-performance-owner@postgresql.org Mon Jan 16 14:10:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C87FA9DC82A for ; Mon, 16 Jan 2006 14:10:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04310-04 for ; Mon, 16 Jan 2006 14:10:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 48A7A9DC81F for ; Mon, 16 Jan 2006 14:10:43 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0GIAcaX009998; Mon, 16 Jan 2006 13:10:38 -0500 (EST) To: Alvaro Herrera cc: Alessandro Baretta , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs In-reply-to: <20060116175738.GB32100@surnet.cl> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <20060116175738.GB32100@surnet.cl> Comments: In-reply-to Alvaro Herrera message dated "Mon, 16 Jan 2006 14:57:38 -0300" Date: Mon, 16 Jan 2006 13:10:38 -0500 Message-ID: <9997.1137435038@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/205 X-Sequence-Number: 16683 Alvaro Herrera writes: > I wonder if we could have a way to "suspend" a transaction and restart > it later in another backend. I think we could do something like this > using the 2PC machinery. > Not that I'm up for coding it; just an idea that crossed my mind. It's not impossible, perhaps, but it would require an order-of-magnitude expansion of the 2PC machinery --- the amount of state associated with an open execution plan is daunting. I think there are discussions about this in the archives. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 16 14:45:19 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3B1BE9DC82A for ; Mon, 16 Jan 2006 14:45:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11876-02 for ; Mon, 16 Jan 2006 14:45:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id CE1979DC807 for ; Mon, 16 Jan 2006 14:45:11 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 16 Jan 2006 10:45:09 -0800 Subject: Re: Suspending SELECTs From: Mark Lewis To: Alessandro Baretta Cc: pgsql-performance@postgresql.org In-Reply-To: <43CB71AC.20203@barettadeit.com> References: <43CB71AC.20203@barettadeit.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Mon, 16 Jan 2006 10:45:09 -0800 Message-Id: <1137437109.12082.60.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-22) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.120, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/206 X-Sequence-Number: 16684 On Mon, 2006-01-16 at 11:13 +0100, Alessandro Baretta wrote: > I am aware that what I am dreaming of is already available through cursors, but > in a web application, cursors are bad boys, and should be avoided. What I would > like to be able to do is to plan a query and run the plan to retreive a limited > number of rows as well as the executor's state. This way, the burden of > maintaining the cursor "on hold", between activations of the web resource which > uses it, is transferred from the DBMS to the web application server, and, most > importantly, the responsibility for garbage-collecting stale cursors is > implicitely delegated to the garbage-collector of active user sessions. Without > this mechanism, we are left with two equally unpleasant solutions: first, any > time a user instantiates a new session, a new cursor would have to be declared > for all relevant queries, and an ad-hoc garbage collection daemon would have to > be written to periodically scan the database for stale cursors to be closed; > otherwise, instead of using cursors, the web application could resort to > OFFSET-LIMIT queries--no garbage collection issues but pathetic performance and > server-load. > > Do we have any way out? > > Alex I know that Tom has pretty much ruled out any persistent cursor implementation in the database, but here's an idea for a workaround in the app: Have a pool of connections used for these queries. When a user runs a query the first time, create a cursor and remember that this user session is associated with that particular connection. When the user tries to view the next page of results, request that particular connection from the pool and continue to use the cursor. Between requests, this connection could of course be used to service other users. This avoids the awfulness of tying up a connection for the entire course of a user session, but still allows you to use cursors for performance. When a user session is invalidated or times out, you remove the mapping for this connection and close the cursor. Whenever there are no more mappings for a particular connection, you can use the opportunity to close the current transaction (to prevent eternal transactions). If the site is at all busy, you will need to implement a pooling policy such as 'do not open new cursors on the connection with the oldest transaction', which will ensure that all transactions can be closed in a finite amount of time, the upper bound on the duration of a transaction is (longest_session_duration * connections in pool). Limitations: 1. You shouldn't do anything that acquires write locks on the database using these connections, because the transactions will be long-running. To mitigate this, use a separate connection pool. 2. Doesn't work well if some queries take a long time to run, because other users may need to wait for the connection, and another connection won't do. 3. If this is a busy web site, you might end up with potentially many thousands of open cursors. I don't know if this introduces an unacceptable performance penalty or other bottleneck in the server? -- Mark Lewis From pgsql-performance-owner@postgresql.org Mon Jan 16 17:23:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 922429DC846 for ; Mon, 16 Jan 2006 17:23:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39381-05 for ; Mon, 16 Jan 2006 17:23:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net [68.15.5.150]) by postgresql.org (Postfix) with ESMTP id 3B5A59DC838 for ; Mon, 16 Jan 2006 17:23:44 -0400 (AST) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k0GKNvH4026427 for ; Mon, 16 Jan 2006 12:23:58 -0800 Message-ID: <43CC0DDF.9080904@modgraph-usa.com> Date: Mon, 16 Jan 2006 13:19:27 -0800 From: "Craig A. James" User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 CC: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> In-Reply-To: <9766.1137433907@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.128 required=5 tests=[AWL=-0.061, MISSING_HEADERS=0.189] X-Spam-Score: 0.128 X-Spam-Level: X-Archive-Number: 200601/207 X-Sequence-Number: 16685 Alessandro Baretta writes: >I am aware that what I am dreaming of is already available through >cursors, but in a web application, cursors are bad boys, and should be >avoided. What I would like to be able to do is to plan a query and run >the plan to retreive a limited number of rows as well as the >executor's state. This way, the burden of maintaining the cursor "on >hold", between activations of the web resource which uses it, is >transferred from the DBMS to the web application server, I think you're trying to do something at the wrong layer of your architecture. This task normally goes in your middleware layer, not your database layer. There are several technologies that allow you to keep persistent database sessions open (for example, mod_perl, mod_cgi among others). If you combine these with what's called "session affinity" (the ability of a load-balancing server to route a particular user back to the same persistent session object every time), then you can create a middleware layer that does exactly what you need. Basically, you create a session object that holds all of the state (such as your cursor, and anything else you need to maintain between requests), and send back a cookie to the client. Each time the client reconnects, your server finds the user's session object using the cookie, and you're ready to go. The main trick is that you have to manage your session objects, primarily to flush the full state to the database, if too much time elapses between requests, and then be able to re-create them on demand. Enterprise Java Beans has a large fraction of its design devoted to this sort of object management. There are solutions for this in just about every middleware technology, from Apache/perl to EJB to CORBA. Search for "session affinity" and you should find a lot of information. Craig From pgsql-performance-owner@postgresql.org Mon Jan 16 17:54:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EDE5B9DC86C for ; Mon, 16 Jan 2006 17:54:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49272-01 for ; Mon, 16 Jan 2006 17:54:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 78CC09DC878 for ; Mon, 16 Jan 2006 17:53:56 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 469D63093D; Mon, 16 Jan 2006 22:53:57 +0100 (MET) From: "Qingqing Zhou" X-Newsgroups: pgsql.performance Subject: Re: Use of * affect the performance Date: Mon, 16 Jan 2006 16:55:11 -0500 Organization: Hub.Org Networking Services Lines: 25 Message-ID: References: <1137422968.1085.25.camel@servidor> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.164 required=5 tests=[AWL=0.164] X-Spam-Score: 0.164 X-Spam-Level: X-Archive-Number: 200601/208 X-Sequence-Number: 16686 "Marcos" wrote > > I always think that use of * in SELECT affected in the performance, > becoming the search slowest. > > But I read in the a Postgres book's that it increases the speed of > search. > > And now???? What the more fast? > If you mean use "*" vs. "explicitely name all columns of a relation", then there is almost no difference except the negligible difference in parsing. If you mean you just want part of the columns of a relation but you still use "*": Yes, you will save one projection operation for each result row but you will pay for more network traffic. In the worst case, say your "*" involves some toast attributes, you just hurt performance. Considering the benefits is so marginal and dangerous, I suggest stay with the idea that "only retrive the columns that you are interested in". Regards, Qingqing From pgsql-performance-owner@postgresql.org Mon Jan 16 18:07:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8B1EF9DC87F for ; Mon, 16 Jan 2006 18:07:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48705-06 for ; Mon, 16 Jan 2006 18:07:52 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.201]) by postgresql.org (Postfix) with ESMTP id 84D709DC87C for ; Mon, 16 Jan 2006 18:07:48 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so830228uge for ; Mon, 16 Jan 2006 14:07:50 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:content-type:content-transfer-encoding; b=NbRrMRw/AU2RHG+IZyVHUn/XEVy6PSWAiDSea93ahzbxwI0SvQYl2z7Tadi8IbnEOpTaGFfzVm8XgnP/zkM6vgmTy3aEnaPe4a6pQANGu5Wk2nK89NJF9YJ9ct9/b/MY2QEfr3iRuwiDwMbPd90uLWbCGddyYUWCO0AiP9j+jkc= Received: by 10.66.254.16 with SMTP id b16mr1800254ugi; Mon, 16 Jan 2006 14:07:50 -0800 (PST) Received: from ?192.168.1.10? ( [84.98.10.34]) by mx.gmail.com with ESMTP id o1sm910245uge.2006.01.16.14.07.49; Mon, 16 Jan 2006 14:07:49 -0800 (PST) Message-ID: <43CC1938.7020807@gmail.com> Date: Mon, 16 Jan 2006 23:07:52 +0100 From: Antoine User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051022) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: new to postgres (and db management) and performance already a problem :-( Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.332 required=5 tests=[RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.332 X-Spam-Level: * X-Archive-Number: 200601/209 X-Sequence-Number: 16687 Hi, We have a horribly designed postgres 8.1.0 database (not my fault!). I am pretty new to database design and management and have really no idea how to diagnose performance problems. The db has only 25-30 tables, and half of them are only there because our codebase needs them (long story, again not my fault!). Basically we have 10 tables that are being accessed, and only a couple of queries that join more than 3 tables. Most of the action takes place on two tables. One of the devs has done some truly atrocious coding and is using the db as his data access mechanism (instead of an in-memory array, and he only needs an array/collection). It is running on an p4 3000ish (desktop model) running early linux 2.6 (mdk 10.1) (512meg of ram) so that shouldn't be an issue, as we are talking only about 20000 inserts a day. It probably gets queried about 20000 times a day too (all vb6 via the pg odbc). So... seeing as I didn't really do any investigation as to setting default sizes for storage and the like - I am wondering whether our performance problems (a programme running 1.5x slower than two weeks ago) might not be coming from the db (or rather, my maintaining of it). I have turned on stats, so as to allow autovacuuming, but have no idea whether that could be related. Is it better to schedule a cron job to do it x times a day? I just left all the default values in postgres.conf... could I do some tweaking? Does anyone know of any practical resources that might guide me in sorting out these sorts of problems? Some stuff with pratical examples would be good so I could compare with what we have. Thanks Antoine ps. I had a look with top and it didn't look like it was going much over 15% cpu, with memory usage negligeable. There are usually about 10 open connections. I couldn't find an easy way to check for disk accessings. pps. The db is just one possible reason for our bottleneck so if you tell me it is very unlikely I will be most reassured! From pgsql-performance-owner@postgresql.org Mon Jan 16 18:42:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B445A9DC838 for ; Mon, 16 Jan 2006 18:42:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61481-05 for ; Mon, 16 Jan 2006 18:42:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id B3C779DC86C for ; Mon, 16 Jan 2006 18:42:48 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34554 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1Eyd3m-000J86-Um for pgsql-performance@postgresql.org; Mon, 16 Jan 2006 17:42:47 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id D2E4B4069; Mon, 16 Jan 2006 17:42:45 -0500 (EST) Date: Mon, 16 Jan 2006 17:42:45 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: new to postgres (and db management) and performance already a problem :-( Message-ID: <20060116224245.GE18743@phlogiston.dyndns.org> References: <43CC1938.7020807@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43CC1938.7020807@gmail.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.063 required=5 tests=[AWL=0.063] X-Spam-Score: 0.063 X-Spam-Level: X-Archive-Number: 200601/210 X-Sequence-Number: 16688 On Mon, Jan 16, 2006 at 11:07:52PM +0100, Antoine wrote: > performance problems (a programme running 1.5x slower than two weeks > ago) might not be coming from the db (or rather, my maintaining of it). > I have turned on stats, so as to allow autovacuuming, but have no idea > whether that could be related. Is it better to schedule a cron job to do > it x times a day? I just left all the default values in postgres.conf... > could I do some tweaking? The first thing you need to do is find out where your problem is. Are queries running slowly? You need to do some EXPLAIN ANALYSE queries to understand that. A -- Andrew Sullivan | ajs@crankycanuck.ca The whole tendency of modern prose is away from concreteness. --George Orwell From pgsql-performance-owner@postgresql.org Mon Jan 16 18:43:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 69FD59DC846 for ; Mon, 16 Jan 2006 18:43:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62321-05 for ; Mon, 16 Jan 2006 18:43:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A22499DC838 for ; Mon, 16 Jan 2006 18:43:29 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0GMhUSE018876; Mon, 16 Jan 2006 17:43:30 -0500 (EST) To: Antoine cc: pgsql-performance@postgresql.org Subject: Re: new to postgres (and db management) and performance already a problem :-( In-reply-to: <43CC1938.7020807@gmail.com> References: <43CC1938.7020807@gmail.com> Comments: In-reply-to Antoine message dated "Mon, 16 Jan 2006 23:07:52 +0100" Date: Mon, 16 Jan 2006 17:43:30 -0500 Message-ID: <18875.1137451410@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/211 X-Sequence-Number: 16689 Antoine writes: > So... seeing as I didn't really do any investigation as to setting > default sizes for storage and the like - I am wondering whether our > performance problems (a programme running 1.5x slower than two weeks > ago) might not be coming from the db (or rather, my maintaining of it). That does sound like a lack-of-vacuuming problem. If the performance goes back where it was after VACUUM FULL, then you can be pretty sure of it. Note that autovacuum is not designed to fix this for you: it only ever issues regular vacuum not vacuum full. > I couldn't find an easy way to check for disk accessings. Watch the output of "vmstat 1" or "iostat 1" for info about that. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 16 18:48:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B3B389DC881 for ; Mon, 16 Jan 2006 18:48:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62124-06 for ; Mon, 16 Jan 2006 18:48:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.refusion.com (mail.refusion.com [213.144.155.20]) by postgresql.org (Postfix) with ESMTP id 82CF69DC886 for ; Mon, 16 Jan 2006 18:48:20 -0400 (AST) Received: from iwing by mail.refusion.com (MDaemon.PRO.v8.1.4.R) with ESMTP id md50000479366.msg for ; Mon, 16 Jan 2006 23:47:02 +0100 Message-ID: <070501c61aee$ed450560$6402a8c0@iwing> From: To: References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> Subject: Re: new to postgres (and db management) and performance already a problem :-( Date: Mon, 16 Jan 2006 23:48:10 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.1830 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 X-Authenticated-Sender: info@alternize.com X-Spam-Processed: mail.refusion.com, Mon, 16 Jan 2006 23:47:02 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 80.238.235.198 X-Return-Path: me@alternize.com X-MDaemon-Deliver-To: pgsql-performance@postgresql.org X-ClamAV: Pass X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.715 required=5 tests=[AWL=-0.708, DNS_FROM_RFC_DSN=2.872, NO_REAL_NAME=0.55, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 2.715 X-Spam-Level: ** X-Archive-Number: 200601/212 X-Sequence-Number: 16690 > That does sound like a lack-of-vacuuming problem. If the performance > goes back where it was after VACUUM FULL, then you can be pretty sure > of it. Note that autovacuum is not designed to fix this for you: it > only ever issues regular vacuum not vacuum full. in our db system (for a website), i notice performance boosts after a vacuum full. but then, a VACUUM FULL takes 50min+ during which the db is not really accessible to web-users. is there another way to perform maintenance tasks AND leaving the db fully operable and accessible? thanks, thomas From pgsql-performance-owner@postgresql.org Mon Jan 16 21:09:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 835369DC86C for ; Mon, 16 Jan 2006 21:08:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84913-02 for ; Mon, 16 Jan 2006 21:09:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 28DF99DC847 for ; Mon, 16 Jan 2006 21:08:55 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0H18tBC022961; Mon, 16 Jan 2006 20:08:55 -0500 (EST) To: me@alternize.com cc: pgsql-performance@postgresql.org Subject: Re: new to postgres (and db management) and performance already a problem :-( In-reply-to: <070501c61aee$ed450560$6402a8c0@iwing> References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> Comments: In-reply-to message dated "Mon, 16 Jan 2006 23:48:10 +0100" Date: Mon, 16 Jan 2006 20:08:55 -0500 Message-ID: <22960.1137460135@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.089 required=5 tests=[AWL=0.089] X-Spam-Score: 0.089 X-Spam-Level: X-Archive-Number: 200601/213 X-Sequence-Number: 16691 writes: > in our db system (for a website), i notice performance boosts after a vacuum > full. but then, a VACUUM FULL takes 50min+ during which the db is not really > accessible to web-users. is there another way to perform maintenance tasks > AND leaving the db fully operable and accessible? You're not doing regular vacuums often enough. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 16 21:29:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C379A9DC88B for ; Mon, 16 Jan 2006 21:29:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87279-10 for ; Mon, 16 Jan 2006 21:29:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.refusion.com (mail.refusion.com [213.144.155.20]) by postgresql.org (Postfix) with ESMTP id D06F19DC849 for ; Mon, 16 Jan 2006 21:29:51 -0400 (AST) Received: from iwing by mail.refusion.com (MDaemon.PRO.v8.1.4.R) with ESMTP id md50000479465.msg for ; Tue, 17 Jan 2006 02:28:33 +0100 Message-ID: <071801c61b05$7ea50c10$6402a8c0@iwing> From: To: "Tom Lane" Cc: References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> Subject: Re: new to postgres (and db management) and performance already a problem :-( Date: Tue, 17 Jan 2006 02:29:43 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.1830 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 X-Authenticated-Sender: info@alternize.com X-Spam-Processed: mail.refusion.com, Tue, 17 Jan 2006 02:28:33 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 80.238.235.198 X-Return-Path: me@alternize.com X-MDaemon-Deliver-To: pgsql-performance@postgresql.org X-ClamAV: Pass X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.72 required=5 tests=[AWL=-0.703, DNS_FROM_RFC_DSN=2.872, NO_REAL_NAME=0.55, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 2.72 X-Spam-Level: ** X-Archive-Number: 200601/214 X-Sequence-Number: 16692 >> in our db system (for a website), i notice performance boosts after a >> vacuum >> full. but then, a VACUUM FULL takes 50min+ during which the db is not >> really >> accessible to web-users. is there another way to perform maintenance >> tasks >> AND leaving the db fully operable and accessible? > > You're not doing regular vacuums often enough. well, shouldn't autovacuum take care of "regular" vacuums? in addition to autovacuum, tables with data changes are vacuumed and reindexed once a day - still performance seems to degrade slowly until a vacuum full is initiated... could an additional daily vacuum over the entire db (even on tables that only get data added, never changed or removed) help? - thomas From pgsql-performance-owner@postgresql.org Tue Jan 17 00:02:59 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1A8249DC810 for ; Tue, 17 Jan 2006 00:02:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14860-09 for ; Tue, 17 Jan 2006 00:02:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 85DE99DC829 for ; Tue, 17 Jan 2006 00:02:54 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id ACE6B30F0A; Tue, 17 Jan 2006 05:02:53 +0100 (MET) From: Christopher Browne X-Newsgroups: pgsql.performance Subject: Re: new to postgres (and db management) and performance already a problem :-( Date: Mon, 16 Jan 2006 22:57:59 -0500 Organization: cbbrowne Computing Inc Lines: 67 Message-ID: References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> <071801c61b05$7ea50c10$6402a8c0@iwing> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, berkeley-unix) Cancel-Lock: sha1:b1uov98r1y7LYOtb4Qo2fnZr+vo= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.655 required=5 tests=[AWL=-0.158, INFO_TLD=0.813] X-Spam-Score: 0.655 X-Spam-Level: X-Archive-Number: 200601/215 X-Sequence-Number: 16693 >>> in our db system (for a website), i notice performance boosts after >>> a vacuum >>> full. but then, a VACUUM FULL takes 50min+ during which the db is >>> not really >>> accessible to web-users. is there another way to perform >>> maintenance tasks >>> AND leaving the db fully operable and accessible? >> >> You're not doing regular vacuums often enough. By the way, you can get that VACUUM FULL to be "less injurious" if you collect a list of tables: pubs=# select table_schema, table_name from information_schema.tables where table_type = 'BASE TABLE'; And then VACUUM FULL table by table. It'll take the same 50 minutes; it'll be more sporadically "unusable" which may turn out better. But that's just one step better; you want more steps :-). > well, shouldn't autovacuum take care of "regular" vacuums? in addition > to autovacuum, tables with data changes are vacuumed and reindexed > once a day - > still performance seems to degrade slowly until a vacuum full is > initiated... could an additional daily vacuum over the entire db (even > on tables that only get data added, never changed or removed) help? Tables which never see updates/deletes don't need to get vacuumed very often. They should only need to get a periodic ANALYZE so that the query optimizer gets the right stats. There are probably many tables where pg_autovacuum is doing a fine job. What you need to do is to figure out which tables *aren't* getting maintained well enough, and see about doing something special to them. What you may want to do is to go table by table and, for each one, do two things: 1) VACUUM VERBOSE, which will report some information about how much dead space there is on the table. 2) Contrib function pgstattuple(), which reports more detailed info about space usage (alas, for just the table). You'll find, between these, that there are some tables that have a LOT of dead space. At that point, there may be three answers: a) PG 8.1 pg_autovacuum allows you to modify how often specific tables are vacuumed; upping the numbers for the offending tables may clear things up b) Schedule cron jobs to periodically (hourly? several times per hour?) VACUUM the "offending" tables c) You may decide to fall back to VACUUM FULL; if you do so just for a small set of tables, the "time of pain" won't be the 50 minutes you're living with now... Try a), b), and c) in order on the "offending" tables as they address the problem at increasing cost... -- (reverse (concatenate 'string "moc.liamg" "@" "enworbbc")) http://linuxdatabases.info/info/x.html "Listen, strange women, lyin' in ponds, distributin' swords, is no basis for a system of government. Supreme executive power derives itself from a mandate from the masses, not from some farcical aquatic ceremony." -- Monty Python and the Holy Grail From pgsql-performance-owner@postgresql.org Tue Jan 17 00:13:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9946E9DC86D for ; Tue, 17 Jan 2006 00:13:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20531-03 for ; Tue, 17 Jan 2006 00:13:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.refusion.com (mail.refusion.com [213.144.155.20]) by postgresql.org (Postfix) with ESMTP id 47FC89DC827 for ; Tue, 17 Jan 2006 00:13:23 -0400 (AST) Received: from iwing by mail.refusion.com (MDaemon.PRO.v8.1.4.R) with ESMTP id md50000479534.msg for ; Tue, 17 Jan 2006 05:12:02 +0100 Message-ID: <074b01c61b1c$538335e0$6402a8c0@iwing> From: To: "Christopher Browne" , References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> <071801c61b05$7ea50c10$6402a8c0@iwing> Subject: Re: new to postgres (and db management) and performance already a problem :-( Date: Tue, 17 Jan 2006 05:13:09 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.1830 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 X-Authenticated-Sender: info@alternize.com X-Spam-Processed: mail.refusion.com, Tue, 17 Jan 2006 05:12:02 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 80.238.235.198 X-Return-Path: me@alternize.com X-MDaemon-Deliver-To: pgsql-performance@postgresql.org X-ClamAV: Pass X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.724 required=5 tests=[AWL=-0.699, DNS_FROM_RFC_DSN=2.872, NO_REAL_NAME=0.55, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 2.724 X-Spam-Level: ** X-Archive-Number: 200601/216 X-Sequence-Number: 16694 > Try a), b), and c) in order on the "offending" tables as they address > the problem at increasing cost... thanks alot for the detailed information! the entire concept of vacuum isn't yet that clear to me, so your explanations and hints are very much appreciated. i'll defenitely try these steps this weekend when the next full vacuum was scheduled :-) best regards, thomas From pgsql-performance-owner@postgresql.org Tue Jan 17 04:14:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 00A9A9DC8DB for ; Tue, 17 Jan 2006 04:14:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63593-01 for ; Tue, 17 Jan 2006 04:14:29 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.204]) by postgresql.org (Postfix) with ESMTP id 5D54D9DC807 for ; Tue, 17 Jan 2006 04:14:26 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 40so1248707nzk for ; Tue, 17 Jan 2006 00:14:27 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=q2nMMWRbqb0bWXLxxWs0uOgADeRlXOCiw4c1eXtaBIYGUecFewl0dtCE52eXiqNBofeaSOYEMO+S8MMwQGNewFuTOWNTEJAhATScJIQXv3Ce3yFe1ePXdJG0HZgfj3GrgqI9tCPGooJtKTZANOGHdZOB8dPbiBleia0IysuFX0A= Received: by 10.65.124.13 with SMTP id b13mr3716656qbn; Tue, 17 Jan 2006 00:14:27 -0800 (PST) Received: by 10.65.59.5 with HTTP; Tue, 17 Jan 2006 00:14:27 -0800 (PST) Message-ID: <92d3a4950601170014m352c75bes@mail.gmail.com> Date: Tue, 17 Jan 2006 09:14:27 +0100 From: Antoine To: "me@alternize.com" Subject: Re: new to postgres (and db management) and performance already a problem :-( Cc: Christopher Browne , pgsql-performance@postgresql.org In-Reply-To: <074b01c61b1c$538335e0$6402a8c0@iwing> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4473_31931275.1137485667200" References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> <071801c61b05$7ea50c10$6402a8c0@iwing> <074b01c61b1c$538335e0$6402a8c0@iwing> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.442 required=5 tests=[AWL=0.441, HTML_MESSAGE=0.001] X-Spam-Score: 0.442 X-Spam-Level: X-Archive-Number: 200601/217 X-Sequence-Number: 16695 ------=_Part_4473_31931275.1137485667200 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 17/01/06, me@alternize.com wrote: > > > Try a), b), and c) in order on the "offending" tables as they address > > the problem at increasing cost... > > thanks alot for the detailed information! the entire concept of vacuum > isn't > yet that clear to me, so your explanations and hints are very much > appreciated. i'll defenitely try these steps this weekend when the next > full > vacuum was scheduled :-) Thanks guys, that pretty much answered my question(s) too. I have a sneakin= g suspicion that vacuuming won't do too much for us however... now that I think about it - we do very little removing, pretty much only inserts and selects. I will give it a vacuum full and see what happens. Cheers Antoine -- This is where I should put some witty comment. ------=_Part_4473_31931275.1137485667200 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

On 17/01/06, me@alternize.com <<= a href=3D"mailto:me@alternize.com">me@alternize.com> wrote: > Try a), b), and c) in order on the "offending" tables as the= y address
> the problem at increasing cost...

thanks alot for = the detailed information! the entire concept of vacuum isn't
yet that cl= ear to me, so your explanations and hints are very much
appreciated. i'll defenitely try these steps this weekend when the next= full
vacuum was scheduled :-)

Thanks guys, that pr= etty much answered my question(s) too. I have a sneaking suspicion that vac= uuming won't do too much for us however... now that I think about it - we d= o very little removing, pretty much only inserts and selects. I will give i= t a vacuum full and see what happens.
Cheers
Antoine




--
= This is where I should put some witty comment. ------=_Part_4473_31931275.1137485667200-- From pgsql-performance-owner@postgresql.org Tue Jan 17 07:09:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5E8849DC870 for ; Tue, 17 Jan 2006 07:09:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93637-02 for ; Tue, 17 Jan 2006 07:09:33 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id 92CEF9DC86A for ; Tue, 17 Jan 2006 07:09:28 -0400 (AST) Received: (qmail invoked by alias); 17 Jan 2006 11:09:30 -0000 Received: from 201-24-233-72.ctame704.dsl.brasiltelecom.net.br (EHLO servidor) [201.24.233.72] by mail.gmx.net (mp034) with SMTP; 17 Jan 2006 12:09:30 +0100 X-Authenticated: #15924888 Subject: Use of Stored Procedures and From: Marcos To: pgsql-performance@postgresql.org Content-Type: text/plain Date: Tue, 17 Jan 2006 09:04:53 +0000 Message-Id: <1137488693.971.23.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.133 required=5 tests=[AWL=0.133] X-Spam-Score: 0.133 X-Spam-Level: X-Archive-Number: 200601/221 X-Sequence-Number: 16699 Hi, I already read the documentation for to use the SPI_PREPARE and SPI_EXEC... but sincerely I don't understand how I will use this resource in my statements. I looked for examples, but I din't good examples :(.. Somebody can help me? Thanks. Marcos. From pgsql-performance-owner@postgresql.org Tue Jan 17 06:19:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 50B999DC86A for ; Tue, 17 Jan 2006 06:19:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81418-07 for ; Tue, 17 Jan 2006 06:19:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 7D6629DC807 for ; Tue, 17 Jan 2006 06:18:59 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id A395730949; Tue, 17 Jan 2006 11:19:01 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 11:18:59 +0100 Organization: Hub.Org Networking Services Lines: 19 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.04 required=5 tests=[AWL=0.040] X-Spam-Score: 0.04 X-Spam-Level: X-Archive-Number: 200601/218 X-Sequence-Number: 16696 hi, I'm curious as to why autovacuum is not designed to do full vacuum. I know that the necessity of doing full vacuums can be reduced by increasing the FSM, but in my opinion that is the wrong decision for many applications. My application does not continuously insert/update/delete tuples at a constant rate. Basically there are long periods of relatively few modifications and short burst of high activity. Increasing the FSM so that even during these bursts most space would be reused would mean to reduce the available memory for all other database tasks. So my question is: What's the use of an autovacuum daemon if I still have to use a cron job to do full vacuums? wouldn't it just be a minor job to enhance autovacuum to be able to perform full vacuums, if one really wants it to do that - even if some developers think that it's the wrong approach? Mike From pgsql-performance-owner@postgresql.org Tue Jan 17 06:29:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 36A019DC807 for ; Tue, 17 Jan 2006 06:29:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84828-07 for ; Tue, 17 Jan 2006 06:29:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vscan01.westnet.com.au (vscan01.westnet.com.au [203.10.1.131]) by postgresql.org (Postfix) with ESMTP id 3A1B49DC870 for ; Tue, 17 Jan 2006 06:29:35 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with ESMTP id CA0C4760CC5; Tue, 17 Jan 2006 18:29:36 +0800 (WST) Received: from vscan01.westnet.com.au ([127.0.0.1]) by localhost (vscan01.westnet.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08818-11; Tue, 17 Jan 2006 18:29:36 +0800 (WST) Received: from [202.72.133.22] (dsl-202-72-133-22.wa.westnet.com.au [202.72.133.22]) by vscan01.westnet.com.au (Postfix) with ESMTP id 634B176090B; Tue, 17 Jan 2006 18:29:36 +0800 (WST) Message-ID: <43CCC711.504@familyhealth.com.au> Date: Tue, 17 Jan 2006 18:29:37 +0800 From: Christopher Kings-Lynne User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Michael Riess CC: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.064 required=5 tests=[AWL=0.064] X-Spam-Score: 0.064 X-Spam-Level: X-Archive-Number: 200601/219 X-Sequence-Number: 16697 > So my question is: What's the use of an autovacuum daemon if I still > have to use a cron job to do full vacuums? wouldn't it just be a minor > job to enhance autovacuum to be able to perform full vacuums, if one > really wants it to do that - even if some developers think that it's the > wrong approach? You should never have to do full vacuums... Chris From pgsql-performance-owner@postgresql.org Tue Jan 17 06:33:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6CDAF9DC884 for ; Tue, 17 Jan 2006 06:33:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85761-03 for ; Tue, 17 Jan 2006 06:33:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 1502B9DC879 for ; Tue, 17 Jan 2006 06:33:01 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 7BE5130949; Tue, 17 Jan 2006 11:33:03 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 11:33:02 +0100 Organization: Hub.Org Networking Services Lines: 20 Message-ID: References: <43CCC711.504@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <43CCC711.504@familyhealth.com.au> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.048 required=5 tests=[AWL=0.048] X-Spam-Score: 0.048 X-Spam-Level: X-Archive-Number: 200601/220 X-Sequence-Number: 16698 Hi, did you read my post? In the first part I explained why I don't want to increase the FSM that much. Mike >> So my question is: What's the use of an autovacuum daemon if I still >> have to use a cron job to do full vacuums? wouldn't it just be a minor >> job to enhance autovacuum to be able to perform full vacuums, if one >> really wants it to do that - even if some developers think that it's >> the wrong approach? > > You should never have to do full vacuums... > > Chris > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > From pgsql-performance-owner@postgresql.org Tue Jan 17 07:35:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2766E9DC884 for ; Tue, 17 Jan 2006 07:35:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96273-06 for ; Tue, 17 Jan 2006 07:35:23 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.197]) by postgresql.org (Postfix) with ESMTP id 298369DC8DB for ; Tue, 17 Jan 2006 07:35:18 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 14so1324625nzn for ; Tue, 17 Jan 2006 03:35:22 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=pJp6J99d3nlrVw8JbHfGeBrKpe/VTLvJI7ebXt77Qs2Ttm2YYx+tFFzydQ3VmwpdXtrHrkES4M2+YSXNU7Z12gsgOsRncjqKDcvisvhSuigmnWmA4FO2oRLCllp2kIKZY/oCfSeQbDAn8NDXR5SZjKVTDSh/lwL3Ds+s49CuUR8= Received: by 10.65.215.3 with SMTP id s3mr3625609qbq; Tue, 17 Jan 2006 03:35:21 -0800 (PST) Received: by 10.64.208.15 with HTTP; Tue, 17 Jan 2006 03:35:20 -0800 (PST) Message-ID: <5e744e3d0601170335v1b367766l4f9297526c52b084@mail.gmail.com> Date: Tue, 17 Jan 2006 17:05:20 +0530 From: Pandurangan R S To: Christopher Kings-Lynne Subject: Re: Autovacuum / full vacuum Cc: Michael Riess , pgsql-performance@postgresql.org In-Reply-To: <43CCC711.504@familyhealth.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <43CCC711.504@familyhealth.com.au> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.124 required=5 tests=[AWL=0.124] X-Spam-Score: 0.124 X-Spam-Level: X-Archive-Number: 200601/222 X-Sequence-Number: 16700 >> You should never have to do full vacuums... I would rather say, You should never have to do full vacuums by any periodic means. It may be done on a adhoc basis, when you have figured out that your table is never going to grow that big again. On 1/17/06, Christopher Kings-Lynne wrote: > > So my question is: What's the use of an autovacuum daemon if I still > > have to use a cron job to do full vacuums? wouldn't it just be a minor > > job to enhance autovacuum to be able to perform full vacuums, if one > > really wants it to do that - even if some developers think that it's th= e > > wrong approach? > > You should never have to do full vacuums... > > Chris > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > From pgsql-performance-owner@postgresql.org Tue Jan 17 08:08:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 82BF89DC944 for ; Tue, 17 Jan 2006 08:08:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02509-04 for ; Tue, 17 Jan 2006 08:08:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms042pub.verizon.net (vms042pub.verizon.net [206.46.252.42]) by postgresql.org (Postfix) with ESMTP id 93A799DC884 for ; Tue, 17 Jan 2006 08:08:05 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IT800G52KDJIZR3@vms042.mailsrvcs.net> for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 06:08:08 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id 915646061604 for ; Tue, 17 Jan 2006 07:08:06 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 15166-04 for ; Tue, 17 Jan 2006 07:08:05 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 7DC0D6061601; Tue, 17 Jan 2006 07:08:05 -0500 (EST) Date: Tue, 17 Jan 2006 07:08:05 -0500 From: Michael Stone Subject: Re: Autovacuum / full vacuum In-reply-to: To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060117120804.GU1408@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us References: <43CCC711.504@familyhealth.com.au> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.106 required=5 tests=[AWL=0.106] X-Spam-Score: 0.106 X-Spam-Level: X-Archive-Number: 200601/223 X-Sequence-Number: 16701 On Tue, Jan 17, 2006 at 11:33:02AM +0100, Michael Riess wrote: >did you read my post? In the first part I explained why I don't want to >increase the FSM that much. Since you didn't quantify it, that wasn't much of a data point. (IOW, you'd generally have to be seriously resource constrained before the FSM would be a significant source of memory consumption--in which case more RAM would probably be a much better solution than screwing with autovacuum.) Mike Stone From pgsql-performance-owner@postgresql.org Tue Jan 17 09:17:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 154279DC944 for ; Tue, 17 Jan 2006 09:17:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12758-10 for ; Tue, 17 Jan 2006 09:17:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from alvh.no-ip.org (201-220-123-7.bk10-dsl.surnet.cl [201.220.123.7]) by postgresql.org (Postfix) with ESMTP id 7F0E49DC950 for ; Tue, 17 Jan 2006 09:17:38 -0400 (AST) Received: by alvh.no-ip.org (Postfix, from userid 1000) id DBE09C2DC59; Tue, 17 Jan 2006 10:19:58 -0300 (CLST) Date: Tue, 17 Jan 2006 10:19:58 -0300 From: Alvaro Herrera To: Michael Riess Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117131958.GC2785@surnet.cl> Mail-Followup-To: Michael Riess , pgsql-performance@postgresql.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.954 required=5 tests=[AWL=0.035, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.954 X-Spam-Level: * X-Archive-Number: 200601/224 X-Sequence-Number: 16702 Michael Riess wrote: > hi, > > I'm curious as to why autovacuum is not designed to do full vacuum. Because a VACUUM FULL is too invasive. Lazy vacuum is so light on the system w.r.t. locks that it's generally not a problem to start one at any time. On the contrary, vacuum full could be a disaster on some situations. What's more, in general a lazy vacuum is enough to keep the dead space within manageability, given a good autovacuum configuration and good FSM configuration, so there's mostly no need for full vacuum. (This is the theory at least.) For the situations where there is a need, we tell you to issue it manually. > So my question is: What's the use of an autovacuum daemon if I still > have to use a cron job to do full vacuums? wouldn't it just be a minor > job to enhance autovacuum to be able to perform full vacuums, if one > really wants it to do that - even if some developers think that it's the > wrong approach? Yes, it is a minor job to "enhance" it to perform vacuum full. The problem is having a good approach to determining _when_ to issue a full vacuum, and having a way to completely disallow it. If you want to do the development work, be my guest (but let us know your design first). If you don't, I guess you would have to wait until it comes high enough on someone's to-do list, maybe because you convinced him (or her, but we don't have Postgres-ladies at the moment AFAIK) monetarily or something. You can, of course, produce a patch and use it internally. This is free software, remember. -- Alvaro Herrera Developer, http://www.PostgreSQL.org "God is real, unless declared as int" From pgsql-performance-owner@postgresql.org Tue Jan 17 09:29:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AA1709DC807 for ; Tue, 17 Jan 2006 09:28:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18967-01 for ; Tue, 17 Jan 2006 09:29:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 0A1DC9DC86A for ; Tue, 17 Jan 2006 09:28:56 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34574 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EyqtQ-0005yg-E7 for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 08:29:00 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id F2C8B406C; Tue, 17 Jan 2006 08:28:59 -0500 (EST) Date: Tue, 17 Jan 2006 08:28:59 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: new to postgres (and db management) and performance already a problem :-( Message-ID: <20060117132859.GD21092@phlogiston.dyndns.org> References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> <071801c61b05$7ea50c10$6402a8c0@iwing> <074b01c61b1c$538335e0$6402a8c0@iwing> <92d3a4950601170014m352c75bes@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <92d3a4950601170014m352c75bes@mail.gmail.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.074 required=5 tests=[AWL=0.074] X-Spam-Score: 0.074 X-Spam-Level: X-Archive-Number: 200601/225 X-Sequence-Number: 16703 On Tue, Jan 17, 2006 at 09:14:27AM +0100, Antoine wrote: > think about it - we do very little removing, pretty much only inserts and > selects. I will give it a vacuum full and see what happens. UPDATES? Remember that, in Postgres, UPDATE is effectively DELETE + INSERT (from the point of view of storage, not the point of view of the user). A -- Andrew Sullivan | ajs@crankycanuck.ca The plural of anecdote is not data. --Roger Brinner From pgsql-performance-owner@postgresql.org Tue Jan 17 09:33:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 86AD39DC944 for ; Tue, 17 Jan 2006 09:33:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19365-02 for ; Tue, 17 Jan 2006 09:33:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id D080C9DC807 for ; Tue, 17 Jan 2006 09:33:39 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mc7a6.m.pppool.de [89.49.199.166]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 9ABD324400F; Tue, 17 Jan 2006 14:40:02 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 8244718148C10; Tue, 17 Jan 2006 14:33:41 +0100 (CET) Message-ID: <43CCF235.1080009@logix-tt.com> Date: Tue, 17 Jan 2006 14:33:41 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Cc: me@alternize.com Subject: Re: new to postgres (and db management) and performance References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> In-Reply-To: <22960.1137460135@sss.pgh.pa.us> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.128 required=5 tests=[AWL=0.128] X-Spam-Score: 0.128 X-Spam-Level: X-Archive-Number: 200601/226 X-Sequence-Number: 16704 Hi, Tom, Tom Lane wrote: >>in our db system (for a website), i notice performance boosts after a vacuum >>full. but then, a VACUUM FULL takes 50min+ during which the db is not really >>accessible to web-users. is there another way to perform maintenance tasks >>AND leaving the db fully operable and accessible? > > You're not doing regular vacuums often enough. It may also help to increase the max_fsm_pages setting, so postmaster has more memory to remember freed pages between VACUUMs. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Tue Jan 17 09:53:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7C8DC9DC944 for ; Tue, 17 Jan 2006 09:52:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19115-08 for ; Tue, 17 Jan 2006 09:53:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id C19149DC884 for ; Tue, 17 Jan 2006 09:52:55 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mc7a6.m.pppool.de [89.49.199.166]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id C0C8324400F; Tue, 17 Jan 2006 14:59:19 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id DF3BB18148C10; Tue, 17 Jan 2006 14:52:58 +0100 (CET) Message-ID: <43CCF6BA.5010909@logix-tt.com> Date: Tue, 17 Jan 2006 14:52:58 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: new to postgres (and db management) and performance References: <43CC1938.7020807@gmail.com> <18875.1137451410@sss.pgh.pa.us> <070501c61aee$ed450560$6402a8c0@iwing> <22960.1137460135@sss.pgh.pa.us> <071801c61b05$7ea50c10$6402a8c0@iwing> <074b01c61b1c$538335e0$6402a8c0@iwing> In-Reply-To: <074b01c61b1c$538335e0$6402a8c0@iwing> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.127 required=5 tests=[AWL=0.127] X-Spam-Score: 0.127 X-Spam-Level: X-Archive-Number: 200601/227 X-Sequence-Number: 16705 Hi, Thomas, me@alternize.com wrote: >> Try a), b), and c) in order on the "offending" tables as they address >> the problem at increasing cost... > > thanks alot for the detailed information! the entire concept of vacuum > isn't yet that clear to me, so your explanations and hints are very much > appreciated. i'll defenitely try these steps this weekend when the next > full vacuum was scheduled :-) Basically, VACUUM scans the whole table and looks for pages containing garbage rows (or row versions), deletes the garbage, and adds those pages to the free space map (if there are free slots). When allocating new rows / row versions, PostgreSQL first tries to fit them in pages from the free space maps before allocating new pages. This is why a high max_fsm_pages setting can help when VACUUM freqency is low. VACUUM FULL additionally moves rows between pages, trying to concentrate all the free space at the end of the tables (aka "defragmentation"), so it can then truncate the files and release the space to the filesystem. CLUSTER basically rebuilds the tables by copying all rows into a new table, in index order, and then dropping the old table, which also reduces fragmentation, but not as strong as VACUUM FULL might. ANALYZE creates statistics about the distribution of values in a column, allowing the query optimizer to estimate the selectivity of query criteria. (This explanation is rather simplified, and ignores indices as well as the fact that a table can consist of multiple files. Also, I believe that newer PostgreSQL versions allow VACUUM to truncate files when free pages happen to appear at the very end of the file.) HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Tue Jan 17 10:02:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EE24A9DC876 for ; Tue, 17 Jan 2006 10:02:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22991-08 for ; Tue, 17 Jan 2006 10:02:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 71E159DC870 for ; Tue, 17 Jan 2006 10:02:47 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 3C29F30F0B; Tue, 17 Jan 2006 15:02:51 +0100 (MET) From: Christopher Browne X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 08:59:28 -0500 Organization: cbbrowne Computing Inc Lines: 14 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, berkeley-unix) Cancel-Lock: sha1:Fd6p+sVXstPx1eTWnKh+9tOj+kc= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.662 required=5 tests=[AWL=-0.151, INFO_TLD=0.813] X-Spam-Score: 0.662 X-Spam-Level: X-Archive-Number: 200601/228 X-Sequence-Number: 16706 > I'm curious as to why autovacuum is not designed to do full vacuum. Because that's terribly invasive due to the locks it takes out. Lazy vacuum may chew some I/O, but it does *not* block your application for the duration. VACUUM FULL blocks the application. That is NOT something that anyone wants to throw into the "activity mix" randomly. -- let name="cbbrowne" and tld="gmail.com" in String.concat "@" [name;tld];; http://linuxdatabases.info/info/slony.html Signs of a Klingon Programmer #11: "This machine is a piece of GAGH! I need dual Pentium processors if I am to do battle with this code!" From pgsql-performance-owner@postgresql.org Tue Jan 17 10:37:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 355769DC870 for ; Tue, 17 Jan 2006 10:37:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39317-03 for ; Tue, 17 Jan 2006 10:37:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 425969DC81E for ; Tue, 17 Jan 2006 10:37:46 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 119B430F0A; Tue, 17 Jan 2006 15:37:50 +0100 (MET) From: Christopher Browne X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 09:04:06 -0500 Organization: cbbrowne Computing Inc Lines: 18 Message-ID: References: <43CCC711.504@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org X-message-flag: Outlook is rather hackable, isn't it? X-Home-Page: http://www.cbbrowne.com/info/ X-Affero: http://svcs.affero.net/rm.php?r=cbbrowne User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, berkeley-unix) Cancel-Lock: sha1:5GFLER1Wib5HwUcSX7No6LgyFx4= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.262 required=5 tests=[AWL=0.262] X-Spam-Score: 0.262 X-Spam-Level: X-Archive-Number: 200601/234 X-Sequence-Number: 16712 > did you read my post? In the first part I explained why I don't want > to increase the FSM that much. No, you didn't. You explained *that* you thought you didn't want to increase the FSM. You didn't explain why. FSM expansion comes fairly cheap, and tends to be an effective way of eliminating the need for VACUUM FULL. That is generally considered to be a good tradeoff. In future versions, there is likely to be more of this sort of thing; for instance, on the ToDo list is a "Vacuum Space Map" that would collect page IDs that need vacuuming so that PostgreSQL could do "quicker" vacuums... -- output = reverse("moc.liamg" "@" "enworbbc") http://cbbrowne.com/info/internet.html Given recent events in Florida, the tourism board in Texas has developed a new advertising campaign based on the slogan "Ya'll come to Texas, where we ain't shot a tourist in a car since November 1963." From pgsql-performance-owner@postgresql.org Tue Jan 17 10:05:31 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BF9279DC81E for ; Tue, 17 Jan 2006 10:05:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22883-05 for ; Tue, 17 Jan 2006 10:05:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 578399DC86A for ; Tue, 17 Jan 2006 10:05:26 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id CD66D30F0A; Tue, 17 Jan 2006 15:05:30 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 15:05:29 +0100 Organization: Hub.Org Networking Services Lines: 7 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.054 required=5 tests=[AWL=0.054] X-Spam-Score: 0.054 X-Spam-Level: X-Archive-Number: 200601/229 X-Sequence-Number: 16707 > VACUUM FULL blocks the application. That is NOT something that anyone > wants to throw into the "activity mix" randomly. There must be a way to implement a daemon which frees up space of a relation without blocking it too long. It could abort after a certain number of blocks have been freed and then move to the next relation. From pgsql-performance-owner@postgresql.org Tue Jan 17 10:11:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 283179DC94A for ; Tue, 17 Jan 2006 10:11:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21943-08 for ; Tue, 17 Jan 2006 10:11:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from outbound.mailhop.org (outbound.mailhop.org [63.208.196.171]) by postgresql.org (Postfix) with ESMTP id 7F2EF9DC884 for ; Tue, 17 Jan 2006 10:11:01 -0400 (AST) Received: from ool-4350c7ad.dyn.optonline.net ([67.80.199.173] helo=[192.168.0.91]) by outbound.mailhop.org with esmtpa (Exim 4.51) id 1EyrY9-000Ol9-1p; Tue, 17 Jan 2006 09:11:05 -0500 X-Mail-Handler: MailHop Outbound by DynDNS X-Originating-IP: 67.80.199.173 X-Report-Abuse-To: abuse@dyndns.com (see http://www.mailhop.org/outbound/abuse.html for abuse reporting information) X-MHO-User: zeut Message-ID: <43CCFA7E.1060307@zeut.net> Date: Tue, 17 Jan 2006 09:09:02 -0500 From: "Matthew T. O'Connor" User-Agent: Thunderbird 1.4 (Windows/20050908) MIME-Version: 1.0 To: Michael Riess CC: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum References: <43CCC711.504@familyhealth.com.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/230 X-Sequence-Number: 16708 Michael Riess wrote: > did you read my post? In the first part I explained why I don't want to > increase the FSM that much. I'm sure he did, but just because you don't have enough FSM space to capture all everything from your "burst", that doesn't mean that space can't be reclaimed. The next time a regular vacuum is run, it will once again try to fill the FSM with any remaining free space it finds in the table. What normally happens is that your table will never bee 100% free of dead space, normally it will settle at some steady state size that is small percentage bigger than the table will be after a full vacuum. As long as that percentage is small enough, the effect on performance is negligible. Have you measured to see if things are truly faster after a VACUUM FULL? Matt From pgsql-performance-owner@postgresql.org Tue Jan 17 10:30:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6A0329DC94B for ; Tue, 17 Jan 2006 10:30:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40435-01 for ; Tue, 17 Jan 2006 10:30:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id 8200C9DC86A for ; Tue, 17 Jan 2006 10:30:11 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mc7a6.m.pppool.de [89.49.199.166]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id C2D7124400F; Tue, 17 Jan 2006 15:36:35 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id DA00C18148BBE; Tue, 17 Jan 2006 15:30:14 +0100 (CET) Message-ID: <43CCFF76.8020801@logix-tt.com> Date: Tue, 17 Jan 2006 15:30:14 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Matthew T. O'Connor" Cc: Michael Riess , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum References: <43CCC711.504@familyhealth.com.au> <43CCFA7E.1060307@zeut.net> In-Reply-To: <43CCFA7E.1060307@zeut.net> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.126 required=5 tests=[AWL=0.126] X-Spam-Score: 0.126 X-Spam-Level: X-Archive-Number: 200601/231 X-Sequence-Number: 16709 Hi, Matthew, Matthew T. O'Connor wrote: > I'm sure he did, but just because you don't have enough FSM space to > capture all everything from your "burst", that doesn't mean that space > can't be reclaimed. The next time a regular vacuum is run, it will once > again try to fill the FSM with any remaining free space it finds in the > table. What normally happens is that your table will never bee 100% > free of dead space, normally it will settle at some steady state size > that is small percentage bigger than the table will be after a full > vacuum. As long as that percentage is small enough, the effect on > performance is negligible. This will work if you've a steady stream of inserts / updates, but not if you happen to have update bulks that exhaust the FSM capacity. The update first fills up all the FSM, and then allocates new pages for the rest. Then VACUUM comes and refills the FSM, however, the FSM does not contain enough free space for the next large bulk update. The same is for deletes and large bulk inserts, btw. So your table keeps growing steadily, until VACUUM FULL or CLUSTER comes along to clean up the mess. Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Tue Jan 17 10:33:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 48CD39DC86A for ; Tue, 17 Jan 2006 10:33:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35034-08 for ; Tue, 17 Jan 2006 10:33:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id BECF29DC81E for ; Tue, 17 Jan 2006 10:33:16 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 8347630F0A; Tue, 17 Jan 2006 15:33:20 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 15:33:18 +0100 Organization: Hub.Org Networking Services Lines: 23 Message-ID: References: <43CCC711.504@familyhealth.com.au> <43CCFA7E.1060307@zeut.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <43CCFA7E.1060307@zeut.net> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/232 X-Sequence-Number: 16710 Hi, yes, some heavily used tables contain approx. 90% free space after a week. I'll try to increase FSM even more, but I think that I will still have to run a full vacuum every week. Prior to 8.1 I was using 7.4 and ran a full vacuum every day, so the autovacuum has helped a lot. But actually I never understood why the database system slows down at all when there is much unused space in the files. Are the unused pages cached by the system, or is there another reason for the impact on the performance? Mike > Have you measured to see if things are truly > faster after a VACUUM FULL? > > Matt > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > From pgsql-performance-owner@postgresql.org Tue Jan 17 10:37:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 08C0F9DC884 for ; Tue, 17 Jan 2006 10:36:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42574-02 for ; Tue, 17 Jan 2006 10:37:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ausimss.pervasive.com (ausimss.pervasive.com [66.45.103.246]) by postgresql.org (Postfix) with ESMTP id D84399DC86A for ; Tue, 17 Jan 2006 10:36:54 -0400 (AST) Received: from ausbayes2.aus.pervasive.com ([172.16.8.6]) by ausimss.pervasive.com with InterScan Messaging Security Suite; Tue, 17 Jan 2006 08:36:55 -0600 Received: from ausmailowa.aus.pervasive.com ([172.16.4.8]) by ausbayes2.aus.pervasive.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 17 Jan 2006 08:36:54 -0600 Received: from ausmail2k4.aus.pervasive.com ([172.16.4.17]) by ausmailowa.aus.pervasive.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 17 Jan 2006 08:36:52 -0600 X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 08:36:53 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Autovacuum / full vacuum Thread-Index: AcYbcxJekTj1WdNoSimFtWQ5m/bnsAAADn3g From: "Larry Rosenman" To: "Michael Riess" , X-OriginalArrivalTime: 17 Jan 2006 14:36:52.0063 (UTC) FILETIME=[74C0F6F0:01C61B73] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.135 required=5 tests=[AWL=0.135] X-Spam-Score: 0.135 X-Spam-Level: X-Archive-Number: 200601/233 X-Sequence-Number: 16711 Michael Riess wrote: > Hi, >=20 > yes, some heavily used tables contain approx. 90% free space after a > week. I'll try to increase FSM even more, but I think that I will > still have to run a full vacuum every week. Prior to 8.1 I was using > 7.4 and ran a full vacuum every day, so the autovacuum has helped a > lot.=20 >=20 > But actually I never understood why the database system slows down at > all when there is much unused space in the files. Are the unused pages > cached by the system, or is there another reason for the impact on the > performance? The reason is that the system needs to LOOK at the pages/tuples to see if the tuples are dead or not.=20 So, the number of dead tuples impacts the scans. LER >=20 > Mike --=20 Larry Rosenman =09 Database Support Engineer PERVASIVE SOFTWARE. INC. 12365B RIATA TRACE PKWY 3015 AUSTIN TX 78727-6531=20 Tel: 512.231.6173 Fax: 512.231.6597 Email: Larry.Rosenman@pervasive.com Web: www.pervasive.com=20 From pgsql-performance-owner@postgresql.org Tue Jan 17 10:50:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1262A9DC959 for ; Tue, 17 Jan 2006 10:50:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41938-09 for ; Tue, 17 Jan 2006 10:50:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id E00579DC884 for ; Tue, 17 Jan 2006 10:50:36 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 7941030F0A; Tue, 17 Jan 2006 15:50:41 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 15:50:38 +0100 Organization: Hub.Org Networking Services Lines: 25 Message-ID: References: <43CCC711.504@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.064 required=5 tests=[AWL=0.064] X-Spam-Score: 0.064 X-Spam-Level: X-Archive-Number: 200601/235 X-Sequence-Number: 16713 Well, I think that the documentation is not exactly easy to understand. I always wondered why there are no examples for common postgresql configurations. All I know is that the default configuration seems to be too low for production use. And while running postgres I get no hints as to which setting needs to be increased to improve performance. I have no chance to see if my FSM settings are too low other than to run vacuum full verbose in psql, pipe the result to a text file and grep for some words to get a somewhat comprehensive idea of how much unused space there is in my system. Don't get me wrong - I really like PostgreSQL and it works well in my application. But somehow I feel that it might run much better ... about the FSM: You say that increasing the FSM is fairly cheap - how should I know that? >> did you read my post? In the first part I explained why I don't want >> to increase the FSM that much. > > No, you didn't. You explained *that* you thought you didn't want to > increase the FSM. You didn't explain why. > > FSM expansion comes fairly cheap ... From pgsql-performance-owner@postgresql.org Tue Jan 17 10:56:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1EE469DC86A for ; Tue, 17 Jan 2006 10:56:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46055-08 for ; Tue, 17 Jan 2006 10:56:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 9C6FD9DC81E for ; Tue, 17 Jan 2006 10:56:49 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34715 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EysGT-000BBI-FQ for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 09:56:53 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 602AF4069; Tue, 17 Jan 2006 09:56:49 -0500 (EST) Date: Tue, 17 Jan 2006 09:56:49 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117145649.GE21092@phlogiston.dyndns.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/236 X-Sequence-Number: 16714 On Tue, Jan 17, 2006 at 11:18:59AM +0100, Michael Riess wrote: > hi, > > I'm curious as to why autovacuum is not designed to do full vacuum. I Because nothing that runs automatically should ever take an exclusive lock on the entire database, which is what VACUUM FULL does. > activity. Increasing the FSM so that even during these bursts most space > would be reused would mean to reduce the available memory for all > other database tasks. I don't believe the hit is enough that you should even notice it. You'd have to post some pretty incredible use cases to show that the tiny loss of memory to FSM is worth (a) an exclusive lock and (b) the loss of efficiency you get from having some preallocated pages in tables. A -- Andrew Sullivan | ajs@crankycanuck.ca The fact that technology doesn't work is no bar to success in the marketplace. --Philip Greenspun From pgsql-performance-owner@postgresql.org Tue Jan 17 11:04:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 11B119DC94A for ; Tue, 17 Jan 2006 11:04:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52541-06 for ; Tue, 17 Jan 2006 11:04:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 00C3A9DC959 for ; Tue, 17 Jan 2006 11:04:39 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 7784E30F0A; Tue, 17 Jan 2006 16:04:44 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 16:04:41 +0100 Organization: Hub.Org Networking Services Lines: 31 Message-ID: References: <20060117145649.GE21092@phlogiston.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <20060117145649.GE21092@phlogiston.dyndns.org> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/237 X-Sequence-Number: 16715 Hi, >> hi, >> >> I'm curious as to why autovacuum is not designed to do full vacuum. I > > Because nothing that runs automatically should ever take an exclusive > lock on the entire database, which is what VACUUM FULL does. I thought that vacuum full only locks the table which it currently operates on? I'm pretty sure that once a table has been vacuumed, it can be accessed without any restrictions while the vacuum process works on the next table. > >> activity. Increasing the FSM so that even during these bursts most space >> would be reused would mean to reduce the available memory for all >> other database tasks. > > I don't believe the hit is enough that you should even notice it. > You'd have to post some pretty incredible use cases to show that the > tiny loss of memory to FSM is worth (a) an exclusive lock and (b) the > loss of efficiency you get from having some preallocated pages in > tables. I have 5000 tables and a workstation with 1 GB RAM which hosts an Apache Web Server, Tomcat Servlet Container and PostgreSQL. RAM is not something that I have plenty of ... and the hardware is fixed and cannot be changed. From pgsql-performance-owner@postgresql.org Tue Jan 17 11:07:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 09E2A9DC97C for ; Tue, 17 Jan 2006 11:07:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57847-05 for ; Tue, 17 Jan 2006 11:07:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms044pub.verizon.net (vms044pub.verizon.net [206.46.252.44]) by postgresql.org (Postfix) with ESMTP id A906D9DC95C for ; Tue, 17 Jan 2006 11:07:31 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IT8008LDSONQ2R3@vms044.mailsrvcs.net> for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 09:07:36 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id E11406061604 for ; Tue, 17 Jan 2006 10:07:33 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 16196-02-6 for ; Tue, 17 Jan 2006 10:07:33 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 34DAF6061601; Tue, 17 Jan 2006 10:07:33 -0500 (EST) Date: Tue, 17 Jan 2006 10:07:32 -0500 From: Michael Stone Subject: Re: Autovacuum / full vacuum In-reply-to: To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060117150732.GY1408@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us References: <43CCC711.504@familyhealth.com.au> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.107 required=5 tests=[AWL=0.107] X-Spam-Score: 0.107 X-Spam-Level: X-Archive-Number: 200601/238 X-Sequence-Number: 16716 On Tue, Jan 17, 2006 at 03:50:38PM +0100, Michael Riess wrote: >about the FSM: You say that increasing the FSM is fairly cheap - how >should I know that? Why would you assume otherwise, to the point of not considering changing the setting? The documentation explains how much memory is used for FSM entries. If you look at vacuum verbose output it will tell you how much memory you're currently using for the FSM. Mike Stone From pgsql-performance-owner@postgresql.org Tue Jan 17 11:08:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BC1B49DC983 for ; Tue, 17 Jan 2006 11:08:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62163-07 for ; Tue, 17 Jan 2006 11:08:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 2B5399DC97C for ; Tue, 17 Jan 2006 11:07:56 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34753 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EysRF-000BoF-3s for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 10:08:01 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 63A814069; Tue, 17 Jan 2006 10:08:00 -0500 (EST) Date: Tue, 17 Jan 2006 10:08:00 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117150800.GF21092@phlogiston.dyndns.org> References: <43CCC711.504@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.078 required=5 tests=[AWL=0.078] X-Spam-Score: 0.078 X-Spam-Level: X-Archive-Number: 200601/239 X-Sequence-Number: 16717 On Tue, Jan 17, 2006 at 03:50:38PM +0100, Michael Riess wrote: > always wondered why there are no examples for common postgresql > configurations. You mean like this one? (for 8.0): > All I know is that the default configuration seems to be > too low for production use. Define "production use". It may be too low for you. > chance to see if my FSM settings are too low other than to run vacuum > full verbose in psql, pipe the result to a text file and grep for some Not true. You don't need a FULL on there to figure this out. > about the FSM: You say that increasing the FSM is fairly cheap - how > should I know that? Do the math. The docs say this: --snip--- max_fsm_pages (integer) Sets the maximum number of disk pages for which free space will be tracked in the shared free-space map. Six bytes of shared memory are consumed for each page slot. This setting must be more than 16 * max_fsm_relations. The default is 20000. This option can only be set at server start. max_fsm_relations (integer) Sets the maximum number of relations (tables and indexes) for which free space will be tracked in the shared free-space map. Roughly seventy bytes of shared memory are consumed for each slot. The default is 1000. This option can only be set at server start. ---snip--- So by default, you have 6 B * 20,000 = 120,000 bytes for the FSM pages. By default, you have 70 B * 1,000 = 70,000 bytes for the FSM relations. Now, there are two knobs. One of them tracks the number of relations. How many relations do you have? Count the number of indexes and tables you have, and give yourself some headroom in case you add some more, and poof, you have your number for the relations. Now all you need to do is figure out what your churn rate is on tables, and count up how many disk pages that's likely to be. Give yourself a little headroom, and the number of FSM pages is done, too. This churn rate is often tough to estimate, though, so you may have to fiddle with it from time to time. A -- Andrew Sullivan | ajs@crankycanuck.ca I remember when computers were frustrating because they *did* exactly what you told them to. That actually seems sort of quaint now. --J.D. Baldwin From pgsql-performance-owner@postgresql.org Tue Jan 17 11:09:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0328F9DC95C for ; Tue, 17 Jan 2006 11:09:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42525-10 for ; Tue, 17 Jan 2006 11:09:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 47EC09DC94A for ; Tue, 17 Jan 2006 11:09:44 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34754 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EysSy-000BwO-Qv for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 10:09:48 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 76EAF4069; Tue, 17 Jan 2006 10:09:48 -0500 (EST) Date: Tue, 17 Jan 2006 10:09:48 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117150948.GG21092@phlogiston.dyndns.org> References: <43CCC711.504@familyhealth.com.au> <43CCFA7E.1060307@zeut.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43CCFA7E.1060307@zeut.net> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/240 X-Sequence-Number: 16718 On Tue, Jan 17, 2006 at 09:09:02AM -0500, Matthew T. O'Connor wrote: > vacuum. As long as that percentage is small enough, the effect on > performance is negligible. Have you measured to see if things are truly Actually, as long as the percentage is small enough and the pages are really empty, the performance effect is positive. If you have VACUUM FULLed table, inserts have to extend the table before inserting, whereas in a table with some space reclaimed, the I/O effect of having to allocate another disk page is already done. A -- Andrew Sullivan | ajs@crankycanuck.ca When my information changes, I alter my conclusions. What do you do sir? --attr. John Maynard Keynes From pgsql-performance-owner@postgresql.org Tue Jan 17 11:10:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 563CC9DC94A for ; Tue, 17 Jan 2006 11:10:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64215-02 for ; Tue, 17 Jan 2006 11:10:37 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.196]) by postgresql.org (Postfix) with ESMTP id BE1FD9DC959 for ; Tue, 17 Jan 2006 11:10:30 -0400 (AST) Received: by zproxy.gmail.com with SMTP id q3so1347140nzb for ; Tue, 17 Jan 2006 07:10:35 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=Hr6I7Tm6WKTYH8V7AfYy9sb64YBdDPV/ECSCLnJ6IlRaqhDL23AqzqINxi8Di4+zX6TLSp+kynhCMIUNmyzAufzzQQgxUk9vYNDMnGW+DQjDehFCUhU3Sn2qgouPJVmPkewf8KYNFMKBc6OCDCZZvTFDEaJyDWovEEBpeCE1jcI= Received: by 10.65.186.10 with SMTP id n10mr3839117qbp; Tue, 17 Jan 2006 07:10:34 -0800 (PST) Received: by 10.65.189.15 with HTTP; Tue, 17 Jan 2006 07:10:34 -0800 (PST) Message-ID: <9e4684ce0601170710o61e2af02o1b53890cfe972812@mail.gmail.com> Date: Tue, 17 Jan 2006 16:10:34 +0100 From: hubert depesz lubaczewski To: Michael Riess Subject: Re: Autovacuum / full vacuum Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3919_18372093.1137510634749" References: <43CCC711.504@familyhealth.com.au> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.213 required=5 tests=[AWL=0.212, HTML_MESSAGE=0.001] X-Spam-Score: 0.213 X-Spam-Level: X-Archive-Number: 200601/241 X-Sequence-Number: 16719 ------=_Part_3919_18372093.1137510634749 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/17/06, Michael Riess wrote: > > about the FSM: You say that increasing the FSM is fairly cheap - how > should I know that? > comment from original postgresql.conf file seems pretty obvious: #max_fsm_pages =3D 20000 # min max_fsm_relations*16, 6 bytes each #max_fsm_relations =3D 1000 # min 100, ~70 bytes each basically setting max_fsm_pages to 1000000 consumes 6 megabytes. and i definitelly doubt you will ever hit that high. depesz ------=_Part_3919_18372093.1137510634749 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/17/06, Michael Riess <mlriess@gmx.de> wrote:
about the FSM: You say that increasing the FSM is fairly cheap - how
sho= uld I know that?

comment from original postgresql= .conf file seems pretty obvious:
#max_fsm_pages =3D 20000  &nb= sp;       # min max_fsm_relations*16, 6 bytes= each
#max_fsm_relations =3D 1000       # min 1= 00, ~70 bytes each

basically setting max_fsm_pages to 1000000 consum= es 6 megabytes. and i definitelly doubt you will ever hit that high.
depesz
------=_Part_3919_18372093.1137510634749-- From pgsql-performance-owner@postgresql.org Tue Jan 17 11:13:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CEC979DC983 for ; Tue, 17 Jan 2006 11:13:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65921-03 for ; Tue, 17 Jan 2006 11:13:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 129D99DC95C for ; Tue, 17 Jan 2006 11:13:39 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0HFDfUF028350; Tue, 17 Jan 2006 10:13:42 -0500 (EST) To: Michael Riess cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum In-reply-to: References: Comments: In-reply-to Michael Riess message dated "Tue, 17 Jan 2006 11:18:59 +0100" Date: Tue, 17 Jan 2006 10:13:41 -0500 Message-ID: <28349.1137510821@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/242 X-Sequence-Number: 16720 Michael Riess writes: > I'm curious as to why autovacuum is not designed to do full vacuum. Locking considerations. VACUUM FULL takes an exclusive lock, which blocks any foreground transactions that want to touch the table --- so it's really not the sort of thing you want being launched at unpredictable times. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 17 11:13:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E1A619DC959 for ; Tue, 17 Jan 2006 11:13:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63399-04 for ; Tue, 17 Jan 2006 11:14:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 3FEF49DC97E for ; Tue, 17 Jan 2006 11:13:53 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34756 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EysWz-000CDf-Rz for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 10:13:57 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 69D374069; Tue, 17 Jan 2006 10:13:57 -0500 (EST) Date: Tue, 17 Jan 2006 10:13:57 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117151357.GH21092@phlogiston.dyndns.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.082 required=5 tests=[AWL=0.082] X-Spam-Score: 0.082 X-Spam-Level: X-Archive-Number: 200601/243 X-Sequence-Number: 16721 On Tue, Jan 17, 2006 at 03:05:29PM +0100, Michael Riess wrote: > There must be a way to implement a daemon which frees up space of a > relation without blocking it too long. Define "too long". If I have a table that needs to respond to a SELECT in 50ms, I don't have time for you to lock my table. If this were such an easy thing to do, don't you think the folks who came up wit the ingenious lazy vacuum system would have done it? Remember, a vacuum full must completely lock the table, because it is physically moving bits around on the disk. So a SELECT can't happen at the same time, because the bits might move out from under the SELECT while it's running. Concurrency is hard, and race conditions are easy, to implement. A -- Andrew Sullivan | ajs@crankycanuck.ca A certain description of men are for getting out of debt, yet are against all taxes for raising money to pay it off. --Alexander Hamilton From pgsql-performance-owner@postgresql.org Tue Jan 17 11:19:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B68FC9DC870 for ; Tue, 17 Jan 2006 11:19:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65580-08 for ; Tue, 17 Jan 2006 11:19:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 85E029DC81E for ; Tue, 17 Jan 2006 11:19:44 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34757 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1Eyscf-000Ccy-8N for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 10:19:49 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 01B494069; Tue, 17 Jan 2006 10:19:44 -0500 (EST) Date: Tue, 17 Jan 2006 10:19:44 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117151944.GI21092@phlogiston.dyndns.org> References: <20060117145649.GE21092@phlogiston.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/244 X-Sequence-Number: 16722 On Tue, Jan 17, 2006 at 04:04:41PM +0100, Michael Riess wrote: > > I thought that vacuum full only locks the table which it currently > operates on? I'm pretty sure that once a table has been vacuumed, it can > be accessed without any restrictions while the vacuum process works on > the next table. Yes, I think the way I phrased it was unfortunate. But if you issue VACUUM FULL you'll get an exclusive lock on everything, although not all at the same time. But of course, if your query load is like this BEGIN; SELECT from t1, t2 where t1.col1 = t2.col2; [application logic] UPDATE t3 . . . COMMIT; you'll find yourself blocked in the first statement on both t1 and t2; and then on t3 as well. You sure don't want that to happen automagically, in the middle of your business day. > I have 5000 tables and a workstation with 1 GB RAM which hosts an Apache > Web Server, Tomcat Servlet Container and PostgreSQL. RAM is not > something that I have plenty of ... and the hardware is fixed and cannot > be changed. I see. Well, I humbly submit that your problem is not the design of the PostgreSQL server, then. "The hardware is fixed and cannot be changed," is the first optimisation I'd make. Heck, I gave away a box to charity only two weeks ago that would solve your problem better than automatically issuing VACUUM FULL. A -- Andrew Sullivan | ajs@crankycanuck.ca Information security isn't a technological problem. It's an economics problem. --Bruce Schneier From pgsql-performance-owner@postgresql.org Tue Jan 17 11:36:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 82B889DC884 for ; Tue, 17 Jan 2006 11:36:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79446-06 for ; Tue, 17 Jan 2006 11:36:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 3BC3B9DC8DE for ; Tue, 17 Jan 2006 11:36:10 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0HFaBCe028619; Tue, 17 Jan 2006 10:36:11 -0500 (EST) To: Michael Riess cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum In-reply-to: References: <43CCC711.504@familyhealth.com.au> <43CCFA7E.1060307@zeut.net> Comments: In-reply-to Michael Riess message dated "Tue, 17 Jan 2006 15:33:18 +0100" Date: Tue, 17 Jan 2006 10:36:11 -0500 Message-ID: <28618.1137512171@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/245 X-Sequence-Number: 16723 Michael Riess writes: > But actually I never understood why the database system slows down at > all when there is much unused space in the files. Perhaps some of your common queries are doing sequential scans? Those would visit the empty pages as well as the full ones. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 17 11:59:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4A1629DC997 for ; Tue, 17 Jan 2006 11:59:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90568-04 for ; Tue, 17 Jan 2006 11:59:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 801A29DC98E for ; Tue, 17 Jan 2006 11:59:26 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 17 Jan 2006 15:59:25 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 17 Jan 2006 09:59:25 -0600 Subject: Re: Autovacuum / full vacuum From: Scott Marlowe To: Andrew Sullivan Cc: pgsql-performance@postgresql.org In-Reply-To: <20060117150800.GF21092@phlogiston.dyndns.org> References: <43CCC711.504@familyhealth.com.au> <20060117150800.GF21092@phlogiston.dyndns.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1137513565.25500.4.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 17 Jan 2006 09:59:25 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.119 required=5 tests=[AWL=0.118, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.119 X-Spam-Level: X-Archive-Number: 200601/246 X-Sequence-Number: 16724 On Tue, 2006-01-17 at 09:08, Andrew Sullivan wrote: > On Tue, Jan 17, 2006 at 03:50:38PM +0100, Michael Riess wrote: > > always wondered why there are no examples for common postgresql > > configurations. > > You mean like this one? (for 8.0): > > I have to admit, looking at the documentation, that we really don't explain this all that well in the administration section, and I can see how easily led astray beginners are. I think it's time I joined the pgsql-docs mailing list... From pgsql-performance-owner@postgresql.org Tue Jan 17 13:04:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4143A9DC959 for ; Tue, 17 Jan 2006 13:04:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08236-04 for ; Tue, 17 Jan 2006 13:04:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 96DE39DC995 for ; Tue, 17 Jan 2006 13:04:05 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 4A3FF30F0B; Tue, 17 Jan 2006 18:04:05 +0100 (MET) From: Chris Browne X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 11:43:14 -0500 Organization: cbbrowne Computing Inc Lines: 44 Message-ID: <608xteerfh.fsf@dba2.int.libertyrms.com> References: <20060117145649.GE21092@phlogiston.dyndns.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.17 (Jumbo Shrimp, linux) Cancel-Lock: sha1:scRukirRnmFuvu8L7LqZyfUa9po= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.259 required=5 tests=[AWL=0.259] X-Spam-Score: 0.259 X-Spam-Level: X-Archive-Number: 200601/247 X-Sequence-Number: 16725 ajs@crankycanuck.ca (Andrew Sullivan) writes: > On Tue, Jan 17, 2006 at 11:18:59AM +0100, Michael Riess wrote: >> hi, >> >> I'm curious as to why autovacuum is not designed to do full vacuum. I > > Because nothing that runs automatically should ever take an exclusive > lock on the entire database, which is what VACUUM FULL does. That's a bit more than what autovacuum would probably do... autovacuum does things table by table, so that what would be locked should just be one table. Even so, I'd not be keen on having anything that runs automatically take an exclusive lock on even as much as a table. >> activity. Increasing the FSM so that even during these bursts most >> space would be reused would mean to reduce the available memory for >> all other database tasks. > > I don't believe the hit is enough that you should even notice > it. You'd have to post some pretty incredible use cases to show that > the tiny loss of memory to FSM is worth (a) an exclusive lock and > (b) the loss of efficiency you get from having some preallocated > pages in tables. There is *a* case for setting up full vacuums of *some* objects. If you have a table whose tuples all get modified in the course of some common query, that will lead to a pretty conspicuous bloating of *that table.* Even with a big FSM, the pattern of how updates take place will lead to that table having ~50% of its space being "dead/free," which is way higher than the desirable "stable proportion" of 10-15%. For that sort of table, it may be attractive to run VACUUM FULL on a regular basis. Of course, it may also be attractive to try to come up with an update process that won't kill the whole table's contents at once ;-). -- let name="cbbrowne" and tld="cbbrowne.com" in String.concat "@" [name;tld];; http://cbbrowne.com/info/x.html "As long as each individual is facing the TV tube alone, formal freedom poses no threat to privilege." --Noam Chomsky From pgsql-performance-owner@postgresql.org Tue Jan 17 13:07:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 87F189DC84E for ; Tue, 17 Jan 2006 13:07:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06774-06 for ; Tue, 17 Jan 2006 13:07:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bramble.mmrd.com (bramble.mmrd.com [65.217.53.66]) by postgresql.org (Postfix) with ESMTP id 9CF609DC81E for ; Tue, 17 Jan 2006 13:07:52 -0400 (AST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by bramble.mmrd.com (8.12.8/8.12.8) with ESMTP id k0HHt8kB002690 for ; Tue, 17 Jan 2006 12:55:08 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [10.225.10.110]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id k0HH8AC24673 for ; Tue, 17 Jan 2006 12:08:11 -0500 Received: from [10.225.105.30] (10.225.105.30 [10.225.105.30]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id TWDAZT6J; Tue, 17 Jan 2006 12:08:08 -0500 Subject: sum of left join greater than its parts From: Robert Treat To: pgsql-performance@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 17 Jan 2006 12:07:38 -0500 Message-Id: <1137517669.28011.728.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.134 required=5 tests=[AWL=0.134] X-Spam-Score: 0.134 X-Spam-Level: X-Archive-Number: 200601/248 X-Sequence-Number: 16726 8.1.1, everything vacuumed/analyzed. basically i have two queries that when executed individually run quite quickly, but if I try to left join the second query onto the first, everything gets quite a bit slower. rms=# explain analyze rms-# SELECT rms-# software_download.* rms-# FROM rms-# ( rms(# SELECT rms(# host_id, max(mtime) as mtime rms(# FROM rms(# software_download rms(# WHERE rms(# bds_status_id not in (6,17,18) rms(# GROUP BY rms(# host_id, software_binary_id rms(# ) latest_download rms-# JOIN software_download using (host_id,mtime) rms-# JOIN software_binary b USING (software_binary_id) rms-# WHERE rms-# binary_type_id IN (3,5,6); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------- Hash Join (cost=870.00..992.56 rows=1 width=96) (actual time=90.566..125.782 rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND ("outer"."?column2?" = "inner".mtime)) -> HashAggregate (cost=475.88..495.32 rows=1555 width=16) (actual time=51.300..70.761 rows=10870 loops=1) -> Seq Scan on software_download (cost=0.00..377.78 rows=13080 width=16) (actual time=0.010..23.700 rows=13167 loops=1) Filter: ((bds_status_id <> 6) AND (bds_status_id <> 17) AND (bds_status_id <> 18)) -> Hash (cost=379.37..379.37 rows=2949 width=96) (actual time=39.167..39.167 rows=639 loops=1) -> Hash Join (cost=5.64..379.37 rows=2949 width=96) (actual time=0.185..37.808 rows=639 loops=1) Hash Cond: ("outer".software_binary_id = "inner".software_binary_id) -> Seq Scan on software_download (cost=0.00..277.16 rows=13416 width=96) (actual time=0.008..19.338 rows=13416 loops=1) -> Hash (cost=5.59..5.59 rows=20 width=4) (actual time=0.149..0.149 rows=22 loops=1) -> Seq Scan on software_binary b (cost=0.00..5.59 rows=20 width=4) (actual time=0.011..0.108 rows=22 loops=1) Filter: ((binary_type_id = 3) OR (binary_type_id = 5) OR (binary_type_id = 6)) Total runtime: 126.704 ms (13 rows) rms=# explain analyze rms-# SELECT rms-# entityid, rmsbinaryid, rmsbinaryid as software_binary_id, timestamp as downloaded, ia.host_id rms-# FROM rms-# (SELECT rms(# entityid, rmsbinaryid,max(msgid) as msgid rms(# FROM rms(# msg306u rms(# WHERE rms(# downloadstatus=1 rms(# GROUP BY entityid,rmsbinaryid rms(# ) a1 rms-# JOIN myapp_app ia on (entityid=myapp_app_id) rms-# JOIN rms-# (SELECT * rms(# FROM msg306u rms(# WHERE rms(# downloadstatus != 0 rms(# ) a2 USING(entityid,rmsbinaryid,msgid) rms-# ; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=1733.79..4620.38 rows=1 width=20) (actual time=81.160..89.826 rows=238 loops=1) -> Nested Loop (cost=1733.79..4615.92 rows=1 width=20) (actual time=81.142..86.826 rows=238 loops=1) Join Filter: ("outer".rmsbinaryid = "inner".rmsbinaryid) -> HashAggregate (cost=1733.79..1740.92 rows=570 width=12) (actual time=81.105..81.839 rows=323 loops=1) -> Bitmap Heap Scan on msg306u (cost=111.75..1540.65 rows=25752 width=12) (actual time=4.490..41.233 rows=25542 loops=1) -> Bitmap Index Scan on rht3 (cost=0.00..111.75 rows=25752 width=0) (actual time=4.248..4.248 rows=25542 loops=1) -> Index Scan using msg306u_entityid_msgid_idx on msg306u (cost=0.00..5.02 rows=1 width=20) (actual time=0.008..0.010 rows=1 loops=323) Index Cond: (("outer".entityid = msg306u.entityid) AND ("outer"."?column3?" = msg306u.msgid)) Filter: (downloadstatus <> '0'::text) -> Index Scan using myapp_app_pkey on myapp_app ia (cost=0.00..4.44 rows=1 width=8) (actual time=0.006..0.007 rows=1 loops=238) Index Cond: ("outer".entityid = ia.myapp_app_id) Total runtime: 90.270 ms (12 rows) and here are the two queries left joined together. rms=# explain analyze rms-# select * from ( rms(# SELECT rms(# software_download.* rms(# FROM rms(# ( rms(# SELECT rms(# host_id, max(mtime) as mtime rms(# FROM rms(# software_download rms(# WHERE rms(# bds_status_id not in (6,17,18) rms(# GROUP BY rms(# host_id, software_binary_id rms(# ) latest_download rms(# JOIN software_download using (host_id,mtime) rms(# JOIN software_binary b USING (software_binary_id) rms(# WHERE rms(# binary_type_id IN (3,5,6) rms(# ) ld rms-# LEFT JOIN rms-# (SELECT rms(# entityid, rmsbinaryid, rmsbinaryid as software_binary_id, timestamp as downloaded, ia.host_id rms(# FROM rms(# (SELECT rms(# entityid, rmsbinaryid,max(msgid) as msgid rms(# FROM rms(# msg306u rms(# WHERE rms(# downloadstatus=1 rms(# GROUP BY entityid,rmsbinaryid rms(# ) a1 rms(# JOIN myapp_app ia on (entityid=myapp_app_id) rms(# JOIN rms(# (SELECT * rms(# FROM msg306u rms(# WHERE rms(# downloadstatus != 0 rms(# ) a2 USING(entityid,rmsbinaryid,msgid) rms(# ) aa USING (host_id,software_binary_id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Nested Loop Left Join (cost=2603.79..5612.95 rows=1 width=112) (actual time=181.988..4359.330 rows=472 loops=1) Join Filter: (("outer".host_id = "inner".host_id) AND ("outer".software_binary_id = "inner".rmsbinaryid)) -> Hash Join (cost=870.00..992.56 rows=1 width=96) (actual time=92.048..131.154 rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND ("outer"."?column2?" = "inner".mtime)) -> HashAggregate (cost=475.88..495.32 rows=1555 width=16) (actual time=52.302..73.892 rows=10870 loops=1) -> Seq Scan on software_download (cost=0.00..377.78 rows=13080 width=16) (actual time=0.010..24.181 rows=13167 loops=1) Filter: ((bds_status_id <> 6) AND (bds_status_id <> 17) AND (bds_status_id <> 18)) -> Hash (cost=379.37..379.37 rows=2949 width=96) (actual time=39.645..39.645 rows=639 loops=1) -> Hash Join (cost=5.64..379.37 rows=2949 width=96) (actual time=0.187..38.265 rows=639 loops=1) Hash Cond: ("outer".software_binary_id = "inner".software_binary_id) -> Seq Scan on software_download (cost=0.00..277.16 rows=13416 width=96) (actual time=0.008..19.905 rows=13416 loops=1) -> Hash (cost=5.59..5.59 rows=20 width=4) (actual time=0.151..0.151 rows=22 loops=1) -> Seq Scan on software_binary b (cost=0.00..5.59 rows=20 width=4) (actual time=0.011..0.109 rows=22 loops=1) Filter: ((binary_type_id = 3) OR (binary_type_id = 5) OR (binary_type_id = 6)) -> Nested Loop (cost=1733.79..4620.38 rows=1 width=20) (actual time=0.196..8.620 rows=238 loops=472) -> Nested Loop (cost=1733.79..4615.92 rows=1 width=16) (actual time=0.186..5.702 rows=238 loops=472) Join Filter: ("outer".rmsbinaryid = "inner".rmsbinaryid) -> HashAggregate (cost=1733.79..1740.92 rows=570 width=12) (actual time=0.173..0.886 rows=323 loops=472) -> Bitmap Heap Scan on msg306u (cost=111.75..1540.65 rows=25752 width=12) (actual time=4.372..41.248 rows=25542 loops=1) -> Bitmap Index Scan on rht3 (cost=0.00..111.75 rows=25752 width=0) (actual time=4.129..4.129 rows=25542 loops=1) -> Index Scan using msg306u_entityid_msgid_idx on msg306u (cost=0.00..5.02 rows=1 width=20) (actual time=0.008..0.010 rows=1 loops=152456) Index Cond: (("outer".entityid = msg306u.entityid) AND ("outer"."?column3?" = msg306u.msgid)) Filter: (downloadstatus <> '0'::text) -> Index Scan using myapp_app_pkey on myapp_app ia (cost=0.00..4.44 rows=1 width=8) (actual time=0.005..0.007 rows=1 loops=112336) Index Cond: ("outer".entityid = ia.myapp_app_id) Total runtime: 4360.552 ms (26 rows) istm this query should be able to return quite a bit faster, and setting enable_nestloop = off seems to back up this theory: rms=# explain analyze rms-# select * from ( rms(# SELECT rms(# software_download.* rms(# FROM rms(# ( rms(# SELECT rms(# host_id, max(mtime) as mtime rms(# FROM rms(# software_download rms(# WHERE rms(# bds_status_id not in (6,17,18) rms(# GROUP BY rms(# host_id, software_binary_id rms(# ) latest_download rms(# JOIN software_download using (host_id,mtime) rms(# JOIN software_binary b USING (software_binary_id) rms(# WHERE rms(# binary_type_id IN (3,5,6) rms(# ) ld rms-# LEFT JOIN rms-# (SELECT rms(# entityid, rmsbinaryid, rmsbinaryid as software_binary_id, timestamp as downloaded, ia.host_id rms(# FROM rms(# (SELECT rms(# entityid, rmsbinaryid,max(msgid) as msgid rms(# FROM rms(# msg306u rms(# WHERE rms(# downloadstatus=1 rms(# GROUP BY entityid,rmsbinaryid rms(# ) a1 rms(# JOIN myapp_app ia on (entityid=myapp_app_id) rms(# JOIN rms(# (SELECT * rms(# FROM msg306u rms(# WHERE rms(# downloadstatus != 0 rms(# ) a2 USING(entityid,rmsbinaryid,msgid) rms(# ) aa USING (host_id,software_binary_id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Hash Left Join (cost=6976.52..7099.10 rows=1 width=112) (actual time=500.681..537.894 rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND ("outer".software_binary_id = "inner".rmsbinaryid)) -> Hash Join (cost=870.00..992.56 rows=1 width=96) (actual time=91.738..127.423 rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND ("outer"."?column2?" = "inner".mtime)) -> HashAggregate (cost=475.88..495.32 rows=1555 width=16) (actual time=52.025..71.872 rows=10870 loops=1) -> Seq Scan on software_download (cost=0.00..377.78 rows=13080 width=16) (actual time=0.009..23.959 rows=13167 loops=1) Filter: ((bds_status_id <> 6) AND (bds_status_id <> 17) AND (bds_status_id <> 18)) -> Hash (cost=379.37..379.37 rows=2949 width=96) (actual time=39.612..39.612 rows=639 loops=1) -> Hash Join (cost=5.64..379.37 rows=2949 width=96) (actual time=0.183..38.220 rows=639 loops=1) Hash Cond: ("outer".software_binary_id = "inner".software_binary_id) -> Seq Scan on software_download (cost=0.00..277.16 rows=13416 width=96) (actual time=0.008..19.511 rows=13416 loops=1) -> Hash (cost=5.59..5.59 rows=20 width=4) (actual time=0.147..0.147 rows=22 loops=1) -> Seq Scan on software_binary b (cost=0.00..5.59 rows=20 width=4) (actual time=0.011..0.108 rows=22 loops=1) Filter: ((binary_type_id = 3) OR (binary_type_id = 5) OR (binary_type_id = 6)) -> Hash (cost=6106.52..6106.52 rows=1 width=20) (actual time=408.915..408.915 rows=238 loops=1) -> Merge Join (cost=5843.29..6106.52 rows=1 width=20) (actual time=338.516..408.477 rows=238 loops=1) Merge Cond: (("outer".rmsbinaryid = "inner".rmsbinaryid) AND ("outer".msgid = "inner".msgid) AND ("outer".entityid = "inner".entityid)) -> Sort (cost=1857.37..1858.80 rows=570 width=16) (actual time=88.816..89.179 rows=323 loops=1) Sort Key: a1.rmsbinaryid, a1.msgid, a1.entityid -> Hash Join (cost=1793.98..1831.28 rows=570 width=16) (actual time=86.452..88.074 rows=323 loops=1) Hash Cond: ("outer".entityid = "inner".myapp_app_id) -> HashAggregate (cost=1733.79..1740.92 rows=570 width=12) (actual time=80.772..81.320 rows=323 loops=1) -> Bitmap Heap Scan on msg306u (cost=111.75..1540.65 rows=25752 width=12) (actual time=4.515..40.984 rows=25542 loops=1) -> Bitmap Index Scan on rht3 (cost=0.00..111.75 rows=25752 width=0) (actual time=4.271..4.271 rows=25542 loops=1) -> Hash (cost=55.95..55.95 rows=1695 width=8) (actual time=5.663..5.663 rows=1695 loops=1) -> Seq Scan on myapp_app ia (cost=0.00..55.95 rows=1695 width=8) (actual time=0.006..2.888 rows=1695 loops=1) -> Sort (cost=3985.92..4050.30 rows=25752 width=20) (actual time=249.682..286.295 rows=25542 loops=1) Sort Key: public.msg306u.rmsbinaryid, public.msg306u.msgid, public.msg306u.entityid -> Seq Scan on msg306u (cost=0.00..1797.28 rows=25752 width=20) (actual time=0.010..80.572 rows=25542 loops=1) Filter: (downloadstatus <> '0'::text) Total runtime: 540.284 ms (31 rows) i've been banging on this one off and on for awhile now with little progress, can someone explain why it is choosing the initial slower plan and/or how to get it to run something closer to the second faster plan? Robert Treat -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL From pgsql-performance-owner@postgresql.org Tue Jan 17 13:17:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EE4669DC97A for ; Tue, 17 Jan 2006 13:17:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08140-10 for ; Tue, 17 Jan 2006 13:17:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id B9CB39DC95C for ; Tue, 17 Jan 2006 13:17:00 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34831 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EyuS4-000K1r-5H for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 12:17:00 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 42F4F406B; Tue, 17 Jan 2006 12:16:56 -0500 (EST) Date: Tue, 17 Jan 2006 12:16:56 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117171656.GL21092@phlogiston.dyndns.org> References: <43CCC711.504@familyhealth.com.au> <20060117150800.GF21092@phlogiston.dyndns.org> <1137513565.25500.4.camel@state.g2switchworks.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1137513565.25500.4.camel@state.g2switchworks.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.083 required=5 tests=[AWL=0.083] X-Spam-Score: 0.083 X-Spam-Level: X-Archive-Number: 200601/249 X-Sequence-Number: 16727 On Tue, Jan 17, 2006 at 09:59:25AM -0600, Scott Marlowe wrote: > I have to admit, looking at the documentation, that we really don't > explain this all that well in the administration section, and I can see > how easily led astray beginners are. I understand what you mean, but I suppose my reaction would be that what we really need is a place to keep these things, with a note in the docs that the "best practice" settings for these are documented at , and evolve over time as people gain expertise with the new features. I suspect, for instance, that nobody knows exactly the right settings for any generic workload yet under 8.1 (although probably people know them well enough for particular workloads). A -- Andrew Sullivan | ajs@crankycanuck.ca This work was visionary and imaginative, and goes to show that visionary and imaginative work need not end up well. --Dennis Ritchie From pgsql-performance-owner@postgresql.org Tue Jan 17 13:25:14 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F0E539DC84E for ; Tue, 17 Jan 2006 13:25:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13446-01 for ; Tue, 17 Jan 2006 13:25:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id 321359DC81E for ; Tue, 17 Jan 2006 13:25:08 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mc7a6.m.pppool.de [89.49.199.166]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 59A2D24400F; Tue, 17 Jan 2006 18:31:27 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 9B0B518148BBE; Tue, 17 Jan 2006 18:25:06 +0100 (CET) Message-ID: <43CD2872.40509@logix-tt.com> Date: Tue, 17 Jan 2006 18:25:06 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Michael Riess Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum References: <43CCC711.504@familyhealth.com.au> <43CCFA7E.1060307@zeut.net> In-Reply-To: X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.125 required=5 tests=[AWL=0.125] X-Spam-Score: 0.125 X-Spam-Level: X-Archive-Number: 200601/250 X-Sequence-Number: 16728 Hi, Michael, Michael Riess wrote: > But actually I never understood why the database system slows down at > all when there is much unused space in the files. Are the unused pages > cached by the system, or is there another reason for the impact on the > performance? No, they are not cached as such, but PostgreSQL caches whole pages, and you don't have only empty pages, but also lots of partially empty pages, so the signal/noise ratio is worse (means PostgreSQL has to fetch more pages to get the same data). Sequential scans etc. are also slower. And some file systems get slower when files get bigger or there are more files, but this effect should not really be noticeable here. HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Tue Jan 17 13:28:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E60B49DC98A for ; Tue, 17 Jan 2006 13:28:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09501-10 for ; Tue, 17 Jan 2006 13:28:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from alvh.no-ip.org (201-220-123-7.bk10-dsl.surnet.cl [201.220.123.7]) by postgresql.org (Postfix) with ESMTP id E2A349DC983 for ; Tue, 17 Jan 2006 13:28:29 -0400 (AST) Received: by alvh.no-ip.org (Postfix, from userid 1000) id 28106C2DC59; Tue, 17 Jan 2006 14:30:47 -0300 (CLST) Date: Tue, 17 Jan 2006 14:30:47 -0300 From: Alvaro Herrera To: Chris Browne Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117173046.GA4296@surnet.cl> Mail-Followup-To: Chris Browne , pgsql-performance@postgresql.org References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <608xteerfh.fsf@dba2.int.libertyrms.com> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.924 required=5 tests=[AWL=0.005, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.924 X-Spam-Level: * X-Archive-Number: 200601/251 X-Sequence-Number: 16729 Chris Browne wrote: > ajs@crankycanuck.ca (Andrew Sullivan) writes: > > On Tue, Jan 17, 2006 at 11:18:59AM +0100, Michael Riess wrote: > >> hi, > >> > >> I'm curious as to why autovacuum is not designed to do full vacuum. I > > > > Because nothing that runs automatically should ever take an exclusive > > lock on the entire database, which is what VACUUM FULL does. > > That's a bit more than what autovacuum would probably do... > autovacuum does things table by table, so that what would be locked > should just be one table. Even a database-wide vacuum does not take locks on more than one table. The table locks are acquired and released one by one, as the operation proceeds. And as you know, autovacuum (both 8.1's and contrib) does issue database-wide vacuums, if it finds a database close to an xid wraparound. -- Alvaro Herrera http://www.advogato.org/person/alvherre "Las mujeres son como hondas: mientras m�s resistencia tienen, m�s lejos puedes llegar con ellas" (Jonas Nightingale, Leap of Faith) From pgsql-performance-owner@postgresql.org Tue Jan 17 13:31:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 97F909DC983 for ; Tue, 17 Jan 2006 13:31:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13446-05 for ; Tue, 17 Jan 2006 13:31:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 627179DC99B for ; Tue, 17 Jan 2006 13:31:44 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 17 Jan 2006 17:31:43 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 17 Jan 2006 11:31:43 -0600 Subject: Re: Autovacuum / full vacuum From: Scott Marlowe To: Andrew Sullivan Cc: pgsql-performance@postgresql.org In-Reply-To: <20060117171656.GL21092@phlogiston.dyndns.org> References: <43CCC711.504@familyhealth.com.au> <20060117150800.GF21092@phlogiston.dyndns.org> <1137513565.25500.4.camel@state.g2switchworks.com> <20060117171656.GL21092@phlogiston.dyndns.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1137519102.25500.36.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 17 Jan 2006 11:31:43 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.119 required=5 tests=[AWL=0.118, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.119 X-Spam-Level: X-Archive-Number: 200601/252 X-Sequence-Number: 16730 On Tue, 2006-01-17 at 11:16, Andrew Sullivan wrote: > On Tue, Jan 17, 2006 at 09:59:25AM -0600, Scott Marlowe wrote: > > I have to admit, looking at the documentation, that we really don't > > explain this all that well in the administration section, and I can see > > how easily led astray beginners are. > > I understand what you mean, but I suppose my reaction would be that > what we really need is a place to keep these things, with a note in > the docs that the "best practice" settings for these are documented > at , and evolve over time as people gain expertise with the > new features. > > I suspect, for instance, that nobody knows exactly the right settings > for any generic workload yet under 8.1 (although probably people know > them well enough for particular workloads). But the problem is bigger than that. The administrative docs were obviously evolved over time, and now they kind of jump around and around covering the same subject from different angles and at different depths. Even I find it hard to find what I need, and I know PostgreSQL administration well enough to be pretty darned good at it. For the beginner, it must seem much more confusing. The more I look at the administration section of the docs, the more I want to reorganize the whole thing, and rewrite large sections of it as well. From pgsql-performance-owner@postgresql.org Tue Jan 17 14:13:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 06A739DC848 for ; Tue, 17 Jan 2006 14:13:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24878-01 for ; Tue, 17 Jan 2006 14:13:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id A5CC39DC81E for ; Tue, 17 Jan 2006 14:13:51 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:34833 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1EyvL4-000Nbs-TV for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 13:13:51 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 7F40E405F; Tue, 17 Jan 2006 13:13:50 -0500 (EST) Date: Tue, 17 Jan 2006 13:13:50 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117181350.GN21092@phlogiston.dyndns.org> References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <608xteerfh.fsf@dba2.int.libertyrms.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.084 required=5 tests=[AWL=0.084] X-Spam-Score: 0.084 X-Spam-Level: X-Archive-Number: 200601/253 X-Sequence-Number: 16731 On Tue, Jan 17, 2006 at 11:43:14AM -0500, Chris Browne wrote: > ajs@crankycanuck.ca (Andrew Sullivan) writes: > > Because nothing that runs automatically should ever take an exclusive > > lock on the entire database, > That's a bit more than what autovacuum would probably do... Or even VACUUM FULL, as I tried to make clearer in another message: the way I phrased it suggests that it's a simultaneous lock on the entire database (when it is most certainly not). I didn't intend to mislead; my apologies. Note, though, that the actual effect for a user might look worse than a lock on the entire database, though, if you conider statement_timeout and certain use patterns. Suppose you want to issue occasional VACCUM FULLs, but your application is prepared for this, and depends on statement_timeout to tell it "sorry, too long, try again". Now, if the exclusive lock on any given table takes less than statement_timeout, so that each statement is able to continue in its time, the application looks like it's having an outage _even though_ it is actually blocked on vacuums. (Yes, it's poor application design. There's plenty of that in the world, and you can't always fix it.) > There is *a* case for setting up full vacuums of *some* objects. If > you have a table whose tuples all get modified in the course of some > common query, that will lead to a pretty conspicuous bloating of *that > table.* Sure. And depending on your use model, that might be good. In many cases, though, a "rotor table + view + truncate" approach would be better, and would allow improved uptime. If you don't care about uptime, and can take long outages every day, then the discussion is sort of moot anyway. And _all_ of this is moot, as near as I can tell, given the OP's claim that the hardware is adequate and immutable, even though the former claim is demonstrably false. A -- Andrew Sullivan | ajs@crankycanuck.ca The fact that technology doesn't work is no bar to success in the marketplace. --Philip Greenspun From pgsql-performance-owner@postgresql.org Tue Jan 17 15:04:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 701F09DC99B for ; Tue, 17 Jan 2006 15:04:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23285-01 for ; Tue, 17 Jan 2006 15:04:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 5901E9DC98D for ; Tue, 17 Jan 2006 15:04:07 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id AC3F130F0B; Tue, 17 Jan 2006 20:04:07 +0100 (MET) From: Chris Browne X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Tue, 17 Jan 2006 13:40:46 -0500 Organization: cbbrowne Computing Inc Lines: 31 Message-ID: <604q42elzl.fsf@dba2.int.libertyrms.com> References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> <20060117173046.GA4296@surnet.cl> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.17 (Jumbo Shrimp, linux) Cancel-Lock: sha1:Vpmknl2KaUjQKfHlAx1h1EfvIUc= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.253 required=5 tests=[AWL=0.253] X-Spam-Score: 0.253 X-Spam-Level: X-Archive-Number: 200601/254 X-Sequence-Number: 16732 alvherre@alvh.no-ip.org (Alvaro Herrera) writes: > Chris Browne wrote: >> ajs@crankycanuck.ca (Andrew Sullivan) writes: >> > On Tue, Jan 17, 2006 at 11:18:59AM +0100, Michael Riess wrote: >> >> hi, >> >> >> >> I'm curious as to why autovacuum is not designed to do full vacuum. I >> > >> > Because nothing that runs automatically should ever take an exclusive >> > lock on the entire database, which is what VACUUM FULL does. >> >> That's a bit more than what autovacuum would probably do... >> autovacuum does things table by table, so that what would be locked >> should just be one table. > > Even a database-wide vacuum does not take locks on more than one table. > The table locks are acquired and released one by one, as the operation > proceeds. And as you know, autovacuum (both 8.1's and contrib) does > issue database-wide vacuums, if it finds a database close to an xid > wraparound. Has that changed recently? I have always seen "vacuumdb" or SQL "VACUUM" (without table specifications) running as one long transaction which doesn't release the locks that it is granted until the end of the transaction. -- "cbbrowne","@","acm.org" http://cbbrowne.com/info/spiritual.html "My nostalgia for Icon makes me forget about any of the bad things. I don't have much nostalgia for Perl, so its faults I remember." -- Scott Gilbert comp.lang.python From pgsql-performance-owner@postgresql.org Tue Jan 17 15:32:59 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 506979DC993 for ; Tue, 17 Jan 2006 15:32:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42969-06 for ; Tue, 17 Jan 2006 15:32:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id BA0FC9DC9A4 for ; Tue, 17 Jan 2006 15:32:55 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0HJWqnb020593; Tue, 17 Jan 2006 14:32:52 -0500 (EST) To: Chris Browne cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum In-reply-to: <604q42elzl.fsf@dba2.int.libertyrms.com> References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> <20060117173046.GA4296@surnet.cl> <604q42elzl.fsf@dba2.int.libertyrms.com> Comments: In-reply-to Chris Browne message dated "Tue, 17 Jan 2006 13:40:46 -0500" Date: Tue, 17 Jan 2006 14:32:52 -0500 Message-ID: <20592.1137526372@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/255 X-Sequence-Number: 16733 Chris Browne writes: > alvherre@alvh.no-ip.org (Alvaro Herrera) writes: >> Even a database-wide vacuum does not take locks on more than one table. >> The table locks are acquired and released one by one, as the operation >> proceeds. > Has that changed recently? I have always seen "vacuumdb" or SQL > "VACUUM" (without table specifications) running as one long > transaction which doesn't release the locks that it is granted until > the end of the transaction. You sure? It's not supposed to, and watching a database-wide vacuum with "select * from pg_locks" doesn't look to me like it ever has locks on more than one table (plus the table's indexes and toast table). regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 17 15:55:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1A1D79DC97C for ; Tue, 17 Jan 2006 15:55:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68618-08 for ; Tue, 17 Jan 2006 15:55:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 37D8D9DC80F for ; Tue, 17 Jan 2006 15:55:45 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id 40B8F40C11A; Tue, 17 Jan 2006 21:00:12 +0100 (CET) Message-ID: <43CD4BD0.9090807@barettadeit.com> Date: Tue, 17 Jan 2006 20:56:00 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> In-Reply-To: <9766.1137433907@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/256 X-Sequence-Number: 16734 Tom Lane wrote: > Alessandro Baretta writes: > >>I am aware that what I am dreaming of is already available through >>cursors, but in a web application, cursors are bad boys, and should be >>avoided. What I would like to be able to do is to plan a query and run >>the plan to retreive a limited number of rows as well as the >>executor's state. This way, the burden of maintaining the cursor "on >>hold", between activations of the web resource which uses it, is >>transferred from the DBMS to the web application server, > > > This is a pipe dream, I'm afraid, as the state of a cursor does not > consist exclusively of bits that can be sent somewhere else and then > retrieved. There are also locks to worry about, as well as the open > transaction itself, and these must stay alive inside the DBMS because > they affect the behavior of other transactions. As an example, once > the cursor's originating transaction closes, there is nothing to stop > other transactions from modifying or removing rows it would have read. I understand most of these issues, and expected this kind of reply. Please, allow me to insist that we reason on this problem and try to find a solution. My reason for doing so is that the future software industry is likely to see more and more web applications retrieving data from virtually endless databases, and in such contexts, it is sensible to ask the final client--the web client--to store the "cursor state", because web interaction is intrinsically asynchronous, and you cannot count on users logging out when they're done, releasing resources allocated to them. Think of Google. Let me propose a possible solution strategy for the problem of "client-side cursors". * Let us admit the limitation that a "client-side cursor" can only be declared in a transaction where no inserts, updates or deletes are allowed, so that such a transaction is virtually non-existent to other transactions. This allows the backend to close the transaction and release locks as soon as the cursor is declared. * When the cursor state is pushed back to the backend, no new transaction is instantiated, but the XID of the original transaction is reused. In the MVCC system, this allows us to achieve a perfectly consistent view of the database at the instant the original transaction started, unless a VACUUM command has been executed in the meantime, in which case I would lose track of tuples which would have been live in the context of the original transaction, but have been updated or deleted and later vacuumed; however, this does not bother me at all. Is this not a viable solution? Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Tue Jan 17 16:14:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2FC669DC841 for ; Tue, 17 Jan 2006 16:14:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80349-05 for ; Tue, 17 Jan 2006 16:14:21 -0400 (AST) X-Greylist: delayed 00:13:10.243888 by SQLgrey- Received: from l0isi08.larcb.ecs.nasa.gov (l0isi08u.ecs.nasa.gov [129.165.226.2]) by postgresql.org (Postfix) with ESMTP id E650D9DC993 for ; Tue, 17 Jan 2006 16:14:14 -0400 (AST) Received: (from hermes@localhost) by l0isi08.larcb.ecs.nasa.gov (AIX5.1/8.11.6p2/8.11.0) id k0HK1jd2187466 for ; Tue, 17 Jan 2006 15:01:45 -0500 X-Authentication-Warning: l0isi08.larcb.ecs.nasa.gov: hermes set sender to using -f Received: by larcb.ecs.nasa.gov via smwrap Version 5.1.5 id smwrapPGapMa; Tue Jan 17 15:01:23 2006 Message-ID: <43CD4CE5.3020506@larcb.ecs.nasa.gov> Date: Tue, 17 Jan 2006 15:00:37 -0500 From: Yantao Shi User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: Subject: wildcard search performance with "like" Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/259 X-Sequence-Number: 16737 Hi, I have a postges 8.1.1 table with over 29 million rows in it. The colunm (file_name) that I need to search on has entries like the following: MOD04_L2.A2005311.1400.004.2005312013848.hdf MYD04_L2.A2005311.0700.004.2005312013437.hdf I have an index on this column. But an index search is performance only when I give the full file_name for search: testdbspc=# explain select file_name from catalog where file_name = 'MOD04_L2.A2005311.1400.004.2005312013848.hdf'; QUERY PLAN Index Scan using catalog_pk_idx on catalog (cost=0.00..6.01 rows=1 width=404) Index Cond: (file_name = 'MOD04_L2.A2005311.1400.004.2005312013848.hdf'::bpchar) (2 rows) What I really need to do most of the time is a multi-wildcard search on this column, which is now doing a whole table scan without using the index at all: testdbspc=# explain select file_name from catalog where file_name like 'MOD04_L2.A2005311.%.004.2005312013%.hdf'; QUERY PLAN Seq Scan on catalog (cost=0.00..429.00 rows=1 width=404) Filter: (file_name ~~ 'MOD04_L2.A2005311.%.004.2005312013%.hdf'::text) (2 rows) Obviously, the performance of the table scan on such a large table is not acceptable. I tried full-text indexing and searching. It did NOT work on this column because all the letters and numbers are linked together with "." and considered one big single word by to_tsvector. Any solutions for this column to use an index search with multiple wild cards? Thanks a lot, Yantao Shi From pgsql-performance-owner@postgresql.org Tue Jan 17 16:04:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 923939DC9A6 for ; Tue, 17 Jan 2006 16:04:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75221-06 for ; Tue, 17 Jan 2006 16:04:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48]) by postgresql.org (Postfix) with ESMTP id 5E3FB9DC9A1 for ; Tue, 17 Jan 2006 16:04:43 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IT9006A16FVHKC5@vms048.mailsrvcs.net> for pgsql-performance@postgresql.org; Tue, 17 Jan 2006 14:04:44 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id AD5C36061604 for ; Tue, 17 Jan 2006 15:04:42 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 18078-04-6 for ; Tue, 17 Jan 2006 15:04:42 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 00E246061601; Tue, 17 Jan 2006 15:04:41 -0500 (EST) Date: Tue, 17 Jan 2006 15:04:41 -0500 From: Michael Stone Subject: Re: Suspending SELECTs In-reply-to: <43CD4BD0.9090807@barettadeit.com> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060117200441.GB1408@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.107 required=5 tests=[AWL=0.107] X-Spam-Score: 0.107 X-Spam-Level: X-Archive-Number: 200601/257 X-Sequence-Number: 16735 On Tue, Jan 17, 2006 at 08:56:00PM +0100, Alessandro Baretta wrote: >I understand most of these issues, and expected this kind of reply. Please, >allow me to insist that we reason on this problem and try to find a >solution. My reason for doing so is that the future software industry is >likely to see more and more web applications retrieving data from virtually >endless databases, and in such contexts, it is sensible to ask the final >client--the web client--to store the "cursor state", because web >interaction is intrinsically asynchronous, and you cannot count on users >logging out when they're done, releasing resources allocated to them. Think >of Google. I don't understand why it is better to rework the db instead of just having the web middleware keep track of what cursors are associated with what sessions? Mike Stone From pgsql-performance-owner@postgresql.org Tue Jan 17 16:06:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0D0F09DC848 for ; Tue, 17 Jan 2006 16:06:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76666-05 for ; Tue, 17 Jan 2006 16:06:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id C2C369DC841 for ; Tue, 17 Jan 2006 16:06:36 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id 68C6640C11A; Tue, 17 Jan 2006 21:11:04 +0100 (CET) Message-ID: <43CD4E5D.7060406@barettadeit.com> Date: Tue, 17 Jan 2006 21:06:53 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Craig A. James" Cc: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CC0DDF.9080904@modgraph-usa.com> In-Reply-To: <43CC0DDF.9080904@modgraph-usa.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/258 X-Sequence-Number: 16736 Craig A. James wrote: > > Alessandro Baretta writes: > > I think you're trying to do something at the wrong layer of your > architecture. This task normally goes in your middleware layer, not > your database layer. I am developing my applications in Objective Caml, and I have written the middleware layer myself. I could easily implement a cursor-pooling strategy, but there is no perfect solution to the problem of guaranteeing that cursors be closed. Remember that web applications require the user to "open a session" by connecting the appropriate HTTP resource, but users as never required to log out. Hence, in order to eventually reclaim all cursors, I must use magical "log-out detection" algorithm, which is usually implemented with a simple timeout. This guarantees the required property of safety (the population of cursors does not diverge) but does not guarantee the required property of liveness (a user connecting to the application, who has opened a session but has not logged out, and thus possesses a session token, should have access the execution context identified by his token). Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Tue Jan 17 16:19:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 626619DC99B for ; Tue, 17 Jan 2006 16:19:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92940-01 for ; Tue, 17 Jan 2006 16:19:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4B8CE9DC993 for ; Tue, 17 Jan 2006 16:19:32 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0HKJVgB021017; Tue, 17 Jan 2006 15:19:31 -0500 (EST) To: Alessandro Baretta cc: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs In-reply-to: <43CD4BD0.9090807@barettadeit.com> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> Comments: In-reply-to Alessandro Baretta message dated "Tue, 17 Jan 2006 20:56:00 +0100" Date: Tue, 17 Jan 2006 15:19:31 -0500 Message-ID: <21016.1137529171@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/260 X-Sequence-Number: 16738 Alessandro Baretta writes: > * When the cursor state is pushed back to the backend, no new > transaction is instantiated, but the XID of the original transaction > is reused. In the MVCC system, this allows us to achieve a perfectly > consistent view of the database at the instant the original > transaction started, unless a VACUUM command has been executed in the > meantime, in which case I would lose track of tuples which would have > been live in the context of the original transaction, but have been > updated or deleted and later vacuumed; however, this does not bother > me at all. > Is this not a viable solution? No. I'm not interested in "solutions" that can be translated as "you may or may not get the right answer, and there's no way even to know whether you did or not". That might be acceptable for your particular application but you certainly can't argue that it's of general usefulness. Also, I can't accept the concept of pushing the entire execution engine state out to the client and then back again; that state is large enough that doing so for every few dozen rows would yield incredibly bad performance. (In most scenarios I think it'd be just as efficient for the client to pull the whole cursor output at the start and page through it for itself.) Worse yet: this would represent a security hole large enough to wheel West Virginia through. We'd have no reasonable way to validate the data the client sends back. Lastly, you underestimate the problems associated with not holding the locks the cursor is using. As an example, it's likely that a btree indexscan wouldn't successfully restart at all, because it couldn't find where it had been if the index page had been split or deleted meanwhile. So not running VACUUM is not enough to guarantee the query will still work. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 17 16:36:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B23929DC9A4 for ; Tue, 17 Jan 2006 16:36:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94406-04 for ; Tue, 17 Jan 2006 16:36:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 32ADF9DC98B for ; Tue, 17 Jan 2006 16:36:24 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 9E85739820; Tue, 17 Jan 2006 14:36:24 -0600 (CST) Date: Tue, 17 Jan 2006 14:36:24 -0600 From: "Jim C. Nasby" To: Tomka Gergely Cc: psql performance list Subject: Re: big databases & hospitals Message-ID: <20060117203624.GC17896@pervasive.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.093 required=5 tests=[AWL=0.093] X-Spam-Score: 0.093 X-Spam-Level: X-Archive-Number: 200601/261 X-Sequence-Number: 16739 On Sat, Jan 14, 2006 at 01:13:02PM +0100, Tomka Gergely wrote: > Hi! > > I need to write a few pages about Postgresql, to convince some suits. They > have a few millions of records, on a few site, but they want to know the > practical limits of Postgresql. So i need some information about the > biggest (in storage space, in record number, in field number, and maybe > table number) postgresql databases. > > Additionally, because this company develops hospital information systems, > if someone knows about a medical institute, which uses Postgresql, and > happy, please send me infomation. I only now subscribed to the advocacy > list, and only started to browse the archives. We have a customer that has around 5000 tables and hasn't had any serious issues from that number of tables (other than \d sometimes not working in psql, but IIRC Tom put a fix in for that already). As for raw size, 100G databases are pretty common. If you search through the list archives you can probably find some examples. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 17 16:40:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CD5FF9DC98B for ; Tue, 17 Jan 2006 16:40:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06940-01 for ; Tue, 17 Jan 2006 16:40:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 1E2C59DC988 for ; Tue, 17 Jan 2006 16:40:43 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 3CE7739830; Tue, 17 Jan 2006 14:40:44 -0600 (CST) Date: Tue, 17 Jan 2006 14:40:44 -0600 From: "Jim C. Nasby" To: Tom Lane Cc: Benjamin Arai , pgsql-performance@postgresql.org Subject: Re: Ensuring data integrity with fsync=off Message-ID: <20060117204044.GD17896@pervasive.com> References: <000601c61936$38548770$fa48fd0a@uni> <20897.1137264103@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20897.1137264103@sss.pgh.pa.us> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.093 required=5 tests=[AWL=0.093] X-Spam-Score: 0.093 X-Spam-Level: X-Archive-Number: 200601/262 X-Sequence-Number: 16740 On Sat, Jan 14, 2006 at 01:41:43PM -0500, Tom Lane wrote: > "Benjamin Arai" writes: > > Right now I run "sync" afte the updates have finished to ensure that the > > data is synced to disk but I am concerned about the segment data and > > anything else I am missing that PostgreSQL explicitly handles. Is there > > something I can do in addition to sync to tell PostgreSQL exlplicitly that > > it is time to ensure everything is stored in its final destionation and etc? > > You need to give PG a CHECKPOINT command to flush stuff out of its > internal buffers. After that finishes, a manual "sync" commnd will > push everything down to disk. > > You realize, of course, that a system failure while the updates are > running might leave your database corrupt? As long as you are prepared > to restore from scratch, this might be a good tradeoff ... but don't > let yourself get caught without an up-to-date backup ... Another alternative that may (or may not) be simpler would be to run everything in one transaction and just let that commit at the end. Also, there is ongoing work towards allowing certain operations to occur without generating any log writes. Currently there is code submitted that allows COPY into a table that was created in the same transaction to go un-logged, though I think it's only in HEAD. In any case, there should be some features that could be very useful to you in 8.2. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 17 16:58:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EEFCE9DC9AB for ; Tue, 17 Jan 2006 16:58:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14834-01 for ; Tue, 17 Jan 2006 16:58:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 8B8B29DC98B for ; Tue, 17 Jan 2006 16:58:26 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 0D09739830; Tue, 17 Jan 2006 14:58:28 -0600 (CST) Date: Tue, 17 Jan 2006 14:58:28 -0600 From: "Jim C. Nasby" To: Alessandro Baretta Cc: "Craig A. James" , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Message-ID: <20060117205828.GE17896@pervasive.com> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CC0DDF.9080904@modgraph-usa.com> <43CD4E5D.7060406@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43CD4E5D.7060406@barettadeit.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.093 required=5 tests=[AWL=0.093] X-Spam-Score: 0.093 X-Spam-Level: X-Archive-Number: 200601/263 X-Sequence-Number: 16741 On Tue, Jan 17, 2006 at 09:06:53PM +0100, Alessandro Baretta wrote: > Craig A. James wrote: > > > >Alessandro Baretta writes: > > > >I think you're trying to do something at the wrong layer of your > >architecture. This task normally goes in your middleware layer, not > >your database layer. > > I am developing my applications in Objective Caml, and I have written the > middleware layer myself. I could easily implement a cursor-pooling > strategy, but there is no perfect solution to the problem of guaranteeing > that cursors be closed. Remember that web applications require the user to > "open a session" by connecting the appropriate HTTP resource, but users as > never required to log out. Hence, in order to eventually reclaim all > cursors, I must use magical "log-out detection" algorithm, which is usually > implemented with a simple timeout. This guarantees the required property of > safety (the population of cursors does not diverge) but does not guarantee > the required property of liveness (a user connecting to the application, > who has opened a session but has not logged out, and thus possesses a > session token, should have access the execution context identified by his > token). With some "AJAX magic", it would probably be pretty easy to create an application that let you know very quickly if a user left the application (ie: browsed to another site, or closed the browser). Essentially, you should be able to set it up so that it will ping the application server fairly frequently (like every 10 seconds), so you could drastically reduce the timeout interval. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 17 17:01:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E86B89DC988 for ; Tue, 17 Jan 2006 17:01:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13897-04 for ; Tue, 17 Jan 2006 17:01:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5F6D89DC86A for ; Tue, 17 Jan 2006 17:01:34 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0HL1XBb021505; Tue, 17 Jan 2006 16:01:33 -0500 (EST) To: Yantao Shi cc: pgsql-performance@postgresql.org Subject: Re: wildcard search performance with "like" In-reply-to: <43CD4CE5.3020506@larcb.ecs.nasa.gov> References: <43CD4CE5.3020506@larcb.ecs.nasa.gov> Comments: In-reply-to Yantao Shi message dated "Tue, 17 Jan 2006 15:00:37 -0500" Date: Tue, 17 Jan 2006 16:01:33 -0500 Message-ID: <21504.1137531693@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/264 X-Sequence-Number: 16742 Yantao Shi writes: > testdbspc=# explain select file_name from catalog where file_name like > 'MOD04_L2.A2005311.%.004.2005312013%.hdf'; > QUERY PLAN > Seq Scan on catalog (cost=0.00..429.00 rows=1 width=404) > Filter: (file_name ~~ 'MOD04_L2.A2005311.%.004.2005312013%.hdf'::text) > (2 rows) I'm betting you are using a non-C locale. You need either to run the database in C locale, or to create a special index type that is compatible with LIKE searches. See http://www.postgresql.org/docs/8.1/static/indexes-opclass.html regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 17 17:04:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7A26D9DC98B for ; Tue, 17 Jan 2006 17:04:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18280-03 for ; Tue, 17 Jan 2006 17:04:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by postgresql.org (Postfix) with ESMTP id 637F29DC988 for ; Tue, 17 Jan 2006 17:04:03 -0400 (AST) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO [192.168.1.27]) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 8836262; Tue, 17 Jan 2006 13:06:51 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: sum of left join greater than its parts Date: Tue, 17 Jan 2006 13:09:53 -0800 User-Agent: KMail/1.8 Cc: Robert Treat References: <1137517669.28011.728.camel@camel> In-Reply-To: <1137517669.28011.728.camel@camel> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601171309.53377.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/265 X-Sequence-Number: 16743 Hmmm, this looks like a planner bug to me: > Hash > Join (cost=870.00..992.56 rows=1 width=96) (actual time=90.566..125.782 > rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND > ("outer"."?column2?" = "inner".mtime)) -> HashAggregate > (cost=475.88..495.32 rows=1555 width=16) (actual time=51.300..70.761 > rows=10870 loops=1) >-- Nested Loop (cost=1733.79..4620.38 rows=1 width=20) (actual > time=81.160..89.826 rows=238 loops=1) -> Nested Loop > (cost=1733.79..4615.92 rows=1 width=20) (actual time=81.142..86.826 > rows=238 loops=1) Join Filter: ("outer".rmsbinaryid = > "inner".rmsbinaryid) -> HashAggregate (cost=1733.79..1740.92 rows=570 > width=12) (actual time=81.105..81.839 rows=323 loops=1) -> Bitmap Heap > Scan on msg306u (cost=111.75..1540.65 rows=25752 width=12) (actual > time=4.490..41.233 rows=25542 loops=1) Notice that for both queries, the estimates are reasonably accurate (within +/- 4x) until they get to left joining the subquery, at which point the estimate of rows joined becomes exactly "1". That looks suspicios to me ... Tom? Neil? -- --Josh Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jan 17 17:13:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C59169DC848 for ; Tue, 17 Jan 2006 17:13:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21310-03 for ; Tue, 17 Jan 2006 17:13:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.envyfinancial.com (unknown [206.248.142.186]) by postgresql.org (Postfix) with ESMTP id 031649DC841 for ; Tue, 17 Jan 2006 17:13:52 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.envyfinancial.com (Postfix) with ESMTP id D338C1CB35; Tue, 17 Jan 2006 16:12:59 -0500 (EST) Received: from mail.envyfinancial.com ([127.0.0.1]) by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15196-07; Tue, 17 Jan 2006 16:12:59 -0500 (EST) Received: by mail.envyfinancial.com (Postfix, from userid 500) id B395D1CB4B; Tue, 17 Jan 2006 16:12:59 -0500 (EST) Date: Tue, 17 Jan 2006 16:12:59 -0500 From: mark@mark.mielke.cc To: Alessandro Baretta Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Message-ID: <20060117211259.GA13926@mark.mielke.cc> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43CD4BD0.9090807@barettadeit.com> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: amavisd-new at mail.envyfinancial.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.64 required=5 tests=[AWL=0.090, NO_REAL_NAME=0.55] X-Spam-Score: 0.64 X-Spam-Level: X-Archive-Number: 200601/266 X-Sequence-Number: 16744 On Tue, Jan 17, 2006 at 08:56:00PM +0100, Alessandro Baretta wrote: > I understand most of these issues, and expected this kind of reply. Please, > allow me to insist that we reason on this problem and try to find a > solution. My reason for doing so is that the future software industry is > likely to see more and more web applications retrieving data from virtually > endless databases, and in such contexts, it is sensible to ask the final > client--the web client--to store the "cursor state", because web > interaction is intrinsically asynchronous, and you cannot count on users > logging out when they're done, releasing resources allocated to them. Think > of Google. What is wrong with LIMIT and OFFSET? I assume your results are ordered in some manner. Especially with web users, who become bored if the page doesn't flicker in a way that appeals to them, how could one have any expectation that the cursor would ever be useful at all? As a 'general' solution, I think optimizing the case where the same query is executed multiple times, with only the LIMIT and OFFSET parameters changing, would be a better bang for the buck. I'm thinking along the lines of materialized views, for queries executed more than a dozen times in a short length of time... :-) In the mean time, I successfully use LIMIT and OFFSET without such an optimization, and things have been fine for me. Cheers, mark -- mark@mielke.cc / markm@ncf.ca / markm@nortel.com __________________________ . . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/ From pgsql-performance-owner@postgresql.org Tue Jan 17 17:40:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 918479DC841 for ; Tue, 17 Jan 2006 17:40:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34769-01 for ; Tue, 17 Jan 2006 17:40:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id 4DD3F9DC80F for ; Tue, 17 Jan 2006 17:40:48 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 17 Jan 2006 13:40:50 -0800 Subject: Re: Suspending SELECTs From: Mark Lewis To: Alessandro Baretta Cc: pgsql-performance@postgresql.org In-Reply-To: <43CD4E5D.7060406@barettadeit.com> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CC0DDF.9080904@modgraph-usa.com> <43CD4E5D.7060406@barettadeit.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Tue, 17 Jan 2006 13:40:50 -0800 Message-Id: <1137534050.17090.23.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-22) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.120, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/267 X-Sequence-Number: 16745 > I am developing my applications in Objective Caml, and I have written the > middleware layer myself. I could easily implement a cursor-pooling strategy, but > there is no perfect solution to the problem of guaranteeing that cursors be > closed. Remember that web applications require the user to "open a session" by > connecting the appropriate HTTP resource, but users as never required to log > out. Hence, in order to eventually reclaim all cursors, I must use magical > "log-out detection" algorithm, which is usually implemented with a simple > timeout. This guarantees the required property of safety (the population of > cursors does not diverge) but does not guarantee the required property of > liveness (a user connecting to the application, who has opened a session but has > not logged out, and thus possesses a session token, should have access the > execution context identified by his token). I fail to see the problem here. Why should "liveness" be a required property? If is it simply that you can't promptly detect when a user is finished with their web session so you can free resources, then remember that there is no requirement that you dedicate a connection to their session in the first place. Even if you're using your own custom middleware, it isn't a very complicated or conceptually difficult thing to implement (see my previous post). Certainly it's simpler than allowing clients to pass around runtime state. As far as implementing this sort of thing in the back-end, it would be really hard with the PostgreSQL versioning model. Oracle can more easily (and kind of does) support cursors like you've described because they implement MVCC differently than PostgreSQL, and in their implementation you're guaranteed that you always have access to the most recent x megabytes of historical rows, so even without an open transaction to keep the required rows around you can still be relatively sure they'll be around for "long enough". In PostgreSQL, historical rows are kept in the tables themselves and periodically vacuumed, so there is no such guarantee, which means that you would need to either implement a lot of complex locking for little material gain, or just hold the cursors in moderately long-running transactions, which leads back to the solution suggested earlier. -- Mark Lewis From pgsql-performance-owner@postgresql.org Tue Jan 17 18:03:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2D92A9DC841 for ; Tue, 17 Jan 2006 18:03:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 37842-07 for ; Tue, 17 Jan 2006 18:03:38 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E2C2D9DC80F for ; Tue, 17 Jan 2006 18:03:33 -0400 (AST) Received: from plain.rackshack.net (unknown [66.98.130.45]) by svr4.postgresql.org (Postfix) with ESMTP id 644395AF057 for ; Tue, 17 Jan 2006 22:03:36 +0000 (GMT) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by plain.rackshack.net (8.12.10/8.12.5) with SMTP id k0HLsl3x011535 for ; Tue, 17 Jan 2006 16:54:47 -0500 From: J@Planeti.Biz Message-ID: <05c301c61bb1$d88c6a00$681e140a@fatchubby> To: Subject: Multiple Order By Criteria Date: Tue, 17 Jan 2006 17:03:27 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_05C0_01C61B87.EF7142B0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.551 required=5 tests=[HTML_MESSAGE=0.001, NO_REAL_NAME=0.55] X-Spam-Score: 0.551 X-Spam-Level: X-Archive-Number: 200601/268 X-Sequence-Number: 16746 This is a multi-part message in MIME format. ------=_NextPart_000_05C0_01C61B87.EF7142B0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm trying to query a table with 250,000+ rows. My query requires I = provide 5 colums in my "order by" clause: select column from table=20 where=20 column >=3D '2004-3-22 0:0:0' order by=20 ds.receipt desc, ds.carrier_id asc, ds.batchnum asc, encounternum asc, ds.encounter_id ASC limit 100 offset 0 I have an index built for each of these columns in my order by clause. = This query takes an unacceptable amount of time to execute. Here are the = results of the explain: Limit (cost=3D229610.78..229611.03 rows=3D100 width=3D717) -> Sort (cost=3D229610.78..230132.37 rows=3D208636 width=3D717) Sort Key: receipt, carrier_id, batchnum, encounternum, = encounter_id -> Seq Scan on detail_summary ds (cost=3D0.00..22647.13 = rows=3D208636 width=3D717) Filter: (receipt >=3D '2004-03-22'::date) When I have the order by just have 1 criteria, it's fine (just = ds.receipt DESC) Limit (cost=3D0.00..177.71 rows=3D100 width=3D717) -> Index Scan Backward using detail_summary_receipt_id_idx on = detail_summary ds (cost=3D0.00..370756.84 rows=3D208636 width=3D717) Index Cond: (receipt >=3D '2004-03-22'::date) I've increased my work_mem to up to 256meg with no speed increase. I = think there's something here I just don't understand. How do I make this go fast ? ------=_NextPart_000_05C0_01C61B87.EF7142B0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I'm trying to query a table with = 250,000+ rows. My=20 query requires I provide 5 colums in my "order by" clause:
 
select
   column
from table
where
 column >=3D '2004-3-22 = 0:0:0'
order by=20
    ds.receipt = desc,
    ds.carrier_id = asc,
    ds.batchnum = asc,
    encounternum = asc,
    ds.encounter_id = ASC
limit 100 offset 0
 
I have an index built for each of these = columns in=20 my order by clause. This query takes an unacceptable amount of time to = execute.=20 Here are the results of the explain:
 
Limit  = (cost=3D229610.78..229611.03 rows=3D100=20 width=3D717)
  ->  Sort  = (cost=3D229610.78..230132.37=20 rows=3D208636 width=3D717)
        = Sort Key:=20 receipt, carrier_id, batchnum, encounternum,=20 encounter_id
        ->  = Seq Scan=20 on detail_summary ds  (cost=3D0.00..22647.13 rows=3D208636=20 width=3D717)
         &nb= sp;   =20 Filter: (receipt >=3D '2004-03-22'::date)
 
When I have the order by just have 1 = criteria, it's=20 fine (just ds.receipt DESC)
 
Limit  (cost=3D0.00..177.71 = rows=3D100=20 width=3D717)
  ->  Index Scan Backward using=20 detail_summary_receipt_id_idx on detail_summary ds  = (cost=3D0.00..370756.84=20 rows=3D208636 width=3D717)
        = Index Cond:=20 (receipt >=3D '2004-03-22'::date)
 
I've increased my work_mem to up to = 256meg with no=20 speed increase. I think there's something here I just don't=20 understand.
 
How do I make this go fast ?

 
 
 
 
------=_NextPart_000_05C0_01C61B87.EF7142B0-- From pgsql-performance-owner@postgresql.org Tue Jan 17 18:19:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 04A009DC993 for ; Tue, 17 Jan 2006 18:19:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42249-10 for ; Tue, 17 Jan 2006 18:19:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by postgresql.org (Postfix) with ESMTP id 1ECAA9DC9A6 for ; Tue, 17 Jan 2006 18:19:47 -0400 (AST) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO [192.168.1.27]) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 8836625; Tue, 17 Jan 2006 14:22:36 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: Multiple Order By Criteria Date: Tue, 17 Jan 2006 14:25:38 -0800 User-Agent: KMail/1.8 Cc: J@planeti.biz References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> In-Reply-To: <05c301c61bb1$d88c6a00$681e140a@fatchubby> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601171425.38772.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/269 X-Sequence-Number: 16747 J, > I have an index built for each of these columns in my order by clause. > This query takes an unacceptable amount of time to execute. Here are the > results of the explain: You need a single index which has all five columns, in order. -- --Josh Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jan 17 18:49:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C96B09DC9AC for ; Tue, 17 Jan 2006 18:49:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54981-03 for ; Tue, 17 Jan 2006 18:49:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 6F2D59DC9B3 for ; Tue, 17 Jan 2006 18:48:57 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id B92A93982E; Tue, 17 Jan 2006 16:28:12 -0600 (CST) Date: Tue, 17 Jan 2006 16:28:12 -0600 From: "Jim C. Nasby" To: Michael Riess Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060117222812.GG17896@pervasive.com> References: <43CCC711.504@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.093 required=5 tests=[AWL=0.093] X-Spam-Score: 0.093 X-Spam-Level: X-Archive-Number: 200601/272 X-Sequence-Number: 16750 On Tue, Jan 17, 2006 at 03:50:38PM +0100, Michael Riess wrote: > Well, > > I think that the documentation is not exactly easy to understand. I > always wondered why there are no examples for common postgresql > configurations. All I know is that the default configuration seems to be > too low for production use. And while running postgres I get no hints as > to which setting needs to be increased to improve performance. I have no There's a number of sites that have lots of info on postgresql.conf tuning. Google for 'postgresql.conf tuning' or 'annotated postgresql.conf'. > chance to see if my FSM settings are too low other than to run vacuum > full verbose in psql, pipe the result to a text file and grep for some > words to get a somewhat comprehensive idea of how much unused space > there is in my system. > > Don't get me wrong - I really like PostgreSQL and it works well in my > application. But somehow I feel that it might run much better ... > > about the FSM: You say that increasing the FSM is fairly cheap - how > should I know that? decibel@phonebook.1[16:26]/opt/local/share/postgresql8:3%grep fsm \ postgresql.conf.sample #max_fsm_pages = 20000 # min max_fsm_relations*16, 6 bytes each #max_fsm_relations = 1000 # min 100, ~70 bytes each decibel@phonebook.1[16:26]/opt/local/share/postgresql8:4% -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 17 18:29:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 30FAE9DC841 for ; Tue, 17 Jan 2006 18:29:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46579-07 for ; Tue, 17 Jan 2006 18:29:14 -0400 (AST) X-Greylist: delayed 00:25:37.625666 by SQLgrey- Received: from plain.rackshack.net (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 004D99DC80F for ; Tue, 17 Jan 2006 18:29:09 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by plain.rackshack.net (8.12.10/8.12.5) with SMTP id k0HMKO3x012136; Tue, 17 Jan 2006 17:20:24 -0500 From: J@Planeti.Biz Message-ID: <05d801c61bb5$6c8824d0$681e140a@fatchubby> To: , References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> <200601171425.38772.josh@agliodbs.com> Subject: Re: Multiple Order By Criteria Date: Tue, 17 Jan 2006 17:29:04 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.255 required=5 tests=[AWL=-0.464, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.255 X-Spam-Level: * X-Archive-Number: 200601/270 X-Sequence-Number: 16748 I created the index, in order. Did a vacuum analyze on the table and my explain still says: Limit (cost=229610.78..229611.03 rows=100 width=717) -> Sort (cost=229610.78..230132.37 rows=208636 width=717) Sort Key: receipt, carrier_id, batchnum, encounternum, encounter_id -> Seq Scan on detail_summary ds (cost=0.00..22647.13 rows=208636 width=717) Filter: (receipt >= '2004-03-22'::date) So, for fun I did set enable_seqscan to off But that didn't help. For some reason, the sort wants to do a seq scan and not use my super new index. Am I doing something wrong ? ----- Original Message ----- From: "Josh Berkus" To: Cc: Sent: Tuesday, January 17, 2006 5:25 PM Subject: Re: [PERFORM] Multiple Order By Criteria > J, > >> I have an index built for each of these columns in my order by clause. >> This query takes an unacceptable amount of time to execute. Here are the >> results of the explain: > > You need a single index which has all five columns, in order. > > -- > --Josh > > Josh Berkus > Aglio Database Solutions > San Francisco > > ---------------------------(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 > From pgsql-performance-owner@postgresql.org Tue Jan 17 18:40:37 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E3B589DC993 for ; Tue, 17 Jan 2006 18:40:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52681-03 for ; Tue, 17 Jan 2006 18:40:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id D756A9DC99E for ; Tue, 17 Jan 2006 18:40:34 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id E2639356DB; Tue, 17 Jan 2006 14:40:36 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DB3063569C; Tue, 17 Jan 2006 14:40:36 -0800 (PST) Date: Tue, 17 Jan 2006 14:40:36 -0800 (PST) From: Stephan Szabo To: Josh Berkus Cc: pgsql-performance@postgresql.org, J@planeti.biz Subject: Re: Multiple Order By Criteria In-Reply-To: <200601171425.38772.josh@agliodbs.com> Message-ID: <20060117143952.D47156@megazone.bigpanda.com> References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> <200601171425.38772.josh@agliodbs.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.084 required=5 tests=[AWL=0.084] X-Spam-Score: 0.084 X-Spam-Level: X-Archive-Number: 200601/271 X-Sequence-Number: 16749 On Tue, 17 Jan 2006, Josh Berkus wrote: > J, > > > I have an index built for each of these columns in my order by clause. > > This query takes an unacceptable amount of time to execute. Here are the > > results of the explain: > > You need a single index which has all five columns, in order. I think he'll also need a reverse opclass for the first column in the index or for the others since he's doing desc, asc, asc, asc, asc. From pgsql-performance-owner@postgresql.org Tue Jan 17 18:50:45 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CC3709DC9C6 for ; Tue, 17 Jan 2006 18:50:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54656-05 for ; Tue, 17 Jan 2006 18:50:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from frank.wiles.org (frank.wiles.org [24.124.39.75]) by postgresql.org (Postfix) with ESMTP id 13ED09DC9C1 for ; Tue, 17 Jan 2006 18:50:36 -0400 (AST) Received: from kungfu (frank.wiles.org [127.0.0.1]) by frank.wiles.org (8.13.1/8.13.1) with SMTP id k0HMoW1A017924; Tue, 17 Jan 2006 16:50:32 -0600 Date: Tue, 17 Jan 2006 16:51:15 -0600 From: Frank Wiles To: mark@mark.mielke.cc Cc: a.baretta@barettadeit.com, tgl@sss.pgh.pa.us, pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Message-Id: <20060117165115.2a5873dc.frank@wiles.org> In-Reply-To: <20060117211259.GA13926@mark.mielke.cc> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/273 X-Sequence-Number: 16751 On Tue, 17 Jan 2006 16:12:59 -0500 mark@mark.mielke.cc wrote: > In the mean time, I successfully use LIMIT and OFFSET without such an > optimization, and things have been fine for me. Same here. --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From pgsql-performance-owner@postgresql.org Tue Jan 17 18:57:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8A52B9DC99E for ; Tue, 17 Jan 2006 18:57:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54541-10 for ; Tue, 17 Jan 2006 18:57:13 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 5F4DE9DC80F for ; Tue, 17 Jan 2006 18:57:09 -0400 (AST) Received: from electronsrus.com (adsl-69-154-123-204.dsl.fyvlar.swbell.net [69.154.123.204]) by svr4.postgresql.org (Postfix) with ESMTP id 86A435AF05E for ; Tue, 17 Jan 2006 22:57:12 +0000 (GMT) Received: from bits.electronsrus.com (bits.electronsrus.com [70.178.169.136]) (authenticated bits=0) by electronsrus.com (8.13.4/8.13.4/Debian-2) with ESMTP id k0HMvEwn023036; Tue, 17 Jan 2006 16:57:15 -0600 From: Fredrick O Jackson To: pgsql-performance@postgresql.org Subject: Re: Multiple Order By Criteria Date: Tue, 17 Jan 2006 16:57:06 -0600 User-Agent: KMail/1.8.3 Cc: J@planeti.biz References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> <200601171425.38772.josh@agliodbs.com> <05d801c61bb5$6c8824d0$681e140a@fatchubby> In-Reply-To: <05d801c61bb5$6c8824d0$681e140a@fatchubby> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601171657.06542@bits.electronsrus.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.585 required=5 tests=[AWL=-0.585, BIZ_TLD=1.169] X-Spam-Score: 0.585 X-Spam-Level: X-Archive-Number: 200601/275 X-Sequence-Number: 16753 try adding the keyword 'date' before the date in your query. I ran into this quite a while back, but I'm not sure I remember the solution. > In Reply to: Tuesday January 17 2006 04:29 pm, J@planeti.biz J@planeti.biz wrote: > I created the index, in order. Did a vacuum analyze on the table and my > explain still says: > > Limit (cost=229610.78..229611.03 rows=100 width=717) > -> Sort (cost=229610.78..230132.37 rows=208636 width=717) > Sort Key: receipt, carrier_id, batchnum, encounternum, encounter_id > -> Seq Scan on detail_summary ds (cost=0.00..22647.13 rows=208636 > width=717) > Filter: (receipt >= '2004-03-22'::date) > > > So, for fun I did > set enable_seqscan to off > > But that didn't help. For some reason, the sort wants to do a seq scan and > not use my super new index. > > Am I doing something wrong ? > > ----- Original Message ----- > From: "Josh Berkus" > To: > Cc: > Sent: Tuesday, January 17, 2006 5:25 PM > Subject: Re: [PERFORM] Multiple Order By Criteria > > > J, > > > >> I have an index built for each of these columns in my order by clause. > >> This query takes an unacceptable amount of time to execute. Here are the > >> results of the explain: > > > > You need a single index which has all five columns, in order. > > > > > > -- > > --Josh > > > > Josh Berkus > > Aglio Database Solutions > > San Francisco > > > > ---------------------------(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 > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org From pgsql-performance-owner@postgresql.org Tue Jan 17 18:53:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A16FD9DC841 for ; Tue, 17 Jan 2006 18:53:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56445-02 for ; Tue, 17 Jan 2006 18:53:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by postgresql.org (Postfix) with ESMTP id E5EF49DC80F for ; Tue, 17 Jan 2006 18:53:11 -0400 (AST) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO [192.168.1.27]) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 8836804; Tue, 17 Jan 2006 14:56:00 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Date: Tue, 17 Jan 2006 14:59:02 -0800 User-Agent: KMail/1.8 Cc: Alessandro Baretta , Tom Lane References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> In-Reply-To: <43CD4BD0.9090807@barettadeit.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601171459.02398.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/274 X-Sequence-Number: 16752 Alessandro, > I understand most of these issues, and expected this kind of reply. > Please, allow me to insist that we reason on this problem and try to > find a solution. My reason for doing so is that the future software > industry is likely to see more and more web applications retrieving data > from virtually endless databases, and in such contexts, it is sensible > to ask the final client--the web client--to store the "cursor state", > because web interaction is intrinsically asynchronous, and you cannot > count on users logging out when they're done, releasing resources > allocated to them. Think of Google. I think you're trying to use an unreasonable difficult method to solve a problem that's already been solved multiple times. What you want is called "query caching." There are about 800 different ways to do this on the middleware or application layer which are 1000% easier than what you're proposing. -- --Josh Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jan 17 19:03:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 526DA9DC841 for ; Tue, 17 Jan 2006 19:03:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56643-08 for ; Tue, 17 Jan 2006 19:03:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from plain.rackshack.net (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 07ACB9DC81C for ; Tue, 17 Jan 2006 19:03:13 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by plain.rackshack.net (8.12.10/8.12.5) with SMTP id k0HMsN3x012824; Tue, 17 Jan 2006 17:54:25 -0500 From: J@Planeti.Biz Message-ID: <063d01c61bba$2d97fc00$681e140a@fatchubby> To: "Stephan Szabo" , "Josh Berkus" Cc: References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> <200601171425.38772.josh@agliodbs.com> <20060117143952.D47156@megazone.bigpanda.com> Subject: Re: Multiple Order By Criteria Date: Tue, 17 Jan 2006 18:03:04 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.547 required=5 tests=[AWL=-0.172, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.547 X-Spam-Level: * X-Archive-Number: 200601/276 X-Sequence-Number: 16754 I created the index like this: CREATE INDEX rcbee_idx ON detail_summary USING btree (receipt, carrier_id, batchnum, encounternum, encounter_id); Is this correct ? How do I make a reverse opclass ? ----- Original Message ----- From: "Stephan Szabo" To: "Josh Berkus" Cc: ; Sent: Tuesday, January 17, 2006 5:40 PM Subject: Re: [PERFORM] Multiple Order By Criteria > > On Tue, 17 Jan 2006, Josh Berkus wrote: > >> J, >> >> > I have an index built for each of these columns in my order by clause. >> > This query takes an unacceptable amount of time to execute. Here are >> > the >> > results of the explain: >> >> You need a single index which has all five columns, in order. > > I think he'll also need a reverse opclass for the first column in the > index or for the others since he's doing desc, asc, asc, asc, asc. > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > From pgsql-performance-owner@postgresql.org Tue Jan 17 19:12:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CD42B9DC99E for ; Tue, 17 Jan 2006 19:12:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57932-03 for ; Tue, 17 Jan 2006 19:12:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by postgresql.org (Postfix) with ESMTP id B4A8A9DC9AD for ; Tue, 17 Jan 2006 19:12:16 -0400 (AST) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO [192.168.1.27]) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 8836929; Tue, 17 Jan 2006 15:15:05 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Date: Tue, 17 Jan 2006 15:18:07 -0800 User-Agent: KMail/1.8 Cc: Alessandro Baretta , Tom Lane References: <43CB71AC.20203@barettadeit.com> <43CD4BD0.9090807@barettadeit.com> <200601171459.02398.josh@agliodbs.com> In-Reply-To: <200601171459.02398.josh@agliodbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601171518.07342.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/277 X-Sequence-Number: 16755 People: To follow up further, what Alessandro is talking about is known as a "keyset cursor". Sybase and SQL Server used to support them; I beleive that they were strictly read-only and had weird issues with record visibility. -- --Josh Josh Berkus Aglio Database Solutions San Francisco From pgsql-performance-owner@postgresql.org Tue Jan 17 19:39:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 846B89DC841 for ; Tue, 17 Jan 2006 19:39:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66093-03 for ; Tue, 17 Jan 2006 19:39:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 60D519DC80F for ; Tue, 17 Jan 2006 19:39:00 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 9D73435784; Tue, 17 Jan 2006 15:39:03 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 99878356B3; Tue, 17 Jan 2006 15:39:03 -0800 (PST) Date: Tue, 17 Jan 2006 15:39:03 -0800 (PST) From: Stephan Szabo To: J@Planeti.Biz Cc: Josh Berkus , pgsql-performance@postgresql.org Subject: Re: Multiple Order By Criteria In-Reply-To: <063d01c61bba$2d97fc00$681e140a@fatchubby> Message-ID: <20060117152915.T50406@megazone.bigpanda.com> References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> <200601171425.38772.josh@agliodbs.com> <20060117143952.D47156@megazone.bigpanda.com> <063d01c61bba$2d97fc00$681e140a@fatchubby> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.67 required=5 tests=[AWL=-0.499, BIZ_TLD=1.169] X-Spam-Score: 0.67 X-Spam-Level: X-Archive-Number: 200601/278 X-Sequence-Number: 16756 On Tue, 17 Jan 2006 J@Planeti.Biz wrote: > I created the index like this: > > CREATE INDEX rcbee_idx > ON detail_summary > USING btree > (receipt, carrier_id, batchnum, encounternum, encounter_id); > > Is this correct ? That would work if you were asking for all the columns ascending or descending, but we don't currently use it for mixed orders. > How do I make a reverse opclass ? There's some information at the following: http://archives.postgresql.org/pgsql-novice/2005-10/msg00254.php http://archives.postgresql.org/pgsql-general/2005-01/msg00121.php http://archives.postgresql.org/pgsql-general/2004-06/msg00565.php From pgsql-performance-owner@postgresql.org Tue Jan 17 20:23:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8B6C39DC9AD for ; Tue, 17 Jan 2006 20:23:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74454-04 for ; Tue, 17 Jan 2006 20:23:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 75F3D9DC80F for ; Tue, 17 Jan 2006 20:23:31 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0I0EifR014288; Tue, 17 Jan 2006 19:14:44 -0500 From: J@Planeti.Biz Message-ID: <003201c61bc5$6652d690$81300d05@fatchubby> To: "Stephan Szabo" Cc: "Josh Berkus" , References: <05c301c61bb1$d88c6a00$681e140a@fatchubby> <200601171425.38772.josh@agliodbs.com> <20060117143952.D47156@megazone.bigpanda.com> <063d01c61bba$2d97fc00$681e140a@fatchubby> <20060117152915.T50406@megazone.bigpanda.com> Subject: Re: Multiple Order By Criteria Date: Tue, 17 Jan 2006 19:23:25 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.644 required=5 tests=[AWL=-0.075, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.644 X-Spam-Level: * X-Archive-Number: 200601/279 X-Sequence-Number: 16757 I've read all of this info, closely. I wish when I was searching for an answer for my problem these pages came up. Oh well. I am getting an idea of what I need to do to make this work well. I was wondering if there is more information to read on how to implement this solution in a more simple way. Much of what's written seems to be towards an audience that should understand certain things automatically. ----- Original Message ----- From: "Stephan Szabo" To: Cc: "Josh Berkus" ; Sent: Tuesday, January 17, 2006 6:39 PM Subject: Re: [PERFORM] Multiple Order By Criteria > > On Tue, 17 Jan 2006 J@Planeti.Biz wrote: > >> I created the index like this: >> >> CREATE INDEX rcbee_idx >> ON detail_summary >> USING btree >> (receipt, carrier_id, batchnum, encounternum, encounter_id); >> >> Is this correct ? > > That would work if you were asking for all the columns ascending or > descending, but we don't currently use it for mixed orders. > >> How do I make a reverse opclass ? > > There's some information at the following: > http://archives.postgresql.org/pgsql-novice/2005-10/msg00254.php > http://archives.postgresql.org/pgsql-general/2005-01/msg00121.php > http://archives.postgresql.org/pgsql-general/2004-06/msg00565.php > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > From pgsql-performance-owner@postgresql.org Tue Jan 17 20:28:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D01B19DC9AE for ; Tue, 17 Jan 2006 20:28:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72185-09 for ; Tue, 17 Jan 2006 20:28:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-5.paradise.net.nz (bm-5a.paradise.net.nz [203.96.152.184]) by postgresql.org (Postfix) with ESMTP id 9806A9DC9DC for ; Tue, 17 Jan 2006 20:28:36 -0400 (AST) Received: from smtp-1.paradise.net.nz (tclsnelb1-src-1.paradise.net.nz [203.96.152.172]) by linda-5.paradise.net.nz (Paradise.net.nz) with ESMTP id <0IT9005CTIKN6T@linda-5.paradise.net.nz> for pgsql-performance@postgresql.org; Wed, 18 Jan 2006 13:26:47 +1300 (NZDT) Received: from [192.168.1.11] (218-101-28-158.dsl.clear.net.nz [218.101.28.158]) by smtp-1.paradise.net.nz (Postfix) with ESMTP id F1A20797FD9; Wed, 18 Jan 2006 13:26:46 +1300 (NZDT) Date: Wed, 18 Jan 2006 13:26:45 +1300 From: Mark Kirkwood Subject: Re: Suspending SELECTs In-reply-to: <20060117211259.GA13926@mark.mielke.cc> To: mark@mark.mielke.cc Cc: Alessandro Baretta , Tom Lane , pgsql-performance@postgresql.org Message-id: <43CD8B45.4090907@paradise.net.nz> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.268 required=5 tests=[AWL=0.268] X-Spam-Score: 0.268 X-Spam-Level: X-Archive-Number: 200601/280 X-Sequence-Number: 16758 mark@mark.mielke.cc wrote: > On Tue, Jan 17, 2006 at 08:56:00PM +0100, Alessandro Baretta wrote: > > > What is wrong with LIMIT and OFFSET? I assume your results are ordered > in some manner. > > Especially with web users, who become bored if the page doesn't flicker > in a way that appeals to them, how could one have any expectation that > the cursor would ever be useful at all? > > As a 'general' solution, I think optimizing the case where the same > query is executed multiple times, with only the LIMIT and OFFSET > parameters changing, would be a better bang for the buck. I'm thinking > along the lines of materialized views, for queries executed more than > a dozen times in a short length of time... :-) > > In the mean time, I successfully use LIMIT and OFFSET without such an > optimization, and things have been fine for me. > Second that. I do seem to recall a case where I used a different variant of this method (possibly a database product that didn't have OFFSET, or maybe because OFFSET was expensive for the case in point), where the ORDER BY key for the last record on the page was saved and the query amended to use it filter for the "next' screen - e.g: 1st time in: SELECT ... FROM table WHERE ... ORDER BY id LIMIT 20; Suppose this displays records for id 10000 -> 10020. When the user hits next, and page saves id=10020 in the session state and executes: SELECT ... FROM table WHERE ... AND id > 10020 ORDER BY id LIMIT 20; Clearly you have to be a little careful about whether to use '>' or '>=' depending on whether 'id' is unique or not (to continue using '>' in the non unique case, you can just save and use all the members of the primary key too). Cheers Mark From pgsql-performance-owner@postgresql.org Tue Jan 17 23:29:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6FC9E9DC97F for ; Tue, 17 Jan 2006 23:29:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14418-05 for ; Tue, 17 Jan 2006 23:29:56 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203]) by postgresql.org (Postfix) with ESMTP id 61F5D9DC896 for ; Tue, 17 Jan 2006 23:29:48 -0400 (AST) Received: by wproxy.gmail.com with SMTP id 70so1482015wra for ; Tue, 17 Jan 2006 19:29:53 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=s/c4l6LwhYBeEBzc6p1ctuzbb+WmccuaY3D9NRKwHK/amC5ox8xvG7ukssJGYAwK5Jdh7TjEY/1OaCkkE9Psv5EqPG70g+FsHq4p7/Xwywdf5cZZzMCW2uZUntT+ECGcM6o2A7AcbDTKTO7I4txyLV3buwtCiusn+GZ8D54Y44Q= Received: by 10.54.70.19 with SMTP id s19mr7225222wra; Tue, 17 Jan 2006 19:29:52 -0800 (PST) Received: from ?64.161.133.227? ( [64.161.133.227]) by mx.gmail.com with ESMTP id 66sm7309215wra.2006.01.17.19.29.52; Tue, 17 Jan 2006 19:29:52 -0800 (PST) Message-ID: <43CDB628.3030007@gmail.com> Date: Tue, 17 Jan 2006 19:29:44 -0800 From: Hari Warrier User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Getting pg to use index on an inherited table (8.1.1) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/281 X-Sequence-Number: 16759 Hi, I have two tables foobar and foobar2 (which inherits from foobar, no extra columns). foobar2 has all the data (574,576 rows), foobar is empty. Both foobar and foobar2 have an index on the only column 'id'. Now I have a list of ids in a tmp_ids tables. A query on foobar2 (child table) uses the index, whereas the same query via foobar (parent) doesn't. Even if I set seq_scan off, it still doesn't use the index on the child table while queried via the parent table. Details are given below. Any help is appreciated. # analyze foobar; ANALYZE # analyze foobar2; ANALYZE # explain analyze select * from foobar2 join tmp_ids using (id); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.00..3013.69 rows=85856 width=4) (actual time=0.038..234.864 rows=44097 loops=1) -> Seq Scan on tmp_ids (cost=0.00..1.52 rows=52 width=4) (actual time=0.008..0.102 rows=52 loops=1) -> Index Scan using foobar2_idx1 on foobar2 (cost=0.00..37.29 rows=1651 width=4) (actual time=0.007..1.785 rows=848 loops=52) Index Cond: (foobar2.id = "outer".id) Total runtime: 302.963 ms (5 rows) # explain analyze select * from foobar join tmp_ids using (id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------ Hash Join (cost=1.65..13267.85 rows=149946 width=4) (actual time=7.338..3837.060 rows=44097 loops=1) Hash Cond: ("outer".id = "inner".id) -> Append (cost=0.00..8883.16 rows=576716 width=4) (actual time=0.012..2797.555 rows=574576 loops=1) -> Seq Scan on foobar (cost=0.00..31.40 rows=2140 width=4) (actual time=0.002..0.002 rows=0 loops=1) -> Seq Scan on foobar2 foobar (cost=0.00..8851.76 rows=574576 width=4) (actual time=0.004..1027.422 rows=574576 loops=1) -> Hash (cost=1.52..1.52 rows=52 width=4) (actual time=0.194..0.194 rows=52 loops=1) -> Seq Scan on tmp_ids (cost=0.00..1.52 rows=52 width=4) (actual time=0.003..0.094 rows=52 loops=1) Total runtime: 3905.074 ms (8 rows) # select version(); version -------------------------------------------------------------------------------------------- PostgreSQL 8.1.1 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 3.3.3 (SuSE Linux) (1 row) # \d foobar Table "public.foobar" Column | Type | Modifiers --------+---------+----------- id | integer | Indexes: "foobar_idx1" btree (id) # \d foobar2 Table "public.foobar2" Column | Type | Modifiers --------+---------+----------- id | integer | Indexes: "foobar2_idx1" btree (id) Inherits: foobar # \d tmp_ids Table "public.tmp_ids" Column | Type | Modifiers --------+---------+----------- id | integer | # set enable_seqscan=off; SET # explain analyze select * from foobar join tmp_ids using (id); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------- Hash Join (cost=200000001.65..300013267.85 rows=149946 width=4) (actual time=7.352..3841.221 rows=44097 loops=1) Hash Cond: ("outer".id = "inner".id) -> Append (cost=100000000.00..200008883.16 rows=576716 width=4) (actual time=0.012..2803.547 rows=574576 loops=1) -> Seq Scan on foobar (cost=100000000.00..100000031.40 rows=2140 width=4) (actual time=0.003..0.003 rows=0 loops=1) -> Seq Scan on foobar2 foobar (cost=100000000.00..100008851.76 rows=574576 width=4) (actual time=0.005..1032.148 rows=574576 loops=1) -> Hash (cost=100000001.52..100000001.52 rows=52 width=4) (actual time=0.194..0.194 rows=52 loops=1) -> Seq Scan on tmp_ids (cost=100000000.00..100000001.52 rows=52 width=4) (actual time=0.004..0.098 rows=52 loops=1) Total runtime: 3909.332 ms (8 rows) Output of "show all" (remember I just turned off seq_scan above) enable_bitmapscan | on | Enables the planner's use of bitmap-scan plans. enable_hashagg | on | Enables the planner's use of hashed aggregation plans. enable_hashjoin | on | Enables the planner's use of hash join plans. enable_indexscan | on | Enables the planner's use of index-scan plans. enable_mergejoin | on | Enables the planner's use of merge join plans. enable_nestloop | on | Enables the planner's use of nested-loop join plans. enable_seqscan | off | Enables the planner's use of sequential-scan plans. enable_sort | on | Enables the planner's use of explicit sort steps. enable_tidscan | on | Enables the planner's use of TID scan plans. From pgsql-performance-owner@postgresql.org Tue Jan 17 23:48:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 32F469DC80F for ; Tue, 17 Jan 2006 23:48:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14595-10 for ; Tue, 17 Jan 2006 23:48:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net [68.15.5.150]) by postgresql.org (Postfix) with ESMTP id 72E739DC896 for ; Tue, 17 Jan 2006 23:48:11 -0400 (AST) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k0I2majD016998; Tue, 17 Jan 2006 18:48:36 -0800 Message-ID: <43CDB97A.8050702@modgraph-usa.com> Date: Tue, 17 Jan 2006 19:43:54 -0800 From: "Craig A. James" User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Alessandro Baretta CC: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CC0DDF.9080904@modgraph-usa.com> <43CD4E5D.7060406@barettadeit.com> In-Reply-To: <43CD4E5D.7060406@barettadeit.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.047 required=5 tests=[AWL=0.047] X-Spam-Score: 0.047 X-Spam-Level: X-Archive-Number: 200601/282 X-Sequence-Number: 16760 Alessandro Baretta wrote: >> I think you're trying to do something at the wrong layer of your >> architecture. This task normally goes in your middleware layer, not >> your database layer. > > I am developing my applications in Objective Caml, and I have written > the middleware layer myself. I could easily implement a cursor-pooling > strategy... You're trying to solve a very hard problem, and you're rewriting a lot of stuff that's been worked on for years by teams of people. If there's any way you switch use something like JBOSS, it might save you a lot of grief and hard work. I eliminated this problem a different way, using what we call a "hitlist". Basically, every query becomes a "select into", something like this: insert into hitlist_xxxx (select id from ...) where "xxxx" is your user's id. Once you do this, it's trivial to return each page to the user almost instantly using offset/limit, or by adding a "ROW_NUM" column of some sort. We manage very large hitlists -- millions of rows. Going from page 1 to page 100,000 takes a fraction of a second. It also has the advantage that the user can come back in a week or a month and the results are still there. The drawback are: 1. Before the user gets the first page, the entire query must complete. 2. You need a way to clean up old hitlists. 3. If you have tens of thousands of users, you'll have a large number of hitlists, and you have to use tablespaces to ensure that Linux filesystem directories don't get too large. 4. It takes space to store everyone's data. (But disk space is so cheap this isn't much of an issue.) You can eliminate #3 by a single shared hitlist with a column of UserID's. But experience shows that a big shared hitlist doesn't work very well: Inserts get slower because the UserID column must be indexed, and you can truncate individual hitlists but you have to delete from a shared hitlist. Craig From pgsql-performance-owner@postgresql.org Wed Jan 18 00:02:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C1E399DC894 for ; Wed, 18 Jan 2006 00:02:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20658-07 for ; Wed, 18 Jan 2006 00:02:27 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 6968F9DC892 for ; Wed, 18 Jan 2006 00:02:27 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0I42L8P004246; Tue, 17 Jan 2006 23:02:21 -0500 (EST) To: Mark Kirkwood cc: mark@mark.mielke.cc, Alessandro Baretta , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs In-reply-to: <43CD8B45.4090907@paradise.net.nz> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CD8B45.4090907@paradise.net.nz> Comments: In-reply-to Mark Kirkwood message dated "Wed, 18 Jan 2006 13:26:45 +1300" Date: Tue, 17 Jan 2006 23:02:21 -0500 Message-ID: <4245.1137556941@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.091 required=5 tests=[AWL=0.091] X-Spam-Score: 0.091 X-Spam-Level: X-Archive-Number: 200601/283 X-Sequence-Number: 16761 Mark Kirkwood writes: > SELECT ... FROM table WHERE ... ORDER BY id LIMIT 20; > Suppose this displays records for id 10000 -> 10020. > When the user hits next, and page saves id=10020 in the session state > and executes: > SELECT ... FROM table WHERE ... AND id > 10020 ORDER BY id LIMIT 20; > Clearly you have to be a little careful about whether to use '>' or '>=' > depending on whether 'id' is unique or not (to continue using '>' in the > non unique case, you can just save and use all the members of the > primary key too). This is actually fairly painful to get right for a multi-column key at the moment. It'll be much easier once I finish up the SQL-spec-row-comparison project. See this thread for background: http://archives.postgresql.org/pgsql-performance/2004-07/msg00188.php regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 18 00:07:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B16339DC833 for ; Wed, 18 Jan 2006 00:07:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22946-05 for ; Wed, 18 Jan 2006 00:07:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5EE399DC883 for ; Wed, 18 Jan 2006 00:07:07 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0I475M3004297; Tue, 17 Jan 2006 23:07:05 -0500 (EST) To: Hari Warrier cc: pgsql-performance@postgresql.org Subject: Re: Getting pg to use index on an inherited table (8.1.1) In-reply-to: <43CDB628.3030007@gmail.com> References: <43CDB628.3030007@gmail.com> Comments: In-reply-to Hari Warrier message dated "Tue, 17 Jan 2006 19:29:44 -0800" Date: Tue, 17 Jan 2006 23:07:05 -0500 Message-ID: <4296.1137557225@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.091 required=5 tests=[AWL=0.091] X-Spam-Score: 0.091 X-Spam-Level: X-Archive-Number: 200601/284 X-Sequence-Number: 16762 Hari Warrier writes: > A query on foobar2 (child table) uses the index, whereas the same query > via foobar (parent) doesn't. A query just on foobar should be able to use the index AFAIR. The problem here is that you have a join, and we are not very good about situations involving joins against inheritance sets (nor joins against UNION ALL subqueries, which is really about the same thing). I'm hoping to get a chance to look into improving this during the 8.2 development cycle. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 18 01:52:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 03A329DC9AC for ; Wed, 18 Jan 2006 01:52:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44279-01 for ; Wed, 18 Jan 2006 01:52:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-1.paradise.net.nz (bm-1a.paradise.net.nz [203.96.152.180]) by postgresql.org (Postfix) with ESMTP id B30AF9DC9A5 for ; Wed, 18 Jan 2006 01:52:03 -0400 (AST) Received: from smtp-2.paradise.net.nz (tclsnelb1-src-1.paradise.net.nz [203.96.152.172]) by linda-1.paradise.net.nz (Paradise.net.nz) with ESMTP id <0IT9007CTXMQ0W@linda-1.paradise.net.nz> for pgsql-performance@postgresql.org; Wed, 18 Jan 2006 18:52:03 +1300 (NZDT) Received: from [192.168.1.11] (218-101-28-158.dsl.clear.net.nz [218.101.28.158]) by smtp-2.paradise.net.nz (Postfix) with ESMTP id 414EF1261726; Wed, 18 Jan 2006 18:52:02 +1300 (NZDT) Date: Wed, 18 Jan 2006 18:51:58 +1300 From: Mark Kirkwood Subject: Re: Suspending SELECTs In-reply-to: <4245.1137556941@sss.pgh.pa.us> To: Tom Lane Cc: mark@mark.mielke.cc, Alessandro Baretta , pgsql-performance@postgresql.org Message-id: <43CDD77E.7080902@paradise.net.nz> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CD8B45.4090907@paradise.net.nz> <4245.1137556941@sss.pgh.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.265 required=5 tests=[AWL=0.265] X-Spam-Score: 0.265 X-Spam-Level: X-Archive-Number: 200601/286 X-Sequence-Number: 16764 Tom Lane wrote: > Mark Kirkwood writes: > >>SELECT ... FROM table WHERE ... ORDER BY id LIMIT 20; > > >>Suppose this displays records for id 10000 -> 10020. >>When the user hits next, and page saves id=10020 in the session state >>and executes: > > >>SELECT ... FROM table WHERE ... AND id > 10020 ORDER BY id LIMIT 20; > > >>Clearly you have to be a little careful about whether to use '>' or '>=' >>depending on whether 'id' is unique or not (to continue using '>' in the >>non unique case, you can just save and use all the members of the >>primary key too). > > > This is actually fairly painful to get right for a multi-column key > at the moment. It'll be much easier once I finish up the > SQL-spec-row-comparison project. Right, I think it was actually an Oracle 7.3 based web app (err... showing age here...) that I used this technique on. Cheers Mark From pgsql-performance-owner@postgresql.org Wed Jan 18 01:51:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 54F6E9DC884 for ; Wed, 18 Jan 2006 01:51:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43128-02 for ; Wed, 18 Jan 2006 01:51:31 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id BA7B79DC833 for ; Wed, 18 Jan 2006 01:51:29 -0400 (AST) Received: from ki-communication.com (unknown [202.147.194.21]) by svr4.postgresql.org (Postfix) with ESMTP id 05CDA5AF07E for ; Wed, 18 Jan 2006 05:51:28 +0000 (GMT) Received: from edp01wks ([192.168.0.127]) by ki-communication.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 18 Jan 2006 12:54:53 +0700 From: "Ahmad Fajar" To: Subject: Re: Multiple Order By Criteria Date: Wed, 18 Jan 2006 12:54:44 +0700 Keywords: Postgresql Message-ID: <001401c61bf3$aec1fef0$7f00a8c0@kicommunication.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Thread-Index: AcYbxX5pEf+aCeStTbS7W2LJDBqN1QALCNdg In-Reply-To: <003201c61bc5$6652d690$81300d05@fatchubby> X-OriginalArrivalTime: 18 Jan 2006 05:54:53.0281 (UTC) FILETIME=[B3B7D510:01C61BF3] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.169 required=5 tests=[BIZ_TLD=1.169] X-Spam-Score: 1.169 X-Spam-Level: * X-Archive-Number: 200601/285 X-Sequence-Number: 16763 -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of J@Planeti.Biz Sent: Rabu, 18 Januari 2006 07:23 To: Stephan Szabo Cc: Josh Berkus; pgsql-performance@postgresql.org Subject: Re: [PERFORM] Multiple Order By Criteria I've read all of this info, closely. I wish when I was searching for an answer for my problem these pages came up. Oh well. Well, I think you have to know about btree index. Btree is good enough, although it's not better. It will perform best, if it doesn't index too many multiple column. In your case, you have to consentrate on 2 or 3 fields that will use frequently. Put the most duplicate value on the front and others are behind. Eq: receipt, carrier_id, batchnum is the most frequently use, but the most duplicate value are: carrier_id, receipt, and batchnum so make btree index (carrier_id, receipt, batchnum). Btree will not suffer, and we also will advantage if the table have relationship with other table with the same fields order. We have not to make another index for that relation. Best regards, ahmad fajar. > I am getting an idea of what I need to do to make this work well. I was > wondering if there is more information to read on how to implement this > solution in a more simple way. Much of what's written seems to be towards > audience that should understand certain things automatically. ----- Original Message ----- From: "Stephan Szabo" To: Cc: "Josh Berkus" ; Sent: Tuesday, January 17, 2006 6:39 PM Subject: Re: [PERFORM] Multiple Order By Criteria > > On Tue, 17 Jan 2006 J@Planeti.Biz wrote: > >> I created the index like this: >> >> CREATE INDEX rcbee_idx >> ON detail_summary >> USING btree >> (receipt, carrier_id, batchnum, encounternum, encounter_id); >> >> Is this correct ? > > That would work if you were asking for all the columns ascending or > descending, but we don't currently use it for mixed orders. > >> How do I make a reverse opclass ? > > There's some information at the following: > http://archives.postgresql.org/pgsql-novice/2005-10/msg00254.php > http://archives.postgresql.org/pgsql-general/2005-01/msg00121.php > http://archives.postgresql.org/pgsql-general/2004-06/msg00565.php > From pgsql-performance-owner@postgresql.org Wed Jan 18 04:57:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 89C699DC833 for ; Wed, 18 Jan 2006 04:57:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71045-09 for ; Wed, 18 Jan 2006 04:57:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id F0E3C9DC9C3 for ; Wed, 18 Jan 2006 04:57:34 -0400 (AST) Received: from [10.1.0.20] (unknown [10.1.0.20]) by mail.barettadeit.com (Postfix) with ESMTP id BD3CD40BF69; Wed, 18 Jan 2006 10:02:03 +0100 (CET) Message-ID: <43CE030E.1070707@barettadeit.com> Date: Wed, 18 Jan 2006 09:57:50 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: mark@mark.mielke.cc Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> In-Reply-To: <20060117211259.GA13926@mark.mielke.cc> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/287 X-Sequence-Number: 16765 mark@mark.mielke.cc wrote: > On Tue, Jan 17, 2006 at 08:56:00PM +0100, Alessandro Baretta wrote: > >>I understand most of these issues, and expected this kind of reply. Please, >>allow me to insist that we reason on this problem and try to find a >>solution. My reason for doing so is that the future software industry is >>likely to see more and more web applications retrieving data from virtually >>endless databases, and in such contexts, it is sensible to ask the final >>client--the web client--to store the "cursor state", because web >>interaction is intrinsically asynchronous, and you cannot count on users >>logging out when they're done, releasing resources allocated to them. Think >>of Google. > > > What is wrong with LIMIT and OFFSET? I assume your results are ordered > in some manner. It looks like this is the only possible solution at present--and in the future, too--but it has a tremendouse performance impact on queries returning thousands of rows. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Wed Jan 18 05:08:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 645B29DC865 for ; Wed, 18 Jan 2006 05:08:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94132-04 for ; Wed, 18 Jan 2006 05:08:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from service-web.de (p15093784.pureserver.info [217.160.106.224]) by postgresql.org (Postfix) with ESMTP id 833A89DC833 for ; Wed, 18 Jan 2006 05:08:31 -0400 (AST) Received: from [10.100.1.50] (074-016-066-080.eggenet.de [80.66.16.74]) by service-web.de (Postfix) with ESMTP id A089120002A; Wed, 18 Jan 2006 10:08:32 +0100 (CET) Message-ID: <43CE0589.3000003@wildenhain.de> Date: Wed, 18 Jan 2006 10:08:25 +0100 From: Tino Wildenhain User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050929) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: Alessandro Baretta Cc: mark@mark.mielke.cc, Tom Lane , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CE030E.1070707@barettadeit.com> In-Reply-To: <43CE030E.1070707@barettadeit.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.025 required=5 tests=[AWL=0.025] X-Spam-Score: 0.025 X-Spam-Level: X-Archive-Number: 200601/288 X-Sequence-Number: 16766 Alessandro Baretta schrieb: > mark@mark.mielke.cc wrote: > ... > > It looks like this is the only possible solution at present--and in the > future, too--but it has a tremendouse performance impact on queries > returning thousands of rows. > Well actually one of the better solutions would be persistent cursors (and therefore connection pooling). I bet this is easier then fiddling with the problems of offset/limit and inventing even more compex caching in the application. Just my 0.02c ++Tino From pgsql-performance-owner@postgresql.org Wed Jan 18 07:15:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C13669DC80F for ; Wed, 18 Jan 2006 07:15:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16787-10 for ; Wed, 18 Jan 2006 07:15:30 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by postgresql.org (Postfix) with SMTP id D764E9DC833 for ; Wed, 18 Jan 2006 07:15:25 -0400 (AST) Received: (qmail invoked by alias); 18 Jan 2006 11:15:22 -0000 Received: from 201-24-233-72.ctame704.dsl.brasiltelecom.net.br (EHLO servidor) [201.24.233.72] by mail.gmx.net (mp019) with SMTP; 18 Jan 2006 12:15:22 +0100 X-Authenticated: #15924888 Subject: Simple Question of Performance ILIKE or Lower From: Marcos To: pgsql-performance@postgresql.org Content-Type: text/plain Date: Wed, 18 Jan 2006 09:10:30 +0000 Message-Id: <1137575430.966.10.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.131 required=5 tests=[AWL=0.131] X-Spam-Score: 0.131 X-Spam-Level: X-Archive-Number: 200601/290 X-Sequence-Number: 16768 Hi, I have a simple question about performance using two resources. What's have the best performance? lower( col1 ) LIKE lower( 'myquestion%' ) OR col1 ILIKE 'myquestion%' Thanks. From pgsql-performance-owner@postgresql.org Wed Jan 18 05:14:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 597AA9DC865 for ; Wed, 18 Jan 2006 05:14:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97785-08 for ; Wed, 18 Jan 2006 05:14:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 5BDEF9DC833 for ; Wed, 18 Jan 2006 05:14:34 -0400 (AST) Received: from [10.1.0.20] (unknown [10.1.0.20]) by mail.barettadeit.com (Postfix) with ESMTP id 8623C96E1; Wed, 18 Jan 2006 10:19:03 +0100 (CET) Message-ID: <43CE0709.4000104@barettadeit.com> Date: Wed, 18 Jan 2006 10:14:49 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: josh@agliodbs.com Cc: pgsql-performance@postgresql.org, Tom Lane Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <43CD4BD0.9090807@barettadeit.com> <200601171459.02398.josh@agliodbs.com> <200601171518.07342.josh@agliodbs.com> In-Reply-To: <200601171518.07342.josh@agliodbs.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/289 X-Sequence-Number: 16767 Josh Berkus wrote: > People: > > To follow up further, what Alessandro is talking about is known as a > "keyset cursor". Sybase and SQL Server used to support them; I beleive > that they were strictly read-only and had weird issues with record > visibility. I would like to thank everyone for sharing their ideas with me. I democratically accept the idea that my middleware will have to support the functionality I would have liked to delegate to PostgreSQL. If I have to implement anything of this sort--just like Tom--I don't want to spend time on a solution lacking generality or imposing unacceptable resource requirements under high load. The keyset-cursor idea is probably the best bet--and BTW, let me specifically thank Josh for mentioning them. What I could do relatively easily is instantiate a thread to iteratively scan a traditional cursor N rows at a time, retrieving only record keys, and finally send them to the query-cache-manager. The application thread would then scan through the cursor results by fetching the rows associated to a given "page" of keys. I would have to keep the full cursor keyset in the application server's session state, but, hopefully, this is not nearly as bad as storing the entire recordset. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Wed Jan 18 10:06:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7F78C9DC833 for ; Wed, 18 Jan 2006 10:06:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50828-03 for ; Wed, 18 Jan 2006 10:06:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 244619DC81D for ; Wed, 18 Jan 2006 10:06:05 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0IDvJfR018003 for ; Wed, 18 Jan 2006 08:57:19 -0500 From: J@Planeti.Biz Message-ID: <00d801c61c38$52863030$81300d05@fatchubby> To: References: <001401c61bf3$aec1fef0$7f00a8c0@kicommunication.com> Subject: Re: Multiple Order By Criteria Date: Wed, 18 Jan 2006 09:06:05 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.108 required=5 tests=[AWL=0.558, NO_REAL_NAME=0.55] X-Spam-Score: 1.108 X-Spam-Level: * X-Archive-Number: 200601/291 X-Sequence-Number: 16769 I have the answer I've been looking for and I'd like to share with all. After help from you guys, it appeared that the real issue was using an index for my order by X DESC clauses. For some reason that doesn't make good sense, postgres doesn't support this, when it kinda should automatically. Take the following end of an SQL statement. order by col1 DESC col2 ASC col3 ASC The first thing I learned is that you need an index that contains all these columns in it, in this order. If one of them has DESC then you have to create a function / operator class for each data type, in this case let's assume it's an int4. So, first thing you do is create a function that you're going to use in your operator: create function int4_revcmp(int4,int4) // --> cal the function whatever you want returns int4 as 'select $2 - $1' language sql; Then you make your operator class. CREATE OPERATOR CLASS int4_revop FOR TYPE int4 USING btree AS OPERATOR 1 > , OPERATOR 2 >= , OPERATOR 3 = , OPERATOR 4 <= , OPERATOR 5 < , FUNCTION 1 int4_revcmp(int4, int4); // --> must be the name of your function you created. Then when you make your index create index rev_idx on table using btree( col1 int4_revop, // --> must be name of operator class you defined. col2, col3 ); What I don't understand is how to make this function / operator class work with a text datatype. I tried interchanging the int4 with char and text and postgres didn't like the (as 'select $2 - $1') in the function, which I can kinda understand. Since I'm slighlty above my head at this point, I don't really know how to do it. Does any smart people here know how ? From pgsql-performance-owner@postgresql.org Wed Jan 18 10:09:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 297E19DC9B3 for ; Wed, 18 Jan 2006 10:09:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49007-09 for ; Wed, 18 Jan 2006 10:09:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 4A0D29DC984 for ; Wed, 18 Jan 2006 10:09:39 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 3350530F0B; Wed, 18 Jan 2006 15:09:43 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Wed, 18 Jan 2006 15:09:42 +0100 Organization: Hub.Org Networking Services Lines: 14 Message-ID: References: <43CCC711.504@familyhealth.com.au> <20060117222812.GG17896@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <20060117222812.GG17896@pervasive.com> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200601/292 X-Sequence-Number: 16770 > There's a number of sites that have lots of info on postgresql.conf > tuning. Google for 'postgresql.conf tuning' or 'annotated > postgresql.conf'. I know some of these sites, but who should I know if the information on those pages is correct? The information on those pages should be published as part of the postgres documentation. Doesn't have to be too much, maybe like this page: http://www.powerpostgresql.com/Downloads/annotated_conf_80.html But it should be part of the documentation to show newbies that not only the information is correct, but also approved of and recommended by the postgres team. From pgsql-performance-owner@postgresql.org Wed Jan 18 10:31:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B5DC29DC9B3 for ; Wed, 18 Jan 2006 10:31:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55637-03 for ; Wed, 18 Jan 2006 10:31:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.envyfinancial.com (unknown [206.248.142.186]) by postgresql.org (Postfix) with ESMTP id 199FA9DC9AC for ; Wed, 18 Jan 2006 10:31:13 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.envyfinancial.com (Postfix) with ESMTP id 36B5F1CE2E; Wed, 18 Jan 2006 09:30:25 -0500 (EST) Received: from mail.envyfinancial.com ([127.0.0.1]) by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08242-05; Wed, 18 Jan 2006 09:30:25 -0500 (EST) Received: by mail.envyfinancial.com (Postfix, from userid 500) id 1C7B41CE30; Wed, 18 Jan 2006 09:30:25 -0500 (EST) Date: Wed, 18 Jan 2006 09:30:25 -0500 From: mark@mark.mielke.cc To: Alessandro Baretta Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Message-ID: <20060118143024.GA8402@mark.mielke.cc> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CE030E.1070707@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43CE030E.1070707@barettadeit.com> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: amavisd-new at mail.envyfinancial.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.646 required=5 tests=[AWL=0.096, NO_REAL_NAME=0.55] X-Spam-Score: 0.646 X-Spam-Level: X-Archive-Number: 200601/293 X-Sequence-Number: 16771 On Wed, Jan 18, 2006 at 09:57:50AM +0100, Alessandro Baretta wrote: > mark@mark.mielke.cc wrote: > >On Tue, Jan 17, 2006 at 08:56:00PM +0100, Alessandro Baretta wrote: > >>I understand most of these issues, and expected this kind of reply. > >>Please, allow me to insist that we reason on this problem and try to find > >>a solution. My reason for doing so is that the future software industry > >>is likely to see more and more web applications retrieving data from > >>virtually endless databases, and in such contexts, it is sensible to ask > >>the final client--the web client--to store the "cursor state", because > >>web interaction is intrinsically asynchronous, and you cannot count on > >>users logging out when they're done, releasing resources allocated to > >>them. Think of Google. > >What is wrong with LIMIT and OFFSET? I assume your results are ordered > >in some manner. > It looks like this is the only possible solution at present--and in the > future, too--but it has a tremendouse performance impact on queries > returning thousands of rows. In the case of one web user generating one query, I don't see how it would have a tremendous performance impact on large queries. You mentioned google. I don't know how you use google - but most of the people I know, rarely ever search through the pages. Generally the answer we want is on the first page. If the ratio of users who search through multiple pages of results, and users who always stop on the first page, is anything significant (better than 2:1?) LIMIT and OFFSET are the desired approach. Why have complicated magic in an application, for a subset of the users? I there is to be a change to PostgreSQL to optimize for this case, I suggest it involve the caching of query plans, executor plans, query results (materialized views?), LIMIT and OFFSET. If we had all of this, you would have exactly what you want, while benefitting many more people than just you. No ugly 'persistent state cursors' or 'import/export cursor state' implementation. People would automatically benefit, without changing their applications. Cheers, mark -- mark@mielke.cc / markm@ncf.ca / markm@nortel.com __________________________ . . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/ From pgsql-performance-owner@postgresql.org Wed Jan 18 11:06:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ECF279DC833 for ; Wed, 18 Jan 2006 11:06:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59026-10 for ; Wed, 18 Jan 2006 11:06:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 4589E9DC81D for ; Wed, 18 Jan 2006 11:06:13 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id D405530F0A; Wed, 18 Jan 2006 16:06:17 +0100 (MET) From: Michael Riess X-Newsgroups: pgsql.performance Subject: Re: wildcard search performance with "like" Date: Wed, 18 Jan 2006 16:06:15 +0100 Organization: Hub.Org Networking Services Lines: 69 Message-ID: References: <43CD4CE5.3020506@larcb.ecs.nasa.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <43CD4CE5.3020506@larcb.ecs.nasa.gov> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.075 required=5 tests=[AWL=0.075] X-Spam-Score: 0.075 X-Spam-Level: X-Archive-Number: 200601/294 X-Sequence-Number: 16772 As far as I know the index is only used when you do a prefix search, for example col like 'xyz%' I think that if you are looking for expressions such as 'A%B', you could rephrase them like this: col like 'A%' AND col like 'A%B' So the database could use the index to narrow down the result and then do a sequential search for the second condition. Mike Yantao Shi schrieb: > Hi, > > I have a postges 8.1.1 table with over 29 million rows in it. The colunm > (file_name) that I need to search on has entries like the following: > > MOD04_L2.A2005311.1400.004.2005312013848.hdf > > MYD04_L2.A2005311.0700.004.2005312013437.hdf > I have an index on this column. But an index search is performance only > when I give the full file_name for search: > > testdbspc=# explain select file_name from catalog where file_name = > 'MOD04_L2.A2005311.1400.004.2005312013848.hdf'; > QUERY PLAN > Index Scan using catalog_pk_idx on catalog (cost=0.00..6.01 rows=1 > width=404) > Index Cond: (file_name = > 'MOD04_L2.A2005311.1400.004.2005312013848.hdf'::bpchar) > (2 rows) > > What I really need to do most of the time is a multi-wildcard search on > this column, which is now doing a whole table scan without using the > index at all: > > testdbspc=# explain select file_name from catalog where file_name like > 'MOD04_L2.A2005311.%.004.2005312013%.hdf'; > QUERY PLAN > Seq Scan on catalog (cost=0.00..429.00 rows=1 width=404) > Filter: (file_name ~~ 'MOD04_L2.A2005311.%.004.2005312013%.hdf'::text) > (2 rows) > > Obviously, the performance of the table scan on such a large table is > not acceptable. > > I tried full-text indexing and searching. It did NOT work on this column > because all the letters and numbers are linked together with "." and > considered one big single word by to_tsvector. > > Any solutions for this column to use an index search with multiple wild > cards? > > Thanks a lot, > Yantao Shi > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > From pgsql-performance-owner@postgresql.org Wed Jan 18 11:10:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3E5879DC984 for ; Wed, 18 Jan 2006 11:10:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62687-02 for ; Wed, 18 Jan 2006 11:10:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id EFCED9DC81D for ; Wed, 18 Jan 2006 11:10:25 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 2D4E635A57; Wed, 18 Jan 2006 07:10:30 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 2B5FC35A49; Wed, 18 Jan 2006 07:10:30 -0800 (PST) Date: Wed, 18 Jan 2006 07:10:30 -0800 (PST) From: Stephan Szabo To: J@Planeti.Biz Cc: pgsql-performance@postgresql.org Subject: Re: Multiple Order By Criteria In-Reply-To: <00d801c61c38$52863030$81300d05@fatchubby> Message-ID: <20060118065824.K33528@megazone.bigpanda.com> References: <001401c61bf3$aec1fef0$7f00a8c0@kicommunication.com> <00d801c61c38$52863030$81300d05@fatchubby> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.698 required=5 tests=[AWL=-0.471, BIZ_TLD=1.169] X-Spam-Score: 0.698 X-Spam-Level: X-Archive-Number: 200601/295 X-Sequence-Number: 16773 On Wed, 18 Jan 2006 J@Planeti.Biz wrote: > I have the answer I've been looking for and I'd like to share with all. > After help from you guys, it appeared that the real issue was using an index > for my order by X DESC clauses. For some reason that doesn't make good > sense, postgres doesn't support this, when it kinda should automatically. Well, the problem is that we do order with the index simply by through following index order. Standard index order is going to give you a sorted order only in some particular order and its inverse. IIRC, there are ways to use an index in all ascending order to do mixed orders, but I think those may involve traversing parts of the index multiple times and hasn't been implemented. > The first thing I learned is that you need an index that contains all these > columns in it, in this order. If one of them has DESC then you have to > create a function / operator class for each data type, in this case let's > assume it's an int4. So, first thing you do is create a function that you're > going to use in your operator: > > create function > int4_revcmp(int4,int4) // --> cal the function whatever you want > returns int4 > as 'select $2 - $1' > language sql; > > Then you make your operator class. > CREATE OPERATOR CLASS int4_revop > FOR TYPE int4 USING btree AS > OPERATOR 1 > , > OPERATOR 2 >= , > OPERATOR 3 = , > OPERATOR 4 <= , > OPERATOR 5 < , > FUNCTION 1 int4_revcmp(int4, int4); // --> must be > the name of your function you created. > > Then when you make your index > > create index rev_idx on table > using btree( > col1 int4_revop, // --> must be name of operator class you > defined. > col2, > col3 > ); > > What I don't understand is how to make this function / operator class work > with a text datatype. I tried interchanging the int4 with char and text and > postgres didn't like the (as 'select $2 - $1') in the function, which I can > kinda understand. Since I'm slighlty above my head at this point, I don't > really know how to do it. Does any smart people here know how ? I think having the function call the helper function for the normal operator class for the type function with the arguments in reverse order may work (or negating its output). If you have any interest, there's an outstanding call for C versions of the helper functions that we could then package up in contrib with the operator class definitions. From pgsql-performance-owner@postgresql.org Wed Jan 18 11:11:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C3ED99DC9CE for ; Wed, 18 Jan 2006 11:11:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62217-06 for ; Wed, 18 Jan 2006 11:11:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 685F19DC984 for ; Wed, 18 Jan 2006 11:11:47 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id E53BC96E1; Wed, 18 Jan 2006 16:16:21 +0100 (CET) Message-ID: <43CE5AC7.50407@barettadeit.com> Date: Wed, 18 Jan 2006 16:12:07 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: mark@mark.mielke.cc Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CE030E.1070707@barettadeit.com> <20060118143024.GA8402@mark.mielke.cc> In-Reply-To: <20060118143024.GA8402@mark.mielke.cc> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/296 X-Sequence-Number: 16774 mark@mark.mielke.cc wrote: > On Wed, Jan 18, 2006 at 09:57:50AM +0100, Alessandro Baretta wrote: > > I there is to be a change to PostgreSQL to optimize for this case, I > suggest it involve the caching of query plans, executor plans, query > results (materialized views?), LIMIT and OFFSET. If we had all of > this, you would have exactly what you want, while benefitting many > more people than just you. No ugly 'persistent state cursors' or > 'import/export cursor state' implementation. People would automatically > benefit, without changing their applications. Actually, many of the features you mention (caching executor plans--that is imposing the use of prepared queries, caching query results and materializing views) I have already implemented in my "middleware". Somehow, apparently, my intuition on the problem of determining what ought to be delegated to the DBMS and what to the "middleware" is the opposites of most people on this list. As I mentioned earlier, I democratically accept the position of the majority--and monarchically I accept Tom's. And, scientifically, I have taken resposibility for proving myself wrong: I have stated my assumptions, I have formulated the hypothesis, I have designed an experiment capable of disproving it, and I have collected the data. Here are the steps and the results of the experiment. Assumptions: Google defines the "best current practices" in web applications. Hypothesis: The "best practice" for returning large data sets is to devise an algorithm (say, persistent cursors, for example) allowing subdivision of recordset is pages of a fixed maximum size, in such a way that sequentially fetching pages of records requires the system to compute each record only once. Experiment: Given the stated assumption, record the time taken by Google to retrieve a sequence of pages of results, relative to the same query string. Repeat the experiment with different settings. Notice that Google actually displays on the results page the time taken to process the request. Results: I'll omit the numerical data, which everyone can easily obtain in only a few minutes, repeating the experiment. I used several query strings containing very common words ("linux debian", "linux kernel", "linux tux"), each yielding millions of results. I set Google to retrieve 100 results per page. Then I ran the query and paged through the data set. The obvious result is that execution time is a monotonously growing function of the page number. This clearly indicates that Google does not use any algorithm of the proposed kind, but rather an OFFSET/LIMIT strategy, thus disproving the hypothesis. It must also be noted that Google refuses to return more than 1000 results per query, thus indicating that the strategy the adopted quite apparently cannot scale indefinitely, for on a query returning a potentially flooding dataset, a user paging through the data would experience a linear slowdown on the number of pages already fetched, and the DBMS workload would also be linear on the number of fetched pages. I do not like this approach, but the fact that Google came up with no better solution is a clear indication that Tome et al. are more than correct. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Wed Jan 18 11:41:59 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E3DD79DC991 for ; Wed, 18 Jan 2006 11:41:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67563-03 for ; Wed, 18 Jan 2006 11:42:01 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.193]) by postgresql.org (Postfix) with ESMTP id 889269DC9AC for ; Wed, 18 Jan 2006 11:41:54 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so372128uge for ; Wed, 18 Jan 2006 07:41:58 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=I0xE1cMZstldul5Q+1+q15TO4Q0RAv4nAfdAdykBHk1q2KMw27n22Y7xMYPFMVOo3+sJG+j2EqaUXrHTntQTy2AYJifpmQm2LL2qA+TygfXxrY/pZBaNVop7F24GKYP2qGQF5qHSgGLWOtQ8sG2pS1nHmVPuhJE1S6RvKd1bXb4= Received: by 10.48.224.19 with SMTP id w19mr427115nfg; Wed, 18 Jan 2006 07:41:57 -0800 (PST) Received: by 10.48.164.6 with HTTP; Wed, 18 Jan 2006 07:41:57 -0800 (PST) Message-ID: <45b42ce40601180741q34553beeu134da075987e8232@mail.gmail.com> Date: Wed, 18 Jan 2006 15:41:57 +0000 From: Harry Jackson To: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs In-Reply-To: <43CE5AC7.50407@barettadeit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 Content-Disposition: inline References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CE030E.1070707@barettadeit.com> <20060118143024.GA8402@mark.mielke.cc> <43CE5AC7.50407@barettadeit.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.159 required=5 tests=[AWL=-0.173, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.159 X-Spam-Level: * X-Archive-Number: 200601/297 X-Sequence-Number: 16775 WW91ciBleHBlcmltZW50IG1hZGUgZmFyIHRvbyBtYW55IGFzc3VtcHRpb25zIGFuZCB0aGUgZGF0 YSBkb2VzIG5vdApzdGFuZCB1cCB0byBzY3J1dGlueS4KCk9uIDEvMTgvMDYsIEFsZXNzYW5kcm8g QmFyZXR0YSA8YS5iYXJldHRhQGJhcmV0dGFkZWl0LmNvbT4gd3JvdGU6Cj4gUmVzdWx0czogSSds bCBvbWl0IHRoZSBudW1lcmljYWwgZGF0YSwgd2hpY2ggZXZlcnlvbmUgY2FuIGVhc2lseSBvYnRh aW4gaW4gb25seQo+IGEgZmV3IG1pbnV0ZXMsIHJlcGVhdGluZyB0aGUgZXhwZXJpbWVudC4gSSB1 c2VkIHNldmVyYWwgcXVlcnkgc3RyaW5ncyBjb250YWluaW5nCj4gdmVyeSBjb21tb24gd29yZHMg KCJsaW51eCBkZWJpYW4iLCAibGludXgga2VybmVsIiwgImxpbnV4IHR1eCIpLCBlYWNoIHlpZWxk aW5nCj4gbWlsbGlvbnMgb2YgcmVzdWx0cy4gSSBzZXQgR29vZ2xlIHRvIHJldHJpZXZlIDEwMCBy ZXN1bHRzIHBlciBwYWdlLiBUaGVuIEkgcmFuCj4gdGhlIHF1ZXJ5IGFuZCBwYWdlZCB0aHJvdWdo IHRoZSBkYXRhIHNldC4gVGhlIG9idmlvdXMgcmVzdWx0IGlzIHRoYXQgZXhlY3V0aW9uCj4gdGlt ZSBpcyBhIG1vbm90b25vdXNseSBncm93aW5nIGZ1bmN0aW9uIG9mIHRoZSBwYWdlIG51bWJlci4g VGhpcyBjbGVhcmx5Cj4gaW5kaWNhdGVzIHRoYXQgR29vZ2xlIGRvZXMgbm90IHVzZSBhbnkgYWxn b3JpdGhtIG9mIHRoZSBwcm9wb3NlZCBraW5kLCBidXQKPiByYXRoZXIgYW4gT0ZGU0VUL0xJTUlU IHN0cmF0ZWd5LCB0aHVzIGRpc3Byb3ZpbmcgdGhlIGh5cG90aGVzaXMuCgpJIGp1c3QgcmFuIHRo ZSBzYW1lIHRlc3QgYW5kIEkgZ290IGEgZGlmZmVyZW50IG91dGNvbWUgdGhhbiB5b3UuIFRoZQps YXN0IHBhZ2UgY2FtZSBiYWNrIHR3aWNlIGFzIGZhc3QgYXMgcGFnZSA0LiBJIG5vdGljZWQgbm8g dHJlbmQgaW4gdGhlCnNwZWVkIG9mIHRoZSByZXN1bHRzIGZyb20gZWFjaCBwYWdlLgoKT2YgY291 cnNlIGl0IGlzIHByb2JhYmx5IGluIGNhY2hlIGJlY2F1c2UgaXRzIHN1Y2ggYSBjb21tb24gdGhp bmcgdG8KYmUgc2VhcmNoZWQgb24gc28gdGhlIGV4cGVyaW1lbnQgaXMgcG9pbnRsZXNzLgoKWW91 IGNhbm5vdCBqdW1wIHRvIHlvdXIgY29uY2x1c2lvbnMgYmFzZWQgb24gYSBmZXcgc2VhcmNoZXMg b24gZ29vZ2xlLgoKPiBJdCBtdXN0IGFsc28gYmUgbm90ZWQgdGhhdCBHb29nbGUgcmVmdXNlcyB0 byByZXR1cm4gbW9yZSB0aGFuIDEwMDAgcmVzdWx0cyBwZXIKPiBxdWVyeSwgdGh1cyBpbmRpY2F0 aW5nIHRoYXQgdGhlIHN0cmF0ZWd5IHRoZSBhZG9wdGVkIHF1aXRlIGFwcGFyZW50bHkgY2Fubm90 Cj4gc2NhbGUgaW5kZWZpbml0ZWx5LCBmb3Igb24gYSBxdWVyeSByZXR1cm5pbmcgYSBwb3RlbnRp YWxseSBmbG9vZGluZyBkYXRhc2V0LCBhCj4gdXNlciBwYWdpbmcgdGhyb3VnaCB0aGUgZGF0YSB3 b3VsZCBleHBlcmllbmNlIGEgbGluZWFyIHNsb3dkb3duIG9uIHRoZSBudW1iZXIgb2YKPiBwYWdl cyBhbHJlYWR5IGZldGNoZWQsIGFuZCB0aGUgREJNUyB3b3JrbG9hZCB3b3VsZCBhbHNvIGJlIGxp bmVhciBvbiB0aGUgbnVtYmVyCj4gb2YgZmV0Y2hlZCBwYWdlcy4KClRoZXJlIGFyZSB2YXJpb3Vz IHJlYXNvbiB3aHkgZ29vZ2xlIG1pZ2h0ICB3YW50IHRvIGxpbWl0IHRoZSBzZWFyY2gKcmVzdWx0 IHJldHVybmVkIGllIHRvIGVuY291cmFnZSBwZW9wbGUgdG8gbmFycm93IHRoZWlyIHNlYXJjaC4g UHJldmVudApzY3JlZW4gc2NyYXBlcnMgZnJvbSBoaXR0aW5nIHRoZW0gcmVhbGx5IGhhcmQgYmxh aCBibGFoLiBQZXJoYXBzIGxlc3MKdGhhbiAwLjAwMDAwMDAxJSBvZiByZWFsIHVzZXJzIChub3Qg c2NyYXBlcnMpIGFjdHVhbGx5IGRpZyBkb3duIHRvIHRoZQoxMHRoIHBhZ2Ugc28gd2hhdHMgdGhl IHBvaW50LgoKVGhlcmUgYXJlIG51bWVyb3VzIG1ldGhvZHMgdGhhdCB5b3UgY2FuIHVzZSB0byBn aXZlIHNlcGFyYXRlIHJlc3VsdApwYWdlcyBzb21lIG9mIHdoaWNoIGluY2x1ZGUgZ29pbmcgYmFj ayB0byB0aGUgZGF0YWJhc2UgYW5kIHNvbWUgZG9uJ3QuCkkgcHJlZmVyIG5vdCB0byBnbyBiYWNr IHRvIHRoZSBkYXRhYmFzZSBpZiBJIGNhbiBhdm9pZCBpdCBhbmQgaWYgYWxsCnlvdSB3YW50IHRv IGRvIGlzIHByb3ZpZGUgYSBmZXcgbGlua3MgdG8gZnVydGhlciBwYWdlcyBvZiByZXN1bHRzIHRo ZW4KZ29pbmcgYmFjayB0byB0aGUgZGF0YWJhc2UgYW5kIHVzaW5nIG9mZnNldHMgaXMgYSB3YXN0 ZSBvZiBJTy4KCi0tCkhhcnJ5Cmh0dHA6Ly93d3cuaGphY2tzb24ub3JnCmh0dHA6Ly93d3cudWts dWcuY28udWsK From pgsql-performance-owner@postgresql.org Wed Jan 18 11:50:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 05C659DC81D for ; Wed, 18 Jan 2006 11:50:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69263-05 for ; Wed, 18 Jan 2006 11:50:55 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id D6EEA9DC984 for ; Wed, 18 Jan 2006 11:50:48 -0400 (AST) Received: from calypso.bi.lt (calypso.bi.lt [213.226.153.10]) by svr4.postgresql.org (Postfix) with ESMTP id 85BA65AF184 for ; Wed, 18 Jan 2006 15:50:54 +0000 (GMT) Received: from calypso.bi.lt (localhost [127.0.0.1]) by calypso.bi.lt (Postfix) with ESMTP id A61714809D8; Wed, 18 Jan 2006 17:50:49 +0200 (EET) Received: from B027543 (inet.bee.lt [213.226.131.30]) by calypso.bi.lt (Postfix) with SMTP id 8C365480258; Wed, 18 Jan 2006 17:50:49 +0200 (EET) Message-ID: <034701c61c46$f427df20$f20214ac@bite.lt> From: "Mindaugas" To: "Tom Lane" Cc: References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> <20060117173046.GA4296@surnet.cl> <604q42elzl.fsf@dba2.int.libertyrms.com> <20592.1137526372@sss.pgh.pa.us> Subject: Re: Autovacuum / full vacuum Date: Wed, 18 Jan 2006 17:50:49 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1257" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/298 X-Sequence-Number: 16776 > >> Even a database-wide vacuum does not take locks on more than one table. > >> The table locks are acquired and released one by one, as the operation > >> proceeds. > > > Has that changed recently? I have always seen "vacuumdb" or SQL > > "VACUUM" (without table specifications) running as one long > > transaction which doesn't release the locks that it is granted until > > the end of the transaction. > > You sure? It's not supposed to, and watching a database-wide vacuum > with "select * from pg_locks" doesn't look to me like it ever has locks > on more than one table (plus the table's indexes and toast table). Are there some plans to remove vacuum altogether? Mindaugas From pgsql-performance-owner@postgresql.org Wed Jan 18 12:51:18 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 25F959DC9E1 for ; Wed, 18 Jan 2006 12:51:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78423-05 for ; Wed, 18 Jan 2006 12:51:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.envyfinancial.com (unknown [206.248.142.186]) by postgresql.org (Postfix) with ESMTP id BC92D9DC9F3 for ; Wed, 18 Jan 2006 12:51:10 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.envyfinancial.com (Postfix) with ESMTP id 43F641CDC2; Wed, 18 Jan 2006 11:50:17 -0500 (EST) Received: from mail.envyfinancial.com ([127.0.0.1]) by localhost (mark.mielke.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 09627-09; Wed, 18 Jan 2006 11:50:17 -0500 (EST) Received: by mail.envyfinancial.com (Postfix, from userid 500) id 28A711CDD7; Wed, 18 Jan 2006 11:50:17 -0500 (EST) Date: Wed, 18 Jan 2006 11:50:17 -0500 From: mark@mark.mielke.cc To: Harry Jackson Cc: pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs Message-ID: <20060118165017.GA10026@mark.mielke.cc> References: <43CB71AC.20203@barettadeit.com> <9766.1137433907@sss.pgh.pa.us> <43CD4BD0.9090807@barettadeit.com> <20060117211259.GA13926@mark.mielke.cc> <43CE030E.1070707@barettadeit.com> <20060118143024.GA8402@mark.mielke.cc> <43CE5AC7.50407@barettadeit.com> <45b42ce40601180741q34553beeu134da075987e8232@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45b42ce40601180741q34553beeu134da075987e8232@mail.gmail.com> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: amavisd-new at mail.envyfinancial.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.65 required=5 tests=[AWL=0.100, NO_REAL_NAME=0.55] X-Spam-Score: 0.65 X-Spam-Level: X-Archive-Number: 200601/299 X-Sequence-Number: 16777 On Wed, Jan 18, 2006 at 03:41:57PM +0000, Harry Jackson wrote: > There are various reason why google might want to limit the search > result returned ie to encourage people to narrow their search. Prevent > screen scrapers from hitting them really hard blah blah. Perhaps less > than 0.00000001% of real users (not scrapers) actually dig down to the > 10th page so whats the point. I recall a day when google crashed, apparently due to a Windows virus that would use google to obtain email addresses. As an unsubstantiated theory - this may have involved many, many clients, all accessing search page results beyond the first page. I don't see google optimizing for the multiple page scenario. Most people (as I think you agree above), are happy with the first or second page, and they are gone. Keeping a cursor for these people as anything more than an offset into search criteria, would not be useful. Cheers, -- mark@mielke.cc / markm@ncf.ca / markm@nortel.com __________________________ . . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/ From pgsql-performance-owner@postgresql.org Wed Jan 18 13:04:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 090D69DCA09 for ; Wed, 18 Jan 2006 13:04:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84455-01 for ; Wed, 18 Jan 2006 13:04:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 70E009DC833 for ; Wed, 18 Jan 2006 13:04:05 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 7D0A33094B; Wed, 18 Jan 2006 18:04:04 +0100 (MET) From: Chris Browne X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum Date: Wed, 18 Jan 2006 11:54:21 -0500 Organization: cbbrowne Computing Inc Lines: 30 Message-ID: <60d5ipcw8y.fsf@dba2.int.libertyrms.com> References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> <20060117173046.GA4296@surnet.cl> <604q42elzl.fsf@dba2.int.libertyrms.com> <20592.1137526372@sss.pgh.pa.us> <034701c61c46$f427df20$f20214ac@bite.lt> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.17 (Jumbo Shrimp, linux) Cancel-Lock: sha1:FRDAIcROqayiJU6iWG92L5oMhVk= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.247 required=5 tests=[AWL=0.247] X-Spam-Score: 0.247 X-Spam-Level: X-Archive-Number: 200601/301 X-Sequence-Number: 16779 mind@bi.lt ("Mindaugas") writes: >> >> Even a database-wide vacuum does not take locks on more than one >> >> table. The table locks are acquired and released one by one, as >> >> the operation proceeds. >> >> > Has that changed recently? I have always seen "vacuumdb" or SQL >> > "VACUUM" (without table specifications) running as one long >> > transaction which doesn't release the locks that it is granted >> > until the end of the transaction. >> >> You sure? It's not supposed to, and watching a database-wide >> vacuum with "select * from pg_locks" doesn't look to me like it >> ever has locks on more than one table (plus the table's indexes and >> toast table). > > Are there some plans to remove vacuum altogether? I don't see that on the TODO list... http://www.postgresql.org/docs/faqs.TODO.html To the contrary, there is a whole section on what functionality to *ADD* to VACUUM. -- let name="cbbrowne" and tld="acm.org" in String.concat "@" [name;tld];; http://www.ntlug.org/~cbbrowne/finances.html "There are two types of hackers working on Linux: those who can spell, and those who can't. There is a constant, pitched battle between the two camps." --Russ Nelson (Linux Kernel Summary, Ver. 1.1.75 -> 1.1.76) From pgsql-performance-owner@postgresql.org Wed Jan 18 12:53:04 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 229849DC9F2 for ; Wed, 18 Jan 2006 12:53:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80150-07 for ; Wed, 18 Jan 2006 12:53:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from alvh.no-ip.org (201-220-123-7.bk10-dsl.surnet.cl [201.220.123.7]) by postgresql.org (Postfix) with ESMTP id 933F69DC833 for ; Wed, 18 Jan 2006 12:53:00 -0400 (AST) Received: by alvh.no-ip.org (Postfix, from userid 1000) id E4A2BC2DC59; Wed, 18 Jan 2006 13:55:21 -0300 (CLST) Date: Wed, 18 Jan 2006 13:55:21 -0300 From: Alvaro Herrera To: Mindaugas Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060118165521.GC19933@surnet.cl> Mail-Followup-To: Mindaugas , Tom Lane , pgsql-performance@postgresql.org References: <20060117145649.GE21092@phlogiston.dyndns.org> <608xteerfh.fsf@dba2.int.libertyrms.com> <20060117173046.GA4296@surnet.cl> <604q42elzl.fsf@dba2.int.libertyrms.com> <20592.1137526372@sss.pgh.pa.us> <034701c61c46$f427df20$f20214ac@bite.lt> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <034701c61c46$f427df20$f20214ac@bite.lt> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.894 required=5 tests=[AWL=-0.025, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.894 X-Spam-Level: * X-Archive-Number: 200601/300 X-Sequence-Number: 16778 Mindaugas wrote: > > >> Even a database-wide vacuum does not take locks on more than one table. > > >> The table locks are acquired and released one by one, as the operation > > >> proceeds. > > > > > Has that changed recently? I have always seen "vacuumdb" or SQL > > > "VACUUM" (without table specifications) running as one long > > > transaction which doesn't release the locks that it is granted until > > > the end of the transaction. > > > > You sure? It's not supposed to, and watching a database-wide vacuum > > with "select * from pg_locks" doesn't look to me like it ever has locks > > on more than one table (plus the table's indexes and toast table). > > Are there some plans to remove vacuum altogether? No, but there are plans to make it as automatic and unintrusive as possible. (User configuration will probably always be needed.) -- Alvaro Herrera Developer, http://www.PostgreSQL.org FOO MANE PADME HUM From pgsql-performance-owner@postgresql.org Wed Jan 18 14:10:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B7F2D9DC833 for ; Wed, 18 Jan 2006 14:09:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93755-08 for ; Wed, 18 Jan 2006 14:09:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from server10.araisoft.com (server10.araisoft.com [72.9.228.195]) by postgresql.org (Postfix) with ESMTP id B7BC89DC9FB for ; Wed, 18 Jan 2006 14:09:54 -0400 (AST) Received: from localhost (unknown [127.0.0.1]) by server10.araisoft.com (Postfix) with ESMTP id 38FDB3D6200E for ; Wed, 18 Jan 2006 10:09:51 -0800 (PST) Received: from server10.araisoft.com ([127.0.0.1]) by localhost (server10.araisoft.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 11304-02 for ; Wed, 18 Jan 2006 10:09:46 -0800 (PST) Received: from uni (uni.cs.ucr.edu [138.23.204.215]) by server10.araisoft.com (Postfix) with ESMTP id 2DBE53D6200D for ; Wed, 18 Jan 2006 10:09:46 -0800 (PST) From: "Benjamin Arai" To: Subject: 3WARE Card performance boost? Date: Wed, 18 Jan 2006 10:09:46 -0800 Message-ID: <00ee01c61c5a$5db2c870$d7cc178a@uni> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00EF_01C61C17.4F8F8870" X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 Thread-Index: AcYcWl0K9MCKAwJ5TNuMbMCEFq0pEQ== X-Virus-Scanned: by amavisd-new at araisoft.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.221 required=5 tests=[AWL=0.220, HTML_MESSAGE=0.001] X-Spam-Score: 0.221 X-Spam-Level: X-Archive-Number: 200601/302 X-Sequence-Number: 16780 This is a multi-part message in MIME format. ------=_NextPart_000_00EF_01C61C17.4F8F8870 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hi, I am currently doing large weekly updates with fsync=off. My updates involves SELECT, UPDATE, DELETE and etc. Setting fsync=off works for me since I take a complete backup before the weekly update and run a "sync" and "CHECKPOINT" after each weekly update has completed to ensure the data is all written to disk. Obviously, I have done this to improve write performance for the update each week. My question is if I install a 3ware or similar card to replace my current software RAID 1 configuration, am I going to see a very large improvement? If so, what would be a ball park figure? Benjamin Arai barai@cs.ucr.edu http://www.benjaminarai.com ------=_NextPart_000_00EF_01C61C17.4F8F8870 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
Hi,
 
I am = currently doing=20 large weekly updates with fsync=3Doff.  My updates involves SELECT, = UPDATE,=20 DELETE and etc.  Setting fsync=3Doff works for me since I take a = complete=20 backup before the weekly update and run a "sync" and "CHECKPOINT" after = each=20 weekly update has completed to ensure the data is all written to = disk. =20
 
Obviously, I have=20 done this to improve write performance for the update each = week.  My=20 question is if I install a 3ware or similar card to replace my = current=20 software RAID 1 configuration, am I going to see a very large = improvement? =20 If so, what would be a ball park figure?
 
Benjamin = Arai
barai@cs.ucr.edu
http://www.benjaminarai.com
 
------=_NextPart_000_00EF_01C61C17.4F8F8870-- From pgsql-performance-owner@postgresql.org Wed Jan 18 14:21:31 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C0A079DC9E1 for ; Wed, 18 Jan 2006 14:21:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95886-08 for ; Wed, 18 Jan 2006 14:21:30 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by postgresql.org (Postfix) with ESMTP id 41BF99DC9BA for ; Wed, 18 Jan 2006 14:21:27 -0400 (AST) Received: from [192.168.1.55] (fc1smp [66.93.38.87]) (authenticated bits=0) by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id k0IIC8Xw029995; Wed, 18 Jan 2006 10:12:08 -0800 Message-ID: <43CE87D1.6010904@commandprompt.com> Date: Wed, 18 Jan 2006 10:24:17 -0800 From: "Joshua D. Drake" Organization: Command Prompt, Inc. User-Agent: Thunderbird 1.5 (X11/20051025) MIME-Version: 1.0 To: Benjamin Arai CC: pgsql-performance@postgresql.org Subject: Re: 3WARE Card performance boost? References: <00ee01c61c5a$5db2c870$d7cc178a@uni> In-Reply-To: <00ee01c61c5a$5db2c870$d7cc178a@uni> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]); Wed, 18 Jan 2006 10:12:08 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.146 required=5 tests=[AWL=0.146] X-Spam-Score: 0.146 X-Spam-Level: X-Archive-Number: 200601/303 X-Sequence-Number: 16781 > Obviously, I have done this to improve write performance for the update > each week. My question is if I install a 3ware or similar card to > replace my current software RAID 1 configuration, am I going to see a > very large improvement? If so, what would be a ball park figure? Well that entirely depends on what level... 1. I would suggest LSI 150-6 not 3ware Why? Because 3ware does not make a midrange card that has a battery backed cache :). That is the only reason. 3ware makes good stuff. So anyway... LSI150-6 with Battery Backed cache option. Put 6 drives on it with a RAID 10 array, turn on write cache and you should have a hauling drive. Joshua D. Drake > > *Benjamin Arai* > barai@cs.ucr.edu > http://www.benjaminarai.com > -- The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 PostgreSQL Replication, Consulting, Custom Development, 24x7 support Managed Services, Shared and Dedicated Hosting Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/ From pgsql-performance-owner@postgresql.org Wed Jan 18 14:26:45 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CD5CA9DC833 for ; Wed, 18 Jan 2006 14:26:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99365-01 for ; Wed, 18 Jan 2006 14:26:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from server10.araisoft.com (server10.araisoft.com [72.9.228.195]) by postgresql.org (Postfix) with ESMTP id 328ED9DC9F2 for ; Wed, 18 Jan 2006 14:26:42 -0400 (AST) Received: from localhost (unknown [127.0.0.1]) by server10.araisoft.com (Postfix) with ESMTP id DA7A13D6200F for ; Wed, 18 Jan 2006 10:26:41 -0800 (PST) Received: from server10.araisoft.com ([127.0.0.1]) by localhost (server10.araisoft.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 02858-01 for ; Wed, 18 Jan 2006 10:26:37 -0800 (PST) Received: from uni (uni.cs.ucr.edu [138.23.204.215]) by server10.araisoft.com (Postfix) with ESMTP id C32C03D6200D for ; Wed, 18 Jan 2006 10:26:36 -0800 (PST) From: "Benjamin Arai" To: Subject: Re: 3WARE Card performance boost? Date: Wed, 18 Jan 2006 10:26:37 -0800 Message-ID: <011201c61c5c$b81cc520$d7cc178a@uni> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0113_01C61C19.A9F98520" X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <00ee01c61c5a$5db2c870$d7cc178a@uni> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 Thread-Index: AcYcWl0K9MCKAwJ5TNuMbMCEFq0pEQAAk7CA X-Virus-Scanned: by amavisd-new at araisoft.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.199 required=5 tests=[AWL=0.198, HTML_MESSAGE=0.001] X-Spam-Score: 0.199 X-Spam-Level: X-Archive-Number: 200601/304 X-Sequence-Number: 16782 This is a multi-part message in MIME format. ------=_NextPart_000_0113_01C61C19.A9F98520 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit My original plan was to buy a 3WARE card and put a 1GB of memory on it to improve writes but I am not sure if that is actually going to help the issue if fsync=off. Benjamin Arai barai@cs.ucr.edu http://www.benjaminarai.com _____ From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Benjamin Arai Sent: Wednesday, January 18, 2006 10:10 AM To: pgsql-performance@postgresql.org Subject: [PERFORM] 3WARE Card performance boost? Hi, I am currently doing large weekly updates with fsync=off. My updates involves SELECT, UPDATE, DELETE and etc. Setting fsync=off works for me since I take a complete backup before the weekly update and run a "sync" and "CHECKPOINT" after each weekly update has completed to ensure the data is all written to disk. Obviously, I have done this to improve write performance for the update each week. My question is if I install a 3ware or similar card to replace my current software RAID 1 configuration, am I going to see a very large improvement? If so, what would be a ball park figure? Benjamin Arai barai@cs.ucr.edu http://www.benjaminarai.com ------=_NextPart_000_0113_01C61C19.A9F98520 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
My original plan was to buy a 3WARE card and = put a 1GB of=20 memory on it to improve writes but I am not sure if that is actually = going to=20 help the issue if fsync=3Doff.
 
Benjamin = Arai
barai@cs.ucr.edu
http://www.benjaminarai.com
 


From: = pgsql-performance-owner@postgresql.org=20 [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of = Benjamin=20 Arai
Sent: Wednesday, January 18, 2006 10:10 = AM
To:=20 pgsql-performance@postgresql.org
Subject: [PERFORM] 3WARE = Card=20 performance boost?

Hi,
 
I am = currently=20 doing large weekly updates with fsync=3Doff.  My updates involves = SELECT,=20 UPDATE, DELETE and etc.  Setting fsync=3Doff works for me since I = take a=20 complete backup before the weekly update and run a "sync" and = "CHECKPOINT"=20 after each weekly update has completed to ensure the data is all = written to=20 disk. 
 
Obviously, I have=20 done this to improve write performance for the update each = week.  My=20 question is if I install a 3ware or similar card to replace my = current=20 software RAID 1 configuration, am I going to see a very large=20 improvement?  If so, what would be a ball park=20 figure?
 
Benjamin = Arai
barai@cs.ucr.edu
http://www.benjaminarai.com
 
------=_NextPart_000_0113_01C61C19.A9F98520-- From pgsql-performance-owner@postgresql.org Wed Jan 18 14:54:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0D5B59DC99E for ; Wed, 18 Jan 2006 14:54:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03173-04 for ; Wed, 18 Jan 2006 14:54:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail1.panix.com (mail1.panix.com [166.84.1.72]) by postgresql.org (Postfix) with ESMTP id 6D1E19DC9A9 for ; Wed, 18 Jan 2006 14:54:18 -0400 (AST) Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mail1.panix.com (Postfix) with ESMTP id 5EF8E58A5B; Wed, 18 Jan 2006 13:54:18 -0500 (EST) Received: (from adler@localhost) by panix2.panix.com (8.11.6p3/8.8.8/PanixN1.1) id k0IIsIT22165; Wed, 18 Jan 2006 13:54:18 -0500 (EST) Date: Wed, 18 Jan 2006 13:54:16 -0500 From: Michael Adler To: Charles Sprickman Cc: pgsql-performance@postgresql.org Subject: Re: SAN/NAS options Message-ID: <20060118185415.GF24298@pobox.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-PGP-Key-ID: 0xFA0F8E88 X-PGP-Key-Fingerprint: B40D 7C75 C44A 443D 8216 29B8 4B82 2C04 FA0F 8E88 X-PGP-Key-URL: User-Agent: Mutt/1.5.10i X-Hashcash: 1:20:060118:pgsql-performance@postgresql.org::R23mAXoorMHxEqxS:00000 0000000000000000000000007zTy X-Hashcash: 1:20:060118:spork@bway.net::P19PIl8SFqe1dNOn:0001h5X X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/305 X-Sequence-Number: 16783 On Sat, Jan 14, 2006 at 09:37:01PM -0500, Charles Sprickman wrote: > Following up to myself again... > > On Wed, 14 Dec 2005, Charles Sprickman wrote: > > >Hello all, > > > >Supermicro 1U w/SCA backplane and 4 bays > >2x2.8 GHz Xeons > >Adaptec 2015S "zero channel" RAID card > > I don't want to throw away the four machines like that that we have. I do > want to throw away the ZCR cards... :) If I ditch those I still have a 1U > box with a U320 scsi plug on the back. > > I'm vaguely considering pairing these two devices: > > http://www.areca.us/products/html/products.htm > > That's an Areca 16 channel SATA II (I haven't even read up on what's new > in SATA II) RAID controller with an optional U320 SCSI daughter card to > connect to the host(s). > > http://www.chenbro.com.tw/Chenbro_Special/RM321.php Not sure how significant, but the RM321 backplane claims to support SATA 150 (aka SATA I) only. -Mike From pgsql-performance-owner@postgresql.org Wed Jan 18 15:12:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 79AE69DC9E1 for ; Wed, 18 Jan 2006 15:12:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07911-04 for ; Wed, 18 Jan 2006 15:12:45 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.194]) by postgresql.org (Postfix) with ESMTP id 973CC9DCA03 for ; Wed, 18 Jan 2006 15:12:43 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so4161uge for ; Wed, 18 Jan 2006 11:12:43 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Jd5qg+cDMnQlLqIEs4oO0yVwjwhgEe6yPiDNWEbUiBXPIQABsgRqWzHcGiWG9fhqOB57eLSpt5WyB6uMWRWENKSjqbqJ1nomfixDOg02AUDyJiTEeN5hIEOwrI2tQ7/rhyzNLCHPLLClTWxpesqQBZdOB+XpUBPLCpJW6QhHXgo= Received: by 10.66.254.16 with SMTP id b16mr2684036ugi; Wed, 18 Jan 2006 11:12:43 -0800 (PST) Received: by 10.67.22.1 with HTTP; Wed, 18 Jan 2006 11:12:43 -0800 (PST) Message-ID: <33c6269f0601181112t4ab4c2b0wd48a4e47ab5e71ec@mail.gmail.com> Date: Wed, 18 Jan 2006 14:12:43 -0500 From: Alex Turner To: "Joshua D. Drake" Subject: Re: 3WARE Card performance boost? Cc: Benjamin Arai , pgsql-performance@postgresql.org In-Reply-To: <43CE87D1.6010904@commandprompt.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <00ee01c61c5a$5db2c870$d7cc178a@uni> <43CE87D1.6010904@commandprompt.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/306 X-Sequence-Number: 16784 http://www.3ware.com/products/serial_ata2-9000.asp Check their data sheet - the cards are BBU ready - all you have to do is order a BBU which you can from here: http://www.newegg.com/Product/Product.asp?Item=3DN82E16815999601 Alex. On 1/18/06, Joshua D. Drake wrote: > > > Obviously, I have done this to improve write performance for the update > > each week. My question is if I install a 3ware or similar card to > > replace my current software RAID 1 configuration, am I going to see a > > very large improvement? If so, what would be a ball park figure? > > Well that entirely depends on what level... > > 1. I would suggest LSI 150-6 not 3ware > > Why? > > Because 3ware does not make a midrange card that has a battery backed > cache :). That is the only reason. 3ware makes good stuff. > > So anyway... LSI150-6 with Battery Backed cache option. Put 6 drives > on it with a RAID 10 array, turn on write cache and you should have > a hauling drive. > > Joshua D. Drake > > > > > > > *Benjamin Arai* > > barai@cs.ucr.edu > > http://www.benjaminarai.com > > > > > -- > The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 > PostgreSQL Replication, Consulting, Custom Development, 24x7 support > Managed Services, Shared and Dedicated Hosting > Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/ > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > From pgsql-performance-owner@postgresql.org Wed Jan 18 15:15:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 22E589DC83F for ; Wed, 18 Jan 2006 15:15:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07342-09 for ; Wed, 18 Jan 2006 15:15:56 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 112A29DC820 for ; Wed, 18 Jan 2006 15:15:54 -0400 (AST) Received: from www.conducivetech.com (conducivetech.com [64.65.134.45]) by svr4.postgresql.org (Postfix) with ESMTP id D37A05AF036 for ; Wed, 18 Jan 2006 19:15:54 +0000 (GMT) Received: from dentaku.sight-n-sound.com (dentaku.sight-n-sound.com [198.107.31.201]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by www.conducivetech.com (Postfix) with ESMTP id C70931838F for ; Wed, 18 Jan 2006 11:15:51 -0800 (PST) From: Michael Crozier To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Date: Wed, 18 Jan 2006 11:15:51 -0800 User-Agent: KMail/1.8.3 References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> In-Reply-To: <60d5ipcw8y.fsf@dba2.int.libertyrms.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601181115.51850.crozierm@conducivetech.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/307 X-Sequence-Number: 16785 On Wednesday 18 January 2006 08:54 am, Chris Browne wrote: > To the contrary, there is a whole section on what functionality to > *ADD* to VACUUM. Near but not quite off the topic of VACUUM and new features... I've been thinking about parsing the vacuum output and storing it in Postgresql. All the tuple, page, cpu time, etc... information would be inserted into a reasonably flat set of tables. The benefits I would expect from this are: * monitoring ability - I could routinely monitor the values in the table to warn when vacuum's are failing or reclaimed space has risen dramatically. I find it easier to write and maintain monitoring agents that perform SQL queries than ones that need to routinely parse log files and coordinate with cron. * historical perspective on tuple use - which a relatively small amount of storage, I could use the vacuum output to get an idea of usage levels over time, which is beneficial for planning additional capacity * historical information could theoretically inform the autovacuum, though I assume there are better alternatives planned. * it could cut down on traffic on this list if admin could see routine maintenance in a historical context. Assuming this isn't a fundamentally horrible idea, it would be nice if there were ways to do this without parsing the pretty-printed vacuum text (ie, callbacks, triggers, guc variable). I'd like to know if anybody does this already, thinks its a bad idea, or can knock me on the noggin with the pg manual and say, "it's already there!". Regards, Michael From pgsql-performance-owner@postgresql.org Wed Jan 18 15:17:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B1C769DC87F for ; Wed, 18 Jan 2006 15:17:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05247-09 for ; Wed, 18 Jan 2006 15:17:09 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.206]) by postgresql.org (Postfix) with ESMTP id DC6E19DC9A9 for ; Wed, 18 Jan 2006 15:17:05 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so6018uge for ; Wed, 18 Jan 2006 11:17:06 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PiChSjjtBXvRG1sTrZSz9jSloKTMp3Fc8LsP2o5wOIl5ohTFpyZ8VdxCh/Qls/KJ3buuR4MpHzrmqUwibeToPn+GCdgpsgwwWVksQc2ejcMPkV6ydYcyxVEMDr1jPO+W+uO9+zSN8T2e4UBhp5XHf4hp0Sgn5hnGxKt+PNgf9KY= Received: by 10.66.249.17 with SMTP id w17mr2725249ugh; Wed, 18 Jan 2006 11:17:04 -0800 (PST) Received: by 10.67.22.1 with HTTP; Wed, 18 Jan 2006 11:17:04 -0800 (PST) Message-ID: <33c6269f0601181117j10bdeb27ke733c9b032e22cbc@mail.gmail.com> Date: Wed, 18 Jan 2006 14:17:04 -0500 From: Alex Turner To: Benjamin Arai Subject: Re: 3WARE Card performance boost? Cc: pgsql-performance@postgresql.org In-Reply-To: <00ee01c61c5a$5db2c870$d7cc178a@uni> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <00ee01c61c5a$5db2c870$d7cc178a@uni> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.786 required=5 tests=[AWL=-0.546, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 0.786 X-Spam-Level: X-Archive-Number: 200601/308 X-Sequence-Number: 16786 A 3ware card will re-order your writes to put them more in disk order, which will probably improve performance a bit, but just going from a software RAID 1 to a hardware RAID 1, I would not imagine that you will see much of a performance boost. Really to get better performance you will need to add more drives, or faster drives. If you are currently running 7200 RPM consumer drives, going to a 10000RPM WD Raptor drive will probably increase performance by about 30%, again not all that much. Alex On 1/18/06, Benjamin Arai wrote: > > Hi, > > I am currently doing large weekly updates with fsync=3Doff. My updates > involves SELECT, UPDATE, DELETE and etc. Setting fsync=3Doff works for m= e > since I take a complete backup before the weekly update and run a "sync" = and > "CHECKPOINT" after each weekly update has completed to ensure the data is > all written to disk. > > Obviously, I have done this to improve write performance for the update e= ach > week. My question is if I install a 3ware or similar card to replace my > current software RAID 1 configuration, am I going to see a very large > improvement? If so, what would be a ball park figure? > > > Benjamin Arai > barai@cs.ucr.edu > http://www.benjaminarai.com > From pgsql-performance-owner@postgresql.org Wed Jan 18 15:23:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6856B9DC820 for ; Wed, 18 Jan 2006 15:23:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06459-06 for ; Wed, 18 Jan 2006 15:23:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from obelix.askesis.nl (laudanum.demon.nl [82.161.125.16]) by postgresql.org (Postfix) with ESMTP id BF98D9DC83F for ; Wed, 18 Jan 2006 15:23:25 -0400 (AST) Received: obelix.askesis.nl 172.31.0.1 from 172.31.1.8 172.31.1.8 via HTTP with MS-WebStorage 6.0.6249 Received: from Panoramix.Askesis.nl by obelix.askesis.nl; 18 Jan 2006 20:23:25 +0100 Subject: Re: 3WARE Card performance boost? From: Joost Kraaijeveld To: Benjamin Arai Cc: pgsql-performance@postgresql.org In-Reply-To: <011201c61c5c$b81cc520$d7cc178a@uni> References: <011201c61c5c$b81cc520$d7cc178a@uni> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Wed, 18 Jan 2006 20:23:25 +0100 Message-Id: <1137612205.12172.3.camel@Panoramix.Askesis.nl> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.061 required=5 tests=[AWL=0.060, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.061 X-Spam-Level: X-Archive-Number: 200601/309 X-Sequence-Number: 16787 On Wed, 2006-01-18 at 10:26 -0800, Benjamin Arai wrote: > My original plan was to buy a 3WARE card and put a 1GB of memory on it > to improve writes but I am not sure if that is actually going to help > the issue if fsync=off. My experience with a 3Ware 9500S-8 card are rather disappointing, especially the write performance of the card, which is extremely poor. Reading is OK. -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 e-mail: J.Kraaijeveld@Askesis.nl web: www.askesis.nl From pgsql-performance-owner@postgresql.org Wed Jan 18 15:37:45 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D1A2D9DC9F7 for ; Wed, 18 Jan 2006 15:37:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11945-10 for ; Wed, 18 Jan 2006 15:37:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 5E78D9DC87F for ; Wed, 18 Jan 2006 15:37:41 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0IJSifR027142; Wed, 18 Jan 2006 14:28:45 -0500 From: J@Planeti.Biz Message-ID: <021e01c61c66$a0899190$81300d05@fatchubby> To: "Stephan Szabo" Cc: References: <001401c61bf3$aec1fef0$7f00a8c0@kicommunication.com> <00d801c61c38$52863030$81300d05@fatchubby> <20060118065824.K33528@megazone.bigpanda.com> <018a01c61c45$a49bc170$81300d05@fatchubby> <20060118090826.Y44833@megazone.bigpanda.com> <01a101c61c54$0c484010$81300d05@fatchubby> <20060118111040.J54519@megazone.bigpanda.com> Subject: Re: Multiple Order By Criteria Date: Wed, 18 Jan 2006 14:36:09 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.605 required=5 tests=[AWL=-0.114, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.605 X-Spam-Level: * X-Archive-Number: 200601/310 X-Sequence-Number: 16788 Here's some C to use to create the operator classes, seems to work ok. --- #include "postgres.h" #include #include "fmgr.h" #include "utils/date.h" /* For date sorts */ PG_FUNCTION_INFO_V1(ddd_date_revcmp); Datum ddd_date_revcmp(PG_FUNCTION_ARGS){ DateADT arg1=PG_GETARG_DATEADT(0); DateADT arg2=PG_GETARG_DATEADT(1); PG_RETURN_INT32(arg2 - arg1); } /* For integer sorts */ PG_FUNCTION_INFO_V1(ddd_int_revcmp); Datum ddd_int_revcmp(PG_FUNCTION_ARGS){ int32 arg1=PG_GETARG_INT32(0); int32 arg2=PG_GETARG_INT32(1); PG_RETURN_INT32(arg2 - arg1); } /* For string sorts */ PG_FUNCTION_INFO_V1(ddd_text_revcmp); Datum ddd_text_revcmp(PG_FUNCTION_ARGS){ text* arg1=PG_GETARG_TEXT_P(0); text* arg2=PG_GETARG_TEXT_P(1); PG_RETURN_INT32(strcmp((char*)VARDATA(arg2),(char*)VARDATA(arg1))); } /* create function ddd_date_revcmp(date,date) returns int4 as '/data/postgres/contrib/cmplib.so', 'ddd_date_revcmp' LANGUAGE C STRICT; create function ddd_int_revcmp(int4,int4) returns int4 as '/data/postgres/contrib/cmplib.so', 'ddd_int_revcmp' LANGUAGE C STRICT; create function ddd_text_revcmp(text,text) returns int4 as '/data/postgres/contrib/cmplib.so', 'ddd_text_revcmp' LANGUAGE C STRICT; */ ----- Original Message ----- From: "Stephan Szabo" To: Sent: Wednesday, January 18, 2006 2:24 PM Subject: Re: [PERFORM] Multiple Order By Criteria > On Wed, 18 Jan 2006 J@Planeti.Biz wrote: > >> Could you explain to me how do create this operator class for a text data >> type ? I think it will give me more of an understanding of what's going >> on >> if I could see this example. > > Using an SQL function (mostly because I'm too lazy to look up the C call > syntax) I think it'd be something like: > > create function bttextrevcmp(text, text) returns int4 as > 'select bttextcmp($2, $1)' language 'sql'; > > CREATE OPERATOR CLASS text_revop > FOR TYPE text USING btree AS > OPERATOR 1 > , > OPERATOR 2 >= , > OPERATOR 3 = , > OPERATOR 4 <= , > OPERATOR 5 < , > FUNCTION 1 bttextrevcmp(text,text); > > I believe bttextcmp is the standard text btree operator class helper > function, so we call it with reverse arguments to try to flip its results > (I think -bttextcmp($1,$2) would also work). > From pgsql-performance-owner@postgresql.org Wed Jan 18 16:28:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0905A9DCA16 for ; Wed, 18 Jan 2006 16:28:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21200-10 for ; Wed, 18 Jan 2006 16:28:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 23CFB9DCA0E for ; Wed, 18 Jan 2006 16:28:33 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0IKSQVu018767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Jan 2006 13:28:30 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0IKSQ63094333; Wed, 18 Jan 2006 13:28:26 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0IKSPPY094332; Wed, 18 Jan 2006 13:28:25 -0700 (MST) (envelope-from mfuhr) Date: Wed, 18 Jan 2006 13:28:25 -0700 From: Michael Fuhr To: Marcos Cc: pgsql-performance@postgresql.org Subject: Re: Use of Stored Procedures and Message-ID: <20060118202825.GA94306@winnie.fuhr.org> References: <1137488693.971.23.camel@servidor> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1137488693.971.23.camel@servidor> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/311 X-Sequence-Number: 16789 On Tue, Jan 17, 2006 at 09:04:53AM +0000, Marcos wrote: > I already read the documentation for to use the SPI_PREPARE and > SPI_EXEC... but sincerely I don't understand how I will use this > resource in my statements. What statements? What problem are you trying to solve? -- Michael Fuhr From pgsql-performance-owner@postgresql.org Wed Jan 18 17:58:19 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F228E9DCA0C for ; Wed, 18 Jan 2006 17:58:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84994-08 for ; Wed, 18 Jan 2006 17:58:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 0305E9DCA3D for ; Wed, 18 Jan 2006 17:58:13 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id DC6CF30F0A; Wed, 18 Jan 2006 22:58:15 +0100 (MET) From: William Yu X-Newsgroups: pgsql.performance Subject: Re: 3WARE Card performance boost? Date: Wed, 18 Jan 2006 13:58:09 -0800 Organization: Hub.Org Networking Services Lines: 15 Message-ID: References: <00ee01c61c5a$5db2c870$d7cc178a@uni> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <00ee01c61c5a$5db2c870$d7cc178a@uni> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/312 X-Sequence-Number: 16790 Benjamin Arai wrote: > Obviously, I have done this to improve write performance for the update > each week. My question is if I install a 3ware or similar card to > replace my current software RAID 1 configuration, am I going to see a > very large improvement? If so, what would be a ball park figure? The key is getting a card with the ability to upgrade the onboard ram. Our previous setup was a LSI MegaRAID 320-1 (128MB), 4xRAID10, fsync=off. Replaced it with a ARC-1170 (1GB) w/ 24x7200RPM SATA2 drives (split into 3 8-drive RAID6 arrays) and performance for us is through the ceiling. For OLTP type updates, we've gotten about +80% increase. For massive 1-statement updates, performance increase is in the +triple digits. From pgsql-performance-owner@postgresql.org Wed Jan 18 18:02:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B16E09DCA1E for ; Wed, 18 Jan 2006 18:02:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91070-10 for ; Wed, 18 Jan 2006 18:02:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 3AFB09DC9F1 for ; Wed, 18 Jan 2006 18:02:25 -0400 (AST) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1EzLNq-0005wj-O8 for pgsql-performance@postgresql.org; Wed, 18 Jan 2006 23:02:26 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1EzLNw-0000NZ-00 for ; Wed, 18 Jan 2006 23:02:32 +0100 Date: Wed, 18 Jan 2006 23:02:32 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: 3WARE Card performance boost? Message-ID: <20060118220232.GB1393@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <00ee01c61c5a$5db2c870$d7cc178a@uni> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.064 required=5 tests=[AWL=0.064] X-Spam-Score: 0.064 X-Spam-Level: X-Archive-Number: 200601/313 X-Sequence-Number: 16791 On Wed, Jan 18, 2006 at 01:58:09PM -0800, William Yu wrote: > The key is getting a card with the ability to upgrade the onboard ram. > > Our previous setup was a LSI MegaRAID 320-1 (128MB), 4xRAID10, > fsync=off. Replaced it with a ARC-1170 (1GB) w/ 24x7200RPM SATA2 drives > (split into 3 8-drive RAID6 arrays) and performance for us is through > the ceiling. Well, the fact that you went from four to 24 disks would perhaps be a bigger factor than the amount of RAM... /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Wed Jan 18 19:04:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 387A09DCA04 for ; Wed, 18 Jan 2006 19:04:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48680-03 for ; Wed, 18 Jan 2006 19:04:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 15E7C9DCA07 for ; Wed, 18 Jan 2006 19:04:01 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id EDB8A30F0A; Thu, 19 Jan 2006 00:04:02 +0100 (MET) From: Chris Browne X-Newsgroups: pgsql.performance Subject: Re: Autovacuum / full vacuum (off-topic?) Date: Wed, 18 Jan 2006 17:04:51 -0500 Organization: cbbrowne Computing Inc Lines: 49 Message-ID: <60bqy9nqf0.fsf@dba2.int.libertyrms.com> References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.18 (linux) Cancel-Lock: sha1:BK5/FY2PRHw809ItOS3rCaLNiw4= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.244 required=5 tests=[AWL=0.244] X-Spam-Score: 0.244 X-Spam-Level: X-Archive-Number: 200601/318 X-Sequence-Number: 16796 crozierm@conducivetech.com (Michael Crozier) writes: > On Wednesday 18 January 2006 08:54 am, Chris Browne wrote: >> To the contrary, there is a whole section on what functionality to >> *ADD* to VACUUM. > > Near but not quite off the topic of VACUUM and new features... > > I've been thinking about parsing the vacuum output and storing it in > Postgresql. All the tuple, page, cpu time, etc... information would > be inserted into a reasonably flat set of tables. > > The benefits I would expect from this are: > > * monitoring ability - I could routinely monitor the values in the > table to warn when vacuum's are failing or reclaimed space has risen > dramatically. I find it easier to write and maintain monitoring > agents that perform SQL queries than ones that need to routinely > parse log files and coordinate with cron. > > * historical perspective on tuple use - which a relatively small > amount of storage, I could use the vacuum output to get an idea of > usage levels over time, which is beneficial for planning additional > capacity > > * historical information could theoretically inform the autovacuum, > though I assume there are better alternatives planned. > > * it could cut down on traffic on this list if admin could see > routine maintenance in a historical context. > > Assuming this isn't a fundamentally horrible idea, it would be nice > if there were ways to do this without parsing the pretty-printed > vacuum text (ie, callbacks, triggers, guc variable). > > I'd like to know if anybody does this already, thinks its a bad > idea, or can knock me on the noggin with the pg manual and say, > "it's already there!". We had someone working on that for a while; I don't think it got to the point of being something ready to unleash on the world. I certainly agree that it would be plenty useful to have this sort of information available. Having a body of historical information could lead to having some "more informed" suggestions for heuristics. -- (reverse (concatenate 'string "gro.mca" "@" "enworbbc")) http://cbbrowne.com/info/unix.html Bad command. Bad, bad command! Sit! Stay! Staaay... From pgsql-performance-owner@postgresql.org Wed Jan 18 18:15:31 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C74479DCA0C for ; Wed, 18 Jan 2006 18:15:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04337-06 for ; Wed, 18 Jan 2006 18:15:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 146F99DC87F for ; Wed, 18 Jan 2006 18:15:27 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 08D2B30F0A; Wed, 18 Jan 2006 23:15:29 +0100 (MET) From: William Yu X-Newsgroups: pgsql.performance Subject: Re: 3WARE Card performance boost? Date: Wed, 18 Jan 2006 14:15:22 -0800 Organization: Hub.Org Networking Services Lines: 27 Message-ID: References: <00ee01c61c5a$5db2c870$d7cc178a@uni> <20060118220232.GB1393@uio.no> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <20060118220232.GB1393@uio.no> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/314 X-Sequence-Number: 16792 Steinar H. Gunderson wrote: > On Wed, Jan 18, 2006 at 01:58:09PM -0800, William Yu wrote: >> The key is getting a card with the ability to upgrade the onboard ram. >> >> Our previous setup was a LSI MegaRAID 320-1 (128MB), 4xRAID10, >> fsync=off. Replaced it with a ARC-1170 (1GB) w/ 24x7200RPM SATA2 drives >> (split into 3 8-drive RAID6 arrays) and performance for us is through >> the ceiling. > > Well, the fact that you went from four to 24 disks would perhaps be a bigger > factor than the amount of RAM... > > /* Steinar */ Actually no. Our 2xOpteron 244 server is NOT fast enough to drive an array this large. That's why we had to split it up into 3 different arrays. I tried all different RAID configs and once past about 8 drives, I got the same performance no matter what because the CPU was pegged at 100%. Right now, 2 of the arrays are just mirroring each other because we can't seem utilize the performance right now. (Also protects against cabling/power supply issues as we're using 3 seperate external enclosures.) The 1GB RAM is much bigger because it almost completely hides the write activity. Looking at iostat while all our jobs are running, there's almost no disk activity. If I manually type "sync", I see 1 big 250MB-500MB write storm for 2 seconds but otherwise, writes just slowly dribble out to disk. From pgsql-performance-owner@postgresql.org Wed Jan 18 18:48:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 70BC79DCA1E for ; Wed, 18 Jan 2006 18:48:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26763-06 for ; Wed, 18 Jan 2006 18:48:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 2C7EB9DC9F7 for ; Wed, 18 Jan 2006 18:48:53 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 0C75339820; Wed, 18 Jan 2006 16:48:56 -0600 (CST) Date: Wed, 18 Jan 2006 16:48:56 -0600 From: "Jim C. Nasby" To: Michael Riess Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum Message-ID: <20060118224856.GX17896@pervasive.com> References: <43CCC711.504@familyhealth.com.au> <20060117222812.GG17896@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/315 X-Sequence-Number: 16793 On Wed, Jan 18, 2006 at 03:09:42PM +0100, Michael Riess wrote: > >There's a number of sites that have lots of info on postgresql.conf > >tuning. Google for 'postgresql.conf tuning' or 'annotated > >postgresql.conf'. > > I know some of these sites, but who should I know if the information on > those pages is correct? The information on those pages should be > published as part of the postgres documentation. Doesn't have to be too > much, maybe like this page: > > http://www.powerpostgresql.com/Downloads/annotated_conf_80.html > > But it should be part of the documentation to show newbies that not only > the information is correct, but also approved of and recommended by the > postgres team. Actually, most of what you find there is probably also found in techdocs. But of course it would be better if the docs did a better job of explaining things... -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 18 18:52:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6524D9DC87B for ; Wed, 18 Jan 2006 18:52:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35536-05 for ; Wed, 18 Jan 2006 18:52:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 9391B9DC820 for ; Wed, 18 Jan 2006 18:52:54 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 4DD2739820; Wed, 18 Jan 2006 16:52:57 -0600 (CST) Date: Wed, 18 Jan 2006 16:52:57 -0600 From: "Jim C. Nasby" To: Michael Crozier Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Message-ID: <20060118225257.GY17896@pervasive.com> References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200601181115.51850.crozierm@conducivetech.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/316 X-Sequence-Number: 16794 On Wed, Jan 18, 2006 at 11:15:51AM -0800, Michael Crozier wrote: > I've been thinking about parsing the vacuum output and storing it in > Postgresql. All the tuple, page, cpu time, etc... information would be > inserted into a reasonably flat set of tables. > Assuming this isn't a fundamentally horrible idea, it would be nice if there > were ways to do this without parsing the pretty-printed vacuum text (ie, > callbacks, triggers, guc variable). The best way to do this would be to modify the vacuum code itself, but the issue is that vacuum (or at least lazyvacuum) doesn't handle transactions like the rest of the backend does, so I suspect that there would be some issues with trying to log the information from the same backend that was running the vacuum. > I'd like to know if anybody does this already, thinks its a bad idea, or can > knock me on the noggin with the pg manual and say, "it's already there!". I think it's a good idea, but you should take a look at the recently added functionality that allows you to investigate the contests of the FSM via a user function (this is either in 8.1 or in HEAD; I can't remember which). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 18 19:02:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E95879DC83F for ; Wed, 18 Jan 2006 19:02:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39654-04 for ; Wed, 18 Jan 2006 19:02:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 924FF9DC899 for ; Wed, 18 Jan 2006 19:02:27 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 6486339820; Wed, 18 Jan 2006 17:02:30 -0600 (CST) Date: Wed, 18 Jan 2006 17:02:30 -0600 From: "Jim C. Nasby" To: Marcos Cc: pgsql-performance@postgresql.org Subject: Re: Simple Question of Performance ILIKE or Lower Message-ID: <20060118230230.GZ17896@pervasive.com> References: <1137575430.966.10.camel@servidor> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1137575430.966.10.camel@servidor> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/317 X-Sequence-Number: 16795 On Wed, Jan 18, 2006 at 09:10:30AM +0000, Marcos wrote: > Hi, > > I have a simple question about performance using two resources. > > What's have the best performance? > > lower( col1 ) LIKE lower( 'myquestion%' ) > > OR > > col1 ILIKE 'myquestion%' If you index lower( col1 ), then the former would likely perform better (if the optimizer knows it could use the index in that case). Otherwise I suspect they'd be the same. Try it and find out. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 18 19:05:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7CC8C9DC899 for ; Wed, 18 Jan 2006 19:05:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45270-06 for ; Wed, 18 Jan 2006 19:05:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 4FB439DC87B for ; Wed, 18 Jan 2006 19:05:29 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 46F5F3982E; Wed, 18 Jan 2006 17:05:32 -0600 (CST) Date: Wed, 18 Jan 2006 17:05:32 -0600 From: "Jim C. Nasby" To: "Joshua D. Drake" Cc: Benjamin Arai , pgsql-performance@postgresql.org Subject: Re: 3WARE Card performance boost? Message-ID: <20060118230532.GA17896@pervasive.com> References: <00ee01c61c5a$5db2c870$d7cc178a@uni> <43CE87D1.6010904@commandprompt.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43CE87D1.6010904@commandprompt.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/319 X-Sequence-Number: 16797 On Wed, Jan 18, 2006 at 10:24:17AM -0800, Joshua D. Drake wrote: > Because 3ware does not make a midrange card that has a battery backed > cache :). That is the only reason. 3ware makes good stuff. Why worry about battery-backup if he's running with fsync off? -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Wed Jan 18 19:36:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2E7909DC820 for ; Wed, 18 Jan 2006 19:36:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66875-06 for ; Wed, 18 Jan 2006 19:36:07 -0400 (AST) X-Greylist: delayed 04:20:13.639376 by SQLgrey- Received: from www.conducivetech.com (conducivetech.com [64.65.134.45]) by postgresql.org (Postfix) with ESMTP id 279269DC80D for ; Wed, 18 Jan 2006 19:36:03 -0400 (AST) Received: from dentaku.sight-n-sound.com (dentaku.sight-n-sound.com [198.107.31.201]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by www.conducivetech.com (Postfix) with ESMTP id 7D3201838E for ; Wed, 18 Jan 2006 15:36:05 -0800 (PST) From: Michael Crozier To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Date: Wed, 18 Jan 2006 15:36:04 -0800 User-Agent: KMail/1.8.3 References: <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> In-Reply-To: <20060118225257.GY17896@pervasive.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601181536.04758.crozierm@conducivetech.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.144 required=5 tests=[AWL=0.144] X-Spam-Score: 0.144 X-Spam-Level: X-Archive-Number: 200601/320 X-Sequence-Number: 16798 On Wednesday 18 January 2006 14:52 pm, Jim C. Nasby wrote: > I think it's a good idea, but you should take a look at the recently > added functionality that allows you to investigate the contests of the > FSM via a user function (this is either in 8.1 or in HEAD; I can't > remember which). I will look at this when time allows. Perhaps there is a combination of triggers on stat tables and asynchronous notifications that would provide this functionality without getting too deep into the vacuum's transaction logic? Were it too integrated with the vacuum, it would likely be too much for contrib/, I assume. thanks, Michael From pgsql-performance-owner@postgresql.org Wed Jan 18 19:41:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 52E539DC820 for ; Wed, 18 Jan 2006 19:41:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73904-05 for ; Wed, 18 Jan 2006 19:41:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from www.conducivetech.com (conducivetech.com [64.65.134.45]) by postgresql.org (Postfix) with ESMTP id 70F519DC80D for ; Wed, 18 Jan 2006 19:41:29 -0400 (AST) Received: from dentaku.sight-n-sound.com (dentaku.sight-n-sound.com [198.107.31.201]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by www.conducivetech.com (Postfix) with ESMTP id A50E21838E for ; Wed, 18 Jan 2006 15:41:32 -0800 (PST) From: Michael Crozier To: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Date: Wed, 18 Jan 2006 15:41:33 -0800 User-Agent: KMail/1.8.3 References: <200601181115.51850.crozierm@conducivetech.com> <60bqy9nqf0.fsf@dba2.int.libertyrms.com> In-Reply-To: <60bqy9nqf0.fsf@dba2.int.libertyrms.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601181541.33376.crozierm@conducivetech.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.137 required=5 tests=[AWL=0.137] X-Spam-Score: 0.137 X-Spam-Level: X-Archive-Number: 200601/321 X-Sequence-Number: 16799 > We had someone working on that for a while; I don't think it got to > the point of being something ready to unleash on the world. Interesting. I will dig around the mailing list archives too see how they went about it... for my own curiosity if nothing else. If you happen to know offhand, I'd appreciate a link. Regards, Michael From pgsql-performance-owner@postgresql.org Wed Jan 18 19:44:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BB6089DCA01 for ; Wed, 18 Jan 2006 19:44:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 75866-01 for ; Wed, 18 Jan 2006 19:44:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 2310A9DC820 for ; Wed, 18 Jan 2006 19:44:37 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 425373982E; Wed, 18 Jan 2006 17:44:40 -0600 (CST) Date: Wed, 18 Jan 2006 17:44:40 -0600 From: "Jim C. Nasby" To: Michael Crozier Cc: pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Message-ID: <20060118234440.GE17896@pervasive.com> References: <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <200601181536.04758.crozierm@conducivetech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200601181536.04758.crozierm@conducivetech.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/322 X-Sequence-Number: 16800 On Wed, Jan 18, 2006 at 03:36:04PM -0800, Michael Crozier wrote: > > On Wednesday 18 January 2006 14:52 pm, Jim C. Nasby wrote: > > I think it's a good idea, but you should take a look at the recently > > added functionality that allows you to investigate the contests of the > > FSM via a user function (this is either in 8.1 or in HEAD; I can't > > remember which). > > I will look at this when time allows. Perhaps there is a combination of > triggers on stat tables and asynchronous notifications that would provide > this functionality without getting too deep into the vacuum's transaction > logic? You can't put triggers on system tables, at least not ones that will be triggered by system operations themselves, because the backend bypasses normal access methods. Also, most of the really interesting info isn't logged anywhere in a system table; stuff like the amount of dead space, tuples removed, etc. > Were it too integrated with the vacuum, it would likely be too much for > contrib/, I assume. Probably. A good alternative might be allowing vacuum to output some machine-friendly information (maybe into a backend-writable file?) and then have code that could load that into a table (though presumably that could should be as simple as just a COPY). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Thu Jan 19 06:49:04 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6984C9DCA69 for ; Thu, 19 Jan 2006 06:49:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87235-07 for ; Thu, 19 Jan 2006 06:49:04 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id DB9309DCA66 for ; Thu, 19 Jan 2006 06:48:59 -0400 (AST) Received: (qmail invoked by alias); 19 Jan 2006 10:49:01 -0000 Received: from unknown (EHLO servidor) [201.11.58.22] by mail.gmx.net (mp008) with SMTP; 19 Jan 2006 11:49:01 +0100 X-Authenticated: #15924888 Subject: Re: Use of Stored Procedures and From: Marcos To: Michael Fuhr Cc: pgsql-performance@postgresql.org In-Reply-To: <20060118202825.GA94306@winnie.fuhr.org> References: <1137488693.971.23.camel@servidor> <20060118202825.GA94306@winnie.fuhr.org> Content-Type: text/plain Date: Thu, 19 Jan 2006 08:44:16 +0000 Message-Id: <1137660256.930.7.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/323 X-Sequence-Number: 16801 > What statements? Sorry. Statements is my code. > What problem are you trying to solve? I want know how I make to use a prepared plan ( http://www.postgresql.org/docs/8.1/static/sql-prepare.html ). I read that I need to use the SPI_PREPARE and SPI_EXEC in my code, but I didn't understand how make it. Thanks From pgsql-performance-owner@postgresql.org Thu Jan 19 07:48:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 962779DCA63 for ; Thu, 19 Jan 2006 07:48:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96313-08 for ; Thu, 19 Jan 2006 07:48:08 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by postgresql.org (Postfix) with SMTP id B72C39DCA56 for ; Thu, 19 Jan 2006 07:48:03 -0400 (AST) Received: (qmail invoked by alias); 19 Jan 2006 11:48:02 -0000 Received: from unknown (EHLO servidor) [201.11.58.22] by mail.gmx.net (mp033) with SMTP; 19 Jan 2006 12:48:02 +0100 X-Authenticated: #15924888 Subject: Re: Use of Stored Procedures and From: Marcos To: Markus Schaber Cc: Michael Fuhr , pgsql-performance@postgresql.org In-Reply-To: <43CF74BD.7000100@logix-tt.com> References: <1137488693.971.23.camel@servidor> <20060118202825.GA94306@winnie.fuhr.org> <1137660256.930.7.camel@servidor> <43CF74BD.7000100@logix-tt.com> Content-Type: text/plain Date: Thu, 19 Jan 2006 09:42:57 +0000 Message-Id: <1137663777.930.10.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/325 X-Sequence-Number: 16803 > Which interface are you using to connect to PostgreSQL? libpq, libpqxx, > pgjdbc, python-popy? > > E. G. PGJDBC handles prepared plans transparently by using the > PreparedStatement class. > > If you use command line PSQL, you can use the PREPARE commands. I'm using the adodb to call the stored procedure (plpgsql). Thanks.. From pgsql-performance-owner@postgresql.org Thu Jan 19 07:15:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3D1F49DC940 for ; Thu, 19 Jan 2006 07:15:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93730-05 for ; Thu, 19 Jan 2006 07:15:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id EC1D49DC8A7 for ; Thu, 19 Jan 2006 07:15:07 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Meb96.m.pppool.de [89.49.235.150]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 9F02A24400F; Thu, 19 Jan 2006 12:15:08 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 5C57C18148C2D; Thu, 19 Jan 2006 12:15:09 +0100 (CET) Message-ID: <43CF74BD.7000100@logix-tt.com> Date: Thu, 19 Jan 2006 12:15:09 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Marcos Cc: Michael Fuhr , pgsql-performance@postgresql.org Subject: Re: Use of Stored Procedures and References: <1137488693.971.23.camel@servidor> <20060118202825.GA94306@winnie.fuhr.org> <1137660256.930.7.camel@servidor> In-Reply-To: <1137660256.930.7.camel@servidor> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.125 required=5 tests=[AWL=0.125] X-Spam-Score: 0.125 X-Spam-Level: X-Archive-Number: 200601/324 X-Sequence-Number: 16802 Hi, Marcos, Marcos wrote: >>What problem are you trying to solve? > > I want know how I make to use a prepared plan > ( http://www.postgresql.org/docs/8.1/static/sql-prepare.html ). I read > that I need to use the SPI_PREPARE and SPI_EXEC in my code, but I didn't > understand how make it. Which interface are you using to connect to PostgreSQL? libpq, libpqxx, pgjdbc, python-popy? E. G. PGJDBC handles prepared plans transparently by using the PreparedStatement class. If you use command line PSQL, you can use the PREPARE commands. Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Thu Jan 19 08:20:59 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4961E9DC850 for ; Thu, 19 Jan 2006 08:20:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01696-08 for ; Thu, 19 Jan 2006 08:20:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id A777D9DC841 for ; Thu, 19 Jan 2006 08:20:53 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Meb96.m.pppool.de [89.49.235.150]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id 8849E24400F; Thu, 19 Jan 2006 13:20:56 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id 5BDAC18148C2D; Thu, 19 Jan 2006 13:20:57 +0100 (CET) Message-ID: <43CF8429.6070401@logix-tt.com> Date: Thu, 19 Jan 2006 13:20:57 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Marcos , pgsql-performance@postgresql.org Subject: Re: Use of Stored Procedures and References: <1137488693.971.23.camel@servidor> <20060118202825.GA94306@winnie.fuhr.org> <1137660256.930.7.camel@servidor> <43CF74BD.7000100@logix-tt.com> <1137663777.930.10.camel@servidor> In-Reply-To: <1137663777.930.10.camel@servidor> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.125 required=5 tests=[AWL=0.125] X-Spam-Score: 0.125 X-Spam-Level: X-Archive-Number: 200601/326 X-Sequence-Number: 16804 Hi, Marcos, Marcos wrote: >>Which interface are you using to connect to PostgreSQL? libpq, libpqxx, >>pgjdbc, python-popy? >> >>E. G. PGJDBC handles prepared plans transparently by using the >>PreparedStatement class. >> >>If you use command line PSQL, you can use the PREPARE commands. > > I'm using the adodb to call the stored procedure (plpgsql). So your statements are inside a plpgsql stored procedure, important to know that. AFAIK, plpgsql uses prepared statements internally, so it should not be necessary to use them explicitly. Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Thu Jan 19 13:38:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6FB309DCA43 for ; Thu, 19 Jan 2006 13:38:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62512-04 for ; Thu, 19 Jan 2006 13:38:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from server10.araisoft.com (server10.araisoft.com [72.9.228.195]) by postgresql.org (Postfix) with ESMTP id B62B59DCA06 for ; Thu, 19 Jan 2006 13:38:16 -0400 (AST) Received: from localhost (unknown [127.0.0.1]) by server10.araisoft.com (Postfix) with ESMTP id 6AD853D6200D for ; Thu, 19 Jan 2006 09:38:13 -0800 (PST) Received: from server10.araisoft.com ([127.0.0.1]) by localhost (server10.araisoft.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 09282-02 for ; Thu, 19 Jan 2006 09:38:07 -0800 (PST) Received: from uni (uni.cs.ucr.edu [138.23.204.215]) by server10.araisoft.com (Postfix) with ESMTP id 172DA3D6200B for ; Thu, 19 Jan 2006 09:38:07 -0800 (PST) From: "Benjamin Arai" To: Subject: Stored Procedures Date: Thu, 19 Jan 2006 09:38:01 -0800 Message-ID: <000001c61d1f$19fed2c0$d7cc178a@uni> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0001_01C61CDC.0BDB92C0" X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcYdHxfGZh71Ht+kT9CLUyLvKorDqg== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-Virus-Scanned: by amavisd-new at araisoft.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.185 required=5 tests=[AWL=0.184, HTML_MESSAGE=0.001] X-Spam-Score: 0.185 X-Spam-Level: X-Archive-Number: 200601/327 X-Sequence-Number: 16805 This is a multi-part message in MIME format. ------=_NextPart_000_0001_01C61CDC.0BDB92C0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, Will simple queries such as "SELECT * FROM blah_table WHERE tag='x'; work any faster by putting them into a stored procedure? Benjamin Arai barai@cs.ucr.edu http://www.benjaminarai.com ------=_NextPart_000_0001_01C61CDC.0BDB92C0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi,
 
Will = simple queries=20 such as "SELECT * FROM blah_table WHERE tag=3D'x'; work any faster by = putting them=20 into a stored procedure?
 
Benjamin = Arai
barai@cs.ucr.edu
http://www.benjaminarai.com
 
------=_NextPart_000_0001_01C61CDC.0BDB92C0-- From pgsql-performance-owner@postgresql.org Thu Jan 19 16:04:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8A4C39DCAB2 for ; Thu, 19 Jan 2006 16:04:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90022-01 for ; Thu, 19 Jan 2006 16:04:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by postgresql.org (Postfix) with ESMTP id 514299DCAAE for ; Thu, 19 Jan 2006 15:34:24 -0400 (AST) Received: from a-kretschmer.de (p54B39DCE.dip0.t-ipconnect.de [84.179.157.206]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id k0JJYMCZ016962 for ; Thu, 19 Jan 2006 20:34:23 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 3.36 #1) id 1EzfYA-0001Px-00 for pgsql-performance@postgresql.org; Thu, 19 Jan 2006 20:34:26 +0100 Date: Thu, 19 Jan 2006 20:34:26 +0100 From: Andreas Kretschmer To: pgsql-performance@postgresql.org Subject: Re: Stored Procedures Message-ID: <20060119193426.GA5403@kaufbach.delug.de> References: <000001c61d1f$19fed2c0$d7cc178a@uni> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <000001c61d1f$19fed2c0$d7cc178a@uni> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.113 required=5 tests=[AWL=0.113] X-Spam-Score: 0.113 X-Spam-Level: X-Archive-Number: 200601/328 X-Sequence-Number: 16806 Benjamin Arai schrieb: > Hi, > > Will simple queries such as "SELECT * FROM blah_table WHERE tag='x'; work any > faster by putting them into a stored procedure? IMHO no, why do you think so? You can use PREPARE instead, if you have many selects like this. HTH, Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknow) Kaufbach, Saxony, Germany, Europe. N 51.05082�, E 13.56889� From pgsql-performance-owner@postgresql.org Thu Jan 19 17:38:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7DCF29DCA11 for ; Thu, 19 Jan 2006 17:38:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14120-05 for ; Thu, 19 Jan 2006 17:38:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yertle.kcilink.com (yertle.kcilink.com [65.205.34.180]) by postgresql.org (Postfix) with ESMTP id 5AE8A9DCA00 for ; Thu, 19 Jan 2006 17:38:32 -0400 (AST) Received: from [192.168.7.103] (host-103.int.kcilink.com [192.168.7.103]) by yertle.kcilink.com (Postfix) with ESMTP id 519E2B80F for ; Thu, 19 Jan 2006 16:38:34 -0500 (EST) Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <00ee01c61c5a$5db2c870$d7cc178a@uni> References: <00ee01c61c5a$5db2c870$d7cc178a@uni> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <32A67C0F-9726-4E79-AA12-B1D2AD83748A@khera.org> Content-Transfer-Encoding: 7bit From: Vivek Khera Subject: Re: 3WARE Card performance boost? Date: Thu, 19 Jan 2006 16:38:33 -0500 To: Postgresql Performance X-Mailer: Apple Mail (2.746.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.042 required=5 tests=[AWL=0.042] X-Spam-Score: 0.042 X-Spam-Level: X-Archive-Number: 200601/329 X-Sequence-Number: 16807 On Jan 18, 2006, at 1:09 PM, Benjamin Arai wrote: > Obviously, I have done this to improve write performance for the > update each > week. My question is if I install a 3ware or similar card to > replace my I'll bet that if you increase your checkpoint_segments (and corresponding timeout value) to something in the 10's or higher it will help you a lot. From pgsql-performance-owner@postgresql.org Thu Jan 19 18:20:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D0ABB9DCB3C for ; Thu, 19 Jan 2006 18:20:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22427-04 for ; Thu, 19 Jan 2006 18:20:27 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 639599DCB31 for ; Thu, 19 Jan 2006 18:20:23 -0400 (AST) Received: from mail.optiosoftware.com (mail.optio.com [192.216.93.10]) by svr4.postgresql.org (Postfix) with ESMTP id E021E5AF09D for ; Thu, 19 Jan 2006 22:20:25 +0000 (GMT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C61D46.8A37A33B" Subject: query plans different for 8.1 on windows and aix Date: Thu, 19 Jan 2006 17:20:22 -0500 Message-ID: <47668A1334CDBF46927C1A0DFEB223D3033ACE@mail.optiosoftware.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: query plans different for 8.1 on windows and aix Thread-Index: AcYdRooBCWr7I2eSQmipOnI40lCipg== From: "Tim Jones" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[AWL=-0.001, HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/330 X-Sequence-Number: 16808 This is a multi-part message in MIME format. ------_=_NextPart_001_01C61D46.8A37A33B Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, =20 I am trying to perform the following type of query 'select patientname ... from patient were patientname LIKE 'JONES%, %' order by patientname asc limit 100'. There about 1.4 million rows in the table. On my windows machine (2GB Ram ,3Ghz, Windows XP, 120GB Hard Drive, postgres 8.1beta4) it takes about 150 millisecs and the query plan is=20 =20 'Limit (cost=3D18381.90..18384.40 rows=3D100 width=3D404)' ' -> Unique (cost=3D18381.90..18418.62 rows=3D1469 width=3D404)' ' -> Sort (cost=3D18381.90..18385.57 rows=3D1469 width=3D404)' ' Sort Key: patientname, patientidentifier, patientvipindicator, patientconfidentiality, patientmrn, patientfacility, patientssn, patientsex, patientbirthdate' ' -> Bitmap Heap Scan on patient (cost=3D81.08..18304.62 rows=3D1469 width=3D404)' ' Filter: ((patientname)::text ~~ ''BILL%, %''::text)' ' -> Bitmap Index Scan on ix_patientname (cost=3D0.00..81.08 rows=3D7347 width=3D0)' ' Index Cond: (((patientname)::text >=3D ''BILL''::character varying) AND ((patientname)::text < ''BILM''::character varying))' However the same query on AIX (4 1.5Ghz processors, 60GB filesystem, 4GB Ram, postgres 8.1.2) it takes like 5 secs because the query plan just uses sequentials scans =20 Limit (cost=3D100054251.96..100054253.41 rows=3D58 width=3D161) -> Unique (cost=3D100054251.96..100054253.41 rows=3D58 width=3D161) -> Sort (cost=3D100054251.96..100054252.11 rows=3D58 = width=3D161) Sort Key: patientname, patientidentifier, patientvipindicator, patientconfidentiality, patientmrn, patientfacility, patientssn, patientsex, patientbirthdate -> Seq Scan on patient = (cost=3D100000000.00..100054250.26 rows=3D58 width=3D161) Filter: ((patientname)::text ~~ 'SMITH%, NA%'::text) Why is postgres using a sequential scan and not the index what parameters do I need to adjust =20 thanks Tim Jones Optio Software ------_=_NextPart_001_01C61D46.8A37A33B Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Hi,
 
  = I am trying=20 to perform the following type of query  'select patientname = ... from=20 patient were patientname LIKE 'JONES%, %' order by patientname asc limit = 100'.=20 There about 1.4 million rows in the table. On my windows machine (2GB = Ram ,3Ghz,=20 Windows XP, 120GB Hard Drive, postgres 8.1beta4) it takes about 150 = millisecs=20 and the query plan is
 
   =20 'Limit  (cost=3D18381.90..18384.40 rows=3D100 = width=3D404)'
' =20 ->  Unique  (cost=3D18381.90..18418.62 rows=3D1469=20 width=3D404)'
'        ->  = Sort  (cost=3D18381.90..18385.57 rows=3D1469=20 width=3D404)'
'         &= nbsp;   =20 Sort Key: patientname, patientidentifier, patientvipindicator,=20 patientconfidentiality, patientmrn, patientfacility, patientssn, = patientsex,=20 patientbirthdate'
'        &nb= sp;    =20 ->  Bitmap Heap Scan on patient  (cost=3D81.08..18304.62 = rows=3D1469=20 width=3D404)'
'         &= nbsp;         =20 Filter: ((patientname)::text ~~ ''BILL%,=20 %''::text)'
'         &nb= sp;         =20 ->  Bitmap Index Scan on ix_patientname  = (cost=3D0.00..81.08=20 rows=3D7347=20 width=3D0)'
'         &nb= sp;           &nbs= p;   =20 Index Cond: (((patientname)::text >=3D ''BILL''::character varying) = AND=20 ((patientname)::text < ''BILM''::character = varying))'
However the same=20 query on AIX (4 1.5Ghz processors, 60GB filesystem, 4GB Ram, postgres = 8.1.2) it=20 takes like 5 secs because the query plan just uses sequentials=20 scans
 
Limit =20 (cost=3D100054251.96..100054253.41 rows=3D58 = width=3D161)
   -> =20 Unique  (cost=3D100054251.96..100054253.41 rows=3D58=20 width=3D161)
         = -> =20 Sort  (cost=3D100054251.96..100054252.11 rows=3D58=20 width=3D161)
         &nb= sp;    =20 Sort Key: patientname, patientidentifier, patientvipindicator,=20 patientconfidentiality, patientmrn, patientfacility, patientssn, = patientsex,=20 patientbirthdate
         = ;     =20 ->  Seq Scan on patient  (cost=3D100000000.00..100054250.26 = rows=3D58=20 width=3D161)
         &nb= sp;          =20 Filter: ((patientname)::text ~~ 'SMITH%, = NA%'::text)
Why is = postgres=20 using a sequential scan and not the index what parameters do I need to=20 adjust
 
thanks
Tim=20 Jones
Optio=20 Software
------_=_NextPart_001_01C61D46.8A37A33B-- From pgsql-performance-owner@postgresql.org Thu Jan 19 18:27:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EAB799DCAAD for ; Thu, 19 Jan 2006 18:27:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24428-04 for ; Thu, 19 Jan 2006 18:27:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A111E9DCAD5 for ; Thu, 19 Jan 2006 18:27:33 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0JMRZ66009910; Thu, 19 Jan 2006 17:27:35 -0500 (EST) To: "Tim Jones" cc: pgsql-performance@postgresql.org Subject: Re: query plans different for 8.1 on windows and aix In-reply-to: <47668A1334CDBF46927C1A0DFEB223D3033ACE@mail.optiosoftware.com> References: <47668A1334CDBF46927C1A0DFEB223D3033ACE@mail.optiosoftware.com> Comments: In-reply-to "Tim Jones" message dated "Thu, 19 Jan 2006 17:20:22 -0500" Date: Thu, 19 Jan 2006 17:27:35 -0500 Message-ID: <9909.1137709655@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.093 required=5 tests=[AWL=0.093] X-Spam-Score: 0.093 X-Spam-Level: X-Archive-Number: 200601/331 X-Sequence-Number: 16809 "Tim Jones" writes: > Why is postgres using a sequential scan and not the index what > parameters do I need to adjust You probably initialized the AIX database in a non-C locale. See the manual concerning LIKE index optimizations. regards, tom lane From pgsql-performance-owner@postgresql.org Thu Jan 19 18:52:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EFD709DCAD7 for ; Thu, 19 Jan 2006 18:52:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28905-07 for ; Thu, 19 Jan 2006 18:52:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id E806F9DCACE for ; Thu, 19 Jan 2006 18:52:50 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k0JMqEj10766; Thu, 19 Jan 2006 17:52:14 -0500 (EST) From: Bruce Momjian Message-Id: <200601192252.k0JMqEj10766@candle.pha.pa.us> Subject: Re: Stable function being evaluated more than once in a single In-Reply-To: <20060114004348.GT9017@pervasive.com> To: "Jim C. Nasby" Date: Thu, 19 Jan 2006 17:52:14 -0500 (EST) CC: Tom Lane , Mark Liberman , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1137711134-28690-0_ Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.123 required=5 tests=[AWL=0.123] X-Spam-Score: 0.123 X-Spam-Level: X-Archive-Number: 200601/332 X-Sequence-Number: 16810 --ELM1137711134-28690-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Here is updated documentation for STABLE. I just changed a few words for clarification. --------------------------------------------------------------------------- Jim C. Nasby wrote: > Adding -docs... > > On Fri, Jan 13, 2006 at 07:27:28PM -0500, Tom Lane wrote: > > "Jim C. Nasby" writes: > > > Is the issue that the optimizer won't combine two function calls (ie: > > > SELECT foo(..) ... WHERE foo(..)), or is it that sometimes it won't make > > > the optimization (maybe depending on the query plan, for example)? > > > > What the STABLE category actually does is give the planner permission to > > use the function within an indexscan qualification, eg, > > WHERE indexed_column = f(42) > > Since an indexscan involves evaluating the comparison expression just > > once and using its value to search the index, this would be incorrect > > if the expression's value might change from row to row. (For VOLATILE > > functions, we assume that the correct behavior is the naive SQL > > semantics of actually computing the WHERE clause at each candidate row.) > > > > There is no function cache and no checking for duplicate expressions. > > I think we do check for duplicate aggregate expressions, but not > > anything else. > > In that case I'd say that the sSTABLE section of 32.6 should be changed > to read: > > A STABLE function cannot modify the database and is guaranteed to > return the same results given the same arguments for all calls within a > single surrounding query. This category gives the planner permission to > use the function within an indexscan qualification. (Since an indexscan > involves evaluating the comparison expression just once and using its > value to search the index, this would be incorrect if the expression's > value might change from row to row.) There is no function cache and no > checking for duplicate expressions. > > I can provide a patch to that effect if it's easier... > > On a related note, would it be difficult to recognize multiple calls of > the same function in one query? ISTM that would be a win for all but the > most trivial of functions... > -- > Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com > Pervasive Software http://pervasive.com work: 512-231-6117 > vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 > > ---------------------------(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 > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 --ELM1137711134-28690-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/bjm/diff" Index: doc/src/sgml/xfunc.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v retrieving revision 1.109 diff -c -c -r1.109 xfunc.sgml *** doc/src/sgml/xfunc.sgml 29 Nov 2005 01:46:54 -0000 1.109 --- doc/src/sgml/xfunc.sgml 19 Jan 2006 22:43:58 -0000 *************** *** 899,911 **** A STABLE function cannot modify the database and is guaranteed to return the same results given the same arguments ! for all calls within a single surrounding query. This category ! allows the optimizer to optimize away multiple calls of the function ! within a single query. In particular, it is safe to use an expression ! containing such a function in an index scan condition. (Since an ! index scan will evaluate the comparison value only once, not once at ! each row, it is not valid to use a VOLATILE function in ! an index scan condition.) --- 899,911 ---- A STABLE function cannot modify the database and is guaranteed to return the same results given the same arguments ! for all rows within a single statement. This category allows the ! optimizer to optimize multiple calls of the function to a single ! call. In particular, it is safe to use an expression containing ! such a function in an index scan condition. (Since an index scan ! will evaluate the comparison value only once, not once at each ! row, it is not valid to use a VOLATILE function in an ! index scan condition.) --ELM1137711134-28690-0_-- From pgsql-performance-owner@postgresql.org Thu Jan 19 18:54:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8328C9DCB53 for ; Thu, 19 Jan 2006 18:54:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28793-07 for ; Thu, 19 Jan 2006 18:54:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.202]) by postgresql.org (Postfix) with ESMTP id AF4ED9DCB4F for ; Thu, 19 Jan 2006 18:54:30 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so104484uge for ; Thu, 19 Jan 2006 14:54:32 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=RGqtYpNhmSlDgi+EEcwOrBUDnp9WsjYl/xHSzWjCiSFGrELokiDcVTDIUUTs8HCrTGiI8dAwtOoO5+JUsaDtM9l5pAVptk9aH8U5jiNwIZdpNo3prtumFK58KX1MFKjgmHU5EM1bFpyKKpUdQwYbdLIZdC2hajGQ9MxqrBAy4vw= Received: by 10.66.241.1 with SMTP id o1mr485432ugh; Thu, 19 Jan 2006 14:54:32 -0800 (PST) Received: by 10.67.22.1 with HTTP; Thu, 19 Jan 2006 14:54:32 -0800 (PST) Message-ID: <33c6269f0601191454u65191b61vcd105256db94a78d@mail.gmail.com> Date: Thu, 19 Jan 2006 17:54:32 -0500 From: Alex Turner To: William Yu Subject: Re: 3WARE Card performance boost? Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <00ee01c61c5a$5db2c870$d7cc178a@uni> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.209 required=5 tests=[AWL=0.209] X-Spam-Score: 0.209 X-Spam-Level: X-Archive-Number: 200601/333 X-Sequence-Number: 16811 He's talking about RAID 1 here, not a gargantuan RAID 6. Onboard RAM on the controller card is going to make very little difference. All it will do is allow the card to re-order writes to a point (not all cards even do this). Alex. On 1/18/06, William Yu wrote: > Benjamin Arai wrote: > > Obviously, I have done this to improve write performance for the update > > each week. My question is if I install a 3ware or similar card to > > replace my current software RAID 1 configuration, am I going to see a > > very large improvement? If so, what would be a ball park figure? > > The key is getting a card with the ability to upgrade the onboard ram. > > Our previous setup was a LSI MegaRAID 320-1 (128MB), 4xRAID10, > fsync=3Doff. Replaced it with a ARC-1170 (1GB) w/ 24x7200RPM SATA2 drives > (split into 3 8-drive RAID6 arrays) and performance for us is through > the ceiling. > > For OLTP type updates, we've gotten about +80% increase. For massive > 1-statement updates, performance increase is in the +triple digits. > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > From pgsql-performance-owner@postgresql.org Thu Jan 19 19:10:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CC7D39DCAAE for ; Thu, 19 Jan 2006 19:10:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31064-08 for ; Thu, 19 Jan 2006 19:10:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-3.paradise.net.nz (bm-3a.paradise.net.nz [203.96.152.182]) by postgresql.org (Postfix) with ESMTP id 41AEA9DC9E6 for ; Thu, 19 Jan 2006 19:10:39 -0400 (AST) Received: from smtp-3.paradise.net.nz (tclsnelb1-src-1.paradise.net.nz [203.96.152.172]) by linda-3.paradise.net.nz (Paradise.net.nz) with ESMTP id <0ITD007FM4DTGI@linda-3.paradise.net.nz> for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 12:10:41 +1300 (NZDT) Received: from [192.168.1.11] (218-101-28-101.dsl.clear.net.nz [218.101.28.101]) by smtp-3.paradise.net.nz (Postfix) with ESMTP id 145F2391F7A; Fri, 20 Jan 2006 12:10:40 +1300 (NZDT) Date: Fri, 20 Jan 2006 12:10:32 +1300 From: Mark Kirkwood Subject: Re: Autovacuum / full vacuum (off-topic?) In-reply-to: <20060118225257.GY17896@pervasive.com> To: "Jim C. Nasby" Cc: Michael Crozier , pgsql-performance@postgresql.org Message-id: <43D01C68.3030204@paradise.net.nz> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.261 required=5 tests=[AWL=0.261] X-Spam-Score: 0.261 X-Spam-Level: X-Archive-Number: 200601/334 X-Sequence-Number: 16812 Jim C. Nasby wrote: > > I think it's a good idea, but you should take a look at the recently > added functionality that allows you to investigate the contests of the > FSM via a user function (this is either in 8.1 or in HEAD; I can't > remember which). AFAICS it is still in the patch queue for 8.2. It's called 'pg_freespacemap' and is available for 8.1/8.0 from the Pgfoundry 'backports' project: http://pgfoundry.org/projects/backports Cheers Mark From pgsql-performance-owner@postgresql.org Thu Jan 19 19:14:18 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8FF6F9DCAD5 for ; Thu, 19 Jan 2006 19:14:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32485-10 for ; Thu, 19 Jan 2006 19:14:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 400019DCACE for ; Thu, 19 Jan 2006 19:14:14 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k0JNCaU17651; Thu, 19 Jan 2006 18:12:36 -0500 (EST) From: Bruce Momjian Message-Id: <200601192312.k0JNCaU17651@candle.pha.pa.us> Subject: Re: Autovacuum / full vacuum (off-topic?) In-Reply-To: <43D01C68.3030204@paradise.net.nz> To: Mark Kirkwood Date: Thu, 19 Jan 2006 18:12:36 -0500 (EST) CC: "Jim C. Nasby" , Michael Crozier , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.123 required=5 tests=[AWL=0.123] X-Spam-Score: 0.123 X-Spam-Level: X-Archive-Number: 200601/335 X-Sequence-Number: 16813 Verified. I am working toward getting all those patches applied. --------------------------------------------------------------------------- Mark Kirkwood wrote: > Jim C. Nasby wrote: > > > > > I think it's a good idea, but you should take a look at the recently > > added functionality that allows you to investigate the contests of the > > FSM via a user function (this is either in 8.1 or in HEAD; I can't > > remember which). > > AFAICS it is still in the patch queue for 8.2. > > It's called 'pg_freespacemap' and is available for 8.1/8.0 from the > Pgfoundry 'backports' project: > > http://pgfoundry.org/projects/backports > > Cheers > > Mark > > > ---------------------------(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 > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgsql-performance-owner@postgresql.org Fri Jan 20 00:39:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0E4519DC82F for ; Fri, 20 Jan 2006 00:39:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96186-10 for ; Fri, 20 Jan 2006 00:39:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from imsm057dat.netvigator.com (imsm057.netvigator.com [218.102.48.210]) by postgresql.org (Postfix) with ESMTP id D60669DC804 for ; Fri, 20 Jan 2006 00:39:22 -0400 (AST) Received: from n2.netvigator.com ([218.102.95.109]) by wmail05dat.netvigator.com (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20060120043809.HVD722.wmail05dat.netvigator.com@n2.netvigator.com> for ; Fri, 20 Jan 2006 12:38:09 +0800 Received: from n2.netvigator.com ([127.0.0.1]) by [127.0.0.1] with ESMTP (SpamPal v1.591) sender ; 20 Jan 2006 12:38:09 +???? Message-Id: <6.2.1.2.0.20060120120150.08ab7b00@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2 Date: Fri, 20 Jan 2006 12:35:36 +0800 To: pgsql-performance@postgresql.org From: K C Lau Subject: SELECT MIN, MAX took longer time than SELECT COUNT, MIN, MAX Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.44 required=5 tests=[DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.44 X-Spam-Level: * X-Archive-Number: 200601/336 X-Sequence-Number: 16814 The following query took 17 seconds: select count(LogSN), min(LogSN), max(LogSN) from Log where create_time < '2005/10/19'; Figuring that getting the count will involve scanning the database, I took it out, but the new query took 200 seconds: select min(LogSN), max(LogSN) from Log where create_time < '2005/10/19'; Is it because the planner is using index pk_log instead of idx_logtime? Anyway to avoid that? I can get instant replies with 2 separate queries for min(LogSN) and max(LogSN) using order by create_time limit 1, but I can't get both values within 1 query using the limit 1 construct. Any suggestions? I am running pg 8.1.2 on Windows 2000. The queries are done immediately after a vacuum analyze. Best regards, KC. ---------------------- esdt=> \d log; create_time | character varying(23) | default '1970/01/01~00:00:00.000'::char acter varying logsn | integer | not null ... Indexes: "pk_log" PRIMARY KEY, btree (logsn) "idx_logtime" btree (create_time, logsn) ... esdt=> vacuum analyze log; VACUUM esdt=> explain analyze select count(LogSN), min(LogSN), max(LogSN) from Log where create_time < '2005/10/19'; Aggregate (cost=57817.74..57817.75 rows=1 width=4) (actual time=17403.381..17403.384 rows=1 loops=1) -> Bitmap Heap Scan on log (cost=1458.31..57172.06 rows=86089 width=4) (actual time=180.368..17039.262 rows=106708 loops=1) Recheck Cond: ((create_time)::text < '2005/10/19'::text) -> Bitmap Index Scan on idx_logtime (cost=0.00..1458.31 rows=86089 width=0) (actual time=168.777..168.777 rows=106708 loops=1) Index Cond: ((create_time)::text < '2005/10/19'::text) Total runtime: 17403.787 ms esdt=> explain analyze select min(LogSN), max(LogSN) from Log where create_time < '2005/10/19'; Result (cost=2.51..2.52 rows=1 width=0) (actual time=200051.507..200051.510 rows=1 loops=1) InitPlan -> Limit (cost=0.00..1.26 rows=1 width=4) (actual time=18.541..18.544 rows=1 loops=1) -> Index Scan using pk_log on log (cost=0.00..108047.11 rows=86089 width=4) (actual time=18.533..18.533 rows=1 loops=1) Filter: (((create_time)::text < '2005/10/19'::text) AND (logsn IS NOT NULL)) -> Limit (cost=0.00..1.26 rows=1 width=4) (actual time=200032.928..200032.931 rows=1 loops=1) -> Index Scan Backward using pk_log on log (cost=0.00..108047.11 rows=86089 width=4) (actual time=200032.920..200032.920 rows=1 loops=1) Filter: (((create_time)::text < '2005/10/19'::text) AND (logsn IS NOT NULL)) Total runtime: 200051.701 ms esdt=> explain analyze select LogSN from Log where create_time < '2005/10/19' order by create_time limit 1; Limit (cost=0.00..0.98 rows=1 width=31) (actual time=0.071..0.073 rows=1 loops=1) -> Index Scan using idx_logtime on log (cost=0.00..84649.94 rows=86089 width=31) (actual time=0.063..0.063 rows=1 loops=1) Index Cond: ((create_time)::text < '2005/10/19'::text) Total runtime: 0.182 ms esdt=> explain analyze select LogSN from Log where create_time < '2005/10/19' order by create_time desc limit 1; Limit (cost=0.00..0.98 rows=1 width=31) (actual time=0.058..0.061 rows=1 loops=1) -> Index Scan Backward using idx_logtime on log (cost=0.00..84649.94 rows=86089 width=31) (actual time=0.051..0.051 rows=1 loops=1) Index Cond: ((create_time)::text < '2005/10/19'::text) Total runtime: 0.186 ms From pgsql-performance-owner@postgresql.org Fri Jan 20 05:14:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A6F9B9DC9A5 for ; Fri, 20 Jan 2006 05:14:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33845-09 for ; Fri, 20 Jan 2006 05:14:17 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.205]) by postgresql.org (Postfix) with ESMTP id 50A3E9DC8DA for ; Fri, 20 Jan 2006 05:14:13 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 13so421506nzn for ; Fri, 20 Jan 2006 01:14:15 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=KJ0pMTVBL+dR3h2ZLIp4X0pLk/Ka1j3jKWnnr2X+xJwcSCA3K3dBvvtRaApDEmeiP4zjhoaVo2kYgiw12FoZxwvHH5QBG+3dcxjXvI8YtsrpsrAoGTvR/GHF+z19xIS1IJwqoOLFmayLBDw7kLj7XCm2bK+oFvyq8+1rBcftoUk= Received: by 10.37.2.65 with SMTP id e65mr1265924nzi; Fri, 20 Jan 2006 01:14:15 -0800 (PST) Received: by 10.36.148.6 with HTTP; Fri, 20 Jan 2006 01:14:15 -0800 (PST) Message-ID: <3a3a16930601200114p27ccb3fdn750286898f39c405@mail.gmail.com> Date: Fri, 20 Jan 2006 18:14:15 +0900 From: James Russell To: pgsql-performance@postgresql.org Subject: Retaining execution plans between connections? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2395_31688086.1137748455547" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.643 required=5 tests=[HTML_00_10=0.642, HTML_MESSAGE=0.001] X-Spam-Score: 0.643 X-Spam-Level: X-Archive-Number: 200601/337 X-Sequence-Number: 16815 ------=_Part_2395_31688086.1137748455547 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi there, I am running a website where each page connects to the DB to retrieve and write information. Each page load uses a separate connection (rather than just sharing one as is the common case) because I use a lot of transactions= . I am looking to speed up performance, and since each page executes a static set of queries where only the parameters change, I was hoping to take advantage of stored procedures since I read that PostgreSQL's caches the execution plans used inside stored procedures. However, the documentation states that this execution plan caching is done on a per-connection basis. If each page uses a separate connection, I can get no performance benefit between pages. In other words, there's no benefit to me in putting a one-shot query that i= s basically the same for every page (e.g. "SELECT * FROM users WHERE user_name=3D''") inside a stored proc, since the generated execut= ion plan will be thrown away once the connection is dropped. Has anyone found a way around this limitation? As I said, I can't share the DB connection between pages (unless someone knows of a way to do this and still retain a level of separation between pages that use the same DB connection). Many thanks, James ------=_Part_2395_31688086.1137748455547 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi there,

I am running a website where each page connects to the DB to retrieve and write information. Each page load uses a separate connection (rather than just sharing one as is the common case) because I use a lot of transactions.

I am looking to speed up performance, and since each page executes a static set of queries where only the parameters change, I was hoping to take advantage of stored procedures since I read that PostgreSQL's caches the execution plans used inside stored procedures.

However, the documentation states that this execution plan caching is done on a per-connection basis. If each page uses a separate connection, I can get no performance benefit between pages.

In other words, there's no benefit to me in putting a one-shot query that is basically the same for every page (e.g. "SELECT * FROM users WHERE user_name=3D'<username>'") inside a stored proc, since the generated execution plan will be thrown away once the connection is dropped.

Has anyone found a way around this limitation? As I said, I can't share the DB connection between pages (unless someone knows of a way to do this and still retain a level of separation between pages that use the same DB connection).

Many thanks,

James
------=_Part_2395_31688086.1137748455547-- From pgsql-performance-owner@postgresql.org Fri Jan 20 05:35:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 40F2D9DCA0E for ; Fri, 20 Jan 2006 05:35:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40663-01 for ; Fri, 20 Jan 2006 05:35:51 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.200]) by postgresql.org (Postfix) with ESMTP id 267399DC878 for ; Fri, 20 Jan 2006 05:35:47 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 14so423022nzn for ; Fri, 20 Jan 2006 01:35:50 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=qVikI9zrRCiYO1TIYgtaHXxr4YLoCmF99Ma31vJN+MOKoJwrXOzUQwJp70S4CXFFPwXjTD1R5pXFSKG43QrfEtWtQBBIT0icubirVKjUQ9r7IDtS13bYnQVJ0CcJQlr+ds6WIGoFCDR1g+FC0p6qajPfqD0ogVX1KGUKorGbI1I= Received: by 10.64.232.3 with SMTP id e3mr1050786qbh; Fri, 20 Jan 2006 01:35:49 -0800 (PST) Received: by 10.64.208.15 with HTTP; Fri, 20 Jan 2006 01:35:49 -0800 (PST) Message-ID: <5e744e3d0601200135q41922750o4cbeb12521e2a61e@mail.gmail.com> Date: Fri, 20 Jan 2006 15:05:49 +0530 From: Pandurangan R S To: James Russell Subject: Re: Retaining execution plans between connections? Cc: pgsql-performance@postgresql.org In-Reply-To: <3a3a16930601200114p27ccb3fdn750286898f39c405@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <3a3a16930601200114p27ccb3fdn750286898f39c405@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.161 required=5 tests=[AWL=0.161] X-Spam-Score: 0.161 X-Spam-Level: X-Archive-Number: 200601/338 X-Sequence-Number: 16816 you could use pgpool http://pgpool.projects.postgresql.org/ On 1/20/06, James Russell wrote: > Hi there, > > I am running a website where each page connects to the DB to retrieve an= d > write information. Each page load uses a separate connection (rather than > just sharing one as is the common case) because I use a lot of transactio= ns. > > I am looking to speed up performance, and since each page executes a sta= tic > set of queries where only the parameters change, I was hoping to take > advantage of stored procedures since I read that PostgreSQL's caches the > execution plans used inside stored procedures. > > However, the documentation states that this execution plan caching is do= ne > on a per-connection basis. If each page uses a separate connection, I can > get no performance benefit between pages. > > In other words, there's no benefit to me in putting a one-shot query tha= t > is basically the same for every page (e.g. "SELECT * FROM users WHERE > user_name=3D''") inside a stored proc, since the generated exec= ution > plan will be thrown away once the connection is dropped. > > Has anyone found a way around this limitation? As I said, I can't share = the > DB connection between pages (unless someone knows of a way to do this and > still retain a level of separation between pages that use the same DB > connection). > > Many thanks, > > James > From pgsql-general-owner@postgresql.org Fri Jan 20 10:07:41 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 71FE79DCAC9 for ; Fri, 20 Jan 2006 10:07:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77414-03 for ; Fri, 20 Jan 2006 10:07:43 -0400 (AST) X-Greylist: delayed 00:06:39.443804 by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id 222849DCAC3 for ; Fri, 20 Jan 2006 10:07:36 -0400 (AST) Received: (qmail invoked by alias); 20 Jan 2006 14:01:00 -0000 Received: from p54A65321.dip.t-dialin.net (EHLO athlon64) [84.166.83.33] by mail.gmx.net (mp039) with SMTP; 20 Jan 2006 15:01:00 +0100 X-Authenticated: #594052 Received: from localhost (HELO [127.0.0.1]) [127.0.0.1] by athlon64 (192.168.0.2) (userid 3) with ESMTP (Classic Hamster Version 2.1 Build 2.1.0.0) ; Fri, 20 Jan 2006 15:02:03 +0100 Message-ID: <43D0ED57.1020608@gmx.de> Date: Fri, 20 Jan 2006 15:01:59 +0100 From: Stephan Vollmer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0 MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Creation of tsearch2 index is very slow X-Enigmail-Version: 0.94.0.0 OpenPGP: id=8D46FCF8 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig0E17953E05D89B8D3538EB92" X-Posting-Agent: Hamster/2.1.0.0 X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/990 X-Sequence-Number: 89935 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig0E17953E05D89B8D3538EB92 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello! I noticed that the creation of a GIST index for tsearch2 takes very long - about 20 minutes. CPU utilization is 100 %, the resulting index file size is ~25 MB. Is this behaviour normal? Full text columns: title author_list tsearch2 word lists: fti_title fti_author_list tsearch2 indexes: idx_fti_title idx_fti_author_list The table has 700,000 records. When I create a normal B-Tree index on the same column for testing purposes, it works quite fast (approx. 30 seconds). The columns that should be indexed are small, only about 10 words on average. System specs: Athlon64 X2 3800+, 2 GB RAM PostgreSQL 8.1.2, Windows XP SP2 I've never noticed this problem before, so could it probably be related to v8.1.2? Or is something in my configuration or table definition that causes this sluggishness? Thanks very much in advance for your help! - Stephan This is the table definition: ----------------------------------------------------------------- CREATE TABLE publications ( id int4 NOT NULL DEFAULT nextval('publications_id_seq'::regclass), publication_type_id int4 NOT NULL DEFAULT 0, keyword text NOT NULL, mdate date, "year" date, title text, fti_title tsvector, author_list text, fti_author_list tsvector, overview_timestamp timestamp, overview_xml text, CONSTRAINT publications_pkey PRIMARY KEY (keyword) USING INDEX TABLESPACE dblp_index, CONSTRAINT publications_publication_type_id_fkey FOREIGN KEY (publication_type_id) REFERENCES publication_types (id) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT publications_year_check CHECK (date_part('month'::text, "year") =3D 1::double precision AND date_part('day'::text, "year") =3D 1::double precision) ) WITHOUT OIDS; CREATE INDEX fki_publications_publication_type_id ON publications USING btree (publication_type_id) TABLESPACE dblp_index; CREATE INDEX idx_fti_author_list ON publications USING gist (fti_author_list) TABLESPACE dblp_index; CREATE INDEX idx_fti_title ON publications USING gist (fti_title) TABLESPACE dblp_index; CREATE INDEX idx_publications_year ON publications USING btree ("year") TABLESPACE dblp_index; CREATE INDEX idx_publications_year_part ON publications USING btree (date_part('year'::text, "year")) TABLESPACE dblp_index; CREATE TRIGGER tsvectorupdate_all BEFORE INSERT OR UPDATE ON publications FOR EACH ROW EXECUTE PROCEDURE multi_tsearch2(); --------------enig0E17953E05D89B8D3538EB92 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFD0O1ajY05go1G/PgRAp3FAKCOFlbFXBab4fmdQGIE+4ZjMLMyeQCeMRBU GFeoqOaMjn5QmaHpNfYfyfs= =9rDq -----END PGP SIGNATURE----- --------------enig0E17953E05D89B8D3538EB92-- From pgsql-general-owner@postgresql.org Fri Jan 20 10:15:59 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A8ACC9DC9D0 for ; Fri, 20 Jan 2006 10:15:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78711-04 for ; Fri, 20 Jan 2006 10:16:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by postgresql.org (Postfix) with SMTP id 4315E9DC889 for ; Fri, 20 Jan 2006 10:15:54 -0400 (AST) Received: (qmail invoked by alias); 20 Jan 2006 14:15:58 -0000 Received: from p54A65321.dip.t-dialin.net (EHLO athlon64) [84.166.83.33] by mail.gmx.net (mp020) with SMTP; 20 Jan 2006 15:15:58 +0100 X-Authenticated: #594052 Received: from localhost (HELO [127.0.0.1]) [127.0.0.1] by athlon64 (192.168.0.2) (userid 3) with ESMTP (Classic Hamster Version 2.1 Build 2.1.0.0) ; Fri, 20 Jan 2006 15:17:07 +0100 Message-ID: <43D0F0E3.6000403@gmx.de> Date: Fri, 20 Jan 2006 15:17:07 +0100 From: Stephan Vollmer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0 MIME-Version: 1.0 CC: pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow References: <43D0ED57.1020608@gmx.de> In-Reply-To: <43D0ED57.1020608@gmx.de> X-Enigmail-Version: 0.94.0.0 OpenPGP: id=8D46FCF8 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig481D5E4C9CD077ADBCEAFFCE" X-Posting-Agent: Hamster/2.1.0.0 X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.126 required=5 tests=[AWL=-0.063, MISSING_HEADERS=0.189] X-Spam-Score: 0.126 X-Spam-Level: X-Archive-Number: 200601/991 X-Sequence-Number: 89936 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig481D5E4C9CD077ADBCEAFFCE Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable PS: What I forgot to mention was that inserting records into the table is also about 2-3 times slower than before (most likely due to the slow index update operations). I dropped the whole database and restored the dumpfile, but the result it the same. When the index is recreated after COPYing the data, it takes more than 20 minutes for _each_ of both tsearch2 indexes. So the total time to restore this table is more than 45 minutes! - Stephan --------------enig481D5E4C9CD077ADBCEAFFCE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFD0PDjjY05go1G/PgRAjYMAJ0YuNGNamZ7++9lkf2awfOVFOQCCwCgh5/S rIwVEHwO9NFxvHniWiKp7DU= =TKBt -----END PGP SIGNATURE----- --------------enig481D5E4C9CD077ADBCEAFFCE-- From pgsql-performance-owner@postgresql.org Fri Jan 20 11:14:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D6FE19DCA82 for ; Fri, 20 Jan 2006 11:14:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86721-07 for ; Fri, 20 Jan 2006 11:14:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mailbox.samurai.com (mailbox.samurai.com [205.207.28.82]) by postgresql.org (Postfix) with ESMTP id D74349DCA7B for ; Fri, 20 Jan 2006 11:14:50 -0400 (AST) Received: from localhost (mailbox.samurai.com [205.207.28.82]) by mailbox.samurai.com (Postfix) with ESMTP id CD65C239472; Fri, 20 Jan 2006 10:14:55 -0500 (EST) Received: from mailbox.samurai.com ([205.207.28.82]) by localhost (mailbox.samurai.com [205.207.28.82]) (amavisd-new, port 10024) with LMTP id 99161-01-9; Fri, 20 Jan 2006 10:14:54 -0500 (EST) Received: from [192.168.1.104] (d38-160-188.home1.cgocable.net [72.38.160.188]) by mailbox.samurai.com (Postfix) with ESMTP id 2F9BB23945C; Fri, 20 Jan 2006 10:14:54 -0500 (EST) Subject: Re: Retaining execution plans between connections? From: Neil Conway To: James Russell Cc: pgsql-performance@postgresql.org In-Reply-To: <3a3a16930601200114p27ccb3fdn750286898f39c405@mail.gmail.com> References: <3a3a16930601200114p27ccb3fdn750286898f39c405@mail.gmail.com> Content-Type: text/plain Date: Fri, 20 Jan 2006 10:14:59 -0500 Message-Id: <1137770099.9330.12.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailbox.samurai.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.117 required=5 tests=[AWL=0.117] X-Spam-Score: 0.117 X-Spam-Level: X-Archive-Number: 200601/339 X-Sequence-Number: 16817 On Fri, 2006-01-20 at 18:14 +0900, James Russell wrote: > I am looking to speed up performance, and since each page executes a > static set of queries where only the parameters change, I was hoping > to take advantage of stored procedures since I read that PostgreSQL's > caches the execution plans used inside stored procedures. Note that you can also take advantage of plan caching by using prepared statements (PREPARE, EXECUTE and DEALLOCATE). These are also session local, however (i.e. you can't share prepared statements between connections). > As I said, I can't share the DB connection between pages (unless > someone knows of a way to do this and still retain a level of > separation between pages that use the same DB connection). You can't share plans among different sessions at the moment. Can you elaborate on why you can't use persistent or pooled database connections? -Neil From pgsql-general-owner@postgresql.org Fri Jan 20 11:35:21 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5F3B39DC87D for ; Fri, 20 Jan 2006 11:35:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92269-07 for ; Fri, 20 Jan 2006 11:35:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8D57A9DC820 for ; Fri, 20 Jan 2006 11:35:17 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KFZLGn017455; Fri, 20 Jan 2006 10:35:21 -0500 (EST) To: Stephan Vollmer cc: pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow In-reply-to: <43D0ED57.1020608@gmx.de> References: <43D0ED57.1020608@gmx.de> Comments: In-reply-to Stephan Vollmer message dated "Fri, 20 Jan 2006 15:01:59 +0100" Date: Fri, 20 Jan 2006 10:35:21 -0500 Message-ID: <17454.1137771321@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/1000 X-Sequence-Number: 89945 Stephan Vollmer writes: > I noticed that the creation of a GIST index for tsearch2 takes very > long - about 20 minutes. CPU utilization is 100 %, the resulting > index file size is ~25 MB. Is this behaviour normal? This has been complained of before. GIST is always going to be slower at index-building than btree; in the btree case there's a simple optimal strategy for making an index (ie, sort the keys) but for GIST we don't know anything better to do than insert the keys one at a time. However, I'm not sure that anyone's tried to do any performance optimization on the GIST insert code ... there might be some low-hanging fruit there. It'd be interesting to look at a gprof profile of what the backend is doing during the index build. Do you have the ability to do that, or would you be willing to give your data to someone else to investigate with? (The behavior is very possibly data-dependent, which is why I want to see a profile with your specific data and not just some random dataset or other.) regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 12:19:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7BAEF9DCB0B for ; Fri, 20 Jan 2006 12:19:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00821-04 for ; Fri, 20 Jan 2006 12:19:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 394E69DC804 for ; Fri, 20 Jan 2006 12:19:35 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k0KGJWE19919; Fri, 20 Jan 2006 11:19:32 -0500 (EST) From: Bruce Momjian Message-Id: <200601201619.k0KGJWE19919@candle.pha.pa.us> Subject: Re: Extremely irregular query performance In-Reply-To: <1137059321.3180.34.camel@localhost.localdomain> To: Simon Riggs Date: Fri, 20 Jan 2006 11:19:32 -0500 (EST) CC: Tom Lane , =?ISO-8859-1?Q?Jean-Philippe_C=F4t=E9?= , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=ELM1137773972-28690-2_ Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.123 required=5 tests=[AWL=0.123] X-Spam-Score: 0.123 X-Spam-Level: X-Archive-Number: 200601/340 X-Sequence-Number: 16818 --ELM1137773972-28690-2_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Simon Riggs wrote: > On Wed, 2006-01-11 at 22:23 -0500, Tom Lane wrote: > > =?iso-8859-1?Q?Jean-Philippe_C=F4t=E9?= writes: > > > Thanks a lot for this info, I was indeed exceeding the genetic > > > optimizer's threshold. Now that it is turned off, I get > > > a very stable response time of 435ms (more or less 5ms) for > > > the same query. It is about three times slower than the best > > > I got with the genetic optimizer on, but the overall average > > > is much lower. > > > > Hmm. It would be interesting to use EXPLAIN ANALYZE to confirm that the > > plan found this way is the same as the best plan found by GEQO, and > > the extra couple hundred msec is the price you pay for the exhaustive > > plan search. If GEQO is managing to find a plan better than the regular > > planner then we need to look into why ... > > It seems worth noting in the EXPLAIN whether GEQO has been used to find > the plan, possibly along with other factors influencing the plan such as > enable_* settings. I thought the best solution would be to replace "QUERY PLAN" with "GEQO QUERY PLAN" when GEQO was in use. However, looking at the code, I see no way to do that cleanly. Instead, I added documentation to EXPLAIN to highlight the fact the execution plan will change when GEQO is in use. (I also removed a documentation mention of the pre-7.3 EXPLAIN output behavior.) -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 --ELM1137773972-28690-2_ Content-Transfer-Encoding: 7bit Content-Type: text/plain Content-Disposition: inline; filename="/bjm/diff" Index: doc/src/sgml/ref/explain.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/ref/explain.sgml,v retrieving revision 1.35 diff -c -c -r1.35 explain.sgml *** doc/src/sgml/ref/explain.sgml 4 Jan 2005 00:39:53 -0000 1.35 --- doc/src/sgml/ref/explain.sgml 20 Jan 2006 16:18:53 -0000 *************** *** 151,161 **** ! Prior to PostgreSQL 7.3, the plan was ! emitted in the form of a NOTICE message. Now it ! appears as a query result (formatted like a table with a single ! text column). --- 151,162 ---- ! Genetic query optimization (GEQO) randomly ! tests execution plans. Therefore, when the number of tables ! exceeds geqo and genetic query optimization is in use, ! the execution plan will change each time the statement is executed. + --ELM1137773972-28690-2_-- From pgsql-performance-owner@postgresql.org Fri Jan 20 12:35:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 32E8F9DCAD2 for ; Fri, 20 Jan 2006 12:35:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02029-08 for ; Fri, 20 Jan 2006 12:34:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 343AA9DCAD0 for ; Fri, 20 Jan 2006 12:34:54 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KGYnB1018685; Fri, 20 Jan 2006 11:34:49 -0500 (EST) To: Bruce Momjian cc: Simon Riggs , =?ISO-8859-1?Q?Jean-Philippe_C=F4t=E9?= , pgsql-performance@postgresql.org Subject: Re: Extremely irregular query performance In-reply-to: <200601201619.k0KGJWE19919@candle.pha.pa.us> References: <200601201619.k0KGJWE19919@candle.pha.pa.us> Comments: In-reply-to Bruce Momjian message dated "Fri, 20 Jan 2006 11:19:32 -0500" Date: Fri, 20 Jan 2006 11:34:49 -0500 Message-ID: <18684.1137774889@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/341 X-Sequence-Number: 16819 Bruce Momjian writes: > > ! Genetic query optimization (GEQO) randomly > ! tests execution plans. Therefore, when the number of tables > ! exceeds geqo and genetic query optimization is in use, > ! the execution plan will change each time the statement is executed. > geqo_threshold, please --- geqo is a boolean. Possibly better wording: Therefore, when the number of tables exceeds geqo_threshold causing genetic query optimization to be used, the execution plan is likely to change each time the statement is executed. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 12:42:16 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 406AD9DC8A2 for ; Fri, 20 Jan 2006 12:42:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03739-07 for ; Fri, 20 Jan 2006 12:42:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 9FDC19DCA54 for ; Fri, 20 Jan 2006 12:42:13 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id k0KGgBS23410; Fri, 20 Jan 2006 11:42:11 -0500 (EST) From: Bruce Momjian Message-Id: <200601201642.k0KGgBS23410@candle.pha.pa.us> Subject: Re: Extremely irregular query performance In-Reply-To: <18684.1137774889@sss.pgh.pa.us> To: Tom Lane Date: Fri, 20 Jan 2006 11:42:11 -0500 (EST) CC: Simon Riggs , =?ISO-8859-1?Q?Jean-Philippe_C=F4t=E9?= , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.123 required=5 tests=[AWL=0.123] X-Spam-Score: 0.123 X-Spam-Level: X-Archive-Number: 200601/342 X-Sequence-Number: 16820 Done, and paragraph added to 8.1.X. (7.3 mention retained for 8.1.X.) --------------------------------------------------------------------------- Tom Lane wrote: > Bruce Momjian writes: > > > > ! Genetic query optimization (GEQO) randomly > > ! tests execution plans. Therefore, when the number of tables > > ! exceeds geqo and genetic query optimization is in use, > > ! the execution plan will change each time the statement is executed. > > > > geqo_threshold, please --- geqo is a boolean. > > Possibly better wording: Therefore, when the number of tables exceeds > geqo_threshold causing genetic query optimization to be used, the > execution plan is likely to change each time the statement is executed. > > regards, tom lane > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From pgsql-general-owner@postgresql.org Fri Jan 20 12:48:52 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 829359DC80D for ; Fri, 20 Jan 2006 12:48:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07305-04 for ; Fri, 20 Jan 2006 12:48:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id B19789DC804 for ; Fri, 20 Jan 2006 12:48:48 -0400 (AST) Received: (qmail invoked by alias); 20 Jan 2006 16:48:47 -0000 Received: from p54A65321.dip.t-dialin.net (EHLO athlon64) [84.166.83.33] by mail.gmx.net (mp001) with SMTP; 20 Jan 2006 17:48:47 +0100 X-Authenticated: #594052 Received: from localhost (HELO [127.0.0.1]) [127.0.0.1] by athlon64 (192.168.0.2) (userid 3) with ESMTP (Classic Hamster Version 2.1 Build 2.1.0.0) ; Fri, 20 Jan 2006 17:49:56 +0100 Message-ID: <43D114B1.5030802@gmx.de> Date: Fri, 20 Jan 2006 17:49:53 +0100 From: Stephan Vollmer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0 MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> In-Reply-To: <17454.1137771321@sss.pgh.pa.us> X-Enigmail-Version: 0.94.0.0 OpenPGP: id=8D46FCF8 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig6AA55D676317398731675352" X-Posting-Agent: Hamster/2.1.0.0 X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.069 required=5 tests=[AWL=0.069] X-Spam-Score: 0.069 X-Spam-Level: X-Archive-Number: 200601/1008 X-Sequence-Number: 89953 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig6AA55D676317398731675352 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Tom Lane wrote: > Stephan Vollmer writes: >> I noticed that the creation of a GIST index for tsearch2 takes very >> long - about 20 minutes. CPU utilization is 100 %, the resulting >> index file size is ~25 MB. Is this behaviour normal? >=20 > This has been complained of before. GIST is always going to be slower > at index-building than btree; in the btree case there's a simple optima= l > strategy for making an index (ie, sort the keys) but for GIST we don't > know anything better to do than insert the keys one at a time. Ah, ok. That explains a lot, although I wonder why it is so much slower. > However, I'm not sure that anyone's tried to do any performance > optimization on the GIST insert code ... there might be some low-hangin= g > fruit there. It'd be interesting to look at a gprof profile of what th= e > backend is doing during the index build. Do you have the ability to do= > that, or would you be willing to give your data to someone else to > investigate with? Unfortunately, I'm not able to investigate it further myself as I'm quite a Postgres newbie. But I could provide someone else with the example table. Maybe someone else could find out why it is so slow. I dropped all unnecessary columns and trimmed the table down to 235,000 rows. The dumped table (compressed with RAR) is 7,1 MB. I don't have a website to upload it but I could send it to someone via e-mail. With this 235,000 row table, index creation times are: - GIST 347063 ms - B-Tree 2515 ms Thanks for your help! - Stephan --------------enig6AA55D676317398731675352 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFD0RS0jY05go1G/PgRAiu5AJ9qZJD6NQR6A4SVAsYQEF8pEJgGWwCcC05D 68LXcNq5ydTl2V+biygQlKY= =xArD -----END PGP SIGNATURE----- --------------enig6AA55D676317398731675352-- From pgsql-general-owner@postgresql.org Fri Jan 20 13:05:04 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C60889DCACB for ; Fri, 20 Jan 2006 13:05:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11007-01 for ; Fri, 20 Jan 2006 13:05:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (unknown [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 71AD89DCAC3 for ; Fri, 20 Jan 2006 13:04:59 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1Ezzgy-0000NK-8S; Sat, 21 Jan 2006 04:04:52 +1100 Date: Fri, 20 Jan 2006 18:04:52 +0100 From: Martijn van Oosterhout To: Tom Lane Cc: Stephan Vollmer , pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow Message-ID: <20060120170452.GC31908@svana.org> Reply-To: Martijn van Oosterhout Mail-Followup-To: Tom Lane , Stephan Vollmer , pgsql-general@postgresql.org References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="w7PDEPdKQumQfZlR" Content-Disposition: inline In-Reply-To: <17454.1137771321@sss.pgh.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.134 required=5 tests=[AWL=0.134] X-Spam-Score: 0.134 X-Spam-Level: X-Archive-Number: 200601/1009 X-Sequence-Number: 89954 --w7PDEPdKQumQfZlR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 10:35:21AM -0500, Tom Lane wrote: > However, I'm not sure that anyone's tried to do any performance > optimization on the GIST insert code ... there might be some low-hanging > fruit there. It'd be interesting to look at a gprof profile of what the > backend is doing during the index build. Do you have the ability to do > that, or would you be willing to give your data to someone else to > investigate with? (The behavior is very possibly data-dependent, which > is why I want to see a profile with your specific data and not just some > random dataset or other.) The cost on inserting would generally go to either penalty, or picksplit. Certainly if you're inserting lots of values in a short interval, I can imagine picksplit being nasty, since the algorithms for a lot of datatypes are not really reknown for their speed. I'm wondering if you could possibly improve the process by grouping into larger blocks. For example, pull out enough tuples to cover 4 pages and then call picksplit three times to split it into the four pages. This gives you 4 entries for the level above the leaves. Keep reading tuples and splitting until you get enough for the next level and call picksplit on those. etc etc. The thing is, you never call penalty here so it's questionable whether the tree will be as efficient as just inserting. For example, if have a data type representing ranges (a,b), straight inserting can produce the perfect tree order like a b-tree (assuming non-overlapping entries). The above process will produce something close, but not quite... Should probably get out a pen-and-paper to model this. After all, if the speed of the picksplit increases superlinearly to the number of elements, calling it will larger sets may prove to be a loss overall... Perhaps the easiest would be to allow datatypes to provide a bulkinsert function, like b-tree does? The question is, what should be its input and output? Have a nice day, --=20 Martijn van Oosterhout 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. --w7PDEPdKQumQfZlR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0Rg0IB7bNG8LQkwRAvTwAKCARWsA4PHKn0GRZ7w1vM4WfX4bCwCgjnWj Zvq9YG0AHxuMxjaIQp3aTkA= =tr1P -----END PGP SIGNATURE----- --w7PDEPdKQumQfZlR-- From pgsql-general-owner@postgresql.org Fri Jan 20 13:09:18 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6DBF19DC820 for ; Fri, 20 Jan 2006 13:09:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11261-03 for ; Fri, 20 Jan 2006 13:09:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 228F19DC804 for ; Fri, 20 Jan 2006 13:09:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KH9DhN025035; Fri, 20 Jan 2006 12:09:13 -0500 (EST) To: Stephan Vollmer cc: pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow In-reply-to: <43D114B1.5030802@gmx.de> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <43D114B1.5030802@gmx.de> Comments: In-reply-to Stephan Vollmer message dated "Fri, 20 Jan 2006 17:49:53 +0100" Date: Fri, 20 Jan 2006 12:09:13 -0500 Message-ID: <25034.1137776953@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/1010 X-Sequence-Number: 89955 Stephan Vollmer writes: > Unfortunately, I'm not able to investigate it further myself as I'm > quite a Postgres newbie. But I could provide someone else with the > example table. Maybe someone else could find out why it is so slow. I'd be willing to take a look, if you'll send me the dump file off-list. > I dropped all unnecessary columns and trimmed the table down to > 235,000 rows. The dumped table (compressed with RAR) is 7,1 MB. I > don't have a website to upload it but I could send it to someone via > e-mail. Don't have RAR --- gzip or bzip2 is fine ... regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 13:12:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C36679DC80D for ; Fri, 20 Jan 2006 13:12:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08251-10 for ; Fri, 20 Jan 2006 13:12:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 526049DC804 for ; Fri, 20 Jan 2006 13:12:14 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 3A3B139840; Fri, 20 Jan 2006 11:12:14 -0600 (CST) Date: Fri, 20 Jan 2006 11:12:14 -0600 From: "Jim C. Nasby" To: Mark Kirkwood Cc: Michael Crozier , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Message-ID: <20060120171214.GE20182@pervasive.com> References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D01C68.3030204@paradise.net.nz> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/343 X-Sequence-Number: 16821 BTW, given all the recent discussion about vacuuming and our MVCC, http://www.pervasive-postgres.com/lp/newsletters/2006/Insights_Postgres_Jan.asp#3 should prove interesting. :) -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-general-owner@postgresql.org Fri Jan 20 13:14:40 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CC5BF9DC9D1 for ; Fri, 20 Jan 2006 13:14:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12044-04 for ; Fri, 20 Jan 2006 13:14:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A12429DC80D for ; Fri, 20 Jan 2006 13:14:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KHEaDk025128; Fri, 20 Jan 2006 12:14:36 -0500 (EST) To: Martijn van Oosterhout cc: Stephan Vollmer , pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow In-reply-to: <20060120170452.GC31908@svana.org> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> Comments: In-reply-to Martijn van Oosterhout message dated "Fri, 20 Jan 2006 18:04:52 +0100" Date: Fri, 20 Jan 2006 12:14:35 -0500 Message-ID: <25127.1137777275@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/1012 X-Sequence-Number: 89957 Martijn van Oosterhout writes: > The cost on inserting would generally go to either penalty, or > picksplit. Certainly if you're inserting lots of values in a short > interval, I can imagine picksplit being nasty, since the algorithms for > a lot of datatypes are not really reknown for their speed. Tut tut ... in the words of the sage, it is a capital mistake to theorize in advance of the data. You may well be right, but on the other hand it could easily be something dumb like an O(N^2) loop over a list structure. I'll post some gprof numbers after Stephan sends me the dump. We should probably move the thread to someplace like pgsql-perform, too. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 13:20:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D7BBD9DC842 for ; Fri, 20 Jan 2006 13:20:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13605-02 for ; Fri, 20 Jan 2006 13:20:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 5EFD59DC820 for ; Fri, 20 Jan 2006 13:20:26 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 9BEFA3983F; Fri, 20 Jan 2006 11:20:26 -0600 (CST) Date: Fri, 20 Jan 2006 11:20:26 -0600 From: "Jim C. Nasby" To: K C Lau Cc: pgsql-performance@postgresql.org Subject: Re: SELECT MIN, MAX took longer time than SELECT COUNT, MIN, MAX Message-ID: <20060120172026.GF20182@pervasive.com> References: <6.2.1.2.0.20060120120150.08ab7b00@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6.2.1.2.0.20060120120150.08ab7b00@localhost> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/344 X-Sequence-Number: 16822 On Fri, Jan 20, 2006 at 12:35:36PM +0800, K C Lau wrote: Here's the problem... the estimate for the backwards index scan is *way* off: > -> Limit (cost=0.00..1.26 rows=1 width=4) (actual > time=200032.928..200032.931 rows=1 loops=1) > -> Index Scan Backward using pk_log on > log (cost=0.00..108047.11 rows=86089 width=4) (actual > time=200032.920..200032.920 rows=1 loops=1) > Filter: (((create_time)::text < '2005/10/19'::text) AND > (logsn IS NOT NULL)) > Total runtime: 200051.701 ms BTW, these queries below are meaningless; they are not equivalent to min(logsn). > esdt=> explain analyze select LogSN from Log where create_time < > '2005/10/19' order by create_time limit 1; > > Limit (cost=0.00..0.98 rows=1 width=31) (actual time=0.071..0.073 rows=1 > loops=1) > -> Index Scan using idx_logtime on log (cost=0.00..84649.94 > rows=86089 width=31) (actual time=0.063..0.063 rows=1 loops=1) > Index Cond: ((create_time)::text < '2005/10/19'::text) > Total runtime: 0.182 ms > > esdt=> explain analyze select LogSN from Log where create_time < > '2005/10/19' order by create_time desc limit 1; > Limit (cost=0.00..0.98 rows=1 width=31) (actual time=0.058..0.061 rows=1 > loops=1) > -> Index Scan Backward using idx_logtime on log (cost=0.00..84649.94 > rows=86089 width=31) (actual time=0.051..0.051 rows=1 loops=1) > Index Cond: ((create_time)::text < '2005/10/19'::text) > Total runtime: 0.186 ms > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 13:29:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3620A9DC87D for ; Fri, 20 Jan 2006 13:29:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13159-09 for ; Fri, 20 Jan 2006 13:29:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by postgresql.org (Postfix) with ESMTP id B28099DC80D for ; Fri, 20 Jan 2006 13:29:09 -0400 (AST) Received: from [192.168.1.100] (or-67-76-146-141.sta.sprint-hsd.net [67.76.146.141]) (authenticated bits=0) by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id k0KHJI9Z032567; Fri, 20 Jan 2006 09:19:22 -0800 Message-ID: <43D11E62.1080206@commandprompt.com> Date: Fri, 20 Jan 2006 09:31:14 -0800 From: "Joshua D. Drake" User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: "Jim C. Nasby" CC: Mark Kirkwood , Michael Crozier , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> <20060120171214.GE20182@pervasive.com> In-Reply-To: <20060120171214.GE20182@pervasive.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]); Fri, 20 Jan 2006 09:19:23 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/345 X-Sequence-Number: 16823 Jim C. Nasby wrote: > BTW, given all the recent discussion about vacuuming and our MVCC, > http://www.pervasive-postgres.com/lp/newsletters/2006/Insights_Postgres_Jan.asp#3 > should prove interesting. :) > Please explain... what is the .asp extension. I have yet to see it reliable in production ;) -- The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 PostgreSQL Replication, Consulting, Custom Development, 24x7 support Managed Services, Shared and Dedicated Hosting Co-Authors: PLphp, PLperl - http://www.commandprompt.com/ From pgsql-performance-owner@postgresql.org Fri Jan 20 13:34:09 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F19989DC87D for ; Fri, 20 Jan 2006 13:34:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15146-08 for ; Fri, 20 Jan 2006 13:34:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id BBC8B9DC80D for ; Fri, 20 Jan 2006 13:34:06 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id AF27939834; Fri, 20 Jan 2006 11:34:06 -0600 (CST) Date: Fri, 20 Jan 2006 11:34:06 -0600 From: "Jim C. Nasby" To: "Joshua D. Drake" Cc: Mark Kirkwood , Michael Crozier , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Message-ID: <20060120173406.GH20182@pervasive.com> References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> <20060120171214.GE20182@pervasive.com> <43D11E62.1080206@commandprompt.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D11E62.1080206@commandprompt.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/346 X-Sequence-Number: 16824 On Fri, Jan 20, 2006 at 09:31:14AM -0800, Joshua D. Drake wrote: > Jim C. Nasby wrote: > >BTW, given all the recent discussion about vacuuming and our MVCC, > >http://www.pervasive-postgres.com/lp/newsletters/2006/Insights_Postgres_Jan.asp#3 > >should prove interesting. :) > > > Please explain... what is the .asp extension. I have yet to see it > reliable in production ;) I lay no claim to our infrastructure. :) -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 13:35:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A23169DCB47 for ; Fri, 20 Jan 2006 13:35:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17299-02 for ; Fri, 20 Jan 2006 13:35:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by postgresql.org (Postfix) with ESMTP id B61B89DCB56 for ; Fri, 20 Jan 2006 13:35:29 -0400 (AST) Received: from [192.168.1.100] (or-67-76-146-141.sta.sprint-hsd.net [67.76.146.141]) (authenticated bits=0) by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id k0KHPsi9000648; Fri, 20 Jan 2006 09:25:57 -0800 Message-ID: <43D11FEE.5080701@commandprompt.com> Date: Fri, 20 Jan 2006 09:37:50 -0800 From: "Joshua D. Drake" User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: "Jim C. Nasby" CC: Mark Kirkwood , Michael Crozier , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> <20060120171214.GE20182@pervasive.com> <43D11E62.1080206@commandprompt.com> <20060120173406.GH20182@pervasive.com> In-Reply-To: <20060120173406.GH20182@pervasive.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]); Fri, 20 Jan 2006 09:25:58 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.069 required=5 tests=[AWL=0.069] X-Spam-Score: 0.069 X-Spam-Level: X-Archive-Number: 200601/347 X-Sequence-Number: 16825 > I lay no claim to our infrastructure. :) > Can I quote the: Pervasive Senior Engineering Consultant on that? -- The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 PostgreSQL Replication, Consulting, Custom Development, 24x7 support Managed Services, Shared and Dedicated Hosting Co-Authors: PLphp, PLperl - http://www.commandprompt.com/ From pgsql-performance-owner@postgresql.org Fri Jan 20 13:44:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 40F239DCA82 for ; Fri, 20 Jan 2006 13:44:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18693-04 for ; Fri, 20 Jan 2006 13:44:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 150E39DCA39 for ; Fri, 20 Jan 2006 13:44:16 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 7F23C39834; Fri, 20 Jan 2006 11:44:16 -0600 (CST) Date: Fri, 20 Jan 2006 11:44:16 -0600 From: "Jim C. Nasby" To: "Joshua D. Drake" Cc: Mark Kirkwood , Michael Crozier , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Message-ID: <20060120174416.GL20182@pervasive.com> References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> <20060120171214.GE20182@pervasive.com> <43D11E62.1080206@commandprompt.com> <20060120173406.GH20182@pervasive.com> <43D11FEE.5080701@commandprompt.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D11FEE.5080701@commandprompt.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.098 required=5 tests=[AWL=0.098] X-Spam-Score: 0.098 X-Spam-Level: X-Archive-Number: 200601/348 X-Sequence-Number: 16826 On Fri, Jan 20, 2006 at 09:37:50AM -0800, Joshua D. Drake wrote: > > >I lay no claim to our infrastructure. :) > > > Can I quote the: Pervasive Senior Engineering Consultant on that? Sure... I've never been asked to consult on our stuff, and in any case, I don't do web front-ends (one of the nice things about working with a team of other consultants). AFAIK IIS will happily talk to PostgreSQL (though maybe I'm wrong there...) I *have* asked what database is being used on the backend though, and depending on the answer to that some folks might have some explaining to do. :) *grabs big can of dog food* -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 13:47:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8700E9DCAD0 for ; Fri, 20 Jan 2006 13:47:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17448-06 for ; Fri, 20 Jan 2006 13:47:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.refusion.com (mail.refusion.com [213.144.155.20]) by postgresql.org (Postfix) with ESMTP id E006B9DCA82 for ; Fri, 20 Jan 2006 13:47:01 -0400 (AST) Received: from iwing by mail.refusion.com (MDaemon.PRO.v8.1.4.R) with ESMTP id md50000486860.msg for ; Fri, 20 Jan 2006 18:45:38 +0100 Message-ID: <0a0c01c61de9$7bc56f80$0201a8c0@iwing> From: To: "Jim C. Nasby" , "Joshua D. Drake" Cc: "Mark Kirkwood" , "Michael Crozier" , References: <034701c61c46$f427df20$f20214ac@bite.lt> <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> <20060120171214.GE20182@pervasive.com> <43D11E62.1080206@commandprompt.com> <20060120173406.GH20182@pervasive.com> <43D11FEE.5080701@commandprompt.com> <20060120174416.GL20182@pervasive.com> Subject: Re: Autovacuum / full vacuum (off-topic?) Date: Fri, 20 Jan 2006 18:46:45 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.1830 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 X-Authenticated-Sender: info@alternize.com X-Spam-Processed: mail.refusion.com, Fri, 20 Jan 2006 18:45:38 +0100 (not processed: message from trusted or authenticated source) X-MDRemoteIP: 80.238.232.174 X-Return-Path: me@alternize.com X-MDaemon-Deliver-To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.727 required=5 tests=[AWL=-0.696, DNS_FROM_RFC_DSN=2.872, NO_REAL_NAME=0.55, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 2.727 X-Spam-Level: ** X-Archive-Number: 200601/349 X-Sequence-Number: 16827 > Sure... I've never been asked to consult on our stuff, and in any case, > I don't do web front-ends (one of the nice things about working with a > team of other consultants). AFAIK IIS will happily talk to PostgreSQL > (though maybe I'm wrong there...) iis (yeah, asp in a successfull productive environement hehe) & postgresql works even better for us than iis & mssql :-) - thomas From pgsql-performance-owner@postgresql.org Fri Jan 20 14:32:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 9AFA09DCB7F for ; Fri, 20 Jan 2006 14:32:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27579-03 for ; Fri, 20 Jan 2006 14:32:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.194]) by postgresql.org (Postfix) with ESMTP id 78E099DCB7D for ; Fri, 20 Jan 2006 14:32:31 -0400 (AST) Received: by uproxy.gmail.com with SMTP id s2so20927uge for ; Fri, 20 Jan 2006 10:32:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:content-type:content-transfer-encoding; b=kwGc4aFAxoKAdWCmZxbz0bU6uWjklHnvYxNGqSRSXbBthdQYKE3hWCMIt8o3bORLh3W8dLTOovbsS2815o9vIIWzn3LocrdtUA6zpjB91B6Vu0c2wOcZWjIUy3w8IxHQDjiZLMTU2eYx/ab/OqwTdTz+DJLmSlgbGf33xCHDYmY= Received: by 10.67.31.14 with SMTP id i14mr940422ugj; Fri, 20 Jan 2006 10:32:31 -0800 (PST) Received: from ?192.168.1.10? ( [81.185.250.153]) by mx.gmail.com with ESMTP id h1sm1364970ugf.2006.01.20.10.32.30; Fri, 20 Jan 2006 10:32:30 -0800 (PST) Message-ID: <43D12CC2.8050408@gmail.com> Date: Fri, 20 Jan 2006 19:32:34 +0100 From: Antoine User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051022) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: query stopped working after tables > 50000 records Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/350 X-Sequence-Number: 16828 Hi, I have a query that does a left outer join. The query gets some text from a reference table where one of the query's main tables may or may not have the text's tables id. It wasn't super fast, but now it simply won't execute. It won't complete either through odbc or via pgadmin (haven't yet tried via psql). A week ago (with considerably fewer records in the main table) it executed fine, not particularly quickly, but not that slowly either. Now it locks up postgres completely (if nothing else needs anything it takes 100% cpu), and even after an hour gives me nothing. I have come up with a solution that gets the text via another query (possibly even a better solution), but this seems very strange. Can anyone shed some light on the subject? I tried a full vacuum on the tables that needed it, and a postgres restart, all to no avail. Cheers Antoine ps. I can send the query if that will help... pps. running a home-compiled 8.1.1 with tables in the query having 70000 records, 30000 records and 10 for the outer join. Without the left outer join it runs in ~ 1 second. From pgsql-performance-owner@postgresql.org Fri Jan 20 14:51:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 72B9C9DC842 for ; Fri, 20 Jan 2006 14:51:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31580-05 for ; Fri, 20 Jan 2006 14:51:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pop.xnet.hr (dns1.xnet.hr [82.193.192.5]) by postgresql.org (Postfix) with ESMTP id BD4D69DCB74 for ; Fri, 20 Jan 2006 14:51:18 -0400 (AST) Received: (qmail 26701 invoked from network); 20 Jan 2006 18:51:45 -0000 Received: by simscan 1.1.0 ppid: 26692, pid: 26694, t: 0.5947s scanners: attach: 1.1.0 clamav: 0.87/m:34/d:1131 spam: 3.1.0 Received: from unknown (HELO ?83.139.74.33?) (83.139.74.33) by pop.xnet.hr with SMTP; 20 Jan 2006 18:51:44 -0000 Message-ID: <43D130EF.3010205@zg.htnet.hr> Date: Fri, 20 Jan 2006 19:50:23 +0100 From: Rikard Pavelic User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/351 X-Sequence-Number: 16829 >>Hi, >> >> Will simple queries such as "SELECT * FROM blah_table WHERE tag='x'; work any >> faster by putting them into a stored procedure? > >IMHO no, why do you think so? You can use PREPARE instead, if you have many >selects like this. I tought that creating stored procedures in database means storing it's execution plan (well, actually storing it like a compiled object). Well, that's what I've learned couple a years ago in colledge ;) What are the advantages of parsing SP functions every time it's called? My position is that preparing stored procedures for execution solves more problems, that it creates. And the most important one to be optimizing access to queries from multiple connections (which is one of the most important reasons for using stored procedures in the first place). Best regards, Rikard From pgsql-performance-owner@postgresql.org Fri Jan 20 14:51:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B63909DC85B for ; Fri, 20 Jan 2006 14:51:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30766-05 for ; Fri, 20 Jan 2006 14:51:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id BD6139DCB78 for ; Fri, 20 Jan 2006 14:51:19 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KIpEhZ025979; Fri, 20 Jan 2006 13:51:14 -0500 (EST) To: "Jim C. Nasby" cc: K C Lau , pgsql-performance@postgresql.org Subject: Re: SELECT MIN, MAX took longer time than SELECT COUNT, MIN, MAX In-reply-to: <20060120172026.GF20182@pervasive.com> References: <6.2.1.2.0.20060120120150.08ab7b00@localhost> <20060120172026.GF20182@pervasive.com> Comments: In-reply-to "Jim C. Nasby" message dated "Fri, 20 Jan 2006 11:20:26 -0600" Date: Fri, 20 Jan 2006 13:51:14 -0500 Message-ID: <25978.1137783074@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/352 X-Sequence-Number: 16830 "Jim C. Nasby" writes: > On Fri, Jan 20, 2006 at 12:35:36PM +0800, K C Lau wrote: > Here's the problem... the estimate for the backwards index scan is *way* > off: >> -> Limit (cost=0.00..1.26 rows=1 width=4) (actual >> time=200032.928..200032.931 rows=1 loops=1) >> -> Index Scan Backward using pk_log on >> log (cost=0.00..108047.11 rows=86089 width=4) (actual >> time=200032.920..200032.920 rows=1 loops=1) >> Filter: (((create_time)::text < '2005/10/19'::text) AND >> (logsn IS NOT NULL)) >> Total runtime: 200051.701 ms It's more subtle than you think. The estimated rowcount is the estimated number of rows fetched if the indexscan were run to completion, which it isn't because the LIMIT cuts it off after the first returned row. That estimate is not bad (we can see from the aggregate plan that the true value would have been 106708, assuming that the "logsn IS NOT NULL" condition isn't filtering anything). The real problem is that it's taking quite a long time for the scan to reach the first row with create_time < 2005/10/19, which is not too surprising if logsn is strongly correlated with create_time ... but in the absence of any cross-column statistics the planner has no very good way to know that. (Hm ... but both of them probably also show a strong correlation to physical order ... we could look at that maybe ...) The default assumption is that the two columns aren't correlated and so it should not take long to hit the first such row, which is why the planner likes the indexscan/limit plan. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 14:56:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 59A3A9DC9CC for ; Fri, 20 Jan 2006 14:56:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32203-05 for ; Fri, 20 Jan 2006 14:56:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pop.xnet.hr (dns1.xnet.hr [82.193.192.5]) by postgresql.org (Postfix) with ESMTP id A0FFE9DCB60 for ; Fri, 20 Jan 2006 14:56:14 -0400 (AST) Received: (qmail 27825 invoked from network); 20 Jan 2006 18:56:41 -0000 Received: by simscan 1.1.0 ppid: 27813, pid: 27815, t: 0.8915s scanners: attach: 1.1.0 clamav: 0.87/m:34/d:1131 spam: 3.1.0 Received: from unknown (HELO ?83.139.74.33?) (83.139.74.33) by pop.xnet.hr with SMTP; 20 Jan 2006 18:56:40 -0000 Message-ID: <43D13217.2030704@zg.htnet.hr> Date: Fri, 20 Jan 2006 19:55:19 +0100 From: Rikard Pavelic User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Stored procedures References: <6.2.1.2.0.20060120120150.08ab7b00@localhost> <20060120172026.GF20182@pervasive.com> <25978.1137783074@sss.pgh.pa.us> In-Reply-To: <25978.1137783074@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/353 X-Sequence-Number: 16831 > >> Hi, >> >> Will simple queries such as "SELECT * FROM blah_table WHERE tag='x'; >> work any >> faster by putting them into a stored procedure? > > IMHO no, why do you think so? You can use PREPARE instead, if you have > many > selects like this. I tought that creating stored procedures in database means storing it's execution plan (well, actually storing it like a compiled object). Well, that's what I've learned couple a years ago in colledge ;) What are the advantages of parsing SP functions every time it's called? My position is that preparing stored procedures for execution solves more problems, that it creates. And the most important one to be optimizing access to queries from multiple connections (which is one of the most important reasons for using stored procedures in the first place). Best regards, Rikard From pgsql-performance-owner@postgresql.org Fri Jan 20 15:02:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 637869DCA39 for ; Fri, 20 Jan 2006 15:02:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31198-09 for ; Fri, 20 Jan 2006 15:02:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id B5B189DCA2C for ; Fri, 20 Jan 2006 15:02:50 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 68D353983D; Fri, 20 Jan 2006 13:02:36 -0600 (CST) Date: Fri, 20 Jan 2006 13:02:36 -0600 From: "Jim C. Nasby" To: me@alternize.com Cc: "Joshua D. Drake" , Mark Kirkwood , Michael Crozier , pgsql-performance@postgresql.org Subject: Re: Autovacuum / full vacuum (off-topic?) Message-ID: <20060120190236.GM20182@pervasive.com> References: <60d5ipcw8y.fsf@dba2.int.libertyrms.com> <200601181115.51850.crozierm@conducivetech.com> <20060118225257.GY17896@pervasive.com> <43D01C68.3030204@paradise.net.nz> <20060120171214.GE20182@pervasive.com> <43D11E62.1080206@commandprompt.com> <20060120173406.GH20182@pervasive.com> <43D11FEE.5080701@commandprompt.com> <20060120174416.GL20182@pervasive.com> <0a0c01c61de9$7bc56f80$0201a8c0@iwing> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0a0c01c61de9$7bc56f80$0201a8c0@iwing> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.098 required=5 tests=[AWL=0.098] X-Spam-Score: 0.098 X-Spam-Level: X-Archive-Number: 200601/354 X-Sequence-Number: 16832 On Fri, Jan 20, 2006 at 06:46:45PM +0100, me@alternize.com wrote: > >Sure... I've never been asked to consult on our stuff, and in any case, > >I don't do web front-ends (one of the nice things about working with a > >team of other consultants). AFAIK IIS will happily talk to PostgreSQL > >(though maybe I'm wrong there...) > > iis (yeah, asp in a successfull productive environement hehe) & postgresql > works even better for us than iis & mssql :-) Just last night I was talking to someone about different databases and what-not (he's stuck in a windows shop using MSSQL and I mentioned I'd heard some bad things about it's stability). I realized at some point that asking about what large installs of something exist is pretty pointless... given enough effort you can make almost anything scale. As an example, there's a cable company with a MySQL database that's nearly 1TB... if that's not proof you can make anything scale, I don't know what is. ;) What people really need to ask about is how hard it is to make something work, and how many problems you're likely to keep encountering. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 15:04:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 00CC79DC85B for ; Fri, 20 Jan 2006 15:04:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33570-06 for ; Fri, 20 Jan 2006 15:04:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id BFEF39DC842 for ; Fri, 20 Jan 2006 15:04:36 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 532813983D; Fri, 20 Jan 2006 13:04:37 -0600 (CST) Date: Fri, 20 Jan 2006 13:04:37 -0600 From: "Jim C. Nasby" To: Antoine Cc: pgsql-performance@postgresql.org Subject: Re: query stopped working after tables > 50000 records Message-ID: <20060120190437.GN20182@pervasive.com> References: <43D12CC2.8050408@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D12CC2.8050408@gmail.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.098 required=5 tests=[AWL=0.098] X-Spam-Score: 0.098 X-Spam-Level: X-Archive-Number: 200601/355 X-Sequence-Number: 16833 Send query, output of EXPLAIN and table definitions. On Fri, Jan 20, 2006 at 07:32:34PM +0100, Antoine wrote: > Hi, > I have a query that does a left outer join. The query gets some text > from a reference table where one of the query's main tables may or may > not have the text's tables id. It wasn't super fast, but now it simply > won't execute. It won't complete either through odbc or via pgadmin > (haven't yet tried via psql). A week ago (with considerably fewer > records in the main table) it executed fine, not particularly quickly, > but not that slowly either. Now it locks up postgres completely (if > nothing else needs anything it takes 100% cpu), and even after an hour > gives me nothing. I have come up with a solution that gets the text via > another query (possibly even a better solution), but this seems very > strange. > Can anyone shed some light on the subject? I tried a full vacuum on the > tables that needed it, and a postgres restart, all to no avail. > Cheers > Antoine > ps. I can send the query if that will help... > pps. running a home-compiled 8.1.1 with tables in the query having 70000 > records, 30000 records and 10 for the outer join. Without the left outer > join it runs in ~ 1 second. > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org > -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 15:10:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CDE529DC99D for ; Fri, 20 Jan 2006 15:10:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33552-07 for ; Fri, 20 Jan 2006 15:10:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 915B69DC842 for ; Fri, 20 Jan 2006 15:10:30 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 863063983D; Fri, 20 Jan 2006 13:10:31 -0600 (CST) Date: Fri, 20 Jan 2006 13:10:31 -0600 From: "Jim C. Nasby" To: Rikard Pavelic Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures Message-ID: <20060120191031.GO20182@pervasive.com> References: <43D130EF.3010205@zg.htnet.hr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D130EF.3010205@zg.htnet.hr> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/356 X-Sequence-Number: 16834 On Fri, Jan 20, 2006 at 07:50:23PM +0100, Rikard Pavelic wrote: > >>Hi, > >> > >>Will simple queries such as "SELECT * FROM blah_table WHERE tag='x'; work > >>any > >>faster by putting them into a stored procedure? > > > > >IMHO no, why do you think so? You can use PREPARE instead, if you have many > >selects like this. > > > I tought that creating stored procedures in database means > storing it's execution plan (well, actually storing it like a > compiled object). Well, that's what I've learned couple a years > ago in colledge ;) My college professor said it, it must be true! ;P My understanding is that in plpgsql, 'bare' queries get prepared and act like prepared statements. IE: SELECT INTO variable field FROM table WHERE condition = true ; > What are the advantages of parsing SP functions every time it's called? > > My position is that preparing stored procedures for execution solves > more problems, that it creates. > And the most important one to be optimizing access to queries from > multiple connections (which is one of the most important reasons > for using stored procedures in the first place). Ok, so post some numbers then. It might be interesting to look at the cost of preparing a statement, although AFAIK that does not store the query plan anywhere. In most databases, query planning seems to be a pretty expensive operation. My experience is that that isn't the case with PostgreSQL. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 15:14:34 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CFA719DCB31 for ; Fri, 20 Jan 2006 15:14:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35561-06 for ; Fri, 20 Jan 2006 15:14:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 0C4A79DCA2C for ; Fri, 20 Jan 2006 15:14:29 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KJETaV026154; Fri, 20 Jan 2006 14:14:29 -0500 (EST) To: Martijn van Oosterhout cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <20060120170452.GC31908@svana.org> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> Comments: In-reply-to Martijn van Oosterhout message dated "Fri, 20 Jan 2006 18:04:52 +0100" Date: Fri, 20 Jan 2006 14:14:29 -0500 Message-ID: <26153.1137784469@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/357 X-Sequence-Number: 16835 [ thread moved to pgsql-performance ] I've obtained a gprof profile on Stephan's sample case (many thanks for providing the data, Stephan). The command is CREATE INDEX foo ON publications_test USING gist (fti_title); where fti_title is a tsvector column. There are 236984 rows in the table, most with between 4 and 10 words in fti_title. sum(length(fti_title)) yields 1636202 ... not sure if this is a relevant measure, however. Using CVS tip with a fairly vanilla configuration (including --enable-cassert), here are all the hotspots down to the 1% level: % cumulative self self total time seconds seconds calls s/call s/call name 20.19 1.90 1.90 588976 0.00 0.00 gistchoose 19.02 3.69 1.79 683471 0.00 0.00 XLogInsert 5.95 4.25 0.56 3575135 0.00 0.00 LWLockAcquire 4.46 4.67 0.42 3579005 0.00 0.00 LWLockRelease 4.14 5.06 0.39 3146848 0.00 0.00 AllocSetAlloc 3.72 5.41 0.35 236984 0.00 0.00 gistdoinsert 3.40 5.73 0.32 876047 0.00 0.00 hash_search 2.76 5.99 0.26 3998576 0.00 0.00 LockBuffer 2.28 6.21 0.22 11514275 0.00 0.00 gistdentryinit 1.86 6.38 0.18 841757 0.00 0.00 UnpinBuffer 1.81 6.55 0.17 12201023 0.00 0.00 FunctionCall1 1.81 6.72 0.17 237044 0.00 0.00 AllocSetCheck 1.49 6.86 0.14 236984 0.00 0.00 gistmakedeal 1.49 7.00 0.14 10206985 0.00 0.00 FunctionCall3 1.49 7.14 0.14 1287874 0.00 0.00 MemoryContextAllocZero 1.28 7.26 0.12 826179 0.00 0.00 PinBuffer 1.17 7.37 0.11 875785 0.00 0.00 hash_any 1.17 7.48 0.11 1857292 0.00 0.00 MemoryContextAlloc 1.17 7.59 0.11 221466 0.00 0.00 PageIndexTupleDelete 1.06 7.69 0.10 9762101 0.00 0.00 gistpenalty Clearly, one thing that would be worth doing is suppressing the WAL traffic when possible, as we already do for btree builds. It seems that gistchoose may have some internal ineffiency too --- I haven't looked at the code yet. The other thing that jumps out is the very large numbers of calls to gistdentryinit, FunctionCall1, FunctionCall3. Some interesting parts of the calls/calledby graph are: ----------------------------------------------- 0.35 8.07 236984/236984 gistbuildCallback [14] [15] 89.5 0.35 8.07 236984 gistdoinsert [15] 0.14 3.55 236984/236984 gistmakedeal [16] 1.90 0.89 588976/588976 gistchoose [17] 0.07 0.83 825960/841757 ReadBuffer [19] 0.09 0.10 825960/1287874 MemoryContextAllocZero [30] 0.12 0.05 1888904/3998576 LockBuffer [29] 0.13 0.00 825960/3575135 LWLockAcquire [21] 0.10 0.00 825960/3579005 LWLockRelease [26] 0.06 0.00 473968/3146848 AllocSetAlloc [27] 0.03 0.00 473968/1857292 MemoryContextAlloc [43] 0.02 0.00 825960/1272423 gistcheckpage [68] ----------------------------------------------- 0.14 3.55 236984/236984 gistdoinsert [15] [16] 39.2 0.14 3.55 236984 gistmakedeal [16] 1.20 0.15 458450/683471 XLogInsert [18] 0.01 0.66 224997/224997 gistxlogInsertCompletion [20] 0.09 0.35 444817/444817 gistgetadjusted [23] 0.08 0.17 456801/456804 formUpdateRdata [32] 0.17 0.01 827612/841757 UnpinBuffer [35] 0.11 0.00 221466/221466 PageIndexTupleDelete [42] 0.02 0.08 456801/460102 gistfillbuffer [45] 0.06 0.04 1649/1649 gistSplit [46] 0.08 0.00 685099/3579005 LWLockRelease [26] 0.03 0.05 446463/446463 gistFindCorrectParent [50] 0.04 0.02 685099/3998576 LockBuffer [29] 0.04 0.00 1649/1649 gistextractbuffer [58] 0.03 0.00 460102/460121 write_buffer [66] 0.02 0.00 825960/826092 ReleaseBuffer [69] 0.02 0.00 221402/221402 gistadjscans [82] 0.00 0.00 1582/1582 gistunion [131] 0.00 0.00 1649/1649 formSplitRdata [147] 0.00 0.00 1649/1649 gistjoinvector [178] 0.00 0.00 3/3 gistnewroot [199] 0.00 0.00 458450/461748 gistnospace [418] 0.00 0.00 458450/458450 WriteNoReleaseBuffer [419] 0.00 0.00 1652/1671 WriteBuffer [433] ----------------------------------------------- 1.90 0.89 588976/588976 gistdoinsert [15] [17] 29.7 1.90 0.89 588976 gistchoose [17] 0.25 0.17 9762101/10892174 FunctionCall3 [38] 0.18 0.14 9762101/11514275 gistdentryinit [28] 0.10 0.00 9762101/9762101 gistpenalty [47] 0.04 0.02 588976/1478610 gistDeCompressAtt [39] ----------------------------------------------- 0.00 0.00 1/683471 gistbuild [12] 0.00 0.00 1/683471 log_heap_update [273] 0.00 0.00 1/683471 RecordTransactionCommit [108] 0.00 0.00 1/683471 smgrcreate [262] 0.00 0.00 3/683471 gistnewroot [199] 0.00 0.00 5/683471 heap_insert [116] 0.00 0.00 12/683471 _bt_insertonpg [195] 0.59 0.07 224997/683471 gistxlogInsertCompletion [20] 1.20 0.15 458450/683471 gistmakedeal [16] [18] 21.4 1.79 0.22 683471 XLogInsert [18] 0.11 0.00 683471/3575135 LWLockAcquire [21] 0.08 0.00 687340/3579005 LWLockRelease [26] 0.03 0.00 683471/683471 GetCurrentTransactionIdIfAny [65] 0.01 0.00 15604/15604 AdvanceXLInsertBuffer [111] 0.00 0.00 3/10094 BufferGetBlockNumber [95] 0.00 0.00 3869/3870 XLogWrite [281] 0.00 0.00 3870/3871 LWLockConditionalAcquire [428] 0.00 0.00 3/3 BufferGetFileNode [611] ----------------------------------------------- 0.00 0.00 3164/11514275 gistunion [131] 0.01 0.00 270400/11514275 gistSplit [46] 0.03 0.02 1478610/11514275 gistDeCompressAtt [39] 0.18 0.14 9762101/11514275 gistchoose [17] [28] 4.0 0.22 0.16 11514275 gistdentryinit [28] 0.16 0.00 11514275/12201023 FunctionCall1 [36] ----------------------------------------------- 0.00 0.00 67/12201023 index_endscan [167] 0.01 0.00 686681/12201023 gistcentryinit [62] 0.16 0.00 11514275/12201023 gistdentryinit [28] [36] 1.8 0.17 0.00 12201023 FunctionCall1 [36] 0.00 0.00 67/67 btendscan [231] 0.00 0.00 12200956/22855929 data_start [414] ----------------------------------------------- 67 index_beginscan_internal [169] 0.01 0.01 444817/10892174 gistgetadjusted [23] 0.25 0.17 9762101/10892174 gistchoose [17] [38] 1.5 0.14 0.00 10206985 FunctionCall3 [38] 0.00 0.00 10206918/22855929 data_start [414] 0.00 0.00 67/67 btbeginscan [486] 67 RelationGetIndexScan [212] Now that we have some data, we can start to think about how to improve matters ... regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 15:39:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 492A89DC889 for ; Fri, 20 Jan 2006 15:39:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38326-06 for ; Fri, 20 Jan 2006 15:39:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pop.xnet.hr (dns1.xnet.hr [82.193.192.5]) by postgresql.org (Postfix) with ESMTP id 66BFD9DC85B for ; Fri, 20 Jan 2006 15:39:36 -0400 (AST) Received: (qmail 5660 invoked from network); 20 Jan 2006 19:39:48 -0000 Received: by simscan 1.1.0 ppid: 5641, pid: 5642, t: 3.6098s scanners: attach: 1.1.0 clamav: 0.87/m:34/d:1131 spam: 3.1.0 Received: from unknown (HELO ?83.139.74.33?) (83.139.74.33) by pop.xnet.hr with SMTP; 20 Jan 2006 19:39:44 -0000 Message-ID: <43D13C2F.1030203@zg.htnet.hr> Date: Fri, 20 Jan 2006 20:38:23 +0100 From: Rikard Pavelic User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> In-Reply-To: <20060120191031.GO20182@pervasive.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/358 X-Sequence-Number: 16836 Jim C. Nasby wrote: > My college professor said it, it must be true! ;P > > The famous joke ;) > My understanding is that in plpgsql, 'bare' queries get prepared and act > like prepared statements. IE: > > SELECT INTO variable > field > FROM table > WHERE condition = true > ; > > Unfortunately I don't know enough about PostgreSQL, but from responses I've been reading I've come to that conclusion. > Ok, so post some numbers then. It might be interesting to look at the > cost of preparing a statement, although AFAIK that does not store the > query plan anywhere. > > In most databases, query planning seems to be a pretty expensive > operation. My experience is that that isn't the case with PostgreSQL. > I didn't think about storing query plan anywhere on the disk, rather keep them in memory pool. It would be great if we had an option to use prepare statement for stored procedure so it would prepare it self the first time it's called and remained prepared until server shutdown or memory pool overflow. This would solve problems with prepare which is per session, so for prepared function to be optimal one must use same connection. From pgsql-performance-owner@postgresql.org Fri Jan 20 16:10:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 355F69DC99D for ; Fri, 20 Jan 2006 16:10:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52209-01 for ; Fri, 20 Jan 2006 16:10:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 72D2F9DC8DF for ; Fri, 20 Jan 2006 16:10:39 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F02ai-0000t4-Fe; Sat, 21 Jan 2006 07:10:36 +1100 Date: Fri, 20 Jan 2006 21:10:36 +0100 From: Martijn van Oosterhout To: Tom Lane Cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120201036.GE31908@svana.org> Reply-To: Martijn van Oosterhout References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="veXX9dWIonWZEC6h" Content-Disposition: inline In-Reply-To: <26153.1137784469@sss.pgh.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.13 required=5 tests=[AWL=0.130] X-Spam-Score: 0.13 X-Spam-Level: X-Archive-Number: 200601/359 X-Sequence-Number: 16837 --veXX9dWIonWZEC6h Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 02:14:29PM -0500, Tom Lane wrote: > [ thread moved to pgsql-performance ] >=20 > I've obtained a gprof profile on Stephan's sample case (many thanks for > providing the data, Stephan). The command is Something I'm missing is the calls to tsearch functions. I'm not 100% familiar with gprof, but is it possible those costs have been added somewhere else because it's in a shared library? Perhaps the costs went into FunctionCall1/3? Have a nice day, --=20 Martijn van Oosterhout 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. --veXX9dWIonWZEC6h Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0UO8IB7bNG8LQkwRAu7FAKCAo1FpTvvZk3lsCsxh8EOtrsBiEACfTZZc /UF8zOxBgBHaGtsL9z9r95o= =eRRD -----END PGP SIGNATURE----- --veXX9dWIonWZEC6h-- From pgsql-performance-owner@postgresql.org Fri Jan 20 16:21:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7322F9DCAC9 for ; Fri, 20 Jan 2006 16:21:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56401-01 for ; Fri, 20 Jan 2006 16:21:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1466D9DCA39 for ; Fri, 20 Jan 2006 16:21:45 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KKLjRt026584; Fri, 20 Jan 2006 15:21:45 -0500 (EST) To: Martijn van Oosterhout cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <20060120201036.GE31908@svana.org> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> Comments: In-reply-to Martijn van Oosterhout message dated "Fri, 20 Jan 2006 21:10:36 +0100" Date: Fri, 20 Jan 2006 15:21:45 -0500 Message-ID: <26583.1137788505@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/360 X-Sequence-Number: 16838 Martijn van Oosterhout writes: > Something I'm missing is the calls to tsearch functions. I'm not 100% > familiar with gprof, but is it possible those costs have been added > somewhere else because it's in a shared library? Perhaps the costs went > into FunctionCall1/3? I think that the tsearch functions must be the stuff charged as "data_start" (which is not actually any symbol in our source code). That is showing as being called by FunctionCallN which is what you'd expect. If the totals given by gprof are correct, then it's down in the noise. I don't think I trust that too much ... but I don't see anything in the gprof manual about how to include a dynamically loaded library in the profile. (I did compile tsearch2 with -pg, but that's evidently not enough.) I'll see if I can link tsearch2 statically to resolve this question. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 16:51:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 988509DCA82 for ; Fri, 20 Jan 2006 16:51:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66410-05 for ; Fri, 20 Jan 2006 16:51:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id B8C979DCB68 for ; Fri, 20 Jan 2006 16:51:33 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F03EK-000102-LE; Sat, 21 Jan 2006 07:51:32 +1100 Date: Fri, 20 Jan 2006 21:51:32 +0100 From: Martijn van Oosterhout To: Tom Lane Cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120205132.GF31908@svana.org> Reply-To: Martijn van Oosterhout References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+JUInw4efm7IfTNU" Content-Disposition: inline In-Reply-To: <26583.1137788505@sss.pgh.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.13 required=5 tests=[AWL=0.130] X-Spam-Score: 0.13 X-Spam-Level: X-Archive-Number: 200601/361 X-Sequence-Number: 16839 --+JUInw4efm7IfTNU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 03:21:45PM -0500, Tom Lane wrote: > If the totals given by gprof are correct, then it's down in the noise. > I don't think I trust that too much ... but I don't see anything in the > gprof manual about how to include a dynamically loaded library in the > profile. (I did compile tsearch2 with -pg, but that's evidently not > enough.) There is some mention on the web of an environment variable you can set: LD_PROFILE=3D These pages seem relevent: http://sourceware.org/ml/binutils/2002-04/msg00047.html http://www.scit.wlv.ac.uk/cgi-bin/mansec?1+gprof It's wierd how some man pages for gprof describe this feature, but the one on my local system doesn't mention it. > I'll see if I can link tsearch2 statically to resolve this question. That'll work too... --=20 Martijn van Oosterhout 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. --+JUInw4efm7IfTNU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0U1UIB7bNG8LQkwRAmr/AJ98WSeO6bufL6WgQR/cUAvIMOJMAwCeJ+mN XdsbU8o8VyyJrhfZLlI7JVs= =7MCw -----END PGP SIGNATURE----- --+JUInw4efm7IfTNU-- From pgsql-performance-owner@postgresql.org Fri Jan 20 17:19:20 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E75D09DC85B for ; Fri, 20 Jan 2006 17:19:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78561-03 for ; Fri, 20 Jan 2006 17:19:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 369199DC842 for ; Fri, 20 Jan 2006 17:19:15 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KLJFWm026959; Fri, 20 Jan 2006 16:19:15 -0500 (EST) To: Martijn van Oosterhout cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <20060120205132.GF31908@svana.org> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> Comments: In-reply-to Martijn van Oosterhout message dated "Fri, 20 Jan 2006 21:51:32 +0100" Date: Fri, 20 Jan 2006 16:19:15 -0500 Message-ID: <26958.1137791955@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/362 X-Sequence-Number: 16840 Well, I feel like a fool, because I failed to notice that the total runtime shown in that profile wasn't anywhere close to the actual wall clock time. gprof is indeed simply not counting the time spent in dynamically-linked code. With tsearch2 statically linked into the backend, a more believable picture emerges: % cumulative self self total time seconds seconds calls Ks/call Ks/call name 98.96 1495.93 1495.93 33035195 0.00 0.00 hemdistsign 0.27 1500.01 4.08 10030581 0.00 0.00 makesign 0.11 1501.74 1.73 588976 0.00 0.00 gistchoose 0.10 1503.32 1.58 683471 0.00 0.00 XLogInsert 0.05 1504.15 0.83 246579 0.00 0.00 sizebitvec 0.05 1504.93 0.78 446399 0.00 0.00 gtsvector_union 0.03 1505.45 0.52 3576475 0.00 0.00 LWLockRelease 0.03 1505.92 0.47 1649 0.00 0.00 gtsvector_picksplit 0.03 1506.38 0.47 3572572 0.00 0.00 LWLockAcquire 0.02 1506.74 0.36 444817 0.00 0.00 gtsvector_same 0.02 1507.09 0.35 4077089 0.00 0.00 AllocSetAlloc 0.02 1507.37 0.28 236984 0.00 0.00 gistdoinsert 0.02 1507.63 0.26 874195 0.00 0.00 hash_search 0.02 1507.89 0.26 9762101 0.00 0.00 gtsvector_penalty 0.01 1508.08 0.19 236984 0.00 0.00 gistmakedeal 0.01 1508.27 0.19 841754 0.00 0.00 UnpinBuffer 0.01 1508.45 0.18 22985469 0.00 0.00 hemdistcache 0.01 1508.63 0.18 3998572 0.00 0.00 LockBuffer 0.01 1508.81 0.18 686681 0.00 0.00 gtsvector_compress 0.01 1508.98 0.17 11514275 0.00 0.00 gistdentryinit So we gotta fix hemdistsign ... regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 17:35:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E6AE09DCA39 for ; Fri, 20 Jan 2006 17:35:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76094-10 for ; Fri, 20 Jan 2006 17:35:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id DDF379DC809 for ; Fri, 20 Jan 2006 17:35:08 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id AB0B539846; Fri, 20 Jan 2006 15:34:55 -0600 (CST) Date: Fri, 20 Jan 2006 15:34:55 -0600 From: "Jim C. Nasby" To: Rikard Pavelic Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures Message-ID: <20060120213455.GT20182@pervasive.com> References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> <43D13C2F.1030203@zg.htnet.hr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D13C2F.1030203@zg.htnet.hr> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/363 X-Sequence-Number: 16841 On Fri, Jan 20, 2006 at 08:38:23PM +0100, Rikard Pavelic wrote: > This would solve problems with prepare which is per session, so for > prepared function to be > optimal one must use same connection. If you're dealing with something that's performance critical you're not going to be constantly re-connecting anyway, so I don't see what the issue is. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Fri Jan 20 17:38:06 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8C8C39DCB73 for ; Fri, 20 Jan 2006 17:38:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80760-06 for ; Fri, 20 Jan 2006 17:37:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id EABF89DCA82 for ; Fri, 20 Jan 2006 17:37:55 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F03xC-00018v-It; Sat, 21 Jan 2006 08:37:54 +1100 Date: Fri, 20 Jan 2006 22:37:54 +0100 From: Martijn van Oosterhout To: Tom Lane Cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120213754.GG31908@svana.org> Reply-To: Martijn van Oosterhout References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="iBwuxWUsK/REspAd" Content-Disposition: inline In-Reply-To: <26958.1137791955@sss.pgh.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200601/364 X-Sequence-Number: 16842 --iBwuxWUsK/REspAd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 04:19:15PM -0500, Tom Lane wrote: > % cumulative self self total =20 > time seconds seconds calls Ks/call Ks/call name =20 > 98.96 1495.93 1495.93 33035195 0.00 0.00 hemdistsign > So we gotta fix hemdistsign ... lol! Yeah, I guess so. Pretty nasty loop. LOOPBIT will iterate 8*63=3D504 times and it's going to do silly bit handling on each and every iteration. Given that all it's doing is counting bits, a simple fix would be to loop over bytes, use XOR and count ones. For extreme speedup create a lookup table with 256 entries to give you the answer straight away... Have a nice day, --=20 Martijn van Oosterhout 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. --iBwuxWUsK/REspAd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0VgyIB7bNG8LQkwRAub5AJ40vYiLjdDd0GIoev7PzdZccAEiHwCfeRqV nO8oYeaYYc4VINZGiZRYkOk= =goOw -----END PGP SIGNATURE----- --iBwuxWUsK/REspAd-- From pgsql-performance-owner@postgresql.org Fri Jan 20 17:57:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2E4FD9DC9D0 for ; Fri, 20 Jan 2006 17:57:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87753-03 for ; Fri, 20 Jan 2006 17:57:16 -0400 (AST) X-Greylist: delayed 00:14:47.294992 by SQLgrey- Received: from prod01.jerrysievers.com (adsl-64-118-249-70.netrox.net [64.118.249.70]) by postgresql.org (Postfix) with ESMTP id A16BB9DC99D for ; Fri, 20 Jan 2006 17:57:12 -0400 (AST) Received: (from gsievers@localhost) by prod01.jerrysievers.com (8.11.0/8.11.0) id k0KLgKd16319; Fri, 20 Jan 2006 16:42:20 -0500 To: pgsql-performance@postgresql.org Subject: Sudden slowdown of Pg server From: Jerry Sievers Date: 20 Jan 2006 16:42:20 -0500 Message-ID: Lines: 70 X-Mailer: Gnus v5.7/Emacs 20.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/367 X-Sequence-Number: 16845 Hello; I am going through a post mortem analysis of an infrequent but recurring problem on a Pg 8.0.3 installation. Application code connects to Pg using J2EE pooled connections. PostgreSQL 8.0.3 on sparc-sun-solaris2.9, compiled by GCC sparc-sun-solaris2.8-gcc (GCC) 3.3.2 Database is quite large with respect to the number of tables, some of which have up to 6 million tuples. Typical idle/busy connection ratio is 3/100 but occationally we'll catch 20 or more busy sessions. The problem manifests itself and appears like a locking issue. About weekly throuput slows down and we notice the busy connection count rising minute by minute. 2, 20, 40... Before long, the app server detects lack of responsiveness and fails over to another app server (not Pg) which in turn attempts a bunch of new connections into Postgres. Sampling of the snapshots of pg_locks and pg_stat_activity tables takes place each minute. I am wishing for a few new ideas as to what to be watching; Here's some observations that I've made. 1. At no time do any UN-granted locks show in pg_locks 2. The number of exclusive locks is small 1, 4, 8 3. Other locks type/mode are numerous but appear like normal workload. 4. There are at least a few old ' In Transaction' cases in activity view 5. No interesting error messages or warning in Pg logs. 6. No crash of Pg backend Other goodies includes a bounty of poor performing queries which are constantly being optimized now for good measure. Aside from the heavy queries, performance is generallly decent. Resource related server configs have been boosted substantially but have not undergone any formal R&D to verify that we're inthe safe under heavy load. An max_fsm_relations setting which is *below* our table and index count was discovered by me today and will be increased this evening during a maint cycle. The slowdown and subsequent run-away app server takes place within a small 2-5 minute window and I have as of yet not been able to get into Psql during the event for a hands-on look. Questions; 1. Is there any type of resource lock that can unconditionally block another session and NOT appear as UN-granted lock? 2. What in particular other runtime info would be most useful to sample here? 3. What Solaris side runtime stats might give some clues here (maybe?)( and how often to sample? Assume needs to be aggressive due to how fast this problem crops up. Any help appreciated Thank you -- ------------------------------------------------------------------------------- Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant 305 321-1144 (mobile http://www.JerrySievers.com/ From pgsql-performance-owner@postgresql.org Fri Jan 20 17:44:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 471969DC842 for ; Fri, 20 Jan 2006 17:44:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85768-05 for ; Fri, 20 Jan 2006 17:44:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id BF4B49DC809 for ; Fri, 20 Jan 2006 17:43:57 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F0432-0003FG-AJ for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 22:43:56 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F0438-0005ro-00 for ; Fri, 20 Jan 2006 22:44:02 +0100 Date: Fri, 20 Jan 2006 22:44:02 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120214402.GA22493@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20060120213754.GG31908@svana.org> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/365 X-Sequence-Number: 16843 On Fri, Jan 20, 2006 at 10:37:54PM +0100, Martijn van Oosterhout wrote: > Given that all it's doing is counting bits, a simple fix would be to > loop over bytes, use XOR and count ones. For extreme speedup create a > lookup table with 256 entries to give you the answer straight away... For extra obfscation: unsigned v = (unsigned)c; int num_bits = (v * 0x1001001001001ULL & 0x84210842108421ULL) % 0x1f; (More more-or-less intelligent options at http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive :-) ) /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 17:50:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 291249DC842 for ; Fri, 20 Jan 2006 17:50:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87988-01 for ; Fri, 20 Jan 2006 17:50:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8DF2A9DCB92 for ; Fri, 20 Jan 2006 17:50:20 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KLoHdN027265; Fri, 20 Jan 2006 16:50:17 -0500 (EST) To: Martijn van Oosterhout cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <20060120213754.GG31908@svana.org> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> Comments: In-reply-to Martijn van Oosterhout message dated "Fri, 20 Jan 2006 22:37:54 +0100" Date: Fri, 20 Jan 2006 16:50:17 -0500 Message-ID: <27264.1137793817@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/366 X-Sequence-Number: 16844 Martijn van Oosterhout writes: > Given that all it's doing is counting bits, a simple fix would be to > loop over bytes, use XOR and count ones. For extreme speedup create a > lookup table with 256 entries to give you the answer straight away... Yeah, I just finished doing that and got about a 20x overall speedup (30-some seconds to build the index instead of 10 minutes). However, hemdistsign is *still* 70% of the runtime after doing that. The problem seems to be that gtsvector_picksplit is calling it an inordinate number of times: 0.53 30.02 1649/1649 FunctionCall2 [19] [20] 52.4 0.53 30.02 1649 gtsvector_picksplit [20] 29.74 0.00 23519673/33035195 hemdistsign [18] 0.14 0.00 22985469/22985469 hemdistcache [50] 0.12 0.00 268480/10030581 makesign [25] 0.02 0.00 270400/270400 fillcache [85] 0.00 0.00 9894/4077032 AllocSetAlloc [34] 0.00 0.00 9894/2787477 MemoryContextAlloc [69] (hemdistcache calls hemdistsign --- I think gprof is doing something funny with tail-calls here, and showing hemdistsign as directly called from gtsvector_picksplit when control really arrives through hemdistcache.) The bulk of the problem is clearly in this loop, which performs O(N^2) comparisons to find the two entries that are furthest apart in hemdist terms: for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) { for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) { if (k == FirstOffsetNumber) fillcache(&cache[j], GETENTRY(entryvec, j)); size_waste = hemdistcache(&(cache[j]), &(cache[k])); if (size_waste > waste) { waste = size_waste; seed_1 = k; seed_2 = j; } } } I wonder if there is a way to improve on that. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 18:14:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8A89A9DC98F for ; Fri, 20 Jan 2006 18:14:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89291-08 for ; Fri, 20 Jan 2006 18:14:22 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from brmea-mail-1.sun.com (brmea-mail-1.Sun.COM [192.18.98.31]) by postgresql.org (Postfix) with ESMTP id 083BC9DC9D0 for ; Fri, 20 Jan 2006 18:14:18 -0400 (AST) Received: from fe-amer-04.sun.com ([192.18.108.178]) by brmea-mail-1.sun.com (8.12.10/8.12.9) with ESMTP id k0KMEGSD028157 for ; Fri, 20 Jan 2006 15:14:16 -0700 (MST) Received: from conversion-daemon.mail-amer.sun.com by mail-amer.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) id <0ITE00K01W5PXN00@mail-amer.sun.com> (original mail from J.K.Shah@Sun.COM) for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 15:14:16 -0700 (MST) Received: from [129.148.168.2] by mail-amer.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPSA id <0ITE00EIMWFLSM51@mail-amer.sun.com>; Fri, 20 Jan 2006 15:14:11 -0700 (MST) Date: Fri, 20 Jan 2006 17:13:58 -0500 From: "Jignesh K. Shah" Subject: Re: Sudden slowdown of Pg server In-reply-to: To: Jerry Sievers Cc: pgsql-performance@postgresql.org Message-id: <43D160A6.4020207@sun.com> Organization: Sun Microsystems MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en References: User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050322) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.120, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/368 X-Sequence-Number: 16846 lockstat is available in Solaris 9. That can help you to determine if there are any kernel level locks that are occuring during that time. Solaris 10 also has plockstat which can be used to identify userland locks happening in your process. Since you have Solaris 9, try the following: You can run (as root) lockstat sleep 5 and note the output which can be long. I guess "prstat -am" output, "iostat -xczn 3", "vmstat 3" outputs will help also. prstat -am has a column called "LAT", if the value is in double digits, then you have a locking issue which will probably result in higher "SLP" value for the process. (Interpretation is data and workload specific which this email is too small to decode) Once you have identified a particular process (if any) to be the source of the problem, get its id and you can look at the outputs of following command which (quite intrusive) truss -c -p $pid 2> truss-syscount.txt (Ctrl-C after a while to stop collecting) truss -a -e -u":::" -p $pid 2> trussout.txt (Ctrl-C after a while to stop collecting) Regards, Jignesh Jerry Sievers wrote: >Hello; > >I am going through a post mortem analysis of an infrequent but >recurring problem on a Pg 8.0.3 installation. Application code >connects to Pg using J2EE pooled connections. > > PostgreSQL 8.0.3 on sparc-sun-solaris2.9, compiled by GCC sparc-sun-solaris2.8-gcc (GCC) 3.3.2 > >Database is quite large with respect to the number of tables, some of >which have up to 6 million tuples. Typical idle/busy connection ratio >is 3/100 but occationally we'll catch 20 or more busy sessions. > >The problem manifests itself and appears like a locking issue. About >weekly throuput slows down and we notice the busy connection count >rising minute by minute. 2, 20, 40... Before long, the app server >detects lack of responsiveness and fails over to another app server >(not Pg) which in turn attempts a bunch of new connections into >Postgres. > >Sampling of the snapshots of pg_locks and pg_stat_activity tables >takes place each minute. > >I am wishing for a few new ideas as to what to be watching; Here's >some observations that I've made. > >1. At no time do any UN-granted locks show in pg_locks >2. The number of exclusive locks is small 1, 4, 8 >3. Other locks type/mode are numerous but appear like normal workload. >4. There are at least a few old ' In Transaction' cases in > activity view >5. No interesting error messages or warning in Pg logs. >6. No crash of Pg backend > >Other goodies includes a bounty of poor performing queries which are >constantly being optimized now for good measure. Aside from the heavy >queries, performance is generallly decent. > >Resource related server configs have been boosted substantially but >have not undergone any formal R&D to verify that we're inthe safe >under heavy load. > >An max_fsm_relations setting which is *below* our table and index >count was discovered by me today and will be increased this evening >during a maint cycle. > >The slowdown and subsequent run-away app server takes place within a >small 2-5 minute window and I have as of yet not been able to get into >Psql during the event for a hands-on look. > >Questions; > >1. Is there any type of resource lock that can unconditionally block > another session and NOT appear as UN-granted lock? > >2. What in particular other runtime info would be most useful to > sample here? > >3. What Solaris side runtime stats might give some clues here > (maybe?)( and how often to sample? Assume needs to be aggressive > due to how fast this problem crops up. > >Any help appreciated > >Thank you > > > > From pgsql-performance-owner@postgresql.org Fri Jan 20 18:16:54 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 86E8B9DCB53 for ; Fri, 20 Jan 2006 18:16:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91234-06 for ; Fri, 20 Jan 2006 18:16:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id E62129DCAE0 for ; Fri, 20 Jan 2006 18:16:48 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F04Ys-0003Sz-BM for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 23:16:50 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F04Yx-0006f9-00 for ; Fri, 20 Jan 2006 23:16:55 +0100 Date: Fri, 20 Jan 2006 23:16:55 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120221655.GA22581@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <27264.1137793817@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <27264.1137793817@sss.pgh.pa.us> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200601/369 X-Sequence-Number: 16847 On Fri, Jan 20, 2006 at 04:50:17PM -0500, Tom Lane wrote: > I wonder if there is a way to improve on that. Ooh, the farthest pair problem (in an N-dimensional vector space, though). I'm pretty sure problems like this has been studied quite extensively in the literature, although perhaps not with the same norm. It's known under both "farthest pair" and "diameter", and probably others. I'm fairly sure it should be solvable in at least O(n log n). /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 18:29:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C6D929DCBB1 for ; Fri, 20 Jan 2006 18:29:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90180-09-5 for ; Fri, 20 Jan 2006 18:29:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth04.mail.atl.earthlink.net (smtpauth04.mail.atl.earthlink.net [209.86.89.64]) by postgresql.org (Postfix) with ESMTP id 8EE589DCB98 for ; Fri, 20 Jan 2006 18:29:50 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=QbkICTfa6f0InnozJwdO1QLdWnX5X+1pY1OcU9ELSrasF/BbXda1WnAklz2T+FfS; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth04.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F04lT-0008UM-Df; Fri, 20 Jan 2006 17:29:51 -0500 Message-Id: <7.0.1.0.2.20060120172335.039f5e20@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Fri, 20 Jan 2006 17:29:46 -0500 To: Tom Lane ,pgsql-performance@postgresql.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-Reply-To: <20060120221655.GA22581@uio.no> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <27264.1137793817@sss.pgh.pa.us> <20060120221655.GA22581@uio.no> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc0afdd2161bb28400118ded016d3efeb2350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.425 required=5 tests=[AWL=-0.054, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.425 X-Spam-Level: X-Archive-Number: 200601/370 X-Sequence-Number: 16848 At 05:16 PM 1/20/2006, Steinar H. Gunderson wrote: >On Fri, Jan 20, 2006 at 04:50:17PM -0500, Tom Lane wrote: > > I wonder if there is a way to improve on that. > >Ooh, the farthest pair problem (in an N-dimensional vector space, though). >I'm pretty sure problems like this has been studied quite extensively in the >literature, although perhaps not with the same norm. It's known under both >"farthest pair" and "diameter", and probably others. I'm fairly sure it >should be solvable in at least O(n log n). If the N-dimensional space is Euclidean (any is the same distance apart in dimension x), then finding the farthest pair can be done in at least O(n). If you do not want the actual distance and can create the proper data structures, particularly if you can update them incrementally as you generate pairs, it is often possible to solve this problem in O(lg n) or O(1). I'll do some grinding. Ron From pgsql-performance-owner@postgresql.org Fri Jan 20 18:33:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BBC2A9DC8DC for ; Fri, 20 Jan 2006 18:33:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 94850-04 for ; Fri, 20 Jan 2006 18:33:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id D21079DC83F for ; Fri, 20 Jan 2006 18:33:31 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F04ox-0001IC-JW; Sat, 21 Jan 2006 09:33:27 +1100 Date: Fri, 20 Jan 2006 23:33:27 +0100 From: Martijn van Oosterhout To: Tom Lane Cc: Stephan Vollmer , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120223327.GH31908@svana.org> Reply-To: Martijn van Oosterhout References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <27264.1137793817@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Cp3Cp8fzgozWLBWL" Content-Disposition: inline In-Reply-To: <27264.1137793817@sss.pgh.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200601/371 X-Sequence-Number: 16849 --Cp3Cp8fzgozWLBWL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 04:50:17PM -0500, Tom Lane wrote: > (hemdistcache calls hemdistsign --- I think gprof is doing something > funny with tail-calls here, and showing hemdistsign as directly called > from gtsvector_picksplit when control really arrives through hemdistcache= =2E) It may be the compiler. All these functions are declared static, which gives the compiler quite a bit of leeway to rearrange code. > The bulk of the problem is clearly in this loop, which performs O(N^2) > comparisons to find the two entries that are furthest apart in hemdist > terms: Ah. A while ago someone came onto the list asking about bit strings indexing[1]. If I'd known tsearch worked like this I would have pointed him to it. Anyway, before he went off to implement it he mentioned "Jarvis-Patrick clustering", whatever that means. Probably more relevent was this thread[2] on -hackers a while back with pseudo-code[3]. How well it works, I don't know, it worked for him evidently, he went away happy... [1] http://archives.postgresql.org/pgsql-general/2005-11/msg00473.php [2] http://archives.postgresql.org/pgsql-hackers/2005-11/msg01067.php [3] http://archives.postgresql.org/pgsql-hackers/2005-11/msg01069.php Hope this helps, --=20 Martijn van Oosterhout 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. --Cp3Cp8fzgozWLBWL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0WU3IB7bNG8LQkwRAuqPAJ973X2/QA/RDPXGVMcHrSyCrq0jwQCfVBBi LozfKSrqRx8SH43mKimWeeQ= =eVLE -----END PGP SIGNATURE----- --Cp3Cp8fzgozWLBWL-- From pgsql-performance-owner@postgresql.org Fri Jan 20 18:46:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id F3C409DCBA8 for ; Fri, 20 Jan 2006 18:46:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97782-05 for ; Fri, 20 Jan 2006 18:46:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth06.mail.atl.earthlink.net (smtpauth06.mail.atl.earthlink.net [209.86.89.66]) by postgresql.org (Postfix) with ESMTP id 395499DCB99 for ; Fri, 20 Jan 2006 18:46:41 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=ZgFP5dKbFLgb1wku2yzRZQ1x4e8t2osrRhz0/pXDtaaanBD/yd+1EKG7+a0dZzOe; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth06.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F051i-0001Sk-Vz; Fri, 20 Jan 2006 17:46:39 -0500 Message-Id: <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Fri, 20 Jan 2006 17:46:34 -0500 To: Martijn van Oosterhout ,Tom Lane , pgsql-performance@postgreSQL.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-Reply-To: <20060120213754.GG31908@svana.org> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc0c2d152795c79d13abd85c8893694cdb350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.428 required=5 tests=[AWL=-0.051, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.428 X-Spam-Level: X-Archive-Number: 200601/372 X-Sequence-Number: 16850 At 04:37 PM 1/20/2006, Martijn van Oosterhout wrote: >On Fri, Jan 20, 2006 at 04:19:15PM -0500, Tom Lane wrote: > > % cumulative self self total > > time seconds seconds calls Ks/call Ks/call name > > 98.96 1495.93 1495.93 33035195 0.00 0.00 hemdistsign > > > > > So we gotta fix hemdistsign ... > >lol! Yeah, I guess so. Pretty nasty loop. LOOPBIT will iterate 8*63=504 >times and it's going to do silly bit handling on each and every >iteration. > >Given that all it's doing is counting bits, a simple fix would be to >loop over bytes, use XOR and count ones. For extreme speedup create a >lookup table with 256 entries to give you the answer straight away... For an even more extreme speedup, don't most modern CPUs have an asm instruction that counts the bits (un)set (AKA "population counting") in various size entities (4b, 8b, 16b, 32b, 64b, and 128b for 64b CPUs with SWAR instructions)? Ron From pgsql-performance-owner@postgresql.org Fri Jan 20 18:49:14 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E0F489DC98F for ; Fri, 20 Jan 2006 18:49:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99186-03 for ; Fri, 20 Jan 2006 18:49:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 281E99DC83F for ; Fri, 20 Jan 2006 18:49:09 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F0549-0003fD-Tl for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 23:49:12 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F054F-0006z7-00 for ; Fri, 20 Jan 2006 23:49:15 +0100 Date: Fri, 20 Jan 2006 23:49:15 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120224915.GA26821@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.067 required=5 tests=[AWL=0.067] X-Spam-Score: 0.067 X-Spam-Level: X-Archive-Number: 200601/373 X-Sequence-Number: 16851 On Fri, Jan 20, 2006 at 05:46:34PM -0500, Ron wrote: > For an even more extreme speedup, don't most modern CPUs have an asm > instruction that counts the bits (un)set (AKA "population counting") > in various size entities (4b, 8b, 16b, 32b, 64b, and 128b for 64b > CPUs with SWAR instructions)? None in the x86 series that I'm aware of, at least. You have instructions for finding the highest set bit, though. /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 18:50:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DF0719DCB9D for ; Fri, 20 Jan 2006 18:50:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97917-06 for ; Fri, 20 Jan 2006 18:50:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 72E4D9DCB84 for ; Fri, 20 Jan 2006 18:50:34 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KMoaed006112; Fri, 20 Jan 2006 17:50:36 -0500 (EST) To: Ron cc: Martijn van Oosterhout , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> Comments: In-reply-to Ron message dated "Fri, 20 Jan 2006 17:46:34 -0500" Date: Fri, 20 Jan 2006 17:50:36 -0500 Message-ID: <6111.1137797436@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.094 required=5 tests=[AWL=0.094] X-Spam-Score: 0.094 X-Spam-Level: X-Archive-Number: 200601/374 X-Sequence-Number: 16852 Ron writes: > For an even more extreme speedup, don't most modern CPUs have an asm > instruction that counts the bits (un)set (AKA "population counting") > in various size entities (4b, 8b, 16b, 32b, 64b, and 128b for 64b > CPUs with SWAR instructions)? Yeah, but fetching from a small constant table is pretty quick too; I doubt it's worth getting involved in machine-specific assembly code for this. I'm much more interested in the idea of improving the furthest-distance algorithm in gtsvector_picksplit --- if we can do that, it'll probably drop the distance calculation down to the point where it's not really worth the trouble to assembly-code it. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 18:57:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8D96B9DCA7B for ; Fri, 20 Jan 2006 18:57:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99549-07 for ; Fri, 20 Jan 2006 18:57:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 773BF9DC98F for ; Fri, 20 Jan 2006 18:57:20 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F05C4-0001N3-OE; Sat, 21 Jan 2006 09:57:20 +1100 Date: Fri, 20 Jan 2006 23:57:20 +0100 From: Martijn van Oosterhout To: Ron Cc: Tom Lane , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120225720.GI31908@svana.org> Reply-To: Martijn van Oosterhout References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kHRd/tpU31Zn62xO" Content-Disposition: inline In-Reply-To: <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200601/375 X-Sequence-Number: 16853 --kHRd/tpU31Zn62xO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 05:46:34PM -0500, Ron wrote: > At 04:37 PM 1/20/2006, Martijn van Oosterhout wrote: > >Given that all it's doing is counting bits, a simple fix would be to > >loop over bytes, use XOR and count ones. For extreme speedup create a > >lookup table with 256 entries to give you the answer straight away... > For an even more extreme speedup, don't most modern CPUs have an asm=20 > instruction that counts the bits (un)set (AKA "population counting")=20 > in various size entities (4b, 8b, 16b, 32b, 64b, and 128b for 64b=20 > CPUs with SWAR instructions)? Quite possibly, though I wouldn't have the foggiest idea how to get the C compiler to generate it. Given that even a lookup table will get you pretty close to that with plain C coding, I think that's quite enough for a function that really is just a small part of a much larger system... Better solution (as Tom points out): work out how to avoid calling it so much in the first place... At the moment each call to gtsvector_picksplit seems to call the distance function around 14262 times. Getting that down by an order of magnitude will help much much more. Have a nice day, --=20 Martijn van Oosterhout 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. --kHRd/tpU31Zn62xO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0WrQIB7bNG8LQkwRApsuAJ0V/pXBmYDiad9ugYq4EyPzt0z69ACeISvA 7fX/GIKw+dp6c7ER15r8jg0= =I2SA -----END PGP SIGNATURE----- --kHRd/tpU31Zn62xO-- From pgsql-performance-owner@postgresql.org Fri Jan 20 19:18:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 526639DCB80 for ; Fri, 20 Jan 2006 19:17:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03179-05 for ; Fri, 20 Jan 2006 19:17:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 874F49DCB73 for ; Fri, 20 Jan 2006 18:57:45 -0400 (AST) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F05CT-0003iG-P5 for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 23:57:47 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F05CZ-00076D-00 for ; Fri, 20 Jan 2006 23:57:51 +0100 Date: Fri, 20 Jan 2006 23:57:51 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120225751.GA27230@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <6111.1137797436@sss.pgh.pa.us> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.073 required=5 tests=[AWL=0.073] X-Spam-Score: 0.073 X-Spam-Level: X-Archive-Number: 200601/377 X-Sequence-Number: 16855 On Fri, Jan 20, 2006 at 05:50:36PM -0500, Tom Lane wrote: > Yeah, but fetching from a small constant table is pretty quick too; > I doubt it's worth getting involved in machine-specific assembly code > for this. I'm much more interested in the idea of improving the > furthest-distance algorithm in gtsvector_picksplit --- if we can do > that, it'll probably drop the distance calculation down to the point > where it's not really worth the trouble to assembly-code it. For the record: Could we do with a less-than-optimal split here? In that case, an extremely simple heuristic is: best = distance(0, 1) best_i = 0 best_j = 1 for i = 2..last: if distance(best_i, i) > best: best = distance(best_i, i) best_j = i else if distance(best_j, i) > best: best = distance(best_j, i) best_i = i I've tested it on various data, and although it's definitely not _correct_, it generally gets within 10%. /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 18:59:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 40E849DCB99 for ; Fri, 20 Jan 2006 18:59:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97917-10 for ; Fri, 20 Jan 2006 18:59:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 0A45F9DCB9D for ; Fri, 20 Jan 2006 18:59:23 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F05E6-0003ip-BG for pgsql-performance@postgresql.org; Fri, 20 Jan 2006 23:59:26 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F05EC-00076k-00 for ; Fri, 20 Jan 2006 23:59:32 +0100 Date: Fri, 20 Jan 2006 23:59:32 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120225932.GB27230@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <27264.1137793817@sss.pgh.pa.us> <20060120221655.GA22581@uio.no> <7.0.1.0.2.20060120172335.039f5e20@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <7.0.1.0.2.20060120172335.039f5e20@earthlink.net> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.07 required=5 tests=[AWL=0.070] X-Spam-Score: 0.07 X-Spam-Level: X-Archive-Number: 200601/376 X-Sequence-Number: 16854 On Fri, Jan 20, 2006 at 05:29:46PM -0500, Ron wrote: > If the N-dimensional space is Euclidean (any is the same > distance apart in dimension x), then finding the farthest pair can be > done in at least O(n). That sounds a bit optimistic. http://portal.acm.org/ft_gateway.cfm?id=167217&type=pdf&coll=GUIDE&dl=GUIDE&CFID=66230761&CFTOKEN=72453878 is from 1993, but still it struggles with getting it down to O(n log n) deterministically, for Euclidian 3-space, and our problem is not Euclidian (although it still satisfies the triangle inequality, which sounds important to me) and in a significantly higher dimension... /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-general-owner@postgresql.org Fri Jan 20 19:22:42 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 532C69DC8DC for ; Fri, 20 Jan 2006 19:22:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02779-08 for ; Fri, 20 Jan 2006 19:22:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C0DCC9DC83F for ; Fri, 20 Jan 2006 19:22:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KNMd5c006377; Fri, 20 Jan 2006 18:22:39 -0500 (EST) To: Stephan Vollmer cc: pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow In-reply-to: <43D114B1.5030802@gmx.de> References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <43D114B1.5030802@gmx.de> Comments: In-reply-to Stephan Vollmer message dated "Fri, 20 Jan 2006 17:49:53 +0100" Date: Fri, 20 Jan 2006 18:22:39 -0500 Message-ID: <6376.1137799359@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/1044 X-Sequence-Number: 89989 Stephan Vollmer writes: > Tom Lane wrote: >> However, I'm not sure that anyone's tried to do any performance >> optimization on the GIST insert code ... there might be some low-hanging >> fruit there. > Unfortunately, I'm not able to investigate it further myself as I'm > quite a Postgres newbie. But I could provide someone else with the > example table. Maybe someone else could find out why it is so slow. The problem seems to be mostly tsearch2's fault rather than the general GIST code. I've applied a partial fix to 8.1 and HEAD branches, which you can find here if you're in a hurry for it: http://archives.postgresql.org/pgsql-committers/2006-01/msg00283.php (the gistidx.c change is all you need for tsearch2) There is some followup discussion in the pgsql-performance list. It seems possible that we can get another factor of 10 or better with a smarter picksplit algorithm --- but that patch will probably be too large to be considered for back-patching into the stable branches. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 19:28:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4DAC29DC83F for ; Fri, 20 Jan 2006 19:28:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05198-05 for ; Fri, 20 Jan 2006 19:28:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 5D70B9DCB93 for ; Fri, 20 Jan 2006 19:28:35 -0400 (AST) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F05gK-0003sT-TQ for pgsql-performance@postgresql.org; Sat, 21 Jan 2006 00:28:37 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F05gR-0007Ph-00 for ; Sat, 21 Jan 2006 00:28:43 +0100 Date: Sat, 21 Jan 2006 00:28:43 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060120232842.GA28433@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <27264.1137793817@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <27264.1137793817@sss.pgh.pa.us> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.069 required=5 tests=[AWL=0.069] X-Spam-Score: 0.069 X-Spam-Level: X-Archive-Number: 200601/378 X-Sequence-Number: 16856 On Fri, Jan 20, 2006 at 04:50:17PM -0500, Tom Lane wrote: > I wonder if there is a way to improve on that. http://www.cs.uwaterloo.ca/~tmchan/slide_isaac.ps: The diameter problem has been studied extensively in the traditional model. Although O(n log n) algorithms have been given for d = 2 and d = 3, only slightly subquadratic algorithms are known for higher dimensions. It doesn't mention a date, but has references to at least 2004-papers, so I'm fairly sure nothing big has happened since that. It sounds like we either want to go for an approximation, or just accept that it's a lot of work to get it better than O(n^2). Or, of course, find some special property of our problem that makes it easier than the general problem :-) /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 19:52:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B8EBB9DC854 for ; Fri, 20 Jan 2006 19:52:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11007-07 for ; Fri, 20 Jan 2006 19:52:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5B51F9DC83F for ; Fri, 20 Jan 2006 19:52:37 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0KNqbHx006533; Fri, 20 Jan 2006 18:52:37 -0500 (EST) To: "Steinar H. Gunderson" cc: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <20060120225751.GA27230@uio.no> References: <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> Comments: In-reply-to "Steinar H. Gunderson" message dated "Fri, 20 Jan 2006 23:57:51 +0100" Date: Fri, 20 Jan 2006 18:52:37 -0500 Message-ID: <6532.1137801157@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/379 X-Sequence-Number: 16857 "Steinar H. Gunderson" writes: > For the record: Could we do with a less-than-optimal split here? Yeah, I was wondering the same. The code is basically choosing two "seed" values to drive the index-page split. Intuitively it seems that "pretty far apart" would be nearly as good as "absolute furthest apart" for this purpose. The cost of a less-than-optimal split would be paid on all subsequent index accesses, though, so it's not clear how far we can afford to go in this direction. It's also worth considering that the entire approach is a heuristic, really --- getting the furthest-apart pair of seeds doesn't guarantee an optimal split as far as I can see. Maybe there's some totally different way to do it. regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 20:05:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 984BC9DC98F for ; Fri, 20 Jan 2006 20:05:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10243-07 for ; Fri, 20 Jan 2006 20:05:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id BB05D9DC83F for ; Fri, 20 Jan 2006 20:05:12 -0400 (AST) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F06Fm-00045f-Al for pgsql-performance@postgresql.org; Sat, 21 Jan 2006 01:05:15 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F06Fr-0007pz-00 for ; Sat, 21 Jan 2006 01:05:19 +0100 Date: Sat, 21 Jan 2006 01:05:19 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060121000519.GA29755@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <6532.1137801157@sss.pgh.pa.us> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200601/380 X-Sequence-Number: 16858 On Fri, Jan 20, 2006 at 06:52:37PM -0500, Tom Lane wrote: > It's also worth considering that the entire approach is a heuristic, > really --- getting the furthest-apart pair of seeds doesn't guarantee > an optimal split as far as I can see. Maybe there's some totally > different way to do it. For those of us who don't know what tsearch2/gist is trying to accomplish here, could you provide some pointers? :-) During my mini-literature-search on Google, I've found various algorithms for locating clusters in high-dimensional metric spaces[1]; some of it might be useful, but I might just be misunderstanding what the real problem is. [1] http://ieeexplore.ieee.org/iel5/69/30435/01401892.pdf?arnumber=1401892 , for instance /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 20:23:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AFC2B9DCB93 for ; Fri, 20 Jan 2006 20:23:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15301-03 for ; Fri, 20 Jan 2006 20:23:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 536339DC83F for ; Fri, 20 Jan 2006 20:23:07 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0L0NAqx006744; Fri, 20 Jan 2006 19:23:10 -0500 (EST) To: "Steinar H. Gunderson" cc: pgsql-performance@postgresql.org, Teodor Sigaev , Oleg Bartunov Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-reply-to: <20060121000519.GA29755@uio.no> References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> Comments: In-reply-to "Steinar H. Gunderson" message dated "Sat, 21 Jan 2006 01:05:19 +0100" Date: Fri, 20 Jan 2006 19:23:10 -0500 Message-ID: <6743.1137802990@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/381 X-Sequence-Number: 16859 "Steinar H. Gunderson" writes: > On Fri, Jan 20, 2006 at 06:52:37PM -0500, Tom Lane wrote: >> It's also worth considering that the entire approach is a heuristic, >> really --- getting the furthest-apart pair of seeds doesn't guarantee >> an optimal split as far as I can see. Maybe there's some totally >> different way to do it. > For those of us who don't know what tsearch2/gist is trying to accomplish > here, could you provide some pointers? :-) Well, we're trying to split an index page that's gotten full into two index pages, preferably with approximately equal numbers of items in each new page (this isn't a hard requirement though). I think the true figure of merit for a split is how often will subsequent searches have to descend into *both* of the resulting pages as opposed to just one --- the less often that is true, the better. I'm not very clear on what tsearch2 is doing with these bitmaps, but it looks like an upper page's downlink has the union (bitwise OR) of the one-bits in the values on the lower page, and you have to visit the lower page if this union has a nonempty intersection with the set you are looking for. If that's correct, what you really want is to divide the values so that the unions of the two sets have minimal overlap ... which seems to me to have little to do with what the code does at present. Teodor, Oleg, can you clarify what's needed here? regards, tom lane From pgsql-performance-owner@postgresql.org Fri Jan 20 20:36:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 914CA9DCBB4 for ; Fri, 20 Jan 2006 20:36:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19008-03 for ; Fri, 20 Jan 2006 20:36:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id D24669DCABE for ; Fri, 20 Jan 2006 20:36:39 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1F06kD-0004T0-K0; Sat, 21 Jan 2006 01:36:41 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1F06kI-0008BL-00; Sat, 21 Jan 2006 01:36:46 +0100 Date: Sat, 21 Jan 2006 01:36:46 +0100 From: "Steinar H. Gunderson" To: Tom Lane Cc: pgsql-performance@postgresql.org, Teodor Sigaev , Oleg Bartunov Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060121003646.GA31406@uio.no> Mail-Followup-To: Tom Lane , pgsql-performance@postgresql.org, Teodor Sigaev , Oleg Bartunov References: <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <6743.1137802990@sss.pgh.pa.us> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/382 X-Sequence-Number: 16860 On Fri, Jan 20, 2006 at 07:23:10PM -0500, Tom Lane wrote: > I'm not very clear on what tsearch2 is doing with these bitmaps, but it > looks like an upper page's downlink has the union (bitwise OR) of the > one-bits in the values on the lower page, and you have to visit the lower > page if this union has a nonempty intersection with the set you are looking > for. If that's correct, what you really want is to divide the values so > that the unions of the two sets have minimal overlap ... which seems to me > to have little to do with what the code does at present. Sort of like the vertex-cover problem? That's probably a lot harder than finding the two farthest points... /* Steinar */ -- Homepage: http://www.sesse.net/ From pgsql-performance-owner@postgresql.org Fri Jan 20 21:34:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DAA969DCBBD for ; Fri, 20 Jan 2006 21:34:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28041-04 for ; Fri, 20 Jan 2006 21:34:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net [68.15.5.150]) by postgresql.org (Postfix) with ESMTP id 1BC749DCBB4 for ; Fri, 20 Jan 2006 21:34:47 -0400 (AST) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k0L0ZQlO026292; Fri, 20 Jan 2006 16:35:26 -0800 Message-ID: <43D18EA9.8060409@modgraph-usa.com> Date: Fri, 20 Jan 2006 17:30:17 -0800 From: "Craig A. James" User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane CC: "Steinar H. Gunderson" , pgsql-performance@postgresql.org, Teodor Sigaev , Oleg Bartunov Subject: Re: [GENERAL] Creation of tsearch2 index is very slow References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> In-Reply-To: <6743.1137802990@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.053 required=5 tests=[AWL=0.053] X-Spam-Score: 0.053 X-Spam-Level: X-Archive-Number: 200601/383 X-Sequence-Number: 16861 Tom Lane wrote: > Well, we're trying to split an index page that's gotten full into two > index pages, preferably with approximately equal numbers of items in > each new page (this isn't a hard requirement though). ... If that's > correct, what you really want is to divide the values so that the unions > of the two sets have minimal overlap ... which seems to me to have > little to do with what the code does at present. This problem has been studied extensively by chemists, and they haven't found any easy solutions. The Jarvis Patrick clustering algorithm might give you hints about a fast approach. In theory it's K*O(N^2), but J-P is preferred for large datasets (millions of molecules) because the coefficient K can be made quite low. It starts with a "similarity metric" for two bit strings, the Tanimoto or Tversky coefficients: http://www.daylight.com/dayhtml/doc/theory/theory.finger.html#RTFToC83 J-P Clustering is described here: http://www.daylight.com/dayhtml/doc/cluster/cluster.a.html#cl33 J-P Clustering is probably not the best for this problem (see the illustrations in the link above to see why), but the general idea of computing N-nearest-neighbors, followed by a partitioning step, could be what's needed. Craig From pgsql-performance-owner@postgresql.org Sat Jan 21 04:00:21 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 19D519DC813 for ; Sat, 21 Jan 2006 04:00:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07165-08 for ; Sat, 21 Jan 2006 04:00:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pop.xnet.hr (dns1.xnet.hr [82.193.192.5]) by postgresql.org (Postfix) with ESMTP id DF2649DC80E for ; Sat, 21 Jan 2006 04:00:15 -0400 (AST) Received: (qmail 10147 invoked from network); 21 Jan 2006 08:00:45 -0000 Received: by simscan 1.1.0 ppid: 10138, pid: 10140, t: 0.4931s scanners: attach: 1.1.0 clamav: 0.87/m:34/d:1131 spam: 3.1.0 Received: from unknown (HELO ?83.139.74.33?) (83.139.74.33) by pop.xnet.hr with SMTP; 21 Jan 2006 08:00:44 -0000 Message-ID: <43D1E9E0.3000905@zg.htnet.hr> Date: Sat, 21 Jan 2006 08:59:28 +0100 From: Rikard Pavelic User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: "Jim C. Nasby" CC: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> <43D13C2F.1030203@zg.htnet.hr> <20060120213455.GT20182@pervasive.com> In-Reply-To: <20060120213455.GT20182@pervasive.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[AWL=0.000, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/384 X-Sequence-Number: 16862 Jim C. Nasby wrote: > If you're dealing with something that's performance critical you're not > going to be constantly re-connecting anyway, so I don't see what the > issue is. > I really missed your point. In multi user environment where each user uses it's connection for identification purposes, this seems like a reasonable optimization. I know there is pgpool, but it's non windows, and it's not the best solution for every other problem. From pgsql-performance-owner@postgresql.org Sat Jan 21 08:22:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 82B389DC808 for ; Sat, 21 Jan 2006 08:22:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51566-10 for ; Sat, 21 Jan 2006 08:22:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth06.mail.atl.earthlink.net (smtpauth06.mail.atl.earthlink.net [209.86.89.66]) by postgresql.org (Postfix) with ESMTP id 4EDBF9DC803 for ; Sat, 21 Jan 2006 08:22:46 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=ByrfgJM8XuXaEswIfiWpV3b58ttvqtH67PCY+cRdJUEomODmFz5zRf1JD3RYyDnH; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth06.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F0HlZ-00087H-0D; Sat, 21 Jan 2006 07:22:49 -0500 Message-Id: <7.0.1.0.2.20060121064930.03aba810@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Sat, 21 Jan 2006 07:22:32 -0500 To: Tom Lane ,pgsql-performance@postgresql.org, From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <6743.1137802990@sss.pgh.pa.us> References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bce28c8ecf338307b698545a7ccd5ca3ab350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.431 required=5 tests=[AWL=-0.048, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.431 X-Spam-Level: X-Archive-Number: 200601/385 X-Sequence-Number: 16863 At 07:23 PM 1/20/2006, Tom Lane wrote: >"Steinar H. Gunderson" writes: > > On Fri, Jan 20, 2006 at 06:52:37PM -0500, Tom Lane wrote: > >> It's also worth considering that the entire approach is a heuristic, > >> really --- getting the furthest-apart pair of seeds doesn't guarantee > >> an optimal split as far as I can see. Maybe there's some totally > >> different way to do it. > > > For those of us who don't know what tsearch2/gist is trying to accomplish > > here, could you provide some pointers? :-) > >Well, we're trying to split an index page that's gotten full into >two index pages, preferably with approximately equal numbers of items in >each new page (this isn't a hard requirement though). Maybe we are over thinking this. What happens if we do the obvious and just make a new page and move the "last" n/2 items on the full page to the new page? Various forms of "move the last n/2 items" can be tested here: 0= just split the table in half. Sometimes KISS works. O(1). 1= the one's with the highest (or lowest) "x" value. 2= the one's with the highest sum of coordinates (x+y+...= values in the top/bottom n/2 of entries). 3= split the table so that each table has entries whose size_waste values add up to approximately the same value. 4= I'm sure there are others. 1-5 can be done in O(n) time w/o auxiliary data. They can be done in O(1) if we've kept track of the appropriate metric as we've built the current page. >I think the true figure of merit for a split is how often will >subsequent searches have to descend into *both* of the resulting >pages as opposed to just one >--- the less often that is true, the better. I'm not very clear on >what tsearch2 is doing with these bitmaps, but it looks like an >upper page's downlink has the union (bitwise OR) of the one-bits in >the values on the lower page, and you have to visit the lower page >if this union has a nonempty intersection with the set you are >looking for. If that's correct, what you really want is to divide >the values so that the unions of the two sets have minimal overlap >... which seems to me to have little to do with what the code does at present. I'm not sure what "upper page" and "lower page" mean here? >Teodor, Oleg, can you clarify what's needed here? Ditto. Guys what is the real motivation and purpose for this code? Ron From pgsql-performance-owner@postgresql.org Sat Jan 21 09:08:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 522AD9DC802 for ; Sat, 21 Jan 2006 09:08:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61297-01 for ; Sat, 21 Jan 2006 09:08:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (unknown [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 06E949DC800 for ; Sat, 21 Jan 2006 09:08:33 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F0ITm-0002jM-RP; Sun, 22 Jan 2006 00:08:30 +1100 Date: Sat, 21 Jan 2006 14:08:30 +0100 From: Martijn van Oosterhout To: Tom Lane Cc: Ron , pgsql-performance@postgreSQL.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060121130830.GA9955@svana.org> Reply-To: Martijn van Oosterhout References: <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="oyUTqETQ0mS9luUI" Content-Disposition: inline In-Reply-To: <6111.1137797436@sss.pgh.pa.us> X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200601/386 X-Sequence-Number: 16864 --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2006 at 05:50:36PM -0500, Tom Lane wrote: > Yeah, but fetching from a small constant table is pretty quick too; > I doubt it's worth getting involved in machine-specific assembly code > for this. I'm much more interested in the idea of improving the > furthest-distance algorithm in gtsvector_picksplit --- if we can do > that, it'll probably drop the distance calculation down to the point > where it's not really worth the trouble to assembly-code it. I've played with another algorithm. Very simple but it's only O(N). It doesn't get the longest distance but it does get close. Basically you take the first two elements as your starting length. Then you loop over each remaining string, each time finding the longest pair out of each set of three. I've only tried it on random strings. The maximum distance for 128 random strings tends to be around 291-295. This algorithm tends to find lengths around 280. Pseudo code below (in Perl). However, IMHO, this algorithm is optimising the wrong thing. It shouldn't be trying to split into sets that are far apart, it should be trying to split into sets that minimize the number of set bits (ie distance from zero), since that's what's will speed up searching. That's harder though (this algorithm does approximate it sort of) and I havn't come up with an algorithm yet sub MaxDistFast { my $strings =3D shift; =20 my $m1 =3D 0; my $m2 =3D 1; my $dist =3D -1; for my $i (2..$#$strings) { my $d1 =3D HammDist( $strings->[$i], $strings->[$m1] ); my $d2 =3D HammDist( $strings->[$i], $strings->[$m2] ); my $m =3D ($d1 > $d2) ? $m1 : $m2; my $d =3D ($d1 > $d2) ? $d1 : $d2; =20 if( $d > $dist ) { $dist =3D $d; $m1 =3D $i; =20 $m2 =3D $m; } } return($m1,$m2,$dist); } Full program available at: http://svana.org/kleptog/temp/picksplit.pl Have a nice day, --=20 Martijn van Oosterhout 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. --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0jJOIB7bNG8LQkwRAjCFAJ9SxIKwvMZr7myOsxl3mZ53qzT3egCggNhI Kejd3P2V+Ija5mieo6q0Vxw= =zvLw -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI-- From pgsql-performance-owner@postgresql.org Sat Jan 21 09:27:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8A74F9DC803 for ; Sat, 21 Jan 2006 09:27:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63606-03 for ; Sat, 21 Jan 2006 09:27:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from imsm057dat.netvigator.com (imsm057.netvigator.com [218.102.48.210]) by postgresql.org (Postfix) with ESMTP id 5CF8C9DC802 for ; Sat, 21 Jan 2006 09:27:26 -0400 (AST) Received: from n2.netvigator.com ([218.102.95.109]) by imsm057dat.netvigator.com (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20060121132728.NZZW14795.imsm057dat.netvigator.com@n2.netvigator.com>; Sat, 21 Jan 2006 21:27:28 +0800 Received: from n2.netvigator.com ([127.0.0.1]) by [127.0.0.1] with ESMTP (SpamPal v1.591) sender ; 21 Jan 2006 21:27:28 +???? Message-Id: <6.2.1.2.0.20060121210512.08cc9310@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2 Date: Sat, 21 Jan 2006 21:12:47 +0800 To: "Jim C. Nasby" From: K C Lau Subject: Re: SELECT MIN, MAX took longer time than SELECT Cc: pgsql-performance@postgresql.org In-Reply-To: <20060120172026.GF20182@pervasive.com> References: <6.2.1.2.0.20060120120150.08ab7b00@localhost> <20060120172026.GF20182@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.2 required=5 tests=[AWL=-0.240, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.2 X-Spam-Level: * X-Archive-Number: 200601/387 X-Sequence-Number: 16865 At 01:20 06/01/21, Jim C. Nasby wrote: >BTW, these queries below are meaningless; they are not equivalent to >min(logsn). > > > esdt=> explain analyze select LogSN from Log where create_time < > > '2005/10/19' order by create_time limit 1; Thank you for pointing it out. It actually returns the min(logsn), as the index is on (create_time, logsn). To be more explicit, I have changed to query to: explain analyze select LogSN from Log where create_time < '2005/10/19' order by create_time, logsn limit 1; esdt=> \d log; create_time | character varying(23) | default '1970/01/01~00:00:00.000'::character varying logsn | integer | not null ... Indexes: "pk_log" PRIMARY KEY, btree (logsn) "idx_logtime" btree (create_time, logsn) Best regards, KC. From pgsql-performance-owner@postgresql.org Sat Jan 21 09:29:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4165E9DC802 for ; Sat, 21 Jan 2006 09:29:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63151-09 for ; Sat, 21 Jan 2006 09:29:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) by postgresql.org (Postfix) with ESMTP id D6C1F9DCC32 for ; Sat, 21 Jan 2006 09:29:12 -0400 (AST) Received: from ra (ra [158.250.29.2]) by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id k0LDTD3p006224; Sat, 21 Jan 2006 16:29:14 +0300 (MSK) Date: Sat, 21 Jan 2006 16:29:13 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@ra.sai.msu.su To: Martijn van Oosterhout cc: Tom Lane , Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-Reply-To: <20060121130830.GA9955@svana.org> Message-ID: References: <17454.1137771321@sss.pgh.pa.us> <20060120170452.GC31908@svana.org> <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060121130830.GA9955@svana.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.377 required=5 tests=[AWL=-0.102, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.377 X-Spam-Level: X-Archive-Number: 200601/388 X-Sequence-Number: 16866 On Sat, 21 Jan 2006, Martijn van Oosterhout wrote: > However, IMHO, this algorithm is optimising the wrong thing. It > shouldn't be trying to split into sets that are far apart, it should be > trying to split into sets that minimize the number of set bits (ie > distance from zero), since that's what's will speed up searching. Martijn, you're right! We want not only to split page to very different parts, but not to increase the number of sets bits in resulted signatures, which are union (OR'ed) of all signatures in part. We need not only fast index creation (thanks, Tom !), but a better index. Some information is available here http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals There are should be more detailed document, but I don't remember where:) > That's harder though (this algorithm does approximate it sort of) > and I havn't come up with an algorithm yet Don't ask how hard we thought :) Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83 From pgsql-performance-owner@postgresql.org Sat Jan 21 09:34:44 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 274379DC802 for ; Sat, 21 Jan 2006 09:34:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64440-03 for ; Sat, 21 Jan 2006 09:34:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) by postgresql.org (Postfix) with ESMTP id 98E289DC803 for ; Sat, 21 Jan 2006 09:34:37 -0400 (AST) Received: from ra (ra [158.250.29.2]) by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id k0LDYc5s006380; Sat, 21 Jan 2006 16:34:38 +0300 (MSK) Date: Sat, 21 Jan 2006 16:34:38 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@ra.sai.msu.su To: Ron cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <7.0.1.0.2.20060121064930.03aba810@earthlink.net> Message-ID: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.376 required=5 tests=[AWL=-0.103, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.376 X-Spam-Level: X-Archive-Number: 200601/389 X-Sequence-Number: 16867 On Sat, 21 Jan 2006, Ron wrote: > At 07:23 PM 1/20/2006, Tom Lane wrote: >> "Steinar H. Gunderson" writes: >> > On Fri, Jan 20, 2006 at 06:52:37PM -0500, Tom Lane wrote: >> >> It's also worth considering that the entire approach is a heuristic, >> >> really --- getting the furthest-apart pair of seeds doesn't guarantee >> >> an optimal split as far as I can see. Maybe there's some totally >> >> different way to do it. >> >> > For those of us who don't know what tsearch2/gist is trying to accomplish >> > here, could you provide some pointers? :-) >> >> Well, we're trying to split an index page that's gotten full into two index >> pages, preferably with approximately equal numbers of items in >> each new page (this isn't a hard requirement though). > > Maybe we are over thinking this. What happens if we do the obvious and just > make a new page and move the "last" n/2 items on the full page to the new > page? > > Various forms of "move the last n/2 items" can be tested here: > 0= just split the table in half. Sometimes KISS works. O(1). > 1= the one's with the highest (or lowest) "x" value. > 2= the one's with the highest sum of coordinates (x+y+...= values in the > top/bottom n/2 of entries). > 3= split the table so that each table has entries whose size_waste values add > up to approximately the same value. > 4= I'm sure there are others. > 1-5 can be done in O(n) time w/o auxiliary data. They can be done in O(1) if > we've kept track of the appropriate metric as we've built the current page. > > >> I think the true figure of merit for a split is how often will subsequent >> searches have to descend into *both* of the resulting pages as opposed to >> just one >> --- the less often that is true, the better. I'm not very clear on what >> tsearch2 is doing with these bitmaps, but it looks like an upper page's >> downlink has the union (bitwise OR) of the one-bits in the values on the >> lower page, and you have to visit the lower page if this union has a >> nonempty intersection with the set you are looking for. If that's correct, >> what you really want is to divide the values so that the unions of the two >> sets have minimal overlap ... which seems to me to have little to do with >> what the code does at present. > I'm not sure what "upper page" and "lower page" mean here? > > >> Teodor, Oleg, can you clarify what's needed here? > Ditto. Guys what is the real motivation and purpose for this code? we want not just split the page by two very distinct parts, but to keep resulted signatures which is ORed signature of all signatures in the page as much 'sparse' as can. some information available here http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals Unfortunately, we're rather busy right now and couldn't be very useful. > > Ron > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83 From pgsql-performance-owner@postgresql.org Sat Jan 21 09:39:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 612BA9DC83A for ; Sat, 21 Jan 2006 09:39:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65458-03 for ; Sat, 21 Jan 2006 09:39:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from imsm057dat.netvigator.com (imsm057.netvigator.com [218.102.48.210]) by postgresql.org (Postfix) with ESMTP id 83C629DC816 for ; Sat, 21 Jan 2006 09:39:09 -0400 (AST) Received: from n2.netvigator.com ([218.102.95.109]) by imsm057dat.netvigator.com (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20060121133912.OAEY14795.imsm057dat.netvigator.com@n2.netvigator.com>; Sat, 21 Jan 2006 21:39:12 +0800 Received: from n2.netvigator.com ([127.0.0.1]) by [127.0.0.1] with ESMTP (SpamPal v1.591) sender ; 21 Jan 2006 21:39:12 +???? Message-Id: <6.2.1.2.0.20060121211310.08cc91c8@localhost> X-Mailer: QUALCOMM Windows Eudora Version 6.2.1.2 Date: Sat, 21 Jan 2006 21:38:55 +0800 To: Tom Lane From: K C Lau Subject: Re: SELECT MIN, MAX took longer time than SELECT Cc: pgsql-performance@postgresql.org In-Reply-To: <25978.1137783074@sss.pgh.pa.us> References: <6.2.1.2.0.20060120120150.08ab7b00@localhost> <20060120172026.GF20182@pervasive.com> <25978.1137783074@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.2 required=5 tests=[AWL=-0.240, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.2 X-Spam-Level: * X-Archive-Number: 200601/390 X-Sequence-Number: 16868 I have worked round the issue by using 2 separate queries with the LIMIT construct. LogSN and create_time are indeed directly correlated, both monotonously increasing, occasionally with multiple LogSN's having the same create_time. What puzzles me is why the query with COUNT, MIN, MAX uses idx_logtime for the scan, but the query without the COUNT uses pk_log and takes much longer. If it had chosen idx_logtime instead, then it should have returned immediately for both MIN and MAX. Best regards, KC. At 02:51 06/01/21, Tom Lane wrote: >"Jim C. Nasby" writes: > > On Fri, Jan 20, 2006 at 12:35:36PM +0800, K C Lau wrote: > > Here's the problem... the estimate for the backwards index scan is *way* > > off: > > >> -> Limit (cost=0.00..1.26 rows=1 width=4) (actual > >> time=200032.928..200032.931 rows=1 loops=1) > >> -> Index Scan Backward using pk_log on > >> log (cost=0.00..108047.11 rows=86089 width=4) (actual > >> time=200032.920..200032.920 rows=1 loops=1) > >> Filter: (((create_time)::text < '2005/10/19'::text) AND > >> (logsn IS NOT NULL)) > >> Total runtime: 200051.701 ms > >It's more subtle than you think. The estimated rowcount is the >estimated number of rows fetched if the indexscan were run to >completion, which it isn't because the LIMIT cuts it off after the >first returned row. That estimate is not bad (we can see from the >aggregate plan that the true value would have been 106708, assuming >that the "logsn IS NOT NULL" condition isn't filtering anything). > >The real problem is that it's taking quite a long time for the scan >to reach the first row with create_time < 2005/10/19, which is not >too surprising if logsn is strongly correlated with create_time ... >but in the absence of any cross-column statistics the planner has >no very good way to know that. (Hm ... but both of them probably >also show a strong correlation to physical order ... we could look >at that maybe ...) The default assumption is that the two columns >aren't correlated and so it should not take long to hit the first such >row, which is why the planner likes the indexscan/limit plan. > > regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 21 12:25:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AA1F39DC801 for ; Sat, 21 Jan 2006 12:25:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92499-10 for ; Sat, 21 Jan 2006 12:25:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (unknown [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 48BE29DC819 for ; Sat, 21 Jan 2006 12:25:39 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F0KHw-0002st-PV; Sun, 22 Jan 2006 02:04:24 +1100 Date: Sat, 21 Jan 2006 16:04:24 +0100 From: Martijn van Oosterhout To: Oleg Bartunov Cc: Tom Lane , Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060121150424.GB9955@svana.org> Reply-To: Martijn van Oosterhout References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060121130830.GA9955@svana.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9zSXsLTf0vkW971A" Content-Disposition: inline In-Reply-To: X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200601/391 X-Sequence-Number: 16869 --9zSXsLTf0vkW971A Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jan 21, 2006 at 04:29:13PM +0300, Oleg Bartunov wrote: > Martijn, you're right! We want not only to split page to very > different parts, but not to increase the number of sets bits in > resulted signatures, which are union (OR'ed) of all signatures=20 > in part. We need not only fast index creation (thanks, Tom !), > but a better index. Some information is available here > http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals > There are should be more detailed document, but I don't remember where:) I see how it works, what I don't quite get is whether the "inverted index" you refer to is what we're working with here, or just what's in tsearchd? > >That's harder though (this algorithm does approximate it sort of) > >and I havn't come up with an algorithm yet >=20 > Don't ask how hard we thought :) Well, looking at how other people are struggling with it, it's definitly a Hard Problem. One thing though, I don't think the picksplit algorithm as is really requires you to strictly have the longest distance, just something reasonably long. So I think the alternate algorithm I posted should produce equivalent results. No idea how to test it though... Have a nice day, --=20 Martijn van Oosterhout 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. --9zSXsLTf0vkW971A Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0k14IB7bNG8LQkwRAqi9AJ4sYMjyepJIRWRypeD02wQJjpWCmwCfaFz6 +3szZsgPCCayrEUyYjAumic= =RjgF -----END PGP SIGNATURE----- --9zSXsLTf0vkW971A-- From pgsql-performance-owner@postgresql.org Sat Jan 21 13:29:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 91A4E9DCC91 for ; Sat, 21 Jan 2006 13:29:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08227-03 for ; Sat, 21 Jan 2006 13:29:08 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 6D9EE9DC801 for ; Sat, 21 Jan 2006 13:29:06 -0400 (AST) Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) by svr4.postgresql.org (Postfix) with ESMTP id 073985AF87D for ; Sat, 21 Jan 2006 15:24:06 +0000 (GMT) Received: from ra (ra [158.250.29.2]) by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id k0LFMqpE008425; Sat, 21 Jan 2006 18:23:02 +0300 (MSK) Date: Sat, 21 Jan 2006 18:22:52 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@ra.sai.msu.su To: Martijn van Oosterhout Cc: Tom Lane , Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-Reply-To: <20060121150424.GB9955@svana.org> Message-ID: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060121130830.GA9955@svana.org> <20060121150424.GB9955@svana.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.384 required=5 tests=[AWL=-0.095, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.384 X-Spam-Level: X-Archive-Number: 200601/394 X-Sequence-Number: 16872 On Sat, 21 Jan 2006, Martijn van Oosterhout wrote: > On Sat, Jan 21, 2006 at 04:29:13PM +0300, Oleg Bartunov wrote: >> Martijn, you're right! We want not only to split page to very >> different parts, but not to increase the number of sets bits in >> resulted signatures, which are union (OR'ed) of all signatures >> in part. We need not only fast index creation (thanks, Tom !), >> but a better index. Some information is available here >> http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals >> There are should be more detailed document, but I don't remember where:) > > I see how it works, what I don't quite get is whether the "inverted > index" you refer to is what we're working with here, or just what's in > tsearchd? just tsearchd. We plan to implement inverted index into PostgreSQL core and then adapt tsearch2 to use it as option for read-only archives. > >>> That's harder though (this algorithm does approximate it sort of) >>> and I havn't come up with an algorithm yet >> >> Don't ask how hard we thought :) > > Well, looking at how other people are struggling with it, it's > definitly a Hard Problem. One thing though, I don't think the picksplit > algorithm as is really requires you to strictly have the longest > distance, just something reasonably long. So I think the alternate > algorithm I posted should produce equivalent results. No idea how to > test it though... you may try our development module 'gevel' to see how dense is a signature. www=# \d v_pages Table "public.v_pages" Column | Type | Modifiers -----------+-------------------+----------- tid | integer | not null path | character varying | not null body | character varying | title | character varying | di | integer | dlm | integer | de | integer | md5 | character(22) | fts_index | tsvector | Indexes: "v_pages_pkey" PRIMARY KEY, btree (tid) "v_pages_path_key" UNIQUE, btree (path) "v_gist_key" gist (fts_index) # select * from gist_print('v_gist_key') as t(level int, valid bool, a gtsvector) where level =1; level | valid | a -------+-------+-------------------------------- 1 | t | 1698 true bits, 318 false bits 1 | t | 1699 true bits, 317 false bits 1 | t | 1701 true bits, 315 false bits 1 | t | 1500 true bits, 516 false bits 1 | t | 1517 true bits, 499 false bits (5 rows) Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83 From pgsql-performance-owner@postgresql.org Sat Jan 21 13:29:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2BF009DCD45 for ; Sat, 21 Jan 2006 13:29:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07471-07-5 for ; Sat, 21 Jan 2006 13:29:32 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 6F7609DCCBC for ; Sat, 21 Jan 2006 13:29:16 -0400 (AST) Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) by svr4.postgresql.org (Postfix) with ESMTP id CC52E5AFB24 for ; Sat, 21 Jan 2006 15:25:43 +0000 (GMT) Received: from ra (ra [158.250.29.2]) by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id k0LFOUAn008468; Sat, 21 Jan 2006 18:24:40 +0300 (MSK) Date: Sat, 21 Jan 2006 18:24:30 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@ra.sai.msu.su To: Martijn van Oosterhout Cc: Tom Lane , Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow In-Reply-To: <20060121150424.GB9955@svana.org> Message-ID: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060121130830.GA9955@svana.org> <20060121150424.GB9955@svana.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.386 required=5 tests=[AWL=-0.093, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.386 X-Spam-Level: X-Archive-Number: 200601/395 X-Sequence-Number: 16873 gevel is available from http://www.sai.msu.su/~megera/postgres/gist/ Oleg On Sat, 21 Jan 2006, Martijn van Oosterhout wrote: > On Sat, Jan 21, 2006 at 04:29:13PM +0300, Oleg Bartunov wrote: >> Martijn, you're right! We want not only to split page to very >> different parts, but not to increase the number of sets bits in >> resulted signatures, which are union (OR'ed) of all signatures >> in part. We need not only fast index creation (thanks, Tom !), >> but a better index. Some information is available here >> http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals >> There are should be more detailed document, but I don't remember where:) > > I see how it works, what I don't quite get is whether the "inverted > index" you refer to is what we're working with here, or just what's in > tsearchd? > >>> That's harder though (this algorithm does approximate it sort of) >>> and I havn't come up with an algorithm yet >> >> Don't ask how hard we thought :) > > Well, looking at how other people are struggling with it, it's > definitly a Hard Problem. One thing though, I don't think the picksplit > algorithm as is really requires you to strictly have the longest > distance, just something reasonably long. So I think the alternate > algorithm I posted should produce equivalent results. No idea how to > test it though... > > Have a nice day, > Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83 From pgsql-performance-owner@postgresql.org Sat Jan 21 12:39:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4281E9DCD75 for ; Sat, 21 Jan 2006 12:39:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98835-03-8 for ; Sat, 21 Jan 2006 12:39:33 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id BE1379DCCE3 for ; Sat, 21 Jan 2006 12:39:16 -0400 (AST) Received: from smtpauth04.mail.atl.earthlink.net (smtpauth04.mail.atl.earthlink.net [209.86.89.64]) by svr4.postgresql.org (Postfix) with ESMTP id 685B75AF98C for ; Sat, 21 Jan 2006 16:12:21 +0000 (GMT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=C0oBqpb3BXJd0V5QrUk2oUOYAEn9t8P6d0m2E0VzrFZiWrBPYfSypl0G6ZVtuEsw; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:Cc:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth04.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F0LLL-0000UO-RJ; Sat, 21 Jan 2006 11:12:00 -0500 Message-Id: <7.0.1.0.2.20060121105907.03955090@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Sat, 21 Jan 2006 11:11:53 -0500 To: Oleg Bartunov , pgsql-performance@postgresql.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very Cc: Tom Lane In-Reply-To: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bcc6e1c1df5990107b178217cceb90f5b4350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.434 required=5 tests=[AWL=-0.045, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.434 X-Spam-Level: X-Archive-Number: 200601/393 X-Sequence-Number: 16871 Perhaps a different approach to this problem is called for: _Managing Gigabytes: Compressing and Indexing Documents and Images_ 2ed Witten, Moffat, Bell ISBN 1-55860-570-3 This is a VERY good book on the subject. I'd also suggest looking at the publicly available work on indexing and searching for search engines like Inktomi (sp?) and Google. Ron At 08:34 AM 1/21/2006, Oleg Bartunov wrote: >On Sat, 21 Jan 2006, Ron wrote: > >>At 07:23 PM 1/20/2006, Tom Lane wrote: >>>"Steinar H. Gunderson" writes: >>> > On Fri, Jan 20, 2006 at 06:52:37PM -0500, Tom Lane wrote: >>> >> It's also worth considering that the entire approach is a heuristic, >>> >> really --- getting the furthest-apart pair of seeds doesn't guarantee >>> >> an optimal split as far as I can see. Maybe there's some totally >>> >> different way to do it. >>> > For those of us who don't know what tsearch2/gist is trying to accomplish >>> > here, could you provide some pointers? :-) >>>Well, we're trying to split an index page that's gotten full into >>>two index pages, preferably with approximately equal numbers of items in >>>each new page (this isn't a hard requirement though). >> >>Maybe we are over thinking this. What happens if we do the obvious >>and just make a new page and move the "last" n/2 items on the full >>page to the new page? >> >>Various forms of "move the last n/2 items" can be tested here: >>0= just split the table in half. Sometimes KISS works. O(1). >>1= the one's with the highest (or lowest) "x" value. >>2= the one's with the highest sum of coordinates (x+y+...= values >>in the top/bottom n/2 of entries). >>3= split the table so that each table has entries whose size_waste >>values add up to approximately the same value. >>4= I'm sure there are others. >>1-5 can be done in O(n) time w/o auxiliary data. They can be done >>in O(1) if we've kept track of the appropriate metric as we've >>built the current page. >> >> >>>I think the true figure of merit for a split is how often will >>>subsequent searches have to descend into *both* of the resulting >>>pages as opposed to just one >>>--- the less often that is true, the better. I'm not very clear >>>on what tsearch2 is doing with these bitmaps, but it looks like an >>>upper page's downlink has the union (bitwise OR) of the one-bits >>>in the values on the lower page, and you have to visit the lower >>>page if this union has a nonempty intersection with the set you >>>are looking for. If that's correct, what you really want is to >>>divide the values so that the unions of the two sets have minimal >>>overlap ... which seems to me to have little to do with what the >>>code does at present. >>I'm not sure what "upper page" and "lower page" mean here? >> >> >>>Teodor, Oleg, can you clarify what's needed here? >>Ditto. Guys what is the real motivation and purpose for this code? > >we want not just split the page by two very distinct parts, but to keep >resulted signatures which is ORed signature of all signatures in the page >as much 'sparse' as can. some information available here >http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals > >Unfortunately, we're rather busy right now and couldn't be very useful. From pgsql-performance-owner@postgresql.org Sat Jan 21 12:33:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2D9729DC857 for ; Sat, 21 Jan 2006 12:33:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96673-03 for ; Sat, 21 Jan 2006 12:33:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) by postgresql.org (Postfix) with ESMTP id 2618A9DC84F for ; Sat, 21 Jan 2006 12:33:29 -0400 (AST) Received: from ra (ra [158.250.29.2]) by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id k0LGXRKK010484; Sat, 21 Jan 2006 19:33:27 +0300 (MSK) Date: Sat, 21 Jan 2006 19:33:27 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@ra.sai.msu.su To: Ron cc: pgsql-performance@postgresql.org, Tom Lane Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <7.0.1.0.2.20060121105907.03955090@earthlink.net> Message-ID: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <7.0.1.0.2.20060121105907.03955090@earthlink.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.38 required=5 tests=[AWL=-0.099, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.38 X-Spam-Level: X-Archive-Number: 200601/392 X-Sequence-Number: 16870 On Sat, 21 Jan 2006, Ron wrote: > Perhaps a different approach to this problem is called for: > > _Managing Gigabytes: Compressing and Indexing Documents and Images_ 2ed > Witten, Moffat, Bell > ISBN 1-55860-570-3 > > This is a VERY good book on the subject. > > I'd also suggest looking at the publicly available work on indexing and > searching for search engines like Inktomi (sp?) and Google. > Ron Ron, you completely miss the problem ! We do know MG and other SE. Actually, we've implemented several search engines based on inverted index technology (see, for example, pgsql.ru/db/pgsearch). tsearch2 was designed for online indexing, while keeping inverted index online is rather difficult problem. We do have plan to implement inverted index as an option for large read-only archives, but now we discuss how to organize online index and if possible to optimize current storage for signatures without breaking search performance. > > > At 08:34 AM 1/21/2006, Oleg Bartunov wrote: >> On Sat, 21 Jan 2006, Ron wrote: >> >>> At 07:23 PM 1/20/2006, Tom Lane wrote: >>>> "Steinar H. Gunderson" writes: >>>> > On Fri, Jan 20, 2006 at 06:52:37PM -0500, Tom Lane wrote: >>>> >> It's also worth considering that the entire approach is a heuristic, >>>> >> really --- getting the furthest-apart pair of seeds doesn't guarantee >>>> >> an optimal split as far as I can see. Maybe there's some totally >>>> >> different way to do it. >>>> > For those of us who don't know what tsearch2/gist is trying to >>>> accomplish >>>> > here, could you provide some pointers? :-) >>>> Well, we're trying to split an index page that's gotten full into two >>>> index pages, preferably with approximately equal numbers of items in >>>> each new page (this isn't a hard requirement though). >>> >>> Maybe we are over thinking this. What happens if we do the obvious and >>> just make a new page and move the "last" n/2 items on the full page to the >>> new page? >>> >>> Various forms of "move the last n/2 items" can be tested here: >>> 0= just split the table in half. Sometimes KISS works. O(1). >>> 1= the one's with the highest (or lowest) "x" value. >>> 2= the one's with the highest sum of coordinates (x+y+...= values in the >>> top/bottom n/2 of entries). >>> 3= split the table so that each table has entries whose size_waste values >>> add up to approximately the same value. >>> 4= I'm sure there are others. >>> 1-5 can be done in O(n) time w/o auxiliary data. They can be done in O(1) >>> if we've kept track of the appropriate metric as we've built the current >>> page. >>> >>> >>>> I think the true figure of merit for a split is how often will subsequent >>>> searches have to descend into *both* of the resulting pages as opposed to >>>> just one >>>> --- the less often that is true, the better. I'm not very clear on what >>>> tsearch2 is doing with these bitmaps, but it looks like an upper page's >>>> downlink has the union (bitwise OR) of the one-bits in the values on the >>>> lower page, and you have to visit the lower page if this union has a >>>> nonempty intersection with the set you are looking for. If that's >>>> correct, what you really want is to divide the values so that the unions >>>> of the two sets have minimal overlap ... which seems to me to have little >>>> to do with what the code does at present. >>> I'm not sure what "upper page" and "lower page" mean here? >>> >>> >>>> Teodor, Oleg, can you clarify what's needed here? >>> Ditto. Guys what is the real motivation and purpose for this code? >> >> we want not just split the page by two very distinct parts, but to keep >> resulted signatures which is ORed signature of all signatures in the page >> as much 'sparse' as can. some information available here >> http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_internals >> >> Unfortunately, we're rather busy right now and couldn't be very useful. > > Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83 From pgsql-performance-owner@postgresql.org Sat Jan 21 14:27:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7F42F9DCB66 for ; Sat, 21 Jan 2006 14:27:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19728-02 for ; Sat, 21 Jan 2006 14:27:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 7197D9DCABF for ; Sat, 21 Jan 2006 14:27:53 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0LIRrK2018772; Sat, 21 Jan 2006 13:27:53 -0500 (EST) To: Ron cc: pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very In-reply-to: <7.0.1.0.2.20060121064930.03aba810@earthlink.net> References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> Comments: In-reply-to Ron message dated "Sat, 21 Jan 2006 07:22:32 -0500" Date: Sat, 21 Jan 2006 13:27:53 -0500 Message-ID: <18771.1137868073@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/396 X-Sequence-Number: 16874 Ron writes: > At 07:23 PM 1/20/2006, Tom Lane wrote: >> Well, we're trying to split an index page that's gotten full into >> two index pages, preferably with approximately equal numbers of items in >> each new page (this isn't a hard requirement though). > Maybe we are over thinking this. What happens if we do the obvious > and just make a new page and move the "last" n/2 items on the full > page to the new page? Search performance will go to hell in a handbasket :-(. We have to make at least some effort to split the page in a way that will allow searches to visit only one of the two child pages rather than both. It's certainly true though that finding the furthest pair is not a necessary component of that. It's reasonable if you try to visualize the problem in 2D or 3D, but I'm not sure that that geometric intuition holds up in such a high-dimensional space as we have here. regards, tom lane From pgsql-general-owner@postgresql.org Sat Jan 21 14:37:24 2006 X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E33769DC85C for ; Sat, 21 Jan 2006 14:37:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21211-01 for ; Sat, 21 Jan 2006 14:37:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by postgresql.org (Postfix) with SMTP id 164779DC801 for ; Sat, 21 Jan 2006 14:37:17 -0400 (AST) Received: (qmail invoked by alias); 21 Jan 2006 18:37:15 -0000 Received: from p54A662C7.dip.t-dialin.net (EHLO athlon64) [84.166.98.199] by mail.gmx.net (mp006) with SMTP; 21 Jan 2006 19:37:15 +0100 X-Authenticated: #594052 Received: from localhost (HELO [127.0.0.1]) [127.0.0.1] by athlon64 (192.168.0.2) (userid 3) with ESMTP (Classic Hamster Version 2.1 Build 2.1.0.0) ; Sat, 21 Jan 2006 19:37:09 +0100 Message-ID: <43D27F52.8090003@gmx.de> Date: Sat, 21 Jan 2006 19:37:06 +0100 From: Stephan Vollmer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0 MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Re: Creation of tsearch2 index is very slow References: <43D0ED57.1020608@gmx.de> <17454.1137771321@sss.pgh.pa.us> <43D114B1.5030802@gmx.de> <6376.1137799359@sss.pgh.pa.us> In-Reply-To: <6376.1137799359@sss.pgh.pa.us> X-Enigmail-Version: 0.94.0.0 OpenPGP: id=8D46FCF8 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig4F286EDFAF0429FEA7647227" X-Posting-Agent: Hamster/2.1.0.0 X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.082 required=5 tests=[AWL=0.082] X-Spam-Score: 0.082 X-Spam-Level: X-Archive-Number: 200601/1057 X-Sequence-Number: 90002 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4F286EDFAF0429FEA7647227 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Tom Lane wrote: > The problem seems to be mostly tsearch2's fault rather than the general= > GIST code. I've applied a partial fix to 8.1 and HEAD branches, which > you can find here if you're in a hurry for it: > http://archives.postgresql.org/pgsql-committers/2006-01/msg00283.php > (the gistidx.c change is all you need for tsearch2) Thanks for all your time and work you and the other guys are spending on this matter! I'll look into the new version, but a.p.o seems to be unreachable at the moment. > There is some followup discussion in the pgsql-performance list. It > seems possible that we can get another factor of 10 or better with a > smarter picksplit algorithm --- but that patch will probably be too > large to be considered for back-patching into the stable branches. I've already been following the discussion on pgsql-perform, although I have to admit that don't understand every detail of the tsearch2 implementation. :-) Thus, I'm sorry that I won't be able to help directly on that problem. But it is interesting to read anyway. Best regards, - Stephan --------------enig4F286EDFAF0429FEA7647227 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFD0n9VjY05go1G/PgRArBqAJ4ydI97FAgXQUjx8nxduAPH74aaIQCeMjLU sey3aS73bsV/s6HGZviCFuM= =iPyV -----END PGP SIGNATURE----- --------------enig4F286EDFAF0429FEA7647227-- From pgsql-performance-owner@postgresql.org Sat Jan 21 16:48:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7B9AA9DC85A for ; Sat, 21 Jan 2006 16:48:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44796-10 for ; Sat, 21 Jan 2006 16:48:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.invendra.net (sbx-01.invendra.net [66.139.76.16]) by postgresql.org (Postfix) with ESMTP id 77A0F9DCB5E for ; Sat, 21 Jan 2006 16:20:48 -0400 (AST) Received: from david.lang.hm (dsl081-044-215.lax1.dsl.speakeasy.net [64.81.44.215]) by mail.invendra.net (Postfix) with ESMTP id 4447C1AC3E9; Sat, 21 Jan 2006 12:21:13 -0800 (PST) Date: Sat, 21 Jan 2006 12:19:26 -0800 (PST) From: David Lang X-X-Sender: dlang@david.lang.hm To: Tom Lane Cc: Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <18771.1137868073@sss.pgh.pa.us> Message-ID: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200601/398 X-Sequence-Number: 16876 On Sat, 21 Jan 2006, Tom Lane wrote: > Ron writes: >> At 07:23 PM 1/20/2006, Tom Lane wrote: >>> Well, we're trying to split an index page that's gotten full into >>> two index pages, preferably with approximately equal numbers of items in >>> each new page (this isn't a hard requirement though). > >> Maybe we are over thinking this. What happens if we do the obvious >> and just make a new page and move the "last" n/2 items on the full >> page to the new page? > > Search performance will go to hell in a handbasket :-(. We have to make > at least some effort to split the page in a way that will allow searches > to visit only one of the two child pages rather than both. does the order of the items within a given page matter? if not this sounds like a partial quicksort algorithm would work. you don't need to fully sort things, but you do want to make sure that everything on the first page is 'less' then everything on the second page so you can skip passes that don't cross a page boundry > It's certainly true though that finding the furthest pair is not a > necessary component of that. It's reasonable if you try to visualize > the problem in 2D or 3D, but I'm not sure that that geometric intuition > holds up in such a high-dimensional space as we have here. I will say that I'm not understanding the problem well enough to understand themulti-dimentional nature of this problem. David Lang From pgsql-performance-owner@postgresql.org Sat Jan 21 16:36:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 010199DC821 for ; Sat, 21 Jan 2006 16:36:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47546-01 for ; Sat, 21 Jan 2006 16:36:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svana.org (svana.org [125.62.94.225]) by postgresql.org (Postfix) with ESMTP id 4DD469DC801 for ; Sat, 21 Jan 2006 16:36:31 -0400 (AST) Received: from kleptog by svana.org with local (Exim 4.50) id 1F0PSo-0003RK-HT; Sun, 22 Jan 2006 07:35:58 +1100 Date: Sat, 21 Jan 2006 21:35:58 +0100 From: Martijn van Oosterhout To: Oleg Bartunov Cc: Tom Lane , Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very slow Message-ID: <20060121203558.GC9955@svana.org> Reply-To: Martijn van Oosterhout References: <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060121130830.GA9955@svana.org> <20060121150424.GB9955@svana.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="1SQmhf2mF2YjsYvc" Content-Disposition: inline In-Reply-To: X-PGP-Key-ID: Length=1024; ID=0x0DC67BE6 X-PGP-Key-Fingerprint: 295F A899 A81A 156D B522 48A7 6394 F08A 0DC6 7BE6 X-PGP-Key-URL: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kleptog@svana.org X-SA-Exim-Scanned: No (on svana.org); SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.128 required=5 tests=[AWL=0.128] X-Spam-Score: 0.128 X-Spam-Level: X-Archive-Number: 200601/397 X-Sequence-Number: 16875 --1SQmhf2mF2YjsYvc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jan 21, 2006 at 06:22:52PM +0300, Oleg Bartunov wrote: > >I see how it works, what I don't quite get is whether the "inverted > >index" you refer to is what we're working with here, or just what's in > >tsearchd? >=20 > just tsearchd. We plan to implement inverted index into PostgreSQL core > and then adapt tsearch2 to use it as option for read-only archives. Hmm, had a look and think about it and I think I see what you mean by an inverted index. I also think your going to have a real exercise implementing it in Postgres because postgres indexes work on the basis of one tuple, one index entry, which I think your inverted index doesn't do. That said, I think GiST could be extended to support your case without too much difficulty. Interesting project though :) BTW, given you appear to have a tsearch2 index with some real-world data, would you be willing to try some alternate picksplit algorithms to see if your gevel module shows any difference? Have a nice day, --=20 Martijn van Oosterhout 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. --1SQmhf2mF2YjsYvc Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD0psuIB7bNG8LQkwRAqsSAJ0dymQlux4JATsdWKjiUXO8uyvBywCfWUtX LcGjTdBwHFMl3Vhvi9UHglE= =mmZh -----END PGP SIGNATURE----- --1SQmhf2mF2YjsYvc-- From pgsql-performance-owner@postgresql.org Sat Jan 21 16:55:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 13C349DCA13 for ; Sat, 21 Jan 2006 16:55:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49129-04 for ; Sat, 21 Jan 2006 16:55:25 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.194]) by postgresql.org (Postfix) with ESMTP id 9FE029DC821 for ; Sat, 21 Jan 2006 16:55:21 -0400 (AST) Received: by xproxy.gmail.com with SMTP id i30so466867wxd for ; Sat, 21 Jan 2006 12:55:23 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:mime-version:content-type; b=V2k9yUnofzp4mcvxxrN+u7hwWYqx0I203t/9qTp1GY/9gI0zj69Vr6DSCFivqgOlpLmNM//uPNAwD/NdvvIaSRuUEqDWApQBF+0xksrGF+wGcWsf47cduFVJYUviV61hpho82gjGElFCEMRGy4N4vIXGGXLAeXo9kIudDf9waOA= Received: by 10.70.60.17 with SMTP id i17mr3928468wxa; Sat, 21 Jan 2006 12:55:23 -0800 (PST) Received: by 10.70.102.3 with HTTP; Sat, 21 Jan 2006 12:55:23 -0800 (PST) Message-ID: Date: Sat, 21 Jan 2006 22:55:23 +0200 From: =?ISO-8859-1?Q?=DCmit_=D6ztosun?= To: pgsql-performance@postgresql.org Subject: Slow queries consisting inner selects and order bys & hack to speed up MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_7951_5594348.1137876923424" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/399 X-Sequence-Number: 16877 ------=_Part_7951_5594348.1137876923424 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, Our application uses typical queries similar to following (very simplified)= : SELECT part_id, part_name, (SELECT SUM(amount) FROM part_movements M WHERE P.part_id =3D M.part_id ) as part_amount FROM parts P LIMIT 50 The parts table holds thousands of items. Movement table stores yearly movement information of those items. We are presenting results to users pag= e by page, hence the limit case. User can sort and filter results. When sorting is introduced, query performance drops significantly: SELECT part_id, part_name, (SELECT SUM(amount) FROM part_movements M WHERE P.part_id =3D M.part_id ) as part_amount FROM parts P ORDER BY part_name LIMIT 50 Postgres seems to compute all possible rows and then sorts the results, which nearly renders the paging meaningless. A dummy WHERE case dramatically improves performance: SELECT part_id, part_name, (SELECT SUM(amount) FROM part_movements M WHERE P.part_id =3D M.part_id ) as part_amount FROM parts P ORDER BY part_name WHERE part_amount > -10000000 LIMIT 50 Is there a way to improve performance of these queries? Is it possible to instruct Postgres to first sort the rows then compute the inner queries? (We have simulated this by using temporary tables and two stage queries, but this is not practical because most queries are automatically generated). Attached is the output of real queries and their corresponding EXPLAIN ANALYZE outputs. Regards, Umit Oztosun ------=_Part_7951_5594348.1137876923424 Content-Type: application/zip; name=pgperf.zip Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="pgperf.zip" UEsDBBQAAgAIADS2NTQ6KGSkkhgAAOJbAgAKAAAAcGdwZXJmLnR4dO1d627bSLL+HyDv0BsEsJSR BXY3r8Y4QCbjweZMZpMTZ89gfxmMxTiEbl5KysR+q32HfbDTZJMSL02yaVESL6UBJiab7GtVseqr 6urr2fIv9L8bx3u4eP7scvd7/uz5s+ur91dvP6NX6LdPH/5AAxReP3+GCn6vRiUPDGxv7d7cOd6t M71xvRX6CaXu3Extb+V+db25XVhIotK5PfvqrpJXNxPnfnmOBs50lWotdSfZWn4hiUq3rcWugtaG Q2SvUPjyar2cjmRm4qvrztz4RGxvCOZBVCY/DfGmkjcEk5DXlMwc8Hf9KSiegeJSn+xKZlCKJOXq mG5mM3vh3rr2xOUUv2Jj2t5Ff/796tMVupk6D+gS+UMb32xWjjdEb64T744km1tOdq0sH52Zf0PQ Bvv7JvYIRkGD0dVhGyOJxkjlxm6/MtLwpnZuU9EDQTPBX6M6lvKL67nzRDf8NhkZr2+CopnjuaNg Lvz7/N7NzF2tnZVb3EI4EnGVu/nLVuuPW1gQvFQyLvTmH7/ups2vqqj9WJlMteKq7IUdXLDGzvBZ cT1DtnjBw+XUL7d+BcODJT3akkbPsx7Uw5WMv4Enj7yAwZzXsnxf3Qd7jWH5jrZ8fMLrEai+drb8 7j6Od8pNpSUc7aqA1ay8mkX1bKckmFwcTgNfLL+snE74i7XQydsPb95fXb+9QoPVZj5guv/Unvkj nbvTte0NR0gZ7qiHFdsz98FB7I9R4g6zGGbO3EW8AimCCdsKZiN4e73xNnFlUWKG43UkOnjpF1Wo ZRyzhtjyvpVZXn+2xn6nLxk5oA+f0O5aTV0bqWszdY3x2VCmxeSAQwPsZrXcMAPU77eFTUPRsaGr pm6YmJoma1mq5sEgVjV6/Rqp5pDVSDTD76m4UMNqfiHWqFVQalh6filRNFpQSrEiKtX0oGZiDIeS i+7er+2ZP2/nZ5JvMJ5wv6Gf2StEUfRzBZ9js0yw++Zx0pQHzj0Y5/5ekXP1FCdaqWuSuqapa20f xp04qzWwbWvYNgaLAQc3hoPh2wtMnPs7P0fX9sRhK2Q/LP77HxRQ2cz2GGfbK3YdES1TzCcO+uas 7PuZzR58WHqyVJicguhOQCFBa4GU30fWkAMIG47fF8kb9sSjM3dYj5ilxh8fZQoi0bOtTkr67BrP WGcVZZCgpkS/L8MnZOsL5yXx7U/c0rK3dEnxEevJVnzsKzeS48+KjrzySHrklW8FSO4DkQzJ7UEk RnIfiCRJ9oFqwiRajH0+8SF9A5+dhM/wHhxUiw4NbFQnGwXrAgpyY8Cpk5q4oB833shNxn4A44Jl C+BU+/gWwCmAl+HbC9jUQbCp/PBQsJlPYzPTLBClZm8ZgE212aiOhVoDn7UPmwIOahIHASzV7Jgp sTU7SJi/Ucvbzn+1WZmN/nbpz3nycWb9Fj8PmnXnQzd227qA8RtrE4tt4EHCaK7C+Nrh+B4wsXZx PYBibcC14csPMqCn8V7ifecgq0BWgbbSEw8eaCtgroCyAspK8x2AoKy0LNIPRBWIqoNpK6O9cjBF DD+IJIC9umP94vy+Y/WANu6ZPJw7a8/PGTC5L6k4zEYQywwwuRf4GP3J2BZERPjVnbFW/MlUzrjM 8e20WMdGtQ75bvPdWcyaOOZEz+odtP3IhHoTl3nXr1G1IRaXBl18JZH3LJEuApVnUgt6vVoXPBXk 2Lq5/vNzOFvonx8/Xn0aTJgsn/tihl+evTnz5fyvV5/QL/8K70XdmC4nmyFiOsItev/uj3efkab4 aQLfLOzZw6ODPmzW95t1IotgkEjwPZvINfu43y5X60usEp3QMSbjcfSnibzlX6tLoqG/3Mn626Wm 0CEa2LfrDRNla3fuXGLL0M2xZajsJfanNaa6zl/SFDRbLu9XlziQkOevEbpeerW0pmlRa1gjwtb4 L2jvd+fhAm3u7x1vEEzXODFnFxdr58c69k7QT+ff6PrWXqDlIrvY0QCUsaKEfSdjTS3tuzo2iO73 mxJ1rFPKX1At1RD0PKQ2Rv+Od4EGYfc5QYRd9tnizVmm/+HIN18+MhU0S3L+8N7c3XnOnb12oqFo bE7ZWIJ/eLdwOAysp0bBRq2ytfb/0aNHeff9keR+C/1m/8E0WGeC3rOnk3PI2jWt8nYpb5eGU63I tMt//7N0F7vJfOEuFo73IjcK5cVys47KSyr2h/VuMXF+cHLZrNzFXTbuxtfJbtzJj4icBNE6qQkZ M00oMR9mdjqIFUwHsSpPB//xfr9dLiZsTkJdGl9crFiHZu5iLVXHdk4H6XgagXJ4cfHFvfNr5kqg ULu5uJgwuhzWMu3cxMh8avJWIhMelVoTOqY4uShEZauycL47HnJ+OLeMaibVZ14UVfVSrTj7g4wi zS2CQUaHFt731WdxAdOchQW+0iwuYPpyqqBQVc6VR5jLIywhFwwuF6wa5ZGMHCQmZ0CzMgM2iX5T g8JKMChMKkwm0Ha5GSi35Pd+tRW+EmbpVwJjvp44SaREZ7NSeT3jX8aS+M2qixx+gGjsAxTMdHhf zblvxO6H35WDf4mEIos1MtZ9XTb4t1x46HqwLrpZl9CSbZjyhjWtPqmVAvWSCF1cXInRv/Q4cIau iwSVUZugioOKlaVUDkhWTnytkW97U0dcuMWR4eT664xEy6UaNwVwioh1lao1SDUBKlyRGtKOLLbm 97ffbC9a85DK9BypZuXcJzn386SmlpWOMRQy1akiKRh2O0kVAgfFwcRl7Tpe0LCEcsls+7qVvNOI Sz4OrNZhLdYtLsP4BxCWTxCWpFxYasIvJVZM3CZhifdQDeP3zZz7GNclLQ+mM3KVRyfHFoKUW7oa brsQDI0hE3TGHorB8AtIW6Ezvm29zjg8hPOBKgEL052NcBznAzEDEUiiLvbd+RBKUiP6eKgN8j7I q5MdcUGk1kbhtpKSspV0i2gmYLjH90+onFdUemz/RGgzY/BPAG033T9B2+GfIBJaU/y+3lb/hMaj C3bW4bH8EypHK1SrI/4JsDX76J9ola3ZAcjt9A4K7lal5tEdFLxhYoCDAhwU7XZQpLy5bXNQdA6Z q+yf4Lq8TsE/Af4JkIL99E90z03bkt0RlCugFBwUsDsCdkeA9yGpG6nKsb0PT2ZA8D6A9wF2R3Rv dwQNDToqYUlyJUrXj747gkMRmgq7I8CSbK33gXZ6d4Q0biYE4GJScJcU5+fXflKcxEua5Euwr+JJ gpbQbu2r0MBt0Tsx2+19FdLAnFALlRWzCTjvYHK2XR4PGbnNreso+w14PEBPhSiZhu3I6JCeeqC9 HITv5dCOvJfDUvheDgKukhgbGgT2csBeDvCmFHt3udmqaqfJNfUE724LvCkUvCnd8KaIQzhhL8eJ vSmn3suhKR2xUsGb0mNvSkf3cnQJ5uvoLhACu0DAndIbd0pHd4H0EA2s7E05WdRP6E2hHZGeFuip 4E3p2P6RHrij08eOiA7bSdCF//9y6aZwA0apIt12y/ZS3erQMXBNhH/sjutRtvwMI+3NSNubciQM gms/TAVBv/D5JxBM0SXzqcqmCW5A68apjpSATRMgP+FICYCfOo/y172lFjZNAMoPmybAm9riTRNV wlG4+NSPLj6j1CwW6Kmgp0I4CghQCEeBcBQIRwE5C+EoEI7SpM29RkfSmYKeCv4oCEfpjKEPiVDb mAjVfCpmDIlQIRFqlxKh1p3qqtrW3TqdNg3Yl25BIlRIhAqJUA9ug546pkcDGxRsUIjpgYOFehyZ g/sXmQMOj96ewmZ2MzKnvecPVdYZOQ/r6tGPYbPgGDbQGeEYtibvo2ntYZRPSy2qHjm1qBmIQGJh cD7EU4uqkFoUUouCf6LYX2omdiEfzT8R+Us75Z+IkB8d/BPd8E8kt41AatGG+CdgLwf4J8DWhL0c LYHcOnremoyDwoCtw+CgaDcyZyZg2a7tyGgtMldVBpocXjfpsWWgxj+3RuvzfJmJo9VBZ+yjFLS6 ua+iNW7aXGlkaWOcEkYqEQijIMAOVwpVSfkIEovH+M+Hp26+uJ47v5m5rHfcUxDzJDxNvFp0bKYG pCkC1ZZb5Fp1S7ZkWJPld/cRyw6lhCW38GMwTzPHK0Yms4+n5oaMDa38yxN5lNU6JHZO9s5KbGov 7GBEPjfgHTeUT2oin2m0OKnP2Nb0pQXkomgJ25fKagHpDgiIPtWb7flSNF+qKpx4qb59tLA7xfyi jnd+xwJTMGgSK7gpAuBE/FIUgVGdX/bnlKfyyOGJUzsMcYq+TlTjxEl6TpwiyZWCIIA4Dyk5TaDN SooG0GY2S/qhaJMImtSCBcBE6TlxinYiq4mkQH2iTarnKsBbV4AEcaYPE5jb3tRON25q5Z/3EESo lGp/O4UBQHKJXtKcXmYpjk3a8tGZTZeTHRKyu5cOB0iTkq7nx3dUCdHNwF7+IMgpByFO2V59EFiG Xlhfp5vZzF64txmCJYYEzYSuK7IPzSjs0c9LH4bxNgu/5guELcNkLGMpaL56/sz/7zebcZWH/s/x Vu5ywd5eLmYPyJ5MmGB+8dV1Z27Ag+g1OsdK8HuBbu2Vw+q+TP6eP7u+en/19jN6hX779OEPNEDh dbG0eDUqeWDAJI57c+d4t87Ux8zQTyh15yaGgxUVkqg0DI1JXAWI6jkaONNVqrXUnWRr+YUkKt22 FrsKWhsOkb1C4cv+LI9kZoIvSmwitjcE8yAqk5+GeFPJG4JJyGtKZg52hFY8AyUfHkZ2JTMoRZJy dWwZ3J64nOKTbP/n368+XaGQGf2hjW82K8dHQa8T744km2Nyb9tKJAgFbUSaTPgIRkGD0dVhGyOJ xkjlxraf2bymogeCZoK/RnUsZaBgJLqR1cJGOfpICRTIRyKuskTtFBcEL5WMKwDat9PmV1XUfqxM plpxVUldr7ieIVu84OFy6pdbv4LhwZIebUmj51kP6uFKxt/Ak0dewGDOa1m+r+6DvcawfEdbPj7h 9QjUyNs03ik3lZZwtKsCVrPyahbVk3XV7hbLLyunE/5iLXTy9sOb91fXb6/QYLWZD3icjT/SuTtd 295whJThjnriwRijgkAdKYIJ28pE1GwXVWKG43XkBGTI1TJOB2JIvObP1tjv9CUjBz+aYnetpq6N 1LWZusb4bCjTYnLAmSCiM0EU0RmSqnkwiFWdCDIK4kSEhRpW8wv9cKOCUsPS80v9wKOCUooVUan0 tpztosdCXCTfEIa+lDCsbx4nTXng3INx7u8VOVdPcaKVuiapa5q61vZh3DACGti2HWwbg8WAgxvD wfDtBSbOD8I7R9f2xGErZD8s/vsfFFDZzPYYZ9srdh0RLVPMJw765qzs+5nNHnxYerJUmJyC6E5q i9Q+soYcQNhs94vnyhvBTuRR+fZzKemza1y0V7yKDBLUlL87WWZBw8fj3/7ELS17S5cUH7GexHcq 7yU3kuPPio688kh65JVvBUjuA5EMye1BJEZyH4gkSfaBasIkWox9PvEhfQOfnYTP8B4cVIsODWxU JxsF6wIKcmPAqZOauKAfN97ITcZ+AOOCZQvgVPv4FsApgJfh2wvY1EGwqfzwULCZT2Mz0ywQpWZv GYBNtdmojoVaA5+1D5sCDmoSBwEs1eyYKbE1O0iYv1HL6WN9/3aJwoRECeu3+HnQrDsfurHb1gWM 31ibWGwDDxJGcxXG1w7H94CJtYvrARRrA64NX36QAT2N9xLvOwdZBbIKtJWeePBAWwFzBZQVUFaa 7wAEZaVlkX4gqkBUHUxbGe2Vgyli+EEkAezVHesX5/cdqwe0cc/k4dxZe37OgMl9ScVhNoJYZoDJ vcDH6E/GtiAiwq/ujLXiT6ZyxmWOb6fFOjaqdch3m+/OYtbEMSd6Vu+g7Ucm1Ju4zLt+jaoNsbg0 6OIribxniXQRqDyTWtDr1brgqSDH1s31n5/D2UL//Pjx6tNgwmT53Bcz/PLszRk/10GYK5AJqV+v PqFf/hU+HXVwupxshohpD7fo/bs/3n1GmsLG+PzZm4U9e3h00IfN+n6zvhDkGHzPZnmdOsrDpJqm U/Y3z5ZobfNJ01RmRTq2/DMAiWKMtejsBG17tlEgM1P5KH+xb6d/2d5ElM81PhhRBtdgFfboqp/t 2e8q0S1hV8PF354Gsrm/d7xBuEAXF2vnx9pfJ7ZC0UX4nfN/q80XXx0cop/Q9m/pi3O0dx3DGJUo FxeLzdzx3Nv4d+t68+UjezROoPsfVq6oPE2xmkrarClVcxTLHVKuUJLI5KkUtcd/Bzic/JTHkhNT eBhewQTw336nkeecmHS4I8ibdD7zwvnueMj54dwy2phUmecnnb7c7nOXazhNnPITNCitQabIyDDC ZQqRlykNPj1csXhiZmUf+dBDuq2+vAc4KVycVBuTKmtX3wnh2bPB6R4nnx3+bPB6Trnl/KPifYWP dIP8FG2q7C99TnOioyo81fYJAqfSSY5whiM69onf4oXG2l7Sqfqpjd09tfZpR3zXI/Zo8pyu/cSe zKHe4YkqasvFntoMsdej47uPemQtwULbQG26zGvpGbW1yDKVa1QqOZoss1quwlFQ4XohzcJzkLDR UBXubetVuGG9+DoxAjWDGPpx8HWiB6KA/dNXfD08vteIxL56UoBdXq9rPcqexjG5qFJSfg5DASDz 4AB8bQqULACvcyVb7wIAH53/TQCAbx0ATzjhE6WpADyR0F/i93UA4AGAB+utIwC81lIAvj1g1CkR eB7YoypHQ6202rQukHuAwB8Ks4oi/tTU2d3gdWwsAK9xztT0Y4myyGBtqzMxsjsIqHAdF2Y0Icza A8B3yZ8IEe7NjnDnyC8xIMIdItwhwr0WgJ3LMEI7AbBzZQljANghwh0i3E8MNBHp8ChiQXgUWGcA sEOE+2nwdQ5KUR0i3CHCHSApiHCHCPfqEe4YfIWgwjU6wp2HEmIdItxbEuGuWzzCHR8pwl3j7WlW 3yPcFYhwb0SEuwER7scH4OsyBmUB+DDWSusSAA8pZloIwIdYJoUI9x5FuOOWW28AwAMAD2AU5JgB BB4Q+O4i8BDh3poId5UvmUqPJspMAOBBhWsDAK+1NMUMRLhDhDvkcIcIdwAqIYc7AOwAsEOEe7Mi 3GloLFGIcAeAHawziHCvhikJwamYNNsdnvnza//wzMRLmuRLEBsvKzDV2uIhAM4CZP5Q4rJrsfHS mJVQKZSVlgmk62Di8gCgPklkkTleXAYBKQhqY6PVRr1jeeM7pDbWHo9v8nh85Vjx+AaPxzcg4zzE 40M8fk/dBeIkj4dzF9QXGQYJccBdsIe7QBziB/H44C4AdwHYfeAuAAAM/AXgLwB/Qav8BbQjkfy9 gslOuwdAXm1svbtAB7UR3AWt2gPQab/ptfNvThTh4gfMcW979txZe87KRZOUvPL/Xy6tFA7pKTLS ardQL9WtEhvDokRAAtNwZ6x/7HFly61HGxs3gBUKYzvM2NqXYyHa09F2TEeFj3M/MB0dfPltNVIq YNv1ZgqFXDMgBzuD1VChCxhC4XseCs9tV2oCtA3QNojLzAZbCqHwbQ2Fh5AIwLZBDkJIBIREQEgE JDcEvfGoIREqhET0ICTi2GgjpEUEtRFCIiAkomEJFdUjJ1SkiWRrPUyoWBk9gISKkFARTizqS0JF xYKEipBQERIqPhncOro7AKLpwK4DdwAc3tEhTB8OLAJMv1sHFnUlLWIbj/g4LTQvY7AqEAgMKlwb TizSO7YhooXnrzU8RSFvTzP7nqKQQIpCSFHYVwCeW/rUOBYAT4UB1y1NUYghRWFrAfgciAtSFB4R gOeCn1rHBuBNsN7AegMAvtdgVB8ReIiqBwS+yQh8SKZ6R6LqWwhZVQbg6zpluyoAT9sqysQh06DC dQ6A58YNtroSG98Cf2KudLG0MU4JF5Vk14xD8Fgq+WkKDE8sFOMuH825+eJ67vxm5rJecUg8BplX FZAWHZupIbB+5WX60GQyfUgNZLL87j7i8s6XsNgWkQvmZOZ4xWBd9vHUbJCxoZV/LaIwS016NgRM mJMFUJLt7IUdjMGnbryj7qIJTORAjJYg9bnZWpG0gBiU0IzcPlrydU43LCDiVC+iqjHNl4RKytzJ 6UYx9atMyShfby3QDrCinY6BT0T9Rfi0Kk39+9B9dYo/PMkZ9ZKc6JuhcoFrWb0jOZHE6THJ0eRh XzWRnKAl1eBCTu8dxdXzie+YkNvuX6iJ4oiZqxgTtXckJ4KpQreV0m2Ko6I02nrSY1dAculE3nPb m9rpRk2t/AMbIj66TNLr7WQFsMAlekkz/crSEZue5aMzmy4nO/t/dy/tW04TiK7nu29kjLAMsON3 m5ym2xXiGYTdxsVUwHo33cxm9sK9zZAfMcopIXR/UvIUSvAf+rz0YQZvs/BrvEAEW2Os6Wi+ev6M //f/UEsBAhQAFAACAAgANLY1NDooZKSSGAAA4lsCAAoAAAAAAAAAAQAgAAAAAAAAAHBncGVyZi50 eHRQSwUGAAAAAAEAAQA4AAAAuhgAAAAA ------=_Part_7951_5594348.1137876923424-- From pgsql-performance-owner@postgresql.org Sat Jan 21 16:56:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DDF359DCA13 for ; Sat, 21 Jan 2006 16:56:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45877-08 for ; Sat, 21 Jan 2006 16:56:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C73879DC85A for ; Sat, 21 Jan 2006 16:56:27 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0LKtnUh001750; Sat, 21 Jan 2006 15:56:29 -0500 (EST) To: David Lang cc: Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very In-reply-to: References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> Comments: In-reply-to David Lang message dated "Sat, 21 Jan 2006 12:19:26 -0800" Date: Sat, 21 Jan 2006 15:55:49 -0500 Message-ID: <1749.1137876949@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/400 X-Sequence-Number: 16878 David Lang writes: > On Sat, 21 Jan 2006, Tom Lane wrote: >> Ron writes: >>> Maybe we are over thinking this. What happens if we do the obvious >>> and just make a new page and move the "last" n/2 items on the full >>> page to the new page? >> >> Search performance will go to hell in a handbasket :-(. We have to make >> at least some effort to split the page in a way that will allow searches >> to visit only one of the two child pages rather than both. > does the order of the items within a given page matter? AFAIK the items within a GIST index page are just stored in insertion order (which is exactly why Ron's suggestion above doesn't work well). There's no semantic significance to it. It's only when we have to split the page that we need to classify the items more finely. regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 21 17:06:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3C33B9DC804 for ; Sat, 21 Jan 2006 17:06:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51628-03 for ; Sat, 21 Jan 2006 17:06:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pop.xnet.hr (dns1.xnet.hr [82.193.192.5]) by postgresql.org (Postfix) with ESMTP id 6193E9DC85A for ; Sat, 21 Jan 2006 17:06:52 -0400 (AST) Received: (qmail 23354 invoked from network); 21 Jan 2006 21:07:24 -0000 Received: by simscan 1.1.0 ppid: 23342, pid: 23348, t: 0.5873s scanners: attach: 1.1.0 clamav: 0.87/m:34/d:1131 spam: 3.1.0 Received: from unknown (HELO ?83.139.74.33?) (83.139.74.33) by pop.xnet.hr with SMTP; 21 Jan 2006 21:07:24 -0000 Message-ID: <43D2A245.6040804@zg.htnet.hr> Date: Sat, 21 Jan 2006 22:06:13 +0100 From: Rikard Pavelic User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> <43D13C2F.1030203@zg.htnet.hr> <20060120213455.GT20182@pervasive.com> In-Reply-To: <20060120213455.GT20182@pervasive.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[AWL=0.000, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/401 X-Sequence-Number: 16879 Jim C. Nasby wrote: > If you're dealing with something that's performance critical you're not > going to be constantly re-connecting anyway, so I don't see what the > issue is. > I didn't include mailing list in my second reply :( so here it is again. Someone may find this interesting... http://archives.postgresql.org/pgsql-general/2004-04/msg00084.php From Tom Lane: "EXECUTE means something different in plpgsql than it does in plain SQL, and you do not need PREPARE at all in plpgsql. plpgsql's automatic caching of plans gives you the effect of PREPARE on every statement without your having to ask for it." From pgsql-performance-owner@postgresql.org Sat Jan 21 19:49:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0D57D9DC880 for ; Sat, 21 Jan 2006 19:49:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73692-06 for ; Sat, 21 Jan 2006 19:49:55 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id C8A0E9DC80A for ; Sat, 21 Jan 2006 19:49:50 -0400 (AST) Received: from mail.intermedia.net (mail.intermedia.net [206.40.48.181]) by svr4.postgresql.org (Postfix) with ESMTP id 02C675AF67B for ; Sat, 21 Jan 2006 23:49:54 +0000 (GMT) Received: from ex1.intermedia.net ([206.40.48.184]) by mail.intermedia.net with Microsoft SMTPSVC(6.0.3790.1830); Sat, 21 Jan 2006 15:49:52 -0800 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: libpq vs. unixODBC performance X-MimeOLE: Produced By Microsoft Exchange V6.5 Date: Sat, 21 Jan 2006 15:49:52 -0800 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: libpq vs. unixODBC performance thread-index: AcYe5V9E5xb8F8FmSdO8mjtu8asi4A== From: "Constantine Filin" To: X-OriginalArrivalTime: 21 Jan 2006 23:49:52.0130 (UTC) FILETIME=[5F446620:01C61EE5] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.479 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.479 X-Spam-Level: X-Archive-Number: 200601/402 X-Sequence-Number: 16880 Greetings - I am really love Postgres and do enjoy hacking around it but I just met a libpq performance issue that I would like to get your help with. I have Postgres 8.0.1 running on Linux version 2.6.10-1.771_FC2. I have an application that makes queries to Postgres. I want to keep the database code in this application as simple as possible because the application is doing lots of other complex things (it is an IP Telephony server). So for the sake of simplicity, I do not "prepare" SQL statements before submitting them to database. Now I have 2 ways to access Postgres - one through unixODBC, the=20 other through libpq. I found that libpq performance is nearly 2 times slower than performance of unixODBC. Specifically, I have a multithreaded test program (using pthreads), where I can run a specified number of simple queries like this: SELECT * FROM extensions WHERE=20 (somecolumn IS NOT NULL)=20 AND (id IN (SELECT extension_id FROM table 2)) The test program can submit the queries using unixODBC or libpq.=20 With 1 execution thread I have these performance results: ODBC: does 200 queries in 2 seconds (100.000000 q/s) libpq: does 200 queries in 3 seconds (66.666667 q/s) With 2 threads the results are: ODBC: does 200 queries in 3 seconds (66.666667 q/s) Libpq: does 200 queries in 6 seconds (33.333333 q/s) With 3 threads: ODBC: does 200 queries in 5 seconds (40.000000 q/s) Libpq: 200 queries in 9 seconds (22.222222 q/s) Obviously libpq is slower. Do you have any ideas why libpq is so much slower than unixODBC? Where do you think the libpq bottleneck is? Are there any libpq options (compile time or runtime) that can make it faster? Respectfully Constantine From pgsql-performance-owner@postgresql.org Sat Jan 21 20:40:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 04E9B9DCC81 for ; Sat, 21 Jan 2006 20:40:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82153-08 for ; Sat, 21 Jan 2006 20:40:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D02E09DCC7E for ; Sat, 21 Jan 2006 20:40:38 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0M0ednl002705; Sat, 21 Jan 2006 19:40:39 -0500 (EST) To: "Constantine Filin" cc: pgsql-performance@postgresql.org Subject: Re: libpq vs. unixODBC performance In-reply-to: References: Comments: In-reply-to "Constantine Filin" message dated "Sat, 21 Jan 2006 15:49:52 -0800" Date: Sat, 21 Jan 2006 19:40:39 -0500 Message-ID: <2704.1137890439@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.095 required=5 tests=[AWL=0.095] X-Spam-Score: 0.095 X-Spam-Level: X-Archive-Number: 200601/403 X-Sequence-Number: 16881 "Constantine Filin" writes: > Do you have any ideas why libpq is so much slower than unixODBC? Perhaps ODBC is batching the queries into a transaction behind your back? Or preparing them for you? regards, tom lane From pgsql-performance-owner@postgresql.org Sun Jan 22 03:53:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8A66C9DCA42 for ; Sun, 22 Jan 2006 03:53:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59560-02 for ; Sun, 22 Jan 2006 03:53:40 -0400 (AST) X-Greylist: delayed 00:06:39.507235 by SQLgrey- Received: from k2smtpout01-01.prod.mesa1.secureserver.net (k2smtpout01-02.prod.mesa1.secureserver.net [64.202.189.89]) by postgresql.org (Postfix) with SMTP id 5C1C89DC818 for ; Sun, 22 Jan 2006 03:53:37 -0400 (AST) Received: (qmail 12793 invoked from network); 22 Jan 2006 07:46:59 -0000 Received: from unknown (HELO mail.servantwebhosting.com) ([68.178.159.82]) (envelope-sender ) by k2smtpout01-01.prod.mesa1.secureserver.net (qmail-ldap-1.03) with SMTP for ; 22 Jan 2006 07:46:59 -0000 Received: (qmail 30432 invoked by uid 2527); 22 Jan 2006 00:46:59 -0700 Received: from 70.64.198.193 by jonah.prod.phx1.secureserver.net (envelope-from , uid 2525) with qmail-scanner-1.25-st-qms (clamdscan: 0.86.2/989. spamassassin: 3.0.2. perlscan: 1.25-st-qms. Clear:RC:0(70.64.198.193):SA:0(-0.6/5.0):. Processed in 4.440342 secs); 22 Jan 2006 07:46:59 -0000 X-Antivirus-MYDOMAIN-Mail-From: pgsql-performance@nullmx.com via jonah.prod.phx1.secureserver.net X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(70.64.198.193):SA:0(-0.6/5.0):. Processed in 4.440342 secs Process 27907) X-Envelope-From: pgsql-performance@nullmx.com Received: from s010600e0296eec95.mj.shawcable.net (HELO ?192.168.1.131?) (rob@nullmx.com@70.64.198.193) by mail.servantwebhosting.com with AES256-SHA encrypted SMTP; 22 Jan 2006 00:46:54 -0700 Message-ID: <43D3386A.8000004@nullmx.com> Date: Sun, 22 Jan 2006 01:46:50 -0600 From: pgsql-performance@nullmx.com Reply-To: pgsql-performance@nullmx.com User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: tsearch2 headline and postgresql.conf Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.55 required=5 tests=[NO_REAL_NAME=0.55] X-Spam-Score: 0.55 X-Spam-Level: X-Archive-Number: 200601/404 X-Sequence-Number: 16882 Hi folks, I'm not sure if this is the right place for this but thought I'd ask. I'm relateively new to postgres having only used it on 3 projects and am just delving into the setup and admin for the second time. I decided to try tsearch2 for this project's search requirements but am having trouble attaining adequate performance. I think I've nailed it down to trouble with the headline() function in tsearch2. In short, there is a crawler that grabs HTML docs and places them in a database. The search is done using tsearch2 pretty much installed according to instructions. I have read a couple online guides suggested by this list for tuning the postgresql.conf file. I only made modest adjustments because I'm not working with top-end hardware and am still uncertain of the actual impact of the different paramenters. I've been learning 'explain' and over the course of reading I have done enough query tweaking to discover the source of my headache seems to be headline(). On a query of 429 documents, of which the avg size of the stripped down document as stored is 21KB, and the max is 518KB (an anomaly), tsearch2 performs exceptionally well returning most queries in about 100ms. On the other hand, following the tsearch2 guide which suggests returning that first portion as a subquery and then generating the headline() from those results, I see the query increase to 4 seconds! This seems to be directly related to document size. If I filter out that 518KB doc along with some 100KB docs by returning "substring( stripped_text FROM 0 FOR 50000) AS stripped_text" I decrease the time to 1.4 seconds, but increase the risk of not getting a headline. Seeing as how this problem is directly tied to document size, I'm wondering if there are any specific settings in postgresql.conf that may help, or is this just a fact of life for the headline() function? Or, does anyone know what the problem is and how to overcome it? From pgsql-performance-owner@postgresql.org Sun Jan 22 04:25:22 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5DAC09DC93B for ; Sun, 22 Jan 2006 04:25:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62702-06 for ; Sun, 22 Jan 2006 04:25:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ra.sai.msu.su (ra.sai.msu.su [158.250.29.2]) by postgresql.org (Postfix) with ESMTP id 6B1FC9DC943 for ; Sun, 22 Jan 2006 04:25:12 -0400 (AST) Received: from ra (ra [158.250.29.2]) by ra.sai.msu.su (8.13.4/8.13.4) with ESMTP id k0M8OtBj024595; Sun, 22 Jan 2006 11:24:55 +0300 (MSK) Date: Sun, 22 Jan 2006 11:24:55 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@ra.sai.msu.su To: pgsql-performance@nullmx.com cc: pgsql-performance@postgresql.org Subject: Re: tsearch2 headline and postgresql.conf In-Reply-To: <43D3386A.8000004@nullmx.com> Message-ID: References: <43D3386A.8000004@nullmx.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.391 required=5 tests=[AWL=-0.088, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.391 X-Spam-Level: X-Archive-Number: 200601/405 X-Sequence-Number: 16883 You didn't provides us any query with explain analyze. Just to make sure you're fine. Oleg On Sun, 22 Jan 2006, pgsql-performance@nullmx.com wrote: > Hi folks, > > I'm not sure if this is the right place for this but thought I'd ask. I'm > relateively new to postgres having only used it on 3 projects and am just > delving into the setup and admin for the second time. > > I decided to try tsearch2 for this project's search requirements but am > having trouble attaining adequate performance. I think I've nailed it down > to trouble with the headline() function in tsearch2. > In short, there is a crawler that grabs HTML docs and places them in a > database. The search is done using tsearch2 pretty much installed according > to instructions. I have read a couple online guides suggested by this list > for tuning the postgresql.conf file. I only made modest adjustments because > I'm not working with top-end hardware and am still uncertain of the actual > impact of the different paramenters. > > I've been learning 'explain' and over the course of reading I have done > enough query tweaking to discover the source of my headache seems to be > headline(). > > On a query of 429 documents, of which the avg size of the stripped down > document as stored is 21KB, and the max is 518KB (an anomaly), tsearch2 > performs exceptionally well returning most queries in about 100ms. > > On the other hand, following the tsearch2 guide which suggests returning that > first portion as a subquery and then generating the headline() from those > results, I see the query increase to 4 seconds! > > This seems to be directly related to document size. If I filter out that > 518KB doc along with some 100KB docs by returning "substring( stripped_text > FROM 0 FOR 50000) AS stripped_text" I decrease the time to 1.4 seconds, but > increase the risk of not getting a headline. > > Seeing as how this problem is directly tied to document size, I'm wondering > if there are any specific settings in postgresql.conf that may help, or is > this just a fact of life for the headline() function? Or, does anyone know > what the problem is and how to overcome it? > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83 From pgsql-performance-owner@postgresql.org Sun Jan 22 12:04:50 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 996039DC93D for ; Sun, 22 Jan 2006 12:04:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47161-10 for ; Sun, 22 Jan 2006 12:04:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 40FFB9DC950 for ; Sun, 22 Jan 2006 12:04:46 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 76C883094B; Sun, 22 Jan 2006 17:04:45 +0100 (MET) From: August Zajonc X-Newsgroups: pgsql.performance Subject: Re: Suspending SELECTs Date: Sun, 22 Jan 2006 11:04:29 -0500 Organization: Hub.Org Networking Services Lines: 39 Message-ID: <43D3AD0D.9050201@augustz.com> References: <43CB71AC.20203@barettadeit.com> <43CD4BD0.9090807@barettadeit.com> <200601171459.02398.josh@agliodbs.com> <200601171518.07342.josh@agliodbs.com> <43CE0709.4000104@barettadeit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org To: Alessandro Baretta User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <43CE0709.4000104@barettadeit.com> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/406 X-Sequence-Number: 16884 Alessandro Baretta wrote: > > What I could do relatively easily is instantiate a thread to iteratively > scan a traditional cursor N rows at a time, retrieving only record keys, > and finally send them to the query-cache-manager. The application thread > would then scan through the cursor results by fetching the rows > associated to a given "page" of keys. I would have to keep the full > cursor keyset in the application server's session state, but, hopefully, > this is not nearly as bad as storing the entire recordset. > > Alex > > > Alessandro, I've very much enjoyed reading your thoughts and the problem your facing and everyone's responses. Since you control the middle layer, could you not use a cookie to keep a cursor open on the middle layer and tie into it on subsequent queries? If you are concerned with too many connections open, you could timeout the sessions quickly and recreate the cursor if someone came back. If they waited 5 minutes to make the next query, certainly they could wait a few extra seconds to offset and reacquire a cursor? The hitlist idea was also a nice one if the size of the data returned is not overwhelming and does not need to track the underlying db at all (ie, no refresh). Mark had a number of good general suggestions though, and I'd like to echo the materialized views as an option that I could see a lot of uses for (and have worked around in the past with SELECT INTO's and like). Interesting stuff. - August From pgsql-performance-owner@postgresql.org Sun Jan 22 16:29:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8EF4E9DC847 for ; Sun, 22 Jan 2006 16:29:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42940-09 for ; Sun, 22 Jan 2006 16:29:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from k2smtpout03-01.prod.mesa1.secureserver.net (k2smtpout03-01.prod.mesa1.secureserver.net [64.202.189.171]) by postgresql.org (Postfix) with SMTP id 827599DC810 for ; Sun, 22 Jan 2006 16:29:13 -0400 (AST) Received: (qmail 2473 invoked from network); 22 Jan 2006 20:29:14 -0000 Received: from unknown (HELO mail.servantwebhosting.com) ([68.178.159.82]) (envelope-sender ) by k2smtpout03-01.prod.mesa1.secureserver.net (qmail-ldap-1.03) with SMTP for ; 22 Jan 2006 20:29:14 -0000 Received: (qmail 30753 invoked by uid 2527); 22 Jan 2006 13:29:14 -0700 Received: from 70.64.198.193 by jonah.prod.phx1.secureserver.net (envelope-from , uid 2525) with qmail-scanner-1.25-st-qms (clamdscan: 0.86.2/989. spamassassin: 3.0.2. perlscan: 1.25-st-qms. Clear:RC:0(70.64.198.193):SA:0(-0.6/5.0):. Processed in 10.727113 secs); 22 Jan 2006 20:29:14 -0000 X-Antivirus-MYDOMAIN-Mail-From: pgsql-performance@nullmx.com via jonah.prod.phx1.secureserver.net X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(70.64.198.193):SA:0(-0.6/5.0):. Processed in 10.727113 secs Process 26208) X-Envelope-From: pgsql-performance@nullmx.com Received: from s010600e0296eec95.mj.shawcable.net (HELO ?192.168.1.131?) (rob@nullmx.com@70.64.198.193) by mail.servantwebhosting.com with AES256-SHA encrypted SMTP; 22 Jan 2006 13:29:03 -0700 Message-ID: <43D3EB0D.5020109@nullmx.com> Date: Sun, 22 Jan 2006 14:29:01 -0600 From: pgsql-performance@nullmx.com Reply-To: pgsql-performance@nullmx.com User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Oleg Bartunov , pgsql-performance@postgresql.org Subject: Re: tsearch2 headline and postgresql.conf References: <43D3386A.8000004@nullmx.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.67 required=5 tests=[AWL=0.120, NO_REAL_NAME=0.55] X-Spam-Score: 0.67 X-Spam-Level: X-Archive-Number: 200601/407 X-Sequence-Number: 16885 Oleg Bartunov wrote: > You didn't provides us any query with explain analyze. > Just to make sure you're fine. > > Oleg > On Sun, 22 Jan 2006, pgsql-performance@nullmx.com wrote: > >> Hi folks, >> >> I'm not sure if this is the right place for this but thought I'd >> ask. I'm relateively new to postgres having only used it on 3 >> projects and am just delving into the setup and admin for the second >> time. >> >> I decided to try tsearch2 for this project's search requirements but >> am having trouble attaining adequate performance. I think I've >> nailed it down to trouble with the headline() function in tsearch2. >> In short, there is a crawler that grabs HTML docs and places them in >> a database. The search is done using tsearch2 pretty much installed >> according to instructions. I have read a couple online guides >> suggested by this list for tuning the postgresql.conf file. I only >> made modest adjustments because I'm not working with top-end hardware >> and am still uncertain of the actual impact of the different >> paramenters. >> >> I've been learning 'explain' and over the course of reading I have >> done enough query tweaking to discover the source of my headache >> seems to be headline(). >> >> On a query of 429 documents, of which the avg size of the stripped >> down document as stored is 21KB, and the max is 518KB (an anomaly), >> tsearch2 performs exceptionally well returning most queries in about >> 100ms. >> >> On the other hand, following the tsearch2 guide which suggests >> returning that first portion as a subquery and then generating the >> headline() from those results, I see the query increase to 4 seconds! >> >> This seems to be directly related to document size. If I filter out >> that 518KB doc along with some 100KB docs by returning "substring( >> stripped_text FROM 0 FOR 50000) AS stripped_text" I decrease the time >> to 1.4 seconds, but increase the risk of not getting a headline. >> >> Seeing as how this problem is directly tied to document size, I'm >> wondering if there are any specific settings in postgresql.conf that >> may help, or is this just a fact of life for the headline() >> function? Or, does anyone know what the problem is and how to >> overcome it? >> > > Regards, > Oleg > _____________________________________________________________ ------------------------ Hi Oleg, Thanks for taking time to look at this. Pardon my omission, I was writing that email rather late at night. The following results from 'explain analyze' are from my devlopment machine which is a dual PIII 600MHz running Debian Linux and Postgres 8.1.2. 512 MB RAM. The production machine yields similar results but it is a virtual server so the resources are rather unpredictable. It is a quad processor and has a larger result set in it's DB. The original query is: explain analyze SELECT url, title, headline(stripped_text,q, 'MaxWords=75, MinWords=25, StartSel=!!!REPLACE_ME!!!,StopSel=!!!/REPLACE_ME!!!'), rank, to_char(timezone('CST', date_last_changed), 'DD Mon YYYY') AS date_last_changed FROM ( SELECT url_id, url, title, stripped_text, date_last_changed, q, rank(index_text, q) AS rank FROM (web_page w LEFT JOIN url u USING (url_id)), to_tsquery('big&search') AS q WHERE (index_text <> '') AND (index_text @@ q) AND (w.url_id NOT IN (1,2)) AND (url NOT LIKE '%badurl.com%') ORDER BY rank DESC, date_last_changed DESC LIMIT 10 OFFSET 0 ) AS useless ; ...and the resultant output of EXPLAIN ANALYZE is: Subquery Scan useless (cost=8.02..8.04 rows=1 width=624) (actual time=769.131..2769.320 rows=10 loops=1) -> Limit (cost=8.02..8.02 rows=1 width=282) (actual time=566.798..566.932 rows=10 loops=1) -> Sort (cost=8.02..8.02 rows=1 width=282) (actual time=566.792..566.870 rows=10 loops=1) Sort Key: rank(w.index_text, q.q), w.date_last_changed -> Nested Loop (cost=2.00..8.01 rows=1 width=282) (actual time=4.068..563.128 rows=178 loops=1) -> Nested Loop (cost=2.00..4.96 rows=1 width=221) (actual time=3.179..388.610 rows=179 loops=1) -> Function Scan on q (cost=0.00..0.01 rows=1 width=32) (actual time=0.025..0.028 rows=1 loops=1) -> Bitmap Heap Scan on web_page w (cost=2.00..4.94 rows=1 width=189) (actual time=3.123..387.547 rows=179 loops=1) Filter: ((w.index_text <> ''::tsvector) AND (w.url_id <> 1) AND (w.url_id <> 2) AND (w.index_text @@ "outer".q)) -> Bitmap Index Scan on idx_index_text (cost=0.00..2.00 rows=1 width=0) (actual time=1.173..1.173 rows=277 loops=1) Index Cond: (w.index_text @@ "outer".q) -> Index Scan using pk_url on url u (cost=0.00..3.03 rows=1 width=65) (actual time=0.044..0.049 rows=1 loops=179) Index Cond: ("outer".url_id = u.url_id) Filter: (url !~~ '%badurl.com%'::text) Total runtime: 2771.023 ms (15 rows) ----- Maybe someone can help me with interpreting the ratio of cost to time too. Do they look appropriate? To give some further data, I've stripped down the query to only return what's necessary for examination here. explain analyze SELECT headline(stripped_text,q) FROM ( SELECT stripped_text, q FROM (web_page w LEFT JOIN url u USING (url_id)), to_tsquery('big&search') AS q WHERE (index_text <> '') AND (index_text @@ q) AND (w.url_id NOT IN (1,2)) LIMIT 10 OFFSET 0 ) AS useless ; Subquery Scan useless (cost=43.25..75.50 rows=1 width=64) (actual time=383.720..2066.962 rows=10 loops=1) -> Limit (cost=43.25..75.49 rows=1 width=129) (actual time=236.814..258.150 rows=10 loops=1) -> Nested Loop (cost=43.25..75.49 rows=1 width=129) (actual time=236.807..258.070 rows=10 loops=1) Join Filter: ("inner".index_text @@ "outer".q) -> Function Scan on q (cost=0.00..0.01 rows=1 width=32) (actual time=0.033..0.033 rows=1 loops=1) -> Merge Right Join (cost=43.25..70.37 rows=409 width=151) (actual time=235.603..237.283 rows=31 loops=1) Merge Cond: ("outer".url_id = "inner".url_id) -> Index Scan using pk_url on url u (cost=0.00..806.68 rows=30418 width=4) (actual time=0.029..0.731 rows=39 loops=1) -> Sort (cost=43.25..44.27 rows=409 width=155) (actual time=235.523..235.654 rows=31 loops=1) Sort Key: w.url_id -> Seq Scan on web_page w (cost=0.00..25.51 rows=409 width=155) (actual time=0.037..230.577 rows=409 loops=1) Filter: ((index_text <> ''::tsvector) AND (url_id <> 1) AND (url_id <> 2)) Total runtime: 2081.569 ms (13 rows) As a demonstration to note the effect of document size on headline speed I've returned only the first 20,000 characters of each document in the subquery shown below. 20K is the size of avg document from the results with 518K being max (an anomaly), and a few 100K documents. explain analyze SELECT headline(stripped_text,q) FROM ( SELECT substring(stripped_text FROM 0 FOR 20000) AS stripped_text, q FROM (web_page w LEFT JOIN url u USING (url_id)), to_tsquery('big&search') AS q WHERE (index_text <> '') AND (index_text @@ q) AND (w.url_id NOT IN (1,2)) LIMIT 10 OFFSET 0 ) AS useless ; Subquery Scan useless (cost=43.25..75.51 rows=1 width=64) (actual time=316.049..906.045 rows=10 loops=1) -> Limit (cost=43.25..75.49 rows=1 width=129) (actual time=239.831..295.151 rows=10 loops=1) -> Nested Loop (cost=43.25..75.49 rows=1 width=129) (actual time=239.825..295.068 rows=10 loops=1) Join Filter: ("inner".index_text @@ "outer".q) -> Function Scan on q (cost=0.00..0.01 rows=1 width=32) (actual time=0.021..0.021 rows=1 loops=1) -> Merge Right Join (cost=43.25..70.37 rows=409 width=151) (actual time=234.711..236.265 rows=31 loops=1) Merge Cond: ("outer".url_id = "inner".url_id) -> Index Scan using pk_url on url u (cost=0.00..806.68 rows=30418 width=4) (actual time=0.046..0.715 rows=39 loops=1) -> Sort (cost=43.25..44.27 rows=409 width=155) (actual time=234.613..234.731 rows=31 loops=1) Sort Key: w.url_id -> Seq Scan on web_page w (cost=0.00..25.51 rows=409 width=155) (actual time=0.030..229.788 rows=409 loops=1) Filter: ((index_text <> ''::tsvector) AND (url_id <> 1) AND (url_id <> 2)) Total runtime: 907.397 ms (13 rows) And finally, returning the whole document without the intervention of headline: explain analyze SELECT stripped_text FROM ( SELECT stripped_text, q FROM (web_page w LEFT JOIN url u USING (url_id)), to_tsquery('big&search') AS q WHERE (index_text <> '') AND (index_text @@ q) AND (w.url_id NOT IN (1,2)) LIMIT 10 OFFSET 0 ) AS useless ; Subquery Scan useless (cost=43.25..75.50 rows=1 width=32) (actual time=235.218..253.048 rows=10 loops=1) -> Limit (cost=43.25..75.49 rows=1 width=129) (actual time=235.210..252.994 rows=10 loops=1) -> Nested Loop (cost=43.25..75.49 rows=1 width=129) (actual time=235.204..252.953 rows=10 loops=1) Join Filter: ("inner".index_text @@ "outer".q) -> Function Scan on q (cost=0.00..0.01 rows=1 width=32) (actual time=0.024..0.024 rows=1 loops=1) -> Merge Right Join (cost=43.25..70.37 rows=409 width=151) (actual time=234.008..234.766 rows=31 loops=1) Merge Cond: ("outer".url_id = "inner".url_id) -> Index Scan using pk_url on url u (cost=0.00..806.68 rows=30418 width=4) (actual time=0.058..0.344 rows=39 loops=1) -> Sort (cost=43.25..44.27 rows=409 width=155) (actual time=233.896..233.952 rows=31 loops=1) Sort Key: w.url_id -> Seq Scan on web_page w (cost=0.00..25.51 rows=409 width=155) (actual time=0.031..229.057 rows=409 loops=1) Filter: ((index_text <> ''::tsvector) AND (url_id <> 1) AND (url_id <> 2)) Total runtime: 254.057 ms (13 rows) Again, I really appreciate any help you folks can give with this. From pgsql-performance-owner@postgresql.org Mon Jan 23 06:19:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 247359DC9DA for ; Mon, 23 Jan 2006 06:19:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08920-07 for ; Mon, 23 Jan 2006 06:19:30 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id 104599DC9BE for ; Mon, 23 Jan 2006 06:19:25 -0400 (AST) Received: (qmail invoked by alias); 23 Jan 2006 10:19:26 -0000 Received: from 201-15-251-250.ctame704.dsl.brasiltelecom.net.br (EHLO servidor) [201.15.251.250] by mail.gmx.net (mp039) with SMTP; 23 Jan 2006 11:19:26 +0100 X-Authenticated: #15924888 Subject: Re: [PERFORMANCE] Stored Procedures From: Marcos To: "Jim C. Nasby" Cc: Rikard Pavelic , pgsql-performance@postgresql.org In-Reply-To: <20060120213455.GT20182@pervasive.com> References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> <43D13C2F.1030203@zg.htnet.hr> <20060120213455.GT20182@pervasive.com> Content-Type: text/plain; charset=iso8859-1 Date: Mon, 23 Jan 2006 08:14:14 +0000 Message-Id: <1138004054.949.10.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/409 X-Sequence-Number: 16887 Em Sex, 2006-01-20 �s 15:34 -0600, Jim C. Nasby escreveu: > On Fri, Jan 20, 2006 at 08:38:23PM +0100, Rikard Pavelic wrote: > > This would solve problems with prepare which is per session, so for > > prepared function to be > > optimal one must use same connection. > > If you're dealing with something that's performance critical you're not > going to be constantly re-connecting anyway, so I don't see what the > issue is. This one was my doubt, perhaps in based desktop applications this is true, but in web applications this is not the re-connecting is constant :(. Then the preprare not have very advantage because your duration is per session. Marcos. From pgsql-performance-owner@postgresql.org Mon Jan 23 06:31:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BDA359DC813 for ; Mon, 23 Jan 2006 06:31:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13825-02 for ; Mon, 23 Jan 2006 06:31:25 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 225E49DC847 for ; Mon, 23 Jan 2006 06:31:20 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id ED0BD12560; Mon, 23 Jan 2006 11:31:35 +0100 (CET) Message-ID: <43D4B07B.5090200@barettadeit.com> Date: Mon, 23 Jan 2006 11:31:23 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: August Zajonc , pgsql-performance@postgresql.org Subject: Re: Suspending SELECTs References: <43CB71AC.20203@barettadeit.com> <43CD4BD0.9090807@barettadeit.com> <200601171459.02398.josh@agliodbs.com> <200601171518.07342.josh@agliodbs.com> <43CE0709.4000104@barettadeit.com> <43D3AD0D.9050201@augustz.com> In-Reply-To: <43D3AD0D.9050201@augustz.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/410 X-Sequence-Number: 16888 August Zajonc wrote: > Alessandro Baretta wrote: > > Alessandro, > > I've very much enjoyed reading your thoughts and the problem your facing > and everyone's responses. Thank you for your interest, Agust. > Since you control the middle layer, could you not use a cookie to keep a > cursor open on the middle layer and tie into it on subsequent queries? I do. The AS/Xcaml calls it "session key". It is usually passed in a cookie for websites and elsewhere--query string or url--for Intranet/Extranet web applications. The session information kept by the AS/Xcaml virtual machine includes cached query results and state information for servlets. I could--although not terribly easily--also use the Xcaml session manager to handle allocation of DB connections from the pool, thus allocating one connection per active session. The session garbage collector would then also have to manage the recycling of stale DB connections. > If you are concerned with too many connections open, you could timeout > the sessions quickly and recreate the cursor if someone came back. If > they waited 5 minutes to make the next query, certainly they could wait > a few extra seconds to offset and reacquire a cursor? Yes I could. Actually, there are quite a few means of handling this issue. The possible strategies for garbage collecting resources allocated to a remote peer is are collectively called "failure-detection algorithms" in the theory of distributed computing. In most cases an "eventually weak failure detector" is necessary and sufficient to guarantee a number of desirable properties in asynchronous systems: termination of execution, bounded open connections, and others. Yet, it is a theorm that no asynchronous algorithm can be devised to implement an eventually weak failure detector. This, in turn, implies that no distributed asynchronous system--i.e. a web application--possesses the above mentioned desirable properties. Hence, from a theoretical standpoint, we can either choose to relax the axioms of the system allowing synchronicity--a failure detector based on a timeout explicitly requires the notion of time--or, as I would prefer, by eliminating the need for termination of execution--i.e. explicit client logout--and bounded open connections by delegating to the client the responsibility of maintaing all relevant state information. Under these assumptions we can live happily in a perfectly asynchronous stateless world like that of HTTP. Now, neither of the two solutions is perfect. In an Intranet/Extranet context, I want to store server side a significant amount of state information, including cached query results, thus entailing the need for a synchronous failure-detector--let's call it "implicit logout detector"--to garbage collect the stale session files generated by the application. In an open website--no login--I do not usually want to use sessions, so I prefer to implement the application so that all relevant state informatoin is maintained by the client. This model is perfect until we reach the issue of "suspending SELECTs", that is, limiting the the cardinality of the record set to a configurable "page-size", allowing the user to page through a vast query result. > The hitlist idea was also a nice one if the size of the data returned is > not overwhelming and does not need to track the underlying db at all > (ie, no refresh). In an open website, immediate refresh is not critical, so long as I can guarantee some decent property of data consistency. Full consistency cannot be achieved, as Tom pointed out. I cordially disagree with Tom on the commandment that "Thou shalt have no property of consistency other than me". Just like we have two different transaction isolation levels, guarateeing different degrees of ACIDity, we could, conceivably wish to formalize a weaker notion of consistency and implement functionality to match with it, which would not be possible under the stronger definition property. > Mark had a number of good general suggestions though, and I'd like to > echo the materialized views as an option that I could see a lot of uses > for (and have worked around in the past with SELECT INTO's and like). I already use materialized views. The database design layer of the AS/Xcaml allows the definition of fragmented materialized views: the view is split in fragments, that is, equivalence classes of the record set with respect to the operation of projection of the view signature to a (small) subset of its columns. Yet, this actually makes the original problem worse, for materialiazed view fragments must be garbage collected at some point, thus offering much of the same conceptual difficulties as cursor pooling strategy. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Mon Jan 23 05:46:19 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0A02E9DC83B for ; Mon, 23 Jan 2006 05:46:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04362-06 for ; Mon, 23 Jan 2006 05:46:19 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.199]) by postgresql.org (Postfix) with ESMTP id 3BDF59DC892 for ; Mon, 23 Jan 2006 05:46:16 -0400 (AST) Received: by wproxy.gmail.com with SMTP id 57so837228wri for ; Mon, 23 Jan 2006 01:46:16 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:message-id:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:x-mimeole; b=sJxxlAwmRPd4t0Yot0TcdJySrovSL4zOONnAlRFHpeKcNnq+737tTEfaIDNVMdCjW36gmnd4TmJPBN228sFb7Kkqfs6GkQ2MgTcoWtCi8Q4mN52bhUcHcglnfjSkl5gJcFhIUvpv5gaKuZRN/8DIUy6rQWWL8BCErjZkjmlhd20= Received: by 10.54.93.20 with SMTP id q20mr5609024wrb; Mon, 23 Jan 2006 01:46:16 -0800 (PST) Received: from FRANKLIN ( [200.180.51.99]) by mx.gmail.com with ESMTP id 26sm1197494wrl.2006.01.23.01.46.15; Mon, 23 Jan 2006 01:46:16 -0800 (PST) From: "Franklin Haut" To: Subject: ENC: RES: pg_dump slow - Solution Date: Mon, 23 Jan 2006 07:46:27 -0300 Message-ID: <001701c6200a$44933e20$8500a8c0@FRANKLIN> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcYekvM6kDjMLf+KSWODDQVoLXJ5qABdzLZg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/408 X-Sequence-Number: 16886 Hi, Finally i found the problem of slow backup/restore, i=B4m only instaled = de Windows 2000 Service Pack 4... :) Thanks to all Franklin =20 -----Mensagem original----- De: Richard Huxton [mailto:dev@archonet.com] Enviada em: quarta-feira, = 30 de novembro de 2005 14:28 Para: Franklin Haut Cc: 'Ron'; pgsql-performance@postgresql.org Assunto: Re: RES: [PERFORM] pg_dump slow Franklin Haut wrote: > Hi, >=20 > Yes, my problem is that the pg_dump takes 40 secs to complete under=20 > WinXP and 50 minutes under W2K! The same database, the same hardware!, = > only diferrent Operational Systems. >=20 > The hardware is:=20 > Pentium4 HT 3.2 GHz > 1024 Mb Memory > HD 120Gb SATA There have been reports of very slow network performance on Win2k = systems with the default configuration. You'll have to check the archives for details I'm afraid. This might apply to you. If you're happy that doesn't affect you then I'd look at the disk system - perhaps XP has newer drivers than Win2k. What do the MS performance-charts show is happening? Specifically, CPU = and disk I/O. -- Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Mon Jan 23 08:30:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3CD949DC847 for ; Mon, 23 Jan 2006 08:30:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32507-09 for ; Mon, 23 Jan 2006 08:30:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.logix-tt.com (serval.logix-tt.com [213.239.221.42]) by postgresql.org (Postfix) with ESMTP id 1D1959DC813 for ; Mon, 23 Jan 2006 08:30:30 -0400 (AST) Received: from kingfisher.intern.logix-tt.com (Mddbe.m.pppool.de [89.49.221.190]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logix-tt.com (Postfix) with ESMTP id B433C24400F; Mon, 23 Jan 2006 13:30:33 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) by kingfisher.intern.logix-tt.com (Postfix) with ESMTP id A071F18189FA6; Mon, 23 Jan 2006 13:30:31 +0100 (CET) Message-ID: <43D4CC67.9050703@logix-tt.com> Date: Mon, 23 Jan 2006 13:30:31 +0100 From: Markus Schaber Organization: Logical Tracking and Tracing International AG, Switzerland User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Cc: Marcos Subject: Re: [PERFORMANCE] Stored Procedures References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> <43D13C2F.1030203@zg.htnet.hr> <20060120213455.GT20182@pervasive.com> <1138004054.949.10.camel@servidor> In-Reply-To: <1138004054.949.10.camel@servidor> X-Enigmail-Version: 0.93.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.124 required=5 tests=[AWL=0.124] X-Spam-Score: 0.124 X-Spam-Level: X-Archive-Number: 200601/411 X-Sequence-Number: 16889 Hi, Marcos, Marcos wrote: > This one was my doubt, perhaps in based desktop applications this is > true, but in web applications this is not the re-connecting is > constant :(. If this is true, then you have a much bigger performance problem than query plan preparation. You really should consider using a connection pool (most web application servers provide pooling facilities) or some other means to keep the connection between several http requests. Worried, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org From pgsql-performance-owner@postgresql.org Mon Jan 23 11:32:32 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A82FC9DC813 for ; Mon, 23 Jan 2006 11:32:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67850-04 for ; Mon, 23 Jan 2006 11:32:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from mail.gmx.net (mail.gmx.net [213.165.64.21]) by postgresql.org (Postfix) with SMTP id A19139DC809 for ; Mon, 23 Jan 2006 11:32:28 -0400 (AST) Received: (qmail invoked by alias); 23 Jan 2006 15:32:31 -0000 Received: from 201-15-251-250.ctame704.dsl.brasiltelecom.net.br (EHLO servidor) [201.15.251.250] by mail.gmx.net (mp017) with SMTP; 23 Jan 2006 16:32:31 +0100 X-Authenticated: #15924888 Subject: Re: [PERFORMANCE] Stored Procedures From: Marcos To: Markus Schaber Cc: pgsql-performance@postgresql.org In-Reply-To: <43D4CC67.9050703@logix-tt.com> References: <43D130EF.3010205@zg.htnet.hr> <20060120191031.GO20182@pervasive.com> <43D13C2F.1030203@zg.htnet.hr> <20060120213455.GT20182@pervasive.com> <1138004054.949.10.camel@servidor> <43D4CC67.9050703@logix-tt.com> Content-Type: text/plain Date: Mon, 23 Jan 2006 13:27:25 +0000 Message-Id: <1138022845.949.26.camel@servidor> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.144 required=5 tests=[AWL=0.144] X-Spam-Score: 0.144 X-Spam-Level: X-Archive-Number: 200601/412 X-Sequence-Number: 16890 Hi Markus > You really should consider using a connection pool (most web application > servers provide pooling facilities) or some other means to keep the > connection between several http requests. Yes. I'm finding a connection pool, I found the pgpool but yet don't understand how it's work I'm go read more about him. Thanks Marcos From pgsql-performance-owner@postgresql.org Mon Jan 23 12:23:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 248C49DC813 for ; Mon, 23 Jan 2006 12:23:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76551-04 for ; Mon, 23 Jan 2006 12:23:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from globalrelay.com (mail1.globalrelay.com [216.18.71.77]) by postgresql.org (Postfix) with ESMTP id DBA1E9DC804 for ; Mon, 23 Jan 2006 12:23:47 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES Received: from [216.160.41.114] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 81841653; Mon, 23 Jan 2006 08:23:28 -0800 From: "Dave Dutcher" To: "'Marcos'" Cc: Subject: Re: [PERFORMANCE] Stored Procedures Date: Mon, 23 Jan 2006 10:23:17 -0600 Message-ID: <000001c62039$579e88b0$8300a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal In-Reply-To: <1138022845.949.26.camel@servidor> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/413 X-Sequence-Number: 16891 I don't think pgpool is what you need. If I understand pgpool correctly, pgpool lets you pool multiple postgres servers together. You are just looking for database connection pooling. A simple connection pool is basically just an application wide list of connections. When a client needs a connection, you just request a connection from the pool. If there is an unused connection in the pool, it is given to the client and removed from the unused pool. If there is no unused connection in the pool, then a new connection is opened. When the client is done with it, the client releases it back into the pool. You can google for 'database connection pool' and you should find a bunch of stuff. It's probably a good idea to find one already written. If you write your own you have to make sure it can deal with things like dead connections, synchronization, and maximum numbers of open connections. Dave -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Marcos Sent: Monday, January 23, 2006 7:27 AM To: Markus Schaber Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] [PERFORMANCE] Stored Procedures Hi Markus > You really should consider using a connection pool (most web application > servers provide pooling facilities) or some other means to keep the > connection between several http requests. Yes. I'm finding a connection pool, I found the pgpool but yet don't understand how it's work I'm go read more about him. Thanks Marcos ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org From pgsql-performance-owner@postgresql.org Mon Jan 23 13:24:48 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E41219DC97A for ; Mon, 23 Jan 2006 13:24:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 91786-03 for ; Mon, 23 Jan 2006 13:24:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from frank.wiles.org (frank.wiles.org [24.124.39.75]) by postgresql.org (Postfix) with ESMTP id 610799DC8D9 for ; Mon, 23 Jan 2006 13:24:41 -0400 (AST) Received: from kungfu (frank.wiles.org [127.0.0.1]) by frank.wiles.org (8.13.1/8.13.1) with SMTP id k0NHOW8Y008844; Mon, 23 Jan 2006 11:24:33 -0600 Date: Mon, 23 Jan 2006 11:25:26 -0600 From: Frank Wiles To: "Dave Dutcher" Cc: mjs_ops@gmx.net, pgsql-performance@postgresql.org Subject: Re: [PERFORMANCE] Stored Procedures Message-Id: <20060123112526.1ee25dcd.frank@wiles.org> In-Reply-To: <000001c62039$579e88b0$8300a8c0@tridecap.com> References: <1138022845.949.26.camel@servidor> <000001c62039$579e88b0$8300a8c0@tridecap.com> X-Mailer: Sylpheed version 2.0.1 (GTK+ 2.6.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.065 required=5 tests=[AWL=0.065] X-Spam-Score: 0.065 X-Spam-Level: X-Archive-Number: 200601/414 X-Sequence-Number: 16892 On Mon, 23 Jan 2006 10:23:17 -0600 "Dave Dutcher" wrote: > I don't think pgpool is what you need. If I understand pgpool > correctly, pgpool lets you pool multiple postgres servers together. > You are just looking for database connection pooling. While pgpool can let you pool together multiple backend servers, it also functions well as just a connection pooling device with only one backend. --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From pgsql-performance-owner@postgresql.org Mon Jan 23 15:19:18 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 166FD9DC9AB for ; Mon, 23 Jan 2006 15:19:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18514-02 for ; Mon, 23 Jan 2006 15:19:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E0FB39DC85C for ; Mon, 23 Jan 2006 15:19:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0NJJED4007600; Mon, 23 Jan 2006 14:19:14 -0500 (EST) To: =?ISO-8859-1?Q?=DCmit_=D6ztosun?= cc: pgsql-performance@postgresql.org Subject: Re: Slow queries consisting inner selects and order bys & hack to speed up In-reply-to: References: Comments: In-reply-to =?ISO-8859-1?Q?=DCmit_=D6ztosun?= message dated "Sat, 21 Jan 2006 22:55:23 +0200" Date: Mon, 23 Jan 2006 14:19:14 -0500 Message-ID: <7599.1138043954@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.096 required=5 tests=[AWL=0.096] X-Spam-Score: 0.096 X-Spam-Level: X-Archive-Number: 200601/415 X-Sequence-Number: 16893 =?ISO-8859-1?Q?=DCmit_=D6ztosun?= writes: > Our application uses typical queries similar to following (very simplified): > SELECT > part_id, > part_name, > (SELECT > SUM(amount) FROM part_movements M > WHERE P.part_id =3D M.part_id > ) as part_amount > FROM parts P > ORDER BY part_name > LIMIT 50 > Postgres seems to compute all possible rows and then sorts the > results, which nearly renders the paging meaningless. Yeah. The general rule is that sorting happens after computing the SELECT values --- this is more or less required for cases where the ORDER BY refers to a SELECT-list item. You'd probably have better results by writing a sub-select: SELECT part_id, part_name, (SELECT SUM(amount) FROM part_movements M WHERE P.part_id = M.part_id ) as part_amount FROM (SELECT part_id, part_name FROM parts P WHERE whatever ORDER BY whatever LIMIT n) as P; This will do the part_movements stuff only for rows that make it out of the sub-select. Another approach is to make sure the ORDER BY is always on an indexed column; in cases where the ORDER BY is done by an indexscan instead of a sort, calculation of the unwanted SELECT-list items does not happen. However, this only works as long as LIMIT+OFFSET is fairly small. Lastly, are you on a reasonably current Postgres version (performance complaints about anything older than 8.0 will no longer be accepted with much grace), and are your statistics up to date? The ANALYZE shows rowcount estimates that seem suspiciously far off: -> Seq Scan on scf_stokkart stok (cost=0.00..142622.54 rows=25 width=503) (actual time=4.726..19324.633 rows=4947 loops=1) Filter: (upper((durum)::text) = 'A'::text) This is important because, if the planner realized that the SELECT-list items were going to be evaluated 5000 times not 25, it might well choose a different plan. regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 23 18:06:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E11149DC85C for ; Mon, 23 Jan 2006 18:06:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52303-09 for ; Mon, 23 Jan 2006 18:06:03 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 0F65C9DC83B for ; Mon, 23 Jan 2006 18:06:00 -0400 (AST) Received: from hotmail.com (bay106-dav5.bay106.hotmail.com [65.54.161.77]) by svr4.postgresql.org (Postfix) with ESMTP id A29ED5AF07A for ; Mon, 23 Jan 2006 22:06:02 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 23 Jan 2006 14:06:00 -0800 Message-ID: Received: from 85.105.24.123 by BAY106-DAV5.phx.gbl with DAV; Mon, 23 Jan 2006 22:06:00 +0000 X-Originating-IP: [85.105.24.123] X-Originating-Email: [a_dursun@hotmail.com] X-Sender: a_dursun@hotmail.com MIME-Version: 1.0 Message-Id: <43D55332.000001.03052@SESS> Date: Tue, 24 Jan 2006 00:05:38 +0200 (GTB Standart Saati) Content-Type: Multipart/Alternative; boundary="------------Boundary-00=_E1GKQL80000000000000" X-Mailer: IncrediMail (4001874) From: "Adnan HOTMAIL" To: Subject: unsubscribe X-FID: FLAVOR00-NONE-0000-0000-000000000000 X-Priority: 3 X-OriginalArrivalTime: 23 Jan 2006 22:06:00.0991 (UTC) FILETIME=[320B8AF0:01C62069] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=4.636 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, HTML_IMAGE_ONLY_12=1.639, HTML_MESSAGE=0.001, HTML_SHORT_LINK_IMG_2=0.951, HTML_TAG_EXIST_TBODY=0.126, MSGID_FROM_MTA_HEADER=0] X-Spam-Score: 4.636 X-Spam-Level: **** X-Archive-Number: 200601/416 X-Sequence-Number: 16894 --------------Boundary-00=_E1GKQL80000000000000 Content-Type: Text/Plain; charset="windows-1254" Content-Transfer-Encoding: quoted-printable unsubscribe =0D =20 --------------Boundary-00=_E1GKQL80000000000000 Content-Type: Text/HTML; charset="windows-1254" Content-Transfer-Encoding: quoted-printable
unsubscribe 
 
3D"Add= --------------Boundary-00=_E1GKQL80000000000000-- From pgsql-performance-owner@postgresql.org Tue Jan 24 12:35:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 71A719DCA1F for ; Tue, 24 Jan 2006 12:35:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40766-02 for ; Tue, 24 Jan 2006 12:35:07 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 0D4E49DCA05 for ; Tue, 24 Jan 2006 12:35:07 -0400 (AST) Received: from mail.libertyrms.com (vgateway.libertyrms.info [207.219.45.62]) by svr4.postgresql.org (Postfix) with ESMTP id B19565AF06E for ; Tue, 24 Jan 2006 16:35:06 +0000 (GMT) Received: from dba5.int.libertyrms.com ([10.1.3.44]) by mail.libertyrms.com with esmtp (Exim 4.22) id 1F1R8I-0006pE-Fl for pgsql-performance@postgresql.org; Tue, 24 Jan 2006 11:35:02 -0500 Message-ID: <43D65736.9020905@ca.afilias.info> Date: Tue, 24 Jan 2006 11:35:02 -0500 From: Brad Nicholson User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Investigating IO Saturation Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Mail-From: bnichols@ca.afilias.info X-SA-Exim-Scanned: No; SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.261 required=5 tests=[AWL=0.261] X-Spam-Score: 0.261 X-Spam-Level: X-Archive-Number: 200601/417 X-Sequence-Number: 16895 I'm investigating a potential IO issue. We're running 7.4 on AIX 5.1. During periods of high activity (reads, writes, and vacuums), we are seeing iostat reporting 100% disk usage. I have a feeling that the iostat numbers are misleading. I can make iostat usage jump from less than 10% to greater than 95% by running a single vacuum against a moderate sized table (no noticeable change in the other activity). Do I actually have a problem with IO? Whether I do or not, at what point should I start to be concerned about IO problems? If my understanding is correct, it should be based on the wait time. Here's the output of vmstat during heavy load (reads, writes, several daily vacuums and a nightly pg_dump). Wait times appear to be alright, but my understanding of when to start being concerned about IO starvation is foggy at best. vmstat 5 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------- r b avm fre re pi po fr sr cy in sy cs us sy id wa 2 2 1548418 67130 0 0 0 141 99 0 1295 22784 13128 11 4 71 14 3 3 1548422 66754 0 0 0 2127 2965 0 2836 29981 25091 26 4 39 31 2 3 1548423 66908 0 0 0 2369 3221 0 3130 34725 28424 25 7 38 30 3 5 1548423 67029 0 0 0 2223 3097 0 2722 31885 25929 26 9 33 32 3 3 1548423 67066 0 0 0 2366 3194 0 2824 43546 36226 30 5 35 31 2 4 1548423 67004 0 0 0 2123 3236 0 2662 25756 21841 22 4 39 35 2 4 1548957 66277 0 0 0 1928 10322 0 2941 36340 29906 28 6 34 33 3 5 1549245 66024 0 0 0 2324 14291 0 2872 39413 25615 25 4 34 37 2 6 1549282 66107 0 0 0 1930 11189 0 2832 72062 32311 26 5 32 38 2 4 1549526 65855 0 0 0 2375 9278 0 2822 40368 32156 29 5 37 29 2 3 1548984 66227 0 0 0 1732 5065 0 2825 39240 30788 26 5 40 30 3 4 1549341 66027 0 0 0 2325 6453 0 2790 37567 30509 28 5 37 30 2 4 1549377 65789 0 0 0 1633 2731 0 2648 35533 27395 20 5 39 36 1 5 1549765 65666 0 0 0 2272 3340 0 2792 43002 34090 26 5 29 40 2 3 1549787 65646 0 0 0 1779 2679 0 2596 37446 29184 22 5 37 36 2 5 1548985 66263 0 0 0 2077 3086 0 2778 49579 39940 26 9 35 30 2 4 1548985 66473 0 0 0 2078 3093 0 2682 23274 18460 22 3 41 34 4 3 1548985 66263 0 0 0 2177 3344 0 2734 43029 35536 29 5 38 28 1 4 1548985 66491 0 0 0 1978 3215 0 2739 28291 22672 23 4 41 32 3 3 1548985 66422 0 0 0 1732 2469 0 2852 71865 30850 28 5 38 29 -- Brad Nicholson 416-673-4106 Database Administrator, Afilias Canada Corp. From pgsql-performance-owner@postgresql.org Tue Jan 24 12:41:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 88D649DC8E1 for ; Tue, 24 Jan 2006 12:41:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41583-04 for ; Tue, 24 Jan 2006 12:41:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by postgresql.org (Postfix) with ESMTP id 509009DC841 for ; Tue, 24 Jan 2006 12:41:14 -0400 (AST) Received: from [192.168.1.101] (or-67-76-146-141.sta.sprint-hsd.net [67.76.146.141]) (authenticated bits=0) by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id k0OGVRFo029978; Tue, 24 Jan 2006 08:31:28 -0800 Message-ID: <43D658D3.5070808@commandprompt.com> Date: Tue, 24 Jan 2006 08:41:55 -0800 From: "Joshua D. Drake" User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Brad Nicholson CC: pgsql-performance@postgresql.org Subject: Re: Investigating IO Saturation References: <43D65736.9020905@ca.afilias.info> In-Reply-To: <43D65736.9020905@ca.afilias.info> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]); Tue, 24 Jan 2006 08:31:28 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.078 required=5 tests=[AWL=0.078] X-Spam-Score: 0.078 X-Spam-Level: X-Archive-Number: 200601/418 X-Sequence-Number: 16896 Brad Nicholson wrote: > I'm investigating a potential IO issue. We're running 7.4 on AIX > 5.1. During periods of high activity (reads, writes, and vacuums), we > are seeing iostat reporting 100% disk usage. I have a feeling that > the iostat numbers are misleading. I can make iostat usage jump from > less than 10% to greater than 95% by running a single vacuum against a > moderate sized table (no noticeable change in the other activity). > Well that isn't surprising. Vacuum is brutal especially on 7.4 as that is pre background writer. What type of IO do you have available (RAID, SCSI?) > Do I actually have a problem with IO? Whether I do or not, at what > point should I start to be concerned about IO problems? If my > understanding is correct, it should be based on the wait time. Here's > the output of vmstat during heavy load (reads, writes, several daily > vacuums and a nightly pg_dump). Wait times appear to be alright, but > my understanding of when to start being concerned about IO starvation > is foggy at best. > > vmstat 5 > kthr memory page faults cpu > ----- ----------- ------------------------ ------------ ----------- > r b avm fre re pi po fr sr cy in sy cs us sy id wa > 2 2 1548418 67130 0 0 0 141 99 0 1295 22784 13128 11 4 71 14 > 3 3 1548422 66754 0 0 0 2127 2965 0 2836 29981 25091 26 4 39 31 > 2 3 1548423 66908 0 0 0 2369 3221 0 3130 34725 28424 25 7 38 30 > 3 5 1548423 67029 0 0 0 2223 3097 0 2722 31885 25929 26 9 33 32 > 3 3 1548423 67066 0 0 0 2366 3194 0 2824 43546 36226 30 5 35 31 > 2 4 1548423 67004 0 0 0 2123 3236 0 2662 25756 21841 22 4 39 35 > 2 4 1548957 66277 0 0 0 1928 10322 0 2941 36340 29906 28 6 > 34 33 > 3 5 1549245 66024 0 0 0 2324 14291 0 2872 39413 25615 25 4 > 34 37 > 2 6 1549282 66107 0 0 0 1930 11189 0 2832 72062 32311 26 5 > 32 38 > 2 4 1549526 65855 0 0 0 2375 9278 0 2822 40368 32156 29 5 37 29 > 2 3 1548984 66227 0 0 0 1732 5065 0 2825 39240 30788 26 5 40 30 > 3 4 1549341 66027 0 0 0 2325 6453 0 2790 37567 30509 28 5 37 30 > 2 4 1549377 65789 0 0 0 1633 2731 0 2648 35533 27395 20 5 39 36 > 1 5 1549765 65666 0 0 0 2272 3340 0 2792 43002 34090 26 5 29 40 > 2 3 1549787 65646 0 0 0 1779 2679 0 2596 37446 29184 22 5 37 36 > 2 5 1548985 66263 0 0 0 2077 3086 0 2778 49579 39940 26 9 35 30 > 2 4 1548985 66473 0 0 0 2078 3093 0 2682 23274 18460 22 3 41 34 > 4 3 1548985 66263 0 0 0 2177 3344 0 2734 43029 35536 29 5 38 28 > 1 4 1548985 66491 0 0 0 1978 3215 0 2739 28291 22672 23 4 41 32 > 3 3 1548985 66422 0 0 0 1732 2469 0 2852 71865 30850 28 5 38 29 > From pgsql-performance-owner@postgresql.org Tue Jan 24 13:04:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7B4E19DCA23 for ; Tue, 24 Jan 2006 13:03:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43833-10 for ; Tue, 24 Jan 2006 13:03:58 -0400 (AST) X-Greylist: delayed 00:28:53.921475 by SQLgrey- Received: from mail.libertyrms.com (vgateway.libertyrms.info [207.219.45.62]) by postgresql.org (Postfix) with ESMTP id 4899A9DCA0F for ; Tue, 24 Jan 2006 13:03:56 -0400 (AST) Received: from dba5.int.libertyrms.com ([10.1.3.44]) by mail.libertyrms.com with esmtp (Exim 4.22) id 1F1RaG-0008Bj-EA; Tue, 24 Jan 2006 12:03:56 -0500 Message-ID: <43D65DFC.2040107@ca.afilias.info> Date: Tue, 24 Jan 2006 12:03:56 -0500 From: Brad Nicholson User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Joshua D. Drake" CC: pgsql-performance@postgresql.org Subject: Re: Investigating IO Saturation References: <43D65736.9020905@ca.afilias.info> <43D658D3.5070808@commandprompt.com> In-Reply-To: <43D658D3.5070808@commandprompt.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Mail-From: bnichols@ca.afilias.info X-SA-Exim-Scanned: No; SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.641 required=5 tests=[AWL=-0.172, INFO_TLD=0.813] X-Spam-Score: 0.641 X-Spam-Level: X-Archive-Number: 200601/419 X-Sequence-Number: 16897 Joshua D. Drake wrote: > Brad Nicholson wrote: > >> I'm investigating a potential IO issue. We're running 7.4 on AIX >> 5.1. During periods of high activity (reads, writes, and vacuums), >> we are seeing iostat reporting 100% disk usage. I have a feeling >> that the iostat numbers are misleading. I can make iostat usage jump >> from less than 10% to greater than 95% by running a single vacuum >> against a moderate sized table (no noticeable change in the other >> activity). >> > Well that isn't surprising. Vacuum is brutal especially on 7.4 as that > is pre background writer. What type of IO do you have available (RAID, > SCSI?) > Data LUN is RAID 10, wal LUN is RAID 1. -- Brad Nicholson 416-673-4106 bnichols@ca.afilias.info Database Administrator, Afilias Canada Corp. From pgsql-performance-owner@postgresql.org Tue Jan 24 13:07:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A53279DC86E for ; Tue, 24 Jan 2006 13:07:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44584-09 for ; Tue, 24 Jan 2006 13:07:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 51AE59DC9FB for ; Tue, 24 Jan 2006 13:07:38 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0OH7cR7019964; Tue, 24 Jan 2006 12:07:38 -0500 (EST) To: Brad Nicholson cc: pgsql-performance@postgresql.org Subject: Re: Investigating IO Saturation In-reply-to: <43D65736.9020905@ca.afilias.info> References: <43D65736.9020905@ca.afilias.info> Comments: In-reply-to Brad Nicholson message dated "Tue, 24 Jan 2006 11:35:02 -0500" Date: Tue, 24 Jan 2006 12:07:38 -0500 Message-ID: <19963.1138122458@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.504 required=5 tests=[AWL=-0.309, INFO_TLD=0.813] X-Spam-Score: 0.504 X-Spam-Level: X-Archive-Number: 200601/420 X-Sequence-Number: 16898 Brad Nicholson writes: > I'm investigating a potential IO issue. We're running 7.4 on AIX 5.1. > During periods of high activity (reads, writes, and vacuums), we are > seeing iostat reporting 100% disk usage. I have a feeling that the > iostat numbers are misleading. I can make iostat usage jump from less > than 10% to greater than 95% by running a single vacuum against a > moderate sized table (no noticeable change in the other activity). That's not particularly surprising, and I see no reason to think that iostat is lying to you. More recent versions of PG include parameters that you can use to "throttle" vacuum's I/O demand ... but unthrottled, it's definitely an I/O hog. The vmstat numbers suggest that vacuum is not completely killing you, but you could probably get some improvement in foreground query performance by throttling it back. There are other good reasons to consider an update, anyway. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 24 13:08:43 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0C5B99DCA3E for ; Tue, 24 Jan 2006 13:08:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47866-02 for ; Tue, 24 Jan 2006 13:08:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by postgresql.org (Postfix) with ESMTP id E52319DCA18 for ; Tue, 24 Jan 2006 13:08:40 -0400 (AST) Received: from [192.168.1.101] (or-67-76-146-141.sta.sprint-hsd.net [67.76.146.141]) (authenticated bits=0) by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id k0OGwoU1003434; Tue, 24 Jan 2006 08:58:54 -0800 Message-ID: <43D65F3E.9040107@commandprompt.com> Date: Tue, 24 Jan 2006 09:09:18 -0800 From: "Joshua D. Drake" User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: Brad Nicholson CC: pgsql-performance@postgresql.org Subject: Re: Investigating IO Saturation References: <43D65736.9020905@ca.afilias.info> <43D658D3.5070808@commandprompt.com> <43D65DFC.2040107@ca.afilias.info> In-Reply-To: <43D65DFC.2040107@ca.afilias.info> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]); Tue, 24 Jan 2006 08:58:55 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.078 required=5 tests=[AWL=0.078] X-Spam-Score: 0.078 X-Spam-Level: X-Archive-Number: 200601/421 X-Sequence-Number: 16899 Brad Nicholson wrote: > Joshua D. Drake wrote: > >> Brad Nicholson wrote: >> >>> I'm investigating a potential IO issue. We're running 7.4 on AIX >>> 5.1. During periods of high activity (reads, writes, and vacuums), >>> we are seeing iostat reporting 100% disk usage. I have a feeling >>> that the iostat numbers are misleading. I can make iostat usage >>> jump from less than 10% to greater than 95% by running a single >>> vacuum against a moderate sized table (no noticeable change in the >>> other activity). >>> >> Well that isn't surprising. Vacuum is brutal especially on 7.4 as >> that is pre background writer. What type of IO do you have available >> (RAID, SCSI?) >> > Data LUN is RAID 10, wal LUN is RAID 1. How many disks? > > From pgsql-performance-owner@postgresql.org Sun Jan 29 23:29:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4C1709DC841 for ; Tue, 24 Jan 2006 14:40:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66829-02 for ; Tue, 24 Jan 2006 14:40:27 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 3CA429DC829 for ; Tue, 24 Jan 2006 14:40:26 -0400 (AST) Received: from mail.androme.com (mail.androme.com [62.58.96.145]) by svr4.postgresql.org (Postfix) with ESMTP id CC9A35AF08F for ; Tue, 24 Jan 2006 18:40:26 +0000 (GMT) Received: from [192.168.10.56] ([192.168.10.56]) by mail.androme.com (8.12.10/8.12.10) with ESMTP id k0OIeMeG009953 for ; Tue, 24 Jan 2006 19:40:22 +0100 Message-ID: <43D67496.2020203@androme.es> Date: Tue, 24 Jan 2006 19:40:22 +0100 From: Arnau Rebassa Villalonga Reply-To: arnaulist@andromeiberica.com User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Where is my bottleneck? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/470 X-Sequence-Number: 16948 Hi all, I have a performance problem and I don't know where is my bottleneck. I have postgresql 7.4.2 running on a debian server with kernel 2.4.26-1-686-smp with two Xeon(TM) at 2.80GHz and 4GB of RAM and a RAID 5 made with SCSI disks. Maybe its not the latest hardware but I think it's not that bad. My problem is that the general performance is not good enough and I don't know where is the bottleneck. It could be because the queries are not optimized as they should be, but I also think it can be a postgresql configuration problem or hardware problem (HDs not beeing fast enough, not enough RAM, ... ) The configuration of postgresql is the default, I tried to tune the postgresql.conf and the results where disappointing, so I left again the default values. When I do top I get: top - 19:10:24 up 452 days, 15:48, 4 users, load average: 6.31, 6.27, 6.52 Tasks: 91 total, 8 running, 83 sleeping, 0 stopped, 0 zombie Cpu(s): 24.8% user, 15.4% system, 0.0% nice, 59.9% idle Mem: 3748956k total, 3629252k used, 119704k free, 57604k buffers Swap: 2097136k total, 14188k used, 2082948k free, 3303620k cached Most of the time the idle value is even higher than 60%. I know it's a problem with a very big scope, but could you give me a hint about where I should look to? Thank you very much -- Arnau From pgsql-performance-owner@postgresql.org Tue Jan 24 16:04:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 415AA9DC801 for ; Tue, 24 Jan 2006 16:04:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26823-04 for ; Tue, 24 Jan 2006 16:04:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 987C89DCA3E for ; Tue, 24 Jan 2006 16:04:04 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 346B330EFE; Tue, 24 Jan 2006 21:04:05 +0100 (MET) From: Chris Browne X-Newsgroups: pgsql.performance Subject: Re: Investigating IO Saturation Date: Tue, 24 Jan 2006 14:43:59 -0500 Organization: cbbrowne Computing Inc Lines: 48 Message-ID: <60oe21o1hc.fsf@dba2.int.libertyrms.com> References: <43D65736.9020905@ca.afilias.info> <19963.1138122458@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4.18 (linux) Cancel-Lock: sha1:HREWQX3IVisBXBNXOqR/J5Bh9gU= To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.649 required=5 tests=[AWL=-0.164, INFO_TLD=0.813] X-Spam-Score: 0.649 X-Spam-Level: X-Archive-Number: 200601/422 X-Sequence-Number: 16900 tgl@sss.pgh.pa.us (Tom Lane) writes: > Brad Nicholson writes: >> I'm investigating a potential IO issue. We're running 7.4 on AIX 5.1. >> During periods of high activity (reads, writes, and vacuums), we are >> seeing iostat reporting 100% disk usage. I have a feeling that the >> iostat numbers are misleading. I can make iostat usage jump from less >> than 10% to greater than 95% by running a single vacuum against a >> moderate sized table (no noticeable change in the other activity). > > That's not particularly surprising, and I see no reason to think that > iostat is lying to you. > > More recent versions of PG include parameters that you can use to > "throttle" vacuum's I/O demand ... but unthrottled, it's definitely > an I/O hog. I believe it's 7.4 where the cost-based vacuum parameters entered in, so that would, in principle, already be an option. [rummaging around...] Hmm.... There was a patch for 7.4, but it's only "standard" as of 8.0... > The vmstat numbers suggest that vacuum is not completely killing you, > but you could probably get some improvement in foreground query > performance by throttling it back. There are other good reasons to > consider an update, anyway. I'd have reservations about "throttling it back" because that would lead to VACUUMs running, and holding transactions open, for 6 hours instead of 2. That is consistent with benchmarking; there was a report of the default policy cutting I/O load by ~80% at the cost of vacuums taking 3x as long to complete. The "real" answer is to move to 8.x, where VACUUM doesn't chew up shared memory cache as it does in 7.4 and earlier. But in the interim, we need to make sure we tilt over the right windmills, or something of the sort :-). -- output = reverse("gro.gultn" "@" "enworbbc") http://www3.sympatico.ca/cbbrowne/linuxxian.html "Women and cats will do as they please, and men and dogs should relax and get used to the idea." -- Robert A. Heinlein From pgsql-performance-owner@postgresql.org Tue Jan 24 17:00:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 89D9A9DC801 for ; Tue, 24 Jan 2006 17:00:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36312-05 for ; Tue, 24 Jan 2006 17:00:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id EF32B9DC81A for ; Tue, 24 Jan 2006 17:00:38 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:36197 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1F1VHJ-000BtZ-Vd for pgsql-performance@postgresql.org; Tue, 24 Jan 2006 16:00:38 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 279194069; Tue, 24 Jan 2006 16:00:37 -0500 (EST) Date: Tue, 24 Jan 2006 16:00:37 -0500 From: Andrew Sullivan To: pgsql-performance@postgresql.org Subject: Re: Investigating IO Saturation Message-ID: <20060124210037.GF7199@phlogiston.dyndns.org> References: <43D65736.9020905@ca.afilias.info> <19963.1138122458@sss.pgh.pa.us> <60oe21o1hc.fsf@dba2.int.libertyrms.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <60oe21o1hc.fsf@dba2.int.libertyrms.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.079 required=5 tests=[AWL=0.079] X-Spam-Score: 0.079 X-Spam-Level: X-Archive-Number: 200601/423 X-Sequence-Number: 16901 On Tue, Jan 24, 2006 at 02:43:59PM -0500, Chris Browne wrote: > I believe it's 7.4 where the cost-based vacuum parameters entered in, > so that would, in principle, already be an option. > > [rummaging around...] > > Hmm.... There was a patch for 7.4, but it's only "standard" as of > 8.0... And it doesn't work very well without changes to buffering. You need both pieces to get it to work. A -- Andrew Sullivan | ajs@crankycanuck.ca In the future this spectacle of the middle classes shocking the avant- garde will probably become the textbook definition of Postmodernism. --Brad Holland From pgsql-performance-owner@postgresql.org Tue Jan 24 19:19:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CBAC79DC87D for ; Tue, 24 Jan 2006 19:19:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64494-10 for ; Tue, 24 Jan 2006 19:19:41 -0400 (AST) X-Greylist: delayed 00:05:40.035327 by SQLgrey- Received: from ntserver-4d22.4dvision.net (mail.4dv.net [66.7.169.9]) by postgresql.org (Postfix) with ESMTP id 0E21E9DC85B for ; Tue, 24 Jan 2006 19:19:36 -0400 (AST) Received: from RideWinter2 (unverified [66.7.168.78]) by ntserver-4d22.4dvision.net (Vircom SMTPRS 4.2.425.16) with SMTP id for ; Tue, 24 Jan 2006 16:11:51 -0700 X-Modus-BlackList: dan@centrifugesolutions.com=OK From: "Daniel Gish" To: Subject: Inconsistant query plan Date: Tue, 24 Jan 2006 16:15:57 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/424 X-Sequence-Number: 16902 Hi, We are running Postgresql 8.1, and getting dramatically inconsistant results after running VACUUM ANALYZE. Sometimes after analyzing the database, the query planner chooses a very efficient plan (15 rows, 4.744 ms), and sometimes a terrible one (24 rows, 3536.995 ms). Here's the abbreviated query: SELECT * FROM t1 INNER JOIN (t2 INNER JOIN (t3 INNER JOIN t4 ON t3.gid = t4.gid) ON t3.gid = t2.gid) ON t2.eid = t1.eid WHERE ... In the efficient plan, t2 is joined to t3 & t4 before being joined to t1. The inefficient plan joins t1 to t2 before joining to the other tables. We've experimented with different settings, such as shared_buffers & max_fsm_pages, to no avail. Anybody have a suggestion for getting the efficient plan to execute consistantly? If you'd like to see the actual query & query plans let me know. Best Regards, Dan From pgsql-performance-owner@postgresql.org Tue Jan 24 19:30:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 61EBC9DC85B for ; Tue, 24 Jan 2006 19:30:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65866-10 for ; Tue, 24 Jan 2006 19:30:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 4B22B9DC832 for ; Tue, 24 Jan 2006 19:30:15 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 24 Jan 2006 23:30:18 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 24 Jan 2006 17:30:18 -0600 Subject: Re: Inconsistant query plan From: Scott Marlowe To: Daniel Gish Cc: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1138145417.25819.39.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 24 Jan 2006 17:30:18 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.131 required=5 tests=[AWL=0.130, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.131 X-Spam-Level: X-Archive-Number: 200601/425 X-Sequence-Number: 16903 On Tue, 2006-01-24 at 17:15, Daniel Gish wrote: > Hi, > We are running Postgresql 8.1, and getting dramatically inconsistant results > after running VACUUM ANALYZE. Sometimes after analyzing the database, the > query planner chooses a very efficient plan (15 rows, 4.744 ms), and > sometimes a terrible one (24 rows, 3536.995 ms). Here's the abbreviated > query: > > SELECT * FROM t1 INNER JOIN (t2 INNER JOIN (t3 INNER JOIN t4 ON t3.gid = > t4.gid) ON t3.gid = t2.gid) ON t2.eid = t1.eid WHERE ... > > In the efficient plan, t2 is joined to t3 & t4 before being joined to t1. > The inefficient plan joins t1 to t2 before joining to the other tables. > > We've experimented with different settings, such as shared_buffers & > max_fsm_pages, to no avail. Anybody have a suggestion for getting the > efficient plan to execute consistantly? If you'd like to see the actual > query & query plans let me know. Have you adjusted the stats target for that column? See \h alter table in psql for the syntax for that. Then run analyze again. From pgsql-performance-owner@postgresql.org Tue Jan 24 19:59:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CA1029DCAB8 for ; Tue, 24 Jan 2006 19:59:06 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70097-08 for ; Tue, 24 Jan 2006 19:59:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 321BC9DCAAD for ; Tue, 24 Jan 2006 19:59:04 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0ONww2T027499 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 Jan 2006 16:59:00 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0ONwvWJ092458; Tue, 24 Jan 2006 16:58:57 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0ONwvlr092457; Tue, 24 Jan 2006 16:58:57 -0700 (MST) (envelope-from mfuhr) Date: Tue, 24 Jan 2006 16:58:57 -0700 From: Michael Fuhr To: Daniel Gish Cc: pgsql-performance@postgresql.org Subject: Re: Inconsistant query plan Message-ID: <20060124235857.GA92385@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.108 required=5 tests=[AWL=0.108] X-Spam-Score: 0.108 X-Spam-Level: X-Archive-Number: 200601/426 X-Sequence-Number: 16904 On Tue, Jan 24, 2006 at 04:15:57PM -0700, Daniel Gish wrote: > We are running Postgresql 8.1, and getting dramatically inconsistant results > after running VACUUM ANALYZE. Sometimes after analyzing the database, the > query planner chooses a very efficient plan (15 rows, 4.744 ms), and > sometimes a terrible one (24 rows, 3536.995 ms). Here's the abbreviated > query: > > SELECT * FROM t1 INNER JOIN (t2 INNER JOIN (t3 INNER JOIN t4 ON t3.gid = > t4.gid) ON t3.gid = t2.gid) ON t2.eid = t1.eid WHERE ... How abbreviated is that example? Are you actually joining more tables than that? In another recent thread varying plans were attributed to exceeding geqo_threshold: http://archives.postgresql.org/pgsql-performance/2006-01/msg00132.php Does your situation look similar? -- Michael Fuhr From pgsql-performance-owner@postgresql.org Tue Jan 24 21:02:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 75C149DCAE4 for ; Tue, 24 Jan 2006 21:02:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85657-04 for ; Tue, 24 Jan 2006 21:02:13 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ntserver-4d22.4dvision.net (mail.4dv.net [66.7.169.9]) by postgresql.org (Postfix) with ESMTP id B32E19DCA02 for ; Tue, 24 Jan 2006 21:02:07 -0400 (AST) Received: from RideWinter2 (unverified [66.7.168.78]) by ntserver-4d22.4dvision.net (Vircom SMTPRS 4.2.425.16) with SMTP id ; Tue, 24 Jan 2006 18:00:03 -0700 X-Modus-BlackList: dan@centrifugesolutions.com=OK From: "Daniel Gish" To: "Michael Fuhr" Cc: Subject: Re: Inconsistant query plan Date: Tue, 24 Jan 2006 18:04:10 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal In-Reply-To: <20060124235857.GA92385@winnie.fuhr.org> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/427 X-Sequence-Number: 16905 Hi, Thanks for your response. The actual query is below; the joins are only 4 deep. Adjusting the stats target did help, but not dramatically. EFFICIENT PLAN: # explain analyze SELECT ev.eid FROM events ev INNER JOIN (events_join ej INNER JOIN (groups_join gj INNER JOIN groups g ON gj.gid = g.gid) ON ej.gid = gj.gid) ON ev.eid = ej.eid WHERE ev.status > 0 AND ej.type_id = 1 AND g.deleted = 'f' AND g.deactivated != 't' AND ev.type_id >= 0 AND gj.uid=3 AND ev.timestart BETWEEN '01/23/2006'::timestamp AND '02/23/2006'::timestamp + '1 day - 1 minute'; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --------------------------------------- Nested Loop (cost=0.00..8370.41 rows=25 width=4) (actual time=4.510..4.510 rows=0 loops=1) -> Nested Loop (cost=0.00..6124.63 rows=673 width=4) (actual time=0.132..3.116 rows=92 loops=1) -> Nested Loop (cost=0.00..70.95 rows=8 width=8) (actual time=0.080..2.226 rows=19 loops=1) -> Index Scan using groups_join_uid_idx on groups_join gj (cost=0.00..16.27 rows=11 width=4) (actual time=0.019..0.471 rows=196 loops=1) Index Cond: (uid = 3) -> Index Scan using groups_pkey on groups g (cost=0.00..4.96 rows=1 width=4) (actual time=0.005..0.006 rows=0 loops=196) Index Cond: ("outer".gid = g.gid) Filter: ((NOT deleted) AND (deactivated <> true)) -> Index Scan using events_join_gid_idx on events_join ej (cost=0.00..752.45 rows=341 width=8) (actual time=0.010..0.027 rows=5 loops=19) Index Cond: (ej.gid = "outer".gid) Filter: (type_id = 1) -> Index Scan using events_pkey on events ev (cost=0.00..3.32 rows=1 width=4) (actual time=0.012..0.012 rows=0 loops=92) Index Cond: (ev.eid = "outer".eid) Filter: ((status > 0) AND (type_id >= 0) AND (timestart >= '2006-01-23 00:00:00'::timestamp without time zone) AND (timestart <= '2006-02-23 23:59:00'::timestamp without time zone)) Total runtime: 4.744 ms (15 rows) INEFFICIENT PLAN: # explain analyze SELECT ev.eid FROM events ev INNER JOIN (events_join ej INNER JOIN (groups_join gj INNER JOIN groups g ON gj.gid = g.gid) ON ej.gid = g.gid) ON ev.eid = ej.eid WHERE ev.status > 0 AND ej.type_id = 1 AND g.deleted = 'f' AND g.deactivated != 't' AND ev.type_id >= 0 AND gj.uid=3 AND ev.timestart BETWEEN '01/23/2006'::timestamp AND '02/23/2006'::timestamp + '1 day - 1 minute'; QUERY PLAN ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --------------------------------------- Nested Loop (cost=978.19..37161.81 rows=133 width=4) (actual time=2511.676..2511.676 rows=0 loops=1) -> Merge Join (cost=978.19..22854.00 rows=4244 width=4) (actual time=1718.420..2510.128 rows=92 loops=1) Merge Cond: ("outer".gid = "inner".gid) -> Index Scan using events_join_gid_idx on events_join ej (cost=0.00..23452.59 rows=740598 width=8) (actual time=0.014..1532.447 rows=626651 loops=1) Filter: (type_id = 1) -> Sort (cost=978.19..978.47 rows=113 width=8) (actual time=2.371..2.540 rows=101 loops=1) Sort Key: g.gid -> Nested Loop (cost=0.00..974.33 rows=113 width=8) (actual time=0.078..2.305 rows=19 loops=1) -> Index Scan using groups_join_uid_idx on groups_join gj (cost=0.00..182.65 rows=159 width=4) (actual time=0.017..0.485 rows=196 loops=1) Index Cond: (uid = 3) -> Index Scan using groups_pkey on groups g (cost=0.00..4.97 rows=1 width=4) (actual time=0.006..0.006 rows=0 loops=196) Index Cond: ("outer".gid = g.gid) Filter: ((NOT deleted) AND (deactivated <> true)) -> Index Scan using events_pkey on events ev (cost=0.00..3.36 rows=1 width=4) (actual time=0.013..0.013 rows=0 loops=92) Index Cond: (ev.eid = "outer".eid) Filter: ((status > 0) AND (type_id >= 0) AND (timestart >= '2006-01-23 00:00:00'::timestamp without time zone) AND (timestart <= '2006-02-23 23:59:00'::timestamp without time zone)) Total runtime: 2511.920 ms (17 rows) Regards, Dan From pgsql-performance-owner@postgresql.org Wed Jan 25 05:05:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5840E9DC998 for ; Wed, 25 Jan 2006 05:05:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27277-08 for ; Wed, 25 Jan 2006 05:05:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.barettadeit.com (unknown [213.255.109.130]) by postgresql.org (Postfix) with ESMTP id 7A5239DC98D for ; Wed, 25 Jan 2006 05:05:42 -0400 (AST) Received: from [10.0.0.10] (alex.barettalocal.com [10.0.0.10]) by mail.barettadeit.com (Postfix) with ESMTP id 340BF12563; Wed, 25 Jan 2006 10:06:05 +0100 (CET) Message-ID: <43D73F68.3040306@barettadeit.com> Date: Wed, 25 Jan 2006 10:05:44 +0100 From: Alessandro Baretta User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Daniel Gish Cc: Michael Fuhr , pgsql-performance@postgresql.org Subject: Re: Inconsistant query plan References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/428 X-Sequence-Number: 16906 Daniel Gish wrote: > Hi, > Thanks for your response. The actual query is below; the joins are only 4 > deep. Adjusting the stats target did help, but not dramatically. > > QUERY PLAN > ---------------------------------------------------------------------------- > ---------------------------------------------------------------------------- > --------------------------------------- > Nested Loop (cost=978.19..37161.81 rows=133 width=4) (actual > time=2511.676..2511.676 rows=0 loops=1) > -> Merge Join (cost=978.19..22854.00 rows=4244 width=4) (actual > time=1718.420..2510.128 rows=92 loops=1) > ... > -> Nested Loop (cost=0.00..974.33 rows=113 width=8) (actual time=0.078..2.305 rows=19 loops=1) I have a similar problem recently. An importat diagnostic tool for these issues is the pg_stats view. Let me suggest that you post the relevant lines from pg_stats, so that with some help you will be able to discover what data advises the query planner to overestimate the cardinality of some joins and underestimate others. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project From pgsql-performance-owner@postgresql.org Wed Jan 25 08:01:36 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C24BD9DCA31 for ; Wed, 25 Jan 2006 08:01:35 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 60033-06 for ; Wed, 25 Jan 2006 08:01:38 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 905A99DCA29 for ; Wed, 25 Jan 2006 08:01:33 -0400 (AST) Received: from office1.i-free.ru (unknown [81.222.216.82]) by svr4.postgresql.org (Postfix) with ESMTP id 34C785AF196 for ; Wed, 25 Jan 2006 12:01:36 +0000 (GMT) Received: from [192.168.0.250] (helo=deepcore.i-free.ru) by office1.i-free.ru with smtp (Exim 3.36 #1 (Debian)) id 1F1jLB-00065K-00 for ; Wed, 25 Jan 2006 15:01:33 +0300 Date: Wed, 25 Jan 2006 15:01:34 +0300 From: Evgeny Gridasov To: pgsql-performance@postgresql.org Subject: DB responce during DB dump Message-Id: <20060125150134.55589806.eugrid@fpm.kubsu.ru> In-Reply-To: References: X-Mailer: Sylpheed version 2.1.9 (GTK+ 2.6.2; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/429 X-Sequence-Number: 16907 Hi, everybody! I experience problems with backing up one of my Postgresql 8.1.2 installations. The problem is that when I do DB backup, all queries begin to run very slow =( The database only grows in its size (~20Gb today), and the number of transactions increases every month. A year ago such slow down was OK, but today it is unacceptable. I found out that pg_dump dramatically increases hdd I/O and because of this most of all queries begin to run slower. My application using this DB server is time-critical, so any kind of slow down is critical. I've written a perl script to limit pg_dump output bandwidth, a simple traffic shaper, which runs as: pg_dumpall -c -U postgres | limit_bandwidth.pl | bzip2 > pgsql_dump.bz2 The limit_bandwidth.pl script limits pipe output at 4Mb/sec rate, which seems to be ok. Is there any other solution to avoid this problem? -- Evgeny Gridasov Software Engineer I-Free, Russia From pgsql-performance-owner@postgresql.org Wed Jan 25 08:44:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D307C9DCB34 for ; Wed, 25 Jan 2006 08:44:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70189-02 for ; Wed, 25 Jan 2006 08:44:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 6AA069DCAD3 for ; Wed, 25 Jan 2006 08:44:43 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id AB21E4095A5; Wed, 25 Jan 2006 12:44:37 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 9978515EE9; Wed, 25 Jan 2006 12:44:45 +0000 (GMT) Message-ID: <43D772BD.8080809@archonet.com> Date: Wed, 25 Jan 2006 12:44:45 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Evgeny Gridasov Cc: pgsql-performance@postgresql.org Subject: Re: DB responce during DB dump References: <20060125150134.55589806.eugrid@fpm.kubsu.ru> In-Reply-To: <20060125150134.55589806.eugrid@fpm.kubsu.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.093 required=5 tests=[AWL=0.093] X-Spam-Score: 0.093 X-Spam-Level: X-Archive-Number: 200601/430 X-Sequence-Number: 16908 Evgeny Gridasov wrote: > Hi, everybody! > > I experience problems with backing up one of my Postgresql 8.1.2 installations. > The problem is that when I do DB backup, all queries begin to run very slow =( > The database only grows in its size (~20Gb today), and the number of transactions increases every month. > A year ago such slow down was OK, but today it is unacceptable. > > I found out that pg_dump dramatically increases hdd I/O and because of this most of all > queries begin to run slower. My application using this DB server is time-critical, so > any kind of slow down is critical. > > I've written a perl script to limit pg_dump output bandwidth, a simple traffic shaper, > which runs as: pg_dumpall -c -U postgres | limit_bandwidth.pl | bzip2 > pgsql_dump.bz2 > The limit_bandwidth.pl script limits pipe output at 4Mb/sec rate, which seems to be ok. > > Is there any other solution to avoid this problem? That's an interesting solution, and I'd guess people might like to see it posted to the list if it's not too big. Also, there's no reason you have to dump from the same machine, you can do so over the network which should reduce activity a little bit. Basically though, it sounds like you either need more disk I/O or a different approach. Have you looked into using PITR log-shipping or replication (e.g. slony) to have an off-machine backup? -- Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Sun Jan 29 23:29:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 566329DC9FF for ; Wed, 25 Jan 2006 12:09:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08304-07 for ; Wed, 25 Jan 2006 12:09:35 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 923DE9DC9F5 for ; Wed, 25 Jan 2006 12:09:31 -0400 (AST) Received: from a5.edbccf.client.atlantech.net (a5.edbccf.client.atlantech.net [207.188.237.165]) by svr4.postgresql.org (Postfix) with ESMTP id 0E95E5AF180 for ; Wed, 25 Jan 2006 16:09:28 +0000 (GMT) Received: from frack.slipt.net (frack [192.168.1.4]) by a5.edbccf.client.atlantech.net (Fixer) with ESMTP id BFE611CEE1 for ; Wed, 25 Jan 2006 11:09:26 -0500 (EST) From: Jen Sale To: pgsql-performance@postgresql.org Subject: Desperate: View not using indexes (very slow) Date: Wed, 25 Jan 2006 11:09:25 -0500 User-Agent: KMail/1.9 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601251109.25876.js@slipt.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/471 X-Sequence-Number: 16949 We recently segmented a large table into calendar month slices and were going to to replace the original, but we are not getting the results we think it should... Everything is vacuumed, and we are using 8.0.3 on amd64. Anything anyone can suggest would be appreciated, our backs against the wall. => explain select suck_id from sucks_new where suck_id in ( select id as suck_id from saved_cart_items where publish_id='60160b57a1969fa228ae3470fbe7a50a' ); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop IN Join (cost=5311290.80..7124499.86 rows=5472 width=32) Join Filter: ("outer".suck_id = "inner".id) -> Subquery Scan sucks_new (cost=5309907.40..6181642.53 rows=13947762 width=32) -> Unique (cost=5309907.40..6042164.91 rows=13947762 width=212) -> Sort (cost=5309907.40..5344776.81 rows=13947762 width=212) Sort Key: suck_id, sitenum -> Append (cost=0.00..632289.24 rows=13947762 width=212) -> Subquery Scan "*SELECT* 1" (cost=0.00..83767.54 rows=1703577 width=209) -> Seq Scan on sucks_2006_01 (cost=0.00..66731.77 rows=1703577 width=209) -> Subquery Scan "*SELECT* 2" (cost=0.00..93670.20 rows=2081560 width=209) -> Seq Scan on sucks_2005_12 (cost=0.00..72854.60 rows=2081560 width=209) -> Subquery Scan "*SELECT* 3" (cost=0.00..91311.16 rows=2021958 width=210) -> Seq Scan on sucks_2005_11 (cost=0.00..71091.58 rows=2021958 width=210) -> Subquery Scan "*SELECT* 4" (cost=0.00..85510.34 rows=1886417 width=211) -> Seq Scan on sucks_2005_10 (cost=0.00..66646.17 rows=1886417 width=211) -> Subquery Scan "*SELECT* 5" (cost=0.00..74216.38 rows=1642719 width=210) -> Seq Scan on sucks_2005_09 (cost=0.00..57789.19 rows=1642719 width=210) -> Subquery Scan "*SELECT* 6" (cost=0.00..64346.12 rows=1429106 width=209) -> Seq Scan on sucks_2005_08 (cost=0.00..50055.06 rows=1429106 width=209) -> Subquery Scan "*SELECT* 7" (cost=0.00..76449.66 rows=1709283 width=209) -> Seq Scan on sucks_2005_07 (cost=0.00..59356.83 rows=1709283 width=209) -> Subquery Scan "*SELECT* 8" (cost=0.00..63017.84 rows=1473142 width=212) -> Seq Scan on sucks_2005_06 "local" (cost=0.00..48286.42 rows=1473142 width=212) -> Materialize (cost=1383.39..1383.60 rows=20 width=12) -> Seq Scan on saved_cart_items (cost=0.00..1383.38 rows=20 width=12) Filter: (publish_id = '60160b57a1969fa228ae3470fbe7a50a'::bpchar) as opposed to => explain select suck_id from sucks_new where suck_id=7136642; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Subquery Scan sucks_new (cost=46.22..46.72 rows=8 width=32) -> Unique (cost=46.22..46.64 rows=8 width=212) -> Sort (cost=46.22..46.24 rows=8 width=212) Sort Key: suck_id, sitenum -> Append (cost=0.00..46.10 rows=8 width=212) -> Subquery Scan "*SELECT* 1" (cost=0.00..5.64 rows=1 width=209) -> Index Scan using sucks_2006_01_pkey on sucks_2006_01 (cost=0.00..5.63 rows=1 width=209) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 2" (cost=0.00..5.95 rows=1 width=209) -> Index Scan using sucks_2005_12_pkey on sucks_2005_12 (cost=0.00..5.94 rows=1 width=209) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 3" (cost=0.00..5.21 rows=1 width=210) -> Index Scan using sucks_2005_11_pkey on sucks_2005_11 (cost=0.00..5.20 rows=1 width=210) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 4" (cost=0.00..5.67 rows=1 width=211) -> Index Scan using sucks_2005_10_pkey on sucks_2005_10 (cost=0.00..5.66 rows=1 width=211) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 5" (cost=0.00..5.78 rows=1 width=210) -> Index Scan using sucks_2005_09_pkey on sucks_2005_09 (cost=0.00..5.77 rows=1 width=210) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 6" (cost=0.00..6.01 rows=1 width=209) -> Index Scan using sucks_2005_08_pkey on sucks_2005_08 (cost=0.00..6.00 rows=1 width=209) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 7" (cost=0.00..5.87 rows=1 width=209) -> Index Scan using sucks_2005_07_pkey on sucks_2005_07 (cost=0.00..5.86 rows=1 width=209) Index Cond: (suck_id = 7136642::numeric) -> Subquery Scan "*SELECT* 8" (cost=0.00..5.98 rows=1 width=212) -> Index Scan using sucks_2005_06_pkey on sucks_2005_06 "local" (cost=0.00..5.97 rows=1 width=212) Index Cond: (suck_id = 7136642::numeric) (29 rows) can someone please tell me what we did wrong? TIA From pgsql-performance-owner@postgresql.org Wed Jan 25 12:24:37 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A9B399DC997 for ; Wed, 25 Jan 2006 12:24:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11054-09 for ; Wed, 25 Jan 2006 12:24:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4A4989DC8A9 for ; Wed, 25 Jan 2006 12:24:33 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0PGLwa5001460; Wed, 25 Jan 2006 11:21:58 -0500 (EST) To: Richard Huxton cc: Evgeny Gridasov , pgsql-performance@postgresql.org Subject: Re: DB responce during DB dump In-reply-to: <43D772BD.8080809@archonet.com> References: <20060125150134.55589806.eugrid@fpm.kubsu.ru> <43D772BD.8080809@archonet.com> Comments: In-reply-to Richard Huxton message dated "Wed, 25 Jan 2006 12:44:45 +0000" Date: Wed, 25 Jan 2006 11:21:58 -0500 Message-ID: <1459.1138206118@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.098 required=5 tests=[AWL=0.098] X-Spam-Score: 0.098 X-Spam-Level: X-Archive-Number: 200601/431 X-Sequence-Number: 16909 Richard Huxton writes: > Evgeny Gridasov wrote: >> I've written a perl script to limit pg_dump output bandwidth, >> ... >> Is there any other solution to avoid this problem? > That's an interesting solution, and I'd guess people might like to see > it posted to the list if it's not too big. Years ago there was some experimentation with dump-rate throttling logic inside pg_dump itself --- there's still a comment about it in pg_dump.c. The experiment didn't seem very successful, which is why it never got to be a permanent feature. I'm curious to know why this perl script is doing a better job than we were able to do inside pg_dump. regards, tom lane From pgsql-performance-owner@postgresql.org Wed Jan 25 12:43:12 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 94B399DC984 for ; Wed, 25 Jan 2006 12:43:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18974-02 for ; Wed, 25 Jan 2006 12:43:09 -0400 (AST) X-Greylist: delayed 04:41:34.005449 by SQLgrey- Received: from office1.i-free.ru (unknown [81.222.216.82]) by postgresql.org (Postfix) with ESMTP id 2AF5E9DC98B for ; Wed, 25 Jan 2006 12:43:09 -0400 (AST) Received: from [192.168.0.250] (helo=deepcore.i-free.ru) by office1.i-free.ru with smtp (Exim 3.36 #1 (Debian)) id 1F1njg-0002vl-00 for ; Wed, 25 Jan 2006 19:43:08 +0300 Date: Wed, 25 Jan 2006 19:43:09 +0300 From: Evgeny Gridasov To: pgsql-performance@postgresql.org Subject: Re: DB responce during DB dump Message-Id: <20060125194309.8cb6e5c8.eugrid@fpm.kubsu.ru> In-Reply-To: <1459.1138206118@sss.pgh.pa.us> References: <20060125150134.55589806.eugrid@fpm.kubsu.ru> <43D772BD.8080809@archonet.com> <1459.1138206118@sss.pgh.pa.us> X-Mailer: Sylpheed version 2.1.9 (GTK+ 2.6.2; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.048 required=5 tests=[AWL=0.048] X-Spam-Score: 0.048 X-Spam-Level: X-Archive-Number: 200601/432 X-Sequence-Number: 16910 All I was trying to achieve is to limit I/O rate done by pg_dump. The script is a very simple pipe rate limitter and nothing more: it reads input, but outputs data no more than at rate specified. I guess it helps because even if pg_dump outputs data at 20 mb/sec, the script won't be able to read it at rate higher than output rate. Pipe buffer is not infinitive, so pg_dump output rate and hard disk reads become almost equal the input rate of my perl script. On Wed, 25 Jan 2006 11:21:58 -0500 Tom Lane wrote: > Years ago there was some experimentation with dump-rate throttling logic > inside pg_dump itself --- there's still a comment about it in pg_dump.c. > The experiment didn't seem very successful, which is why it never got to > be a permanent feature. I'm curious to know why this perl script is > doing a better job than we were able to do inside pg_dump. -- Evgeny Gridasov Software Engineer I-Free, Russia From pgsql-performance-owner@postgresql.org Wed Jan 25 12:47:30 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7F1B39DCA2E for ; Wed, 25 Jan 2006 12:47:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19424-06 for ; Wed, 25 Jan 2006 12:47:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from office1.i-free.ru (unknown [81.222.216.82]) by postgresql.org (Postfix) with ESMTP id 3AFB99DCA39 for ; Wed, 25 Jan 2006 12:47:26 -0400 (AST) Received: from [192.168.0.250] (helo=deepcore.i-free.ru) by office1.i-free.ru with smtp (Exim 3.36 #1 (Debian)) id 1F1nnq-0003a6-00 for ; Wed, 25 Jan 2006 19:47:26 +0300 Date: Wed, 25 Jan 2006 19:47:27 +0300 From: Evgeny Gridasov To: pgsql-performance@postgresql.org Subject: Re: DB responce during DB dump Message-Id: <20060125194727.685144d7.eugrid@fpm.kubsu.ru> In-Reply-To: <43D772BD.8080809@archonet.com> References: <20060125150134.55589806.eugrid@fpm.kubsu.ru> <43D772BD.8080809@archonet.com> X-Mailer: Sylpheed version 2.1.9 (GTK+ 2.6.2; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.068 required=5 tests=[AWL=0.068] X-Spam-Score: 0.068 X-Spam-Level: X-Archive-Number: 200601/433 X-Sequence-Number: 16911 Ok, It's VERY simple =) here: http://deepcore.i-free.ru/simple_shaper.pl I could dump it to a spare machine, but I don't have one. Current DB server is 2xXEON / 4GbRAM / RAID10 (4 SCSI HDD). Performance is excellent, except during backups. I wanted to set up some kind of replication but it's useless - I don't have a spare machine now, may be in future... On Wed, 25 Jan 2006 12:44:45 +0000 Richard Huxton wrote: > > That's an interesting solution, and I'd guess people might like to see > it posted to the list if it's not too big. > > Also, there's no reason you have to dump from the same machine, you can > do so over the network which should reduce activity a little bit. > > Basically though, it sounds like you either need more disk I/O or a > different approach. > > Have you looked into using PITR log-shipping or replication (e.g. slony) > to have an off-machine backup? -- Evgeny Gridasov Software Engineer I-Free, Russia From pgsql-performance-owner@postgresql.org Wed Jan 25 21:46:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 218E39DCB97 for ; Wed, 25 Jan 2006 21:46:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22893-08 for ; Wed, 25 Jan 2006 21:46:07 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from brmea-mail-2.sun.com (brmea-mail-2.Sun.COM [192.18.98.43]) by postgresql.org (Postfix) with ESMTP id C64FB9DCBC5 for ; Wed, 25 Jan 2006 21:46:01 -0400 (AST) Received: from phys-d3-ha21sca-2 ([129.145.155.165]) by brmea-mail-2.sun.com (8.12.10/8.12.9) with ESMTP id k0Q1k58u029255 for ; Wed, 25 Jan 2006 18:46:06 -0700 (MST) Received: from conversion-daemon.ha21sca-mail1.sfbay.sun.com by ha21sca-mail1.sfbay.sun.com (iPlanet Messaging Server 5.2 HotFix 1.24 (built Dec 19 2003)) id <0ITO00H01FLP1M@ha21sca-mail1.sfbay.sun.com> (original mail from Robert.Lor@Sun.COM) for pgsql-performance@postgresql.org; Wed, 25 Jan 2006 17:46:56 -0800 (PST) Received: from [10.0.1.49] (vpn-129-150-29-236.SFBay.Sun.COM [129.150.29.236]) by ha21sca-mail1.sfbay.sun.com (iPlanet Messaging Server 5.2 HotFix 1.24 (built Dec 19 2003)) with ESMTP id <0ITO00IKXFM7XJ@ha21sca-mail1.sfbay.sun.com> for pgsql-performance@postgresql.org; Wed, 25 Jan 2006 17:46:55 -0800 (PST) Date: Wed, 25 Jan 2006 17:46:12 -0800 From: Robert Lor Subject: PostgreSQL Solaris packages now in beta To: pgsql-performance@postgresql.org Message-id: <43D829E4.1060503@sun.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (Macintosh/20050716) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.041 required=5 tests=[AWL=0.040, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.041 X-Spam-Level: X-Archive-Number: 200601/434 X-Sequence-Number: 16912 With big thanks to Josh Berkus and Devrim Gunduz, I'm happy to announce that Sun has just released a Solaris distribution of PostgreSQL 8.1.2 with ready-to-install packages for both Sparc and x86. These packages are currently in Beta, and we expect to FCS in 2 -3 weeks. The packages, along with an install guide, are available for download at http://pgfoundry.org/projects/solarispackages/ We have tightly integrated PostgreSQL with Solaris in a manner similar to the Linux distributions available on postgresql.org. In fact, the directory structures are identical. Starting with Solaris 10 Update 2, PostgreSQL will be distributed with every copy of Solaris, via download and physical media. We welcome any and all feedback on this PostgreSQL Solaris distribution. Please subscribe to the solarispackages-general@pgfoundry.org mailing list to give us feedback: http://pgfoundry.org/mail/?group_id=1000063 BTW, I'm a senior engineer at Sun Microsystems, recently working with the PostgreSQL community (namely Josh Berkus, Devrim Gunduz, and Gavin Sherry) on the Solaris Packages Project at PgFoundry, PostgreSQL performance optimization on Solaris, and leveraging Solaris 10 capabilities (e.g. DTrace) specifically for PostgreSQL. I'll be posting a Solaris performance tuning guide in a few weeks. Regards, Robert Lor From pgsql-performance-owner@postgresql.org Thu Jan 26 06:06:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 00E309DC880 for ; Thu, 26 Jan 2006 06:06:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47883-10 for ; Thu, 26 Jan 2006 06:06:25 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.204]) by postgresql.org (Postfix) with ESMTP id F22759DC871 for ; Thu, 26 Jan 2006 06:06:21 -0400 (AST) Received: by xproxy.gmail.com with SMTP id s14so201247wxc for ; Thu, 26 Jan 2006 02:06:24 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=UzUV/ghGH8p8iARcqV3zjcJY0HJBBNe9irFk7iHtV/zGdKfZo45IEEXMiOeybD1jftdtPzNesOcusBgkSvVJvQi6UWffQdC92ZxThrnerckn+AWXippjXBUtkDYqKQadH9Clm58jHX7Fyu4rxriPzky4p+VU153tpxgN9xiS9gg= Received: by 10.70.17.13 with SMTP id 13mr1965932wxq; Thu, 26 Jan 2006 02:06:24 -0800 (PST) Received: by 10.70.37.19 with HTTP; Thu, 26 Jan 2006 02:06:24 -0800 (PST) Message-ID: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> Date: Thu, 26 Jan 2006 11:06:24 +0100 From: Paul Mackay To: pgsql-performance@postgresql.org Subject: Physical column size MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_37670_2165376.1138269984348" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.946 required=5 tests=[HTML_10_20=0.945, HTML_MESSAGE=0.001] X-Spam-Score: 0.946 X-Spam-Level: X-Archive-Number: 200601/435 X-Sequence-Number: 16913 ------=_Part_37670_2165376.1138269984348 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, I've created a table like this : CREATE TABLE tmp_A ( c "char", i int4 ); And another one CREATE TABLE tmp_B ( i int4, ii int4 ); I then inerted a bit more than 19 million rows in each table (exactly the same number of rows in each). The end result is that the physical size on disk used by table tmp_A is exactly the same as table tmp_B (as revealed by the pg_relation_size function) ! Given that a "char" field is supposed to be 1 byte in size and = a int4 4 bytes, shouldn't the tmp_A use a smaller disk space ? Or is it that any value, whatever the type, requires at least 4 bytes to be stored ? Thanks, Paul ------=_Part_37670_2165376.1138269984348 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi,

I've created a table like this :
CREATE TABLE tmp_A (
c &= quot;char",
i int4
);

And another one
CREATE TABLE tm= p_B (
i int4,
ii int4
);

I then inerted a bit more than 19 = million rows in each table (exactly the same number of rows in each).=20

The end result is that the physical size on disk used by table tmp_= A is exactly the same as table tmp_B (as revealed by the pg_relation_size f= unction) ! Given that a "char" field is supposed to be 1 byte in = size and a int4 4 bytes, shouldn't the tmp_A use a smaller disk space ? Or = is it that any value, whatever the type, requires at least 4 bytes to be st= ored ?=20

Thanks,
Paul
------=_Part_37670_2165376.1138269984348-- From pgsql-performance-owner@postgresql.org Thu Jan 26 06:22:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2AE819DCB79 for ; Thu, 26 Jan 2006 06:22:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56694-04 for ; Thu, 26 Jan 2006 06:22:06 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id D832A9DCB61 for ; Thu, 26 Jan 2006 06:22:02 -0400 (AST) Received: from relay.icomedias.com (relay.icomedias.com [62.99.232.66]) by svr4.postgresql.org (Postfix) with ESMTP id 6D98B5AF1AC for ; Thu, 26 Jan 2006 10:22:05 +0000 (GMT) Received: from loki.icomedias.com ([10.192.17.128]) by relay.icomedias.com (8.13.4/8.13.4) with ESMTP id k0QALwsk023423; Thu, 26 Jan 2006 11:21:58 +0100 From: Mario Weilguni To: pgsql-performance@postgresql.org Subject: Re: Physical column size Date: Thu, 26 Jan 2006 12:22:03 +0100 User-Agent: KMail/1.9 Cc: Paul Mackay References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> In-Reply-To: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601261222.03526.mweilguni@sime.com> X-Scanned-By: MIMEDefang 2.54 on 10.192.64.200 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.107 required=5 tests=[AWL=0.107] X-Spam-Score: 0.107 X-Spam-Level: X-Archive-Number: 200601/436 X-Sequence-Number: 16914 Am Donnerstag, 26. Januar 2006 11:06 schrieb Paul Mackay: > Hi, > > I've created a table like this : > CREATE TABLE tmp_A ( > c "char", > i int4 > ); > > And another one > CREATE TABLE tmp_B ( > i int4, > ii int4 > ); > > I then inerted a bit more than 19 million rows in each table (exactly the > same number of rows in each). > > The end result is that the physical size on disk used by table tmp_A is > exactly the same as table tmp_B (as revealed by the pg_relation_size > function) ! Given that a "char" field is supposed to be 1 byte in size and > a int4 4 bytes, shouldn't the tmp_A use a smaller disk space ? Or is it > that any value, whatever the type, requires at least 4 bytes to be stored ? I think this is caused by alignment. From pgsql-performance-owner@postgresql.org Thu Jan 26 10:56:29 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A602D9DC801 for ; Thu, 26 Jan 2006 10:56:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11387-05 for ; Thu, 26 Jan 2006 10:56:32 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from brmea-mail-4.sun.com (brmea-mail-4.Sun.COM [192.18.98.36]) by postgresql.org (Postfix) with ESMTP id A61BC9DC800 for ; Thu, 26 Jan 2006 10:56:25 -0400 (AST) Received: from fe-amer-04.sun.com ([192.18.108.178]) by brmea-mail-4.sun.com (8.12.10/8.12.9) with ESMTP id k0QEuUuf026463 for ; Thu, 26 Jan 2006 07:56:30 -0700 (MST) Received: from conversion-daemon.mail-amer.sun.com by mail-amer.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) id <0ITP00J01G1PX100@mail-amer.sun.com> (original mail from J.K.Shah@Sun.COM) for pgsql-performance@postgresql.org; Thu, 26 Jan 2006 07:56:30 -0700 (MST) Received: from [129.148.168.2] by mail-amer.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPSA id <0ITP00EAZG64SEV1@mail-amer.sun.com> for pgsql-performance@postgresql.org; Thu, 26 Jan 2006 07:56:30 -0700 (MST) Date: Thu, 26 Jan 2006 09:56:14 -0500 From: "Jignesh K. Shah" Subject: Re: PostgreSQL Solaris packages now in beta In-reply-to: <43D829E4.1060503@sun.com> To: Robert Lor Cc: pgsql-performance@postgresql.org Message-id: <43D8E30E.6030401@sun.com> Organization: Sun Microsystems MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en References: <43D829E4.1060503@sun.com> User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050322) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.120, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/437 X-Sequence-Number: 16915 For people installing PostgreSQL on Solaris with the new packaget, it will show a greatly improved experience to get PostgreSQL up and running which was quite a inhibitor in terms of "Love at First Sight". This will now help people familiar with Solaris have a great first impression of PostgreSQL and hence lower the barrier of entry to PostgreSQL. With more than 3.7 million downloads of Solaris 10 already, now PostgreSQL have accesss to probably a 3.7 million incremental user-base of these relatively "New" PostgreSQL users. Regards, Jignesh Robert Lor wrote: > > With big thanks to Josh Berkus and Devrim Gunduz, I'm happy to > announce that Sun has just released a Solaris distribution of > PostgreSQL 8.1.2 with ready-to-install packages for both Sparc and > x86. These packages are currently in Beta, and we expect to FCS in 2 > -3 weeks. The packages, along with an install guide, are available > for download at http://pgfoundry.org/projects/solarispackages/ > > We have tightly integrated PostgreSQL with Solaris in a manner similar > to the Linux distributions available on postgresql.org. In fact, the > directory structures are identical. Starting with Solaris 10 Update > 2, PostgreSQL will be distributed with every copy of Solaris, via > download and physical media. > > We welcome any and all feedback on this PostgreSQL Solaris > distribution. Please subscribe to the > solarispackages-general@pgfoundry.org mailing list to give us > feedback: http://pgfoundry.org/mail/?group_id=1000063 > > BTW, I'm a senior engineer at Sun Microsystems, recently working with > the PostgreSQL community (namely Josh Berkus, Devrim Gunduz, and Gavin > Sherry) on the Solaris Packages Project at PgFoundry, PostgreSQL > performance optimization on Solaris, and leveraging Solaris 10 > capabilities (e.g. DTrace) specifically for PostgreSQL. I'll be > posting a Solaris performance tuning guide in a few weeks. > > Regards, > Robert Lor > > > > ---------------------------(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 From pgsql-performance-owner@postgresql.org Thu Jan 26 11:43:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 73FDD9DC811 for ; Thu, 26 Jan 2006 11:43:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23436-02 for ; Thu, 26 Jan 2006 11:43:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 374FB9DC800 for ; Thu, 26 Jan 2006 11:43:12 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0QFXBAn012852 for ; Thu, 26 Jan 2006 10:33:11 -0500 From: J@Planeti.Biz Message-ID: <005d01c6228f$3772dca0$0d310d05@fatchubby> To: References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> Subject: Query optimization with X Y JOIN Date: Thu, 26 Jan 2006 10:43:12 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_005A_01C62265.4E685720" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.06 required=5 tests=[AWL=0.509, HTML_MESSAGE=0.001, NO_REAL_NAME=0.55] X-Spam-Score: 1.06 X-Spam-Level: * X-Archive-Number: 200601/438 X-Sequence-Number: 16916 This is a multi-part message in MIME format. ------=_NextPart_000_005A_01C62265.4E685720 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hey guys, how u been. This is quite a newbie question, but I need to ask = it. I'm trying to wrap my mind around the syntax of join and why and = when to use it. I understand the concept of making a query go faster by = creating indexes, but it seems that when I want data from multiple = tables that link together the query goes slow. The slow is typically due = to expensive nested loops. The reason is, all my brain understands is: select tablea.data tableb.data tablec.data from tablea tableb tablec where tablea.pri_key =3D tableb.foreign_key AND tableb.pri_key =3D tablec.foreign_key AND... From what I read, it seems you can use inner/outer right/left join on = (bla) but when I see syntax examples I see that sometimes tables are = omitted from the 'from' section of the query and other times, no. = Sometimes I see that the join commands are nested and others, no and = sometimes I see joins syntax that only applies to one table. From what I = understand join can be used to tell the database the fast way to murge = table data together to get results by specifiying the table that has the = primary keys and the table that has the foreign keys. I've read all through the postgres docs on this command and I'm still = left lost. Can someone please explain to me in simple language how to = use these commands or provide me with a link. I need it to live right = now. Thanx. ------=_NextPart_000_005A_01C62265.4E685720 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hey guys, how u been. This is quite a = newbie=20 question, but I need to ask it. I'm trying to wrap my mind around the = syntax of=20 join and why and when to use it. I understand the concept of making a = query go=20 faster by creating indexes, but it seems that when I want data from = multiple=20 tables that link together the query goes slow. The slow is typically due = to=20 expensive nested loops. The reason is, all my brain understands = is:
 
select
    = tablea.data
    = tableb.data
    = tablec.data
from
    tablea
    tableb
    tablec
where
    tablea.pri_key =3D=20 tableb.foreign_key AND
    tableb.pri_key =3D=20 tablec.foreign_key AND...
 
From what I read, it seems you can use = inner/outer=20 right/left join on (bla) but when I see syntax examples I see that = sometimes=20 tables are omitted from the 'from' section of the query and other times, = no.=20 Sometimes I see that the join commands are nested and others, no and = sometimes I=20 see joins syntax that only applies to one table. From what I understand = join can=20 be used to tell the database the fast way to murge table data together = to get=20 results by specifiying the table that has the primary keys and the table = that=20 has the foreign keys.
 
I've read all through the postgres docs = on this=20 command and I'm still left lost. Can someone please explain to me in = simple=20 language how to use these commands or provide me with a link. I need it = to live=20 right now. Thanx.
 
    =
------=_NextPart_000_005A_01C62265.4E685720-- From pgsql-performance-owner@postgresql.org Thu Jan 26 11:50:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C1A389DC811 for ; Thu, 26 Jan 2006 11:50:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21950-08 for ; Thu, 26 Jan 2006 11:50:32 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id B540E9DC809 for ; Thu, 26 Jan 2006 11:50:25 -0400 (AST) Received: from dc1.storediq.com (66-194-80-196.gen.twtelecom.net [66.194.80.196]) by svr4.postgresql.org (Postfix) with ESMTP id 8AFA85AF0A6 for ; Thu, 26 Jan 2006 15:50:31 +0000 (GMT) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C62290.3B86CD20" Subject: Incorrect Total runtime Reported by Explain Analyze!? Date: Thu, 26 Jan 2006 09:50:29 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Incorrect Total runtime Reported by Explain Analyze!? Thread-Index: AcYikEpL+ShCAH03QKK6jT3nwCEF2g== From: "Jozsef Szalay" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.327 required=5 tests=[HTML_MESSAGE=0.001, PLING_QUERY=0.326] X-Spam-Score: 0.327 X-Spam-Level: X-Archive-Number: 200601/439 X-Sequence-Number: 16917 This is a multi-part message in MIME format. ------_=_NextPart_001_01C62290.3B86CD20 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi All, =20 I have seen it on occasion that the total runtime reported by explain analyze was much higher than the actual time the query needed to complete. The differences in my case ranged between 20-120 seconds. I'm just curious if anyone else has experienced this and whether there is something that I can do to convince explain analyze to report the execution time of the query itself rather than the time of its own execution. Engine version is 8.1.1. =20 Thanks for the help! =20 ------_=_NextPart_001_01C62290.3B86CD20 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi All,

 

I have seen it on occasion that the total runtime = reported by explain analyze was much higher than the actual time the query needed = to complete. The differences in my case ranged between 20-120 seconds. = I’m just curious if anyone else has experienced this and whether there is = something that I can do to convince explain analyze to report the execution time = of the query itself rather than the time of its own execution. Engine version is = 8.1.1.

 

Thanks for the help!

 

------_=_NextPart_001_01C62290.3B86CD20-- From pgsql-performance-owner@postgresql.org Thu Jan 26 12:17:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D145C9DCA05 for ; Thu, 26 Jan 2006 12:17:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46966-02 for ; Thu, 26 Jan 2006 12:17:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net [68.15.5.150]) by postgresql.org (Postfix) with ESMTP id 188549DCA00 for ; Thu, 26 Jan 2006 12:17:20 -0400 (AST) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k0QFIjpL032252 for ; Thu, 26 Jan 2006 07:18:45 -0800 Message-ID: <43D8F4FD.4040703@modgraph-usa.com> Date: Thu, 26 Jan 2006 08:12:45 -0800 From: "Craig A. James" User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Query optimization with X Y JOIN References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> In-Reply-To: <005d01c6228f$3772dca0$0d310d05@fatchubby> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.634 required=5 tests=[AWL=-0.535, BIZ_TLD=1.169] X-Spam-Score: 0.634 X-Spam-Level: X-Archive-Number: 200601/440 X-Sequence-Number: 16918 First, this isn't really the right place to ask -- this forum is about performance, not SQL syntax. Second, this isn't a question anyone can answer in a reasonable length of time. What you're asking for usually is taught in a class on relational database theory, which is typically a semester or two in college. If you really need a crash course, dig around on the web for terms like "SQL Tutorial". Good luck, Craig J@Planeti.Biz wrote: > Hey guys, how u been. This is quite a newbie question, but I need to ask > it. I'm trying to wrap my mind around the syntax of join and why and > when to use it. I understand the concept of making a query go faster by > creating indexes, but it seems that when I want data from multiple > tables that link together the query goes slow. The slow is typically due > to expensive nested loops. The reason is, all my brain understands is: > > select > tablea.data > tableb.data > tablec.data > from > tablea > tableb > tablec > where > tablea.pri_key = tableb.foreign_key AND > tableb.pri_key = tablec.foreign_key AND... > > From what I read, it seems you can use inner/outer right/left join on > (bla) but when I see syntax examples I see that sometimes tables are > omitted from the 'from' section of the query and other times, no. > Sometimes I see that the join commands are nested and others, no and > sometimes I see joins syntax that only applies to one table. From what I > understand join can be used to tell the database the fast way to murge > table data together to get results by specifiying the table that has the > primary keys and the table that has the foreign keys. > > I've read all through the postgres docs on this command and I'm still > left lost. Can someone please explain to me in simple language how to > use these commands or provide me with a link. I need it to live right > now. Thanx. > > From pgsql-performance-owner@postgresql.org Thu Jan 26 12:25:18 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 04CCA9DC9E5 for ; Thu, 26 Jan 2006 12:25:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48002-04 for ; Thu, 26 Jan 2006 12:25:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 2B76D9DC9C1 for ; Thu, 26 Jan 2006 12:25:13 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0QGFBAn014590 for ; Thu, 26 Jan 2006 11:15:11 -0500 From: J@Planeti.Biz Message-ID: <008001c62295$156b8fc0$0d310d05@fatchubby> To: References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> <43D8F4FD.4040703@modgraph-usa.com> Subject: Re: Query optimization with X Y JOIN Date: Thu, 26 Jan 2006 11:25:12 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.588 required=5 tests=[AWL=-0.131, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.588 X-Spam-Level: * X-Archive-Number: 200601/441 X-Sequence-Number: 16919 If I want my database to go faster, due to X then I would think that the issue is about performance. I wasn't aware of a paticular constraint on X. I have more that a rudementary understanding of what's going on here, I was just hoping that someone could shed some light on the basic principal of this JOIN command and its syntax. Most people I ask, don't give me straight answers and what I have already read on the web is not very helpful thus far. ----- Original Message ----- From: "Craig A. James" To: Sent: Thursday, January 26, 2006 11:12 AM Subject: Re: [PERFORM] Query optimization with X Y JOIN > First, this isn't really the right place to ask -- this forum is about > performance, not SQL syntax. > > Second, this isn't a question anyone can answer in a reasonable length of > time. What you're asking for usually is taught in a class on relational > database theory, which is typically a semester or two in college. > > If you really need a crash course, dig around on the web for terms like > "SQL Tutorial". > > Good luck, > Craig > > > J@Planeti.Biz wrote: >> Hey guys, how u been. This is quite a newbie question, but I need to ask >> it. I'm trying to wrap my mind around the syntax of join and why and when >> to use it. I understand the concept of making a query go faster by >> creating indexes, but it seems that when I want data from multiple tables >> that link together the query goes slow. The slow is typically due to >> expensive nested loops. The reason is, all my brain understands is: >> select >> tablea.data >> tableb.data >> tablec.data >> from >> tablea >> tableb >> tablec >> where >> tablea.pri_key = tableb.foreign_key AND >> tableb.pri_key = tablec.foreign_key AND... >> From what I read, it seems you can use inner/outer right/left join on >> (bla) but when I see syntax examples I see that sometimes tables are >> omitted from the 'from' section of the query and other times, no. >> Sometimes I see that the join commands are nested and others, no and >> sometimes I see joins syntax that only applies to one table. From what I >> understand join can be used to tell the database the fast way to murge >> table data together to get results by specifiying the table that has the >> primary keys and the table that has the foreign keys. >> I've read all through the postgres docs on this command and I'm still >> left lost. Can someone please explain to me in simple language how to use >> these commands or provide me with a link. I need it to live right now. >> Thanx. >> > > ---------------------------(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 > From pgsql-sql-owner@postgresql.org Thu Jan 26 12:33:39 2006 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3C5509DC9E7 for ; Thu, 26 Jan 2006 12:33:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50759-01 for ; Thu, 26 Jan 2006 12:33:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.203]) by postgresql.org (Postfix) with ESMTP id 0DF419DC9D1 for ; Thu, 26 Jan 2006 12:33:34 -0400 (AST) Received: by wproxy.gmail.com with SMTP id 57so370523wri for ; Thu, 26 Jan 2006 08:33:34 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=lTh1Pbb0swSWzto/ysGm6f0kip5bqOlSYD3pXYmUC87mkxB/xhneLzoFz5kmyqv4ITcweqgbIOLL4pLUy6eP7bCGn0J4vPtgaON8jDnI/7bmfZ6aVsPIV7iB+WU+x+XV0W2kDSphUP6baHo8k0VTasDUa6UZAjdKBzSw9uubtYE= Received: by 10.54.69.14 with SMTP id r14mr2600776wra; Thu, 26 Jan 2006 08:33:34 -0800 (PST) Received: by 10.54.93.8 with HTTP; Thu, 26 Jan 2006 08:33:34 -0800 (PST) Message-ID: Date: Thu, 26 Jan 2006 11:33:34 -0500 From: Jaime Casanova To: "J@planeti.biz" Subject: Re: [PERFORM] Query optimization with X Y JOIN Cc: pgsql-sql@postgresql.org In-Reply-To: <008001c62295$156b8fc0$0d310d05@fatchubby> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> <43D8F4FD.4040703@modgraph-usa.com> <008001c62295$156b8fc0$0d310d05@fatchubby> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.677 required=5 tests=[AWL=-0.492, BIZ_TLD=1.169] X-Spam-Score: 0.677 X-Spam-Level: X-Archive-Number: 200601/186 X-Sequence-Number: 23975 On 1/26/06, J@planeti.biz wrote: > If I want my database to go faster, due to X then I would think that the > issue is about performance. I wasn't aware of a paticular constraint on X= . > > I have more that a rudementary understanding of what's going on here, I w= as > just hoping that someone could shed some light on the basic principal of > this JOIN command and its syntax. Most people I ask, don't give me straig= ht > answers and what I have already read on the web is not very helpful thus > far. http://www.postgresql.org/docs/current/static/sql-select.html -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;) From pgsql-performance-owner@postgresql.org Thu Jan 26 12:33:10 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EA5C99DC87E for ; Thu, 26 Jan 2006 12:33:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47905-09 for ; Thu, 26 Jan 2006 12:33:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from hosting.commandprompt.com (128.commandprompt.com [207.173.200.128]) by postgresql.org (Postfix) with ESMTP id 31C939DC835 for ; Thu, 26 Jan 2006 12:33:06 -0400 (AST) Received: from [192.168.1.100] (or-67-76-146-141.sta.sprint-hsd.net [67.76.146.141]) (authenticated bits=0) by hosting.commandprompt.com (8.13.4/8.13.4) with ESMTP id k0QGN9ww030026; Thu, 26 Jan 2006 08:23:12 -0800 Message-ID: <43D8FA03.304@commandprompt.com> Date: Thu, 26 Jan 2006 08:34:11 -0800 From: "Joshua D. Drake" User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: J@Planeti.Biz CC: pgsql-performance@postgresql.org Subject: Re: Query optimization with X Y JOIN References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> <43D8F4FD.4040703@modgraph-usa.com> <008001c62295$156b8fc0$0d310d05@fatchubby> In-Reply-To: <008001c62295$156b8fc0$0d310d05@fatchubby> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (hosting.commandprompt.com [192.168.1.101]); Thu, 26 Jan 2006 08:23:12 -0800 (PST) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.663 required=5 tests=[AWL=-0.506, BIZ_TLD=1.169] X-Spam-Score: 0.663 X-Spam-Level: X-Archive-Number: 200601/442 X-Sequence-Number: 16920 J@Planeti.Biz wrote: > If I want my database to go faster, due to X then I would think that > the issue is about performance. I wasn't aware of a paticular > constraint on X. > > I have more that a rudementary understanding of what's going on here, > I was just hoping that someone could shed some light on the basic > principal of this JOIN command and its syntax. Most people I ask, > don't give me straight answers and what I have already read on the web > is not very helpful thus far. What you are looking for is here: http://sqlzoo.net/ It is an excellent website that discusses in depth but at a tutorial style level how and what SQL is and how to use it. Including JOINS. FYI, a JOIN is basically a FROM with an integrated WHERE clause. That is a very simplified description and isn't 100% accurate but it is close. I strongly suggest the website I mentioned above as it will resolve your question. Joshua D. Drake -- The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564 PostgreSQL Replication, Consulting, Custom Development, 24x7 support Managed Services, Shared and Dedicated Hosting Co-Authors: PLphp, PLperl - http://www.commandprompt.com/ From pgsql-performance-owner@postgresql.org Thu Jan 26 12:35:49 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8983E9DCA00 for ; Thu, 26 Jan 2006 12:35:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49855-08 for ; Thu, 26 Jan 2006 12:35:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id DA7E49DC809 for ; Thu, 26 Jan 2006 12:35:45 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Thu, 26 Jan 2006 16:35:43 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 26 Jan 2006 10:35:43 -0600 Subject: Re: Incorrect Total runtime Reported by Explain Analyze!? From: Scott Marlowe To: Jozsef Szalay Cc: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-Id: <1138293343.22740.5.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 26 Jan 2006 10:35:43 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.295 required=5 tests=[AWL=-0.032, PLING_QUERY=0.326, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.295 X-Spam-Level: X-Archive-Number: 200601/443 X-Sequence-Number: 16921 On Thu, 2006-01-26 at 09:50, Jozsef Szalay wrote: > Hi All, >=20 > =20 >=20 > I have seen it on occasion that the total runtime reported by explain > analyze was much higher than the actual time the query needed to > complete. The differences in my case ranged between 20-120 seconds. > I=E2=80=99m just curious if anyone else has experienced this and whether = there > is something that I can do to convince explain analyze to report the > execution time of the query itself rather than the time of its own > execution. Engine version is 8.1.1. I've seen this problem before in 7.4 and 8.0 as well. From pgsql-performance-owner@postgresql.org Thu Jan 26 12:47:59 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DFE8D9DC9D1 for ; Thu, 26 Jan 2006 12:47:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50926-05 for ; Thu, 26 Jan 2006 12:47:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id EB4969DC9C1 for ; Thu, 26 Jan 2006 12:47:55 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 0873440AE94; Thu, 26 Jan 2006 16:47:42 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 99D9E11F6F; Thu, 26 Jan 2006 16:47:53 +0000 (GMT) Message-ID: <43D8FD39.8000408@archonet.com> Date: Thu, 26 Jan 2006 16:47:53 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: J@Planeti.Biz Cc: pgsql-performance@postgresql.org Subject: Re: Query optimization with X Y JOIN References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> <43D8F4FD.4040703@modgraph-usa.com> <008001c62295$156b8fc0$0d310d05@fatchubby> In-Reply-To: <008001c62295$156b8fc0$0d310d05@fatchubby> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.683 required=5 tests=[AWL=-0.486, BIZ_TLD=1.169] X-Spam-Score: 0.683 X-Spam-Level: X-Archive-Number: 200601/444 X-Sequence-Number: 16922 J@Planeti.Biz wrote: > If I want my database to go faster, due to X then I would think that the > issue is about performance. I wasn't aware of a paticular constraint on X. You haven't asked a performance question yet though. > I have more that a rudementary understanding of what's going on here, I > was just hoping that someone could shed some light on the basic > principal of this JOIN command and its syntax. Most people I ask, don't > give me straight answers and what I have already read on the web is not > very helpful thus far. OK - firstly it's not a JOIN command. It's a SELECT query that happens to join (in your example) three tables together. The syntax is specified in the SQL reference section of the manuals, and I don't think it's different from the standard SQL spec here. A query that joins two or more tables (be they real base-tables, views or sub-query result-sets) produces the product of both. Normally you don't want this so you apply constraints to that join (table_a.col1 = table_b.col2). In some cases you want all the rows from one side of a join, whether or not you get a match on the other side of the join. This is called an outer join and results in NULLs for all the columns on the "outside" of the join. A left-join returns all rows from the table on the left of the join, a right-join from the table on the right of it. When planning a join, the planner will try to estimate how many matches it will see on each side, taking into account any extra constraints (you might want only some of the rows in table_a anyway). It then decides whether to use any indexes on the relevant column(s). Now, if you think the planner is making a mistake we'll need to see the output of EXPLAIN ANALYSE for the query and will want to know that you've vacuumed and analysed the tables in question. Does that help at all? -- Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Thu Jan 26 12:50:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D1BBD9DC80E for ; Thu, 26 Jan 2006 12:50:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53906-02 for ; Thu, 26 Jan 2006 12:50:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 282AF9DC809 for ; Thu, 26 Jan 2006 12:50:02 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 8A1AE40BAF7; Thu, 26 Jan 2006 16:49:49 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 46F7F11F6F; Thu, 26 Jan 2006 16:50:00 +0000 (GMT) Message-ID: <43D8FDB7.10905@archonet.com> Date: Thu, 26 Jan 2006 16:49:59 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Jozsef Szalay Cc: pgsql-performance@postgresql.org Subject: Re: Incorrect Total runtime Reported by Explain Analyze!? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.267 required=5 tests=[AWL=-0.059, PLING_QUERY=0.326] X-Spam-Score: 0.267 X-Spam-Level: X-Archive-Number: 200601/445 X-Sequence-Number: 16923 Jozsef Szalay wrote: > > I have seen it on occasion that the total runtime reported by explain > analyze was much higher than the actual time the query needed to > complete. The differences in my case ranged between 20-120 seconds. I'm > just curious if anyone else has experienced this and whether there is > something that I can do to convince explain analyze to report the > execution time of the query itself rather than the time of its own > execution. Engine version is 8.1.1. I think it's down to all the gettime() calls that have to be made to measure how long each stage of the query takes. In some cases these can take a substantial part of the overall query time. I seem to recall one of the BSDs was particularly bad in this respect a couple of years ago. Does that sound like your problem? -- Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Thu Jan 26 13:13:38 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7B6E19DC835 for ; Thu, 26 Jan 2006 13:13:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55089-10 for ; Thu, 26 Jan 2006 13:13:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 1D46F9DC809 for ; Thu, 26 Jan 2006 13:13:34 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0QH3VAn016899 for ; Thu, 26 Jan 2006 12:03:32 -0500 From: J@Planeti.Biz Message-ID: <009a01c6229b$d67c6670$0d310d05@fatchubby> To: References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> <43D8F4FD.4040703@modgraph-usa.com> <008001c62295$156b8fc0$0d310d05@fatchubby> <43D8FD39.8000408@archonet.com> Subject: Re: Query optimization with X Y JOIN Date: Thu, 26 Jan 2006 12:13:33 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.62 required=5 tests=[AWL=-0.099, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.62 X-Spam-Level: * X-Archive-Number: 200601/446 X-Sequence-Number: 16924 Yes, that helps a great deal. Thank you so much. ----- Original Message ----- From: "Richard Huxton" To: Cc: Sent: Thursday, January 26, 2006 11:47 AM Subject: Re: [PERFORM] Query optimization with X Y JOIN > J@Planeti.Biz wrote: >> If I want my database to go faster, due to X then I would think that the >> issue is about performance. I wasn't aware of a paticular constraint on >> X. > > You haven't asked a performance question yet though. > >> I have more that a rudementary understanding of what's going on here, I >> was just hoping that someone could shed some light on the basic principal >> of this JOIN command and its syntax. Most people I ask, don't give me >> straight answers and what I have already read on the web is not very >> helpful thus far. > > OK - firstly it's not a JOIN command. It's a SELECT query that happens to > join (in your example) three tables together. The syntax is specified in > the SQL reference section of the manuals, and I don't think it's different > from the standard SQL spec here. > > A query that joins two or more tables (be they real base-tables, views or > sub-query result-sets) produces the product of both. Normally you don't > want this so you apply constraints to that join (table_a.col1 = > table_b.col2). > > In some cases you want all the rows from one side of a join, whether or > not you get a match on the other side of the join. This is called an outer > join and results in NULLs for all the columns on the "outside" of the > join. A left-join returns all rows from the table on the left of the join, > a right-join from the table on the right of it. > > When planning a join, the planner will try to estimate how many matches it > will see on each side, taking into account any extra constraints (you > might want only some of the rows in table_a anyway). It then decides > whether to use any indexes on the relevant column(s). > > Now, if you think the planner is making a mistake we'll need to see the > output of EXPLAIN ANALYSE for the query and will want to know that you've > vacuumed and analysed the tables in question. > > Does that help at all? > -- > Richard Huxton > Archonet Ltd > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster > From pgsql-performance-owner@postgresql.org Thu Jan 26 13:35:28 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1F4989DC9C1 for ; Thu, 26 Jan 2006 13:35:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61061-06 for ; Thu, 26 Jan 2006 13:35:26 -0400 (AST) X-Greylist: delayed 01:44:55.570362 by SQLgrey- Received: from dc1.storediq.com (66-194-80-196.gen.twtelecom.net [66.194.80.196]) by postgresql.org (Postfix) with ESMTP id 836229DC9C6 for ; Thu, 26 Jan 2006 13:35:25 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: Incorrect Total runtime Reported by Explain Analyze!? Date: Thu, 26 Jan 2006 11:35:25 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Incorrect Total runtime Reported by Explain Analyze!? Thread-Index: AcYimI1ubX+5EvLDQkOkGDJFoW4h9QABGxTA From: "Jozsef Szalay" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.446 required=5 tests=[AWL=0.120, PLING_QUERY=0.326] X-Spam-Score: 0.446 X-Spam-Level: X-Archive-Number: 200601/447 X-Sequence-Number: 16925 It might be. I'm running on Fedora Linux kernel 2.6.5-1.358smp, GCC 3.3.3, glibc-2.3.3-27 -----Original Message----- From: Richard Huxton [mailto:dev@archonet.com]=20 Sent: Thursday, January 26, 2006 10:50 AM To: Jozsef Szalay Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] Incorrect Total runtime Reported by Explain Analyze!? Jozsef Szalay wrote: >=20 > I have seen it on occasion that the total runtime reported by explain > analyze was much higher than the actual time the query needed to > complete. The differences in my case ranged between 20-120 seconds. I'm > just curious if anyone else has experienced this and whether there is > something that I can do to convince explain analyze to report the > execution time of the query itself rather than the time of its own > execution. Engine version is 8.1.1. I think it's down to all the gettime() calls that have to be made to=20 measure how long each stage of the query takes. In some cases these can=20 take a substantial part of the overall query time. I seem to recall one=20 of the BSDs was particularly bad in this respect a couple of years ago.=20 Does that sound like your problem? --=20 Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Thu Jan 26 13:57:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4FF429DC835 for ; Thu, 26 Jan 2006 13:57:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67758-03 for ; Thu, 26 Jan 2006 13:57:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 2CA319DC861 for ; Thu, 26 Jan 2006 13:57:29 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k0QHvOVN030090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Jan 2006 10:57:26 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k0QHvNSe083311; Thu, 26 Jan 2006 10:57:23 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k0QHvNfx083310; Thu, 26 Jan 2006 10:57:23 -0700 (MST) (envelope-from mfuhr) Date: Thu, 26 Jan 2006 10:57:23 -0700 From: Michael Fuhr To: Richard Huxton Cc: Jozsef Szalay , pgsql-performance@postgresql.org Subject: Re: Incorrect Total runtime Reported by Explain Analyze!? Message-ID: <20060126175723.GA83137@winnie.fuhr.org> References: <43D8FDB7.10905@archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D8FDB7.10905@archonet.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.274 required=5 tests=[AWL=-0.052, PLING_QUERY=0.326] X-Spam-Score: 0.274 X-Spam-Level: X-Archive-Number: 200601/448 X-Sequence-Number: 16926 On Thu, Jan 26, 2006 at 04:49:59PM +0000, Richard Huxton wrote: > Jozsef Szalay wrote: > >I have seen it on occasion that the total runtime reported by explain > >analyze was much higher than the actual time the query needed to > >complete. The differences in my case ranged between 20-120 seconds. I'm > >just curious if anyone else has experienced this and whether there is > >something that I can do to convince explain analyze to report the > >execution time of the query itself rather than the time of its own > >execution. Engine version is 8.1.1. > > I think it's down to all the gettime() calls that have to be made to > measure how long each stage of the query takes. In some cases these can > take a substantial part of the overall query time. Another possibility is that the total query time was indeed that long because the query was blocked waiting for a lock. For example: T1: BEGIN; T2: BEGIN; T1: SELECT * FROM foo WHERE id = 1 FOR UPDATE; T2: EXPLAIN ANALYZE UPDATE foo SET x = x + 1 WHERE id = 1; T1: (do something for a long time) T1: COMMIT; When T2's EXPLAIN ANALYZE finally returns it'll show something like this: test=> EXPLAIN ANALYZE UPDATE foo SET x = x + 1 WHERE id = 1; QUERY PLAN --------------------------------------------------------------------------------------------------------------- Index Scan using foo_pkey on foo (cost=0.00..3.92 rows=1 width=14) (actual time=0.123..0.138 rows=1 loops=1) Index Cond: (id = 1) Total runtime: 31926.304 ms (3 rows) SELECT queries can be blocked by operations that take an Access Exclusive lock, such as CLUSTER, VACUUM FULL, or REINDEX. Have you ever examined pg_locks during one of these queries to look for ungranted locks? If this weren't 8.1 I'd ask if you had any triggers (including foreign key constraints), whose execution time EXPLAIN ANALYZE doesn't show in earlier versions. For example: 8.1.2: test=> EXPLAIN ANALYZE DELETE FROM foo WHERE id = 1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Index Scan using foo_pkey on foo (cost=0.00..3.92 rows=1 width=6) (actual time=0.136..0.154 rows=1 loops=1) Index Cond: (id = 1) Trigger for constraint bar_fooid_fkey: time=1538.054 calls=1 Total runtime: 1539.732 ms (4 rows) 8.0.6: test=> EXPLAIN ANALYZE DELETE FROM foo WHERE id = 1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Index Scan using foo_pkey on foo (cost=0.00..3.92 rows=1 width=6) (actual time=0.124..0.147 rows=1 loops=1) Index Cond: (id = 1) Total runtime: 1746.173 ms (3 rows) -- Michael Fuhr From pgsql-performance-owner@postgresql.org Thu Jan 26 13:59:52 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 404379DC9CC for ; Thu, 26 Jan 2006 13:59:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67934-04 for ; Thu, 26 Jan 2006 13:59:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 1707C9DC861 for ; Thu, 26 Jan 2006 13:59:49 -0400 (AST) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Thu, 26 Jan 2006 17:59:49 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 26 Jan 2006 11:59:50 -0600 Subject: Re: Incorrect Total runtime Reported by Explain Analyze!? From: Scott Marlowe To: Michael Fuhr Cc: Richard Huxton , Jozsef Szalay , pgsql-performance@postgresql.org In-Reply-To: <20060126175723.GA83137@winnie.fuhr.org> References: <43D8FDB7.10905@archonet.com> <20060126175723.GA83137@winnie.fuhr.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1138298389.22740.11.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 26 Jan 2006 11:59:49 -0600 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.297 required=5 tests=[AWL=-0.030, PLING_QUERY=0.326, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.297 X-Spam-Level: X-Archive-Number: 200601/449 X-Sequence-Number: 16927 On Thu, 2006-01-26 at 11:57, Michael Fuhr wrote: > On Thu, Jan 26, 2006 at 04:49:59PM +0000, Richard Huxton wrote: > > Jozsef Szalay wrote: > > >I have seen it on occasion that the total runtime reported by explain > > >analyze was much higher than the actual time the query needed to > > >complete. The differences in my case ranged between 20-120 seconds. I'm > > >just curious if anyone else has experienced this and whether there is > > >something that I can do to convince explain analyze to report the > > >execution time of the query itself rather than the time of its own > > >execution. Engine version is 8.1.1. > > > > I think it's down to all the gettime() calls that have to be made to > > measure how long each stage of the query takes. In some cases these can > > take a substantial part of the overall query time. > > Another possibility is that the total query time was indeed that > long because the query was blocked waiting for a lock. For example: Could be, but I've had this happen where the query returned in like 1 second but reported 30 seconds run time. From pgsql-performance-owner@postgresql.org Thu Jan 26 14:03:39 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 726BB9DC824 for ; Thu, 26 Jan 2006 14:03:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68501-07 for ; Thu, 26 Jan 2006 14:03:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from dc1.storediq.com (66-194-80-196.gen.twtelecom.net [66.194.80.196]) by postgresql.org (Postfix) with ESMTP id EBC3D9DC80E for ; Thu, 26 Jan 2006 14:03:36 -0400 (AST) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: Incorrect Total runtime Reported by Explain Analyze!? Date: Thu, 26 Jan 2006 12:03:36 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Incorrect Total runtime Reported by Explain Analyze!? Thread-Index: AcYiofvWiiaVJqL8T6aAGuys1AC26gAAGcRg From: "Jozsef Szalay" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.446 required=5 tests=[AWL=0.120, PLING_QUERY=0.326] X-Spam-Score: 0.446 X-Spam-Level: X-Archive-Number: 200601/450 X-Sequence-Number: 16928 Very good points thanks. In my case however, I was doing performance tests and therefore I had a very controlled environment with a single client (me) doing strictly read-only multi-join queries. -----Original Message----- From: Michael Fuhr [mailto:mike@fuhr.org]=20 Sent: Thursday, January 26, 2006 11:57 AM To: Richard Huxton Cc: Jozsef Szalay; pgsql-performance@postgresql.org Subject: Re: [PERFORM] Incorrect Total runtime Reported by Explain Analyze!? On Thu, Jan 26, 2006 at 04:49:59PM +0000, Richard Huxton wrote: > Jozsef Szalay wrote: > >I have seen it on occasion that the total runtime reported by explain > >analyze was much higher than the actual time the query needed to > >complete. The differences in my case ranged between 20-120 seconds. I'm > >just curious if anyone else has experienced this and whether there is > >something that I can do to convince explain analyze to report the > >execution time of the query itself rather than the time of its own > >execution. Engine version is 8.1.1. >=20 > I think it's down to all the gettime() calls that have to be made to=20 > measure how long each stage of the query takes. In some cases these can=20 > take a substantial part of the overall query time. Another possibility is that the total query time was indeed that long because the query was blocked waiting for a lock. For example: T1: BEGIN; T2: BEGIN; T1: SELECT * FROM foo WHERE id =3D 1 FOR UPDATE; T2: EXPLAIN ANALYZE UPDATE foo SET x =3D x + 1 WHERE id =3D 1; T1: (do something for a long time) T1: COMMIT; When T2's EXPLAIN ANALYZE finally returns it'll show something like this: test=3D> EXPLAIN ANALYZE UPDATE foo SET x =3D x + 1 WHERE id =3D 1; QUERY PLAN ------------------------------------------------------------------------ --------------------------------------- Index Scan using foo_pkey on foo (cost=3D0.00..3.92 rows=3D1 = width=3D14) (actual time=3D0.123..0.138 rows=3D1 loops=3D1) Index Cond: (id =3D 1) Total runtime: 31926.304 ms (3 rows) SELECT queries can be blocked by operations that take an Access Exclusive lock, such as CLUSTER, VACUUM FULL, or REINDEX. Have you ever examined pg_locks during one of these queries to look for ungranted locks? If this weren't 8.1 I'd ask if you had any triggers (including foreign key constraints), whose execution time EXPLAIN ANALYZE doesn't show in earlier versions. For example: 8.1.2: test=3D> EXPLAIN ANALYZE DELETE FROM foo WHERE id =3D 1; QUERY PLAN ------------------------------------------------------------------------ -------------------------------------- Index Scan using foo_pkey on foo (cost=3D0.00..3.92 rows=3D1 = width=3D6) (actual time=3D0.136..0.154 rows=3D1 loops=3D1) Index Cond: (id =3D 1) Trigger for constraint bar_fooid_fkey: time=3D1538.054 calls=3D1 Total runtime: 1539.732 ms (4 rows) 8.0.6: test=3D> EXPLAIN ANALYZE DELETE FROM foo WHERE id =3D 1; QUERY PLAN ------------------------------------------------------------------------ -------------------------------------- Index Scan using foo_pkey on foo (cost=3D0.00..3.92 rows=3D1 = width=3D6) (actual time=3D0.124..0.147 rows=3D1 loops=3D1) Index Cond: (id =3D 1) Total runtime: 1746.173 ms (3 rows) --=20 Michael Fuhr From pgsql-performance-owner@postgresql.org Thu Jan 26 20:18:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2359C9DCB7C for ; Thu, 26 Jan 2006 20:18:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92219-04 for ; Thu, 26 Jan 2006 20:18:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth10.mail.atl.earthlink.net (smtpauth10.mail.atl.earthlink.net [209.86.89.70]) by postgresql.org (Postfix) with ESMTP id A05399DC821 for ; Thu, 26 Jan 2006 20:18:38 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=q5q6IEDZFHkAZkahVjCUFY0cKQP6kW1reVDkrb5Dq18V2E+4KwJjwXwolspnETXo; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth10.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F2HK4-0002O7-VO; Thu, 26 Jan 2006 19:18:41 -0500 Message-Id: <7.0.1.0.2.20060126190219.0388a918@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Thu, 26 Jan 2006 19:18:35 -0500 To: Tom Lane ,pgsql-performance@postgresql.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <18771.1137868073@sss.pgh.pa.us> References: <26153.1137784469@sss.pgh.pa.us> <20060120201036.GE31908@svana.org> <26583.1137788505@sss.pgh.pa.us> <20060120205132.GF31908@svana.org> <26958.1137791955@sss.pgh.pa.us> <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc004fdcc95518a4489059963154eec587350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.436 required=5 tests=[AWL=-0.043, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.436 X-Spam-Level: X-Archive-Number: 200601/451 X-Sequence-Number: 16929 At 01:27 PM 1/21/2006, Tom Lane wrote: >Ron writes: > > At 07:23 PM 1/20/2006, Tom Lane wrote: > >> Well, we're trying to split an index page that's gotten full into > >> two index pages, preferably with approximately equal numbers of items in > >> each new page (this isn't a hard requirement though). > > > Maybe we are over thinking this. What happens if we do the obvious > > and just make a new page and move the "last" n/2 items on the full > > page to the new page? > >Search performance will go to hell in a handbasket :-(. We have to make >at least some effort to split the page in a way that will allow searches >to visit only one of the two child pages rather than both. > >It's certainly true though that finding the furthest pair is not a >necessary component of that. It's reasonable if you try to visualize >the problem in 2D or 3D, but I'm not sure that that geometric intuition >holds up in such a high-dimensional space as we have here. After reading the various papers available on GiST and RD trees, I think I have a decent suggestion. Since RD tree keys contain the keys of their descendents/components in them, they are basically a representation of a depth first search. This can be useful for intra-document searches. OTOH, inter-document searches are going to be more akin to breadth first searches using RD trees. Thus my suggestion is that we maintain =two= index structures for text data. The first contains as many keys and all their descendents as possible. When we can no longer fit a specific complete "path" into a page, we start a new one; trying to keep complete top level to leaf key sets within a page. This will minimize paging during intra-document searches. The second index keeps siblings within a page and avoids putting parents or children within a page unless the entire depth first search can be kept within the page in addition to the siblings present. This will minimize paging during inter-document searches. Traditional B-tree ordering methods can be used to define the ordering/placement of pages within each index, which will minimize head seeks to find the correct page to scan. Since the criteria for putting a key within a page or starting a new page is simple, performance for those tasks should be O(1). The price is the extra space used for two indexes instead of one, but at first glance that seems well worth it. Comments? Ron From pgsql-performance-owner@postgresql.org Thu Jan 26 20:58:00 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id ED20F9DC85C for ; Thu, 26 Jan 2006 20:57:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09518-05 for ; Thu, 26 Jan 2006 20:58:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from alvh.no-ip.org (201-220-123-7.bk10-dsl.surnet.cl [201.220.123.7]) by postgresql.org (Postfix) with ESMTP id E0B4E9DC821 for ; Thu, 26 Jan 2006 20:57:56 -0400 (AST) Received: by alvh.no-ip.org (Postfix, from userid 1000) id 1CADBC2DC59; Thu, 26 Jan 2006 22:00:55 -0300 (CLST) Date: Thu, 26 Jan 2006 22:00:55 -0300 From: Alvaro Herrera To: Ron Cc: Tom Lane , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very Message-ID: <20060127010054.GD13501@surnet.cl> Mail-Followup-To: Ron , Tom Lane , pgsql-performance@postgresql.org References: <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> <7.0.1.0.2.20060126190219.0388a918@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7.0.1.0.2.20060126190219.0388a918@earthlink.net> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.783 required=5 tests=[AWL=-0.136, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.783 X-Spam-Level: * X-Archive-Number: 200601/452 X-Sequence-Number: 16930 Ron wrote: > At 01:27 PM 1/21/2006, Tom Lane wrote: > >Ron writes: > >> At 07:23 PM 1/20/2006, Tom Lane wrote: > >>> Well, we're trying to split an index page that's gotten full into > >>> two index pages, preferably with approximately equal numbers of items in > >>> each new page (this isn't a hard requirement though). > After reading the various papers available on GiST and RD trees, I > think I have a decent suggestion. I for one don't understand what does your suggestion have to do with the problem at hand ... not that I have a better one myself. -- Alvaro Herrera http://www.amazon.com/gp/registry/CTMLCN8V17R4 "Siempre hay que alimentar a los dioses, aunque la tierra est� seca" (Orual) From pgsql-performance-owner@postgresql.org Thu Jan 26 21:55:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8ADC19DCC30 for ; Thu, 26 Jan 2006 21:55:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22025-02-2 for ; Thu, 26 Jan 2006 21:55:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth04.mail.atl.earthlink.net (smtpauth04.mail.atl.earthlink.net [209.86.89.64]) by postgresql.org (Postfix) with ESMTP id 8A76D9DCC10 for ; Thu, 26 Jan 2006 21:55:49 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=aqi4xk+ix+r20QJxwS/n62XmYF/XB1nHsKGI0utwM7myGRuGVSrP7+u/f3+v/+Kg; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth04.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F2Iq8-00019V-T3; Thu, 26 Jan 2006 20:55:53 -0500 Message-Id: <7.0.1.0.2.20060126202809.03838ab0@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Thu, 26 Jan 2006 20:55:46 -0500 To: Alvaro Herrera , pgsql-performance@postgresql.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <20060127010054.GD13501@surnet.cl> References: <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> <7.0.1.0.2.20060126190219.0388a918@earthlink.net> <20060127010054.GD13501@surnet.cl> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc94879345c8970e4509a5c572567efd7c350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.438 required=5 tests=[AWL=-0.041, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.438 X-Spam-Level: X-Archive-Number: 200601/453 X-Sequence-Number: 16931 At 08:00 PM 1/26/2006, Alvaro Herrera wrote: >Ron wrote: > > At 01:27 PM 1/21/2006, Tom Lane wrote: > > >Ron writes: > > >> At 07:23 PM 1/20/2006, Tom Lane wrote: > > >>> Well, we're trying to split an index page that's gotten full into > > >>> two index pages, preferably with approximately equal numbers > of items in > > >>> each new page (this isn't a hard requirement though). > > > After reading the various papers available on GiST and RD trees, I > > think I have a decent suggestion. > >I for one don't understand what does your suggestion have to do with the >problem at hand ... not that I have a better one myself. We have two problems here. The first is that the page splitting code for these indexes currently has O(N^2) performance. The second is that whatever solution we do use for this functionality, we still need good performance during searches that use the index. It's not clear that the solutions we've discussed to splitting index pages thus far will result in good performance during searches. My suggestion is intended to address both issues. If I'm right it helps obtain high performance during searches while allowing the index page splitting code to be O(1) Ron. From pgsql-performance-owner@postgresql.org Thu Jan 26 22:33:58 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2D6F19DCC05 for ; Thu, 26 Jan 2006 22:33:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27768-08 for ; Thu, 26 Jan 2006 22:34:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net [68.15.5.150]) by postgresql.org (Postfix) with ESMTP id EB31D9DC80C for ; Thu, 26 Jan 2006 22:33:54 -0400 (AST) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k0R1ZP6V026135; Thu, 26 Jan 2006 17:35:25 -0800 Message-ID: <43D98582.1050501@modgraph-usa.com> Date: Thu, 26 Jan 2006 18:29:22 -0800 From: "Craig A. James" User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ron , pgsql-performance@postgresql.org Subject: Re: [GENERAL] Creation of tsearch2 index is very References: <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> <7.0.1.0.2.20060126190219.0388a918@earthlink.net> <20060127010054.GD13501@surnet.cl> <7.0.1.0.2.20060126202809.03838ab0@earthlink.net> In-Reply-To: <7.0.1.0.2.20060126202809.03838ab0@earthlink.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.09 required=5 tests=[AWL=0.090] X-Spam-Score: 0.09 X-Spam-Level: X-Archive-Number: 200601/454 X-Sequence-Number: 16932 Ron writes: > We have two problems here. > The first is that the page splitting code for these indexes currently > has O(N^2) performance. > The second is that whatever solution we do use for this functionality, > we still need good performance during searches that use the index. No, unfortunately that's not the problem that needs to be solved. The problem is figuring out WHICH records to put in the "left" and "right" trees once you split them. If you can figure that out, then your suggestion (and perhaps other techniques) could be useful. The problem boils down to this: You have a whole bunch of essentially random bitmaps. You have two buckets. You want to put half of the bitmaps in one bucket, and half in the other bucket, and when you get through, you want all of the bitmaps in each bucket to be maximally similar to each other, and maximally dissimilar to the ones in the other bucket. That way, when you OR all the bitmaps in each bucket together to build the bitmap for the left and right child nodes of the tree, you'll get maximum separation -- the chances that you'll have to descend BOTH the left and right nodes of the tree are minimized. Unfortunately, this problem is very likely in the set of NP-complete problems, i.e. like the famous "Traveling Salesman Problem," you can prove there's no algorithm that will give the answer in a reasonable time. In this case, "reasonable" would be measured in milliseconds to seconds, but in fact an actual "perfect" split of a set of bitmaps probably can't be computed in the lifetime of the universe for more than a few hundred bitmaps. That's the problem that's being discussed: How do you decide which bitmaps go in each of the two buckets? Any solution will necessarily be imperfect, a pragmatic algorithm that gives an imperfect, but acceptable, answer. As I mentioned earlier, chemists make extensive use of bitmaps to categorize and group molecules. They use Tanimoto or Tversky similarity metrics (Tanimoto is a special case of Tversky), because it's extremely fast to compare two bitmaps, and the score is highly correlated with the number of bits the two bitmaps have in common. But even with a fast "distance" metric like Tanimoto, there's still no easy way to decide which bucket to put each bitmap into. Craig From pgsql-performance-owner@postgresql.org Thu Jan 26 23:33:11 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 373509DC823 for ; Thu, 26 Jan 2006 23:33:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40262-10 for ; Thu, 26 Jan 2006 23:33:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth06.mail.atl.earthlink.net (smtpauth06.mail.atl.earthlink.net [209.86.89.66]) by postgresql.org (Postfix) with ESMTP id D7FBA9DC80C for ; Thu, 26 Jan 2006 23:33:07 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=G/haqylpHTrfTpFZ/u/TyFFGcdvA9iAolbK/XmAaMOuk5hsVzLTbJfVx6t9k8+pH; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth06.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F2KMK-0004Fp-8J; Thu, 26 Jan 2006 22:33:12 -0500 Message-Id: <7.0.1.0.2.20060126221829.037961c8@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Thu, 26 Jan 2006 22:33:07 -0500 To: "Craig A. James" , pgsql-performance@postgresql.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very In-Reply-To: <43D98582.1050501@modgraph-usa.com> References: <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> <7.0.1.0.2.20060126190219.0388a918@earthlink.net> <20060127010054.GD13501@surnet.cl> <7.0.1.0.2.20060126202809.03838ab0@earthlink.net> <43D98582.1050501@modgraph-usa.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bcd2af7d1bac20dea471250ed08b8f1098350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.44 required=5 tests=[AWL=-0.039, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.44 X-Spam-Level: X-Archive-Number: 200601/455 X-Sequence-Number: 16933 You seem to have missed my point. I just gave a very clear description of how to "decide which bitmaps go in each of the two buckets" by reformulating the question into "decide which bitmaps go in each of =four= buckets". The intent is to have two indexes, one optimized for one common class of searches, and the other optimized for another common class of searches. By decomposing the optimization problem into two simpler problems, the hope is that we address all the issues reasonably simply while still getting decent performance. Nothing is free. The price we pay, and it is significant, is that we now have two indexes where before we had only one. Ron At 09:29 PM 1/26/2006, Craig A. James wrote: >Ron writes: >>We have two problems here. >>The first is that the page splitting code for these indexes >>currently has O(N^2) performance. >>The second is that whatever solution we do use for this >>functionality, we still need good performance during searches that >>use the index. > >No, unfortunately that's not the problem that needs to be solved. > >The problem is figuring out WHICH records to put in the "left" and >"right" trees once you split them. If you can figure that out, then >your suggestion (and perhaps other techniques) could be useful. > >The problem boils down to this: You have a whole bunch of >essentially random bitmaps. You have two buckets. You want to put >half of the bitmaps in one bucket, and half in the other bucket, and >when you get through, you want all of the bitmaps in each bucket to >be maximally similar to each other, and maximally dissimilar to the >ones in the other bucket. > >That way, when you OR all the bitmaps in each bucket together to >build the bitmap for the left and right child nodes of the tree, >you'll get maximum separation -- the chances that you'll have to >descend BOTH the left and right nodes of the tree are minimized. > >Unfortunately, this problem is very likely in the set of NP-complete >problems, i.e. like the famous "Traveling Salesman Problem," you can >prove there's no algorithm that will give the answer in a reasonable >time. In this case, "reasonable" would be measured in milliseconds >to seconds, but in fact an actual "perfect" split of a set of >bitmaps probably can't be computed in the lifetime of the universe >for more than a few hundred bitmaps. > >That's the problem that's being discussed: How do you decide which >bitmaps go in each of the two buckets? Any solution will >necessarily be imperfect, a pragmatic algorithm that gives an >imperfect, but acceptable, answer. > >As I mentioned earlier, chemists make extensive use of bitmaps to >categorize and group molecules. They use Tanimoto or Tversky >similarity metrics (Tanimoto is a special case of Tversky), because >it's extremely fast to compare two bitmaps, and the score is highly >correlated with the number of bits the two bitmaps have in common. > >But even with a fast "distance" metric like Tanimoto, there's still >no easy way to decide which bucket to put each bitmap into. > >Craig From pgsql-performance-owner@postgresql.org Fri Jan 27 03:52:53 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A8EDF9DC877 for ; Fri, 27 Jan 2006 03:52:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65292-07 for ; Fri, 27 Jan 2006 03:52:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpauth01.mail.atl.earthlink.net (smtpauth01.mail.atl.earthlink.net [209.86.89.61]) by postgresql.org (Postfix) with ESMTP id 798F19DC9C2 for ; Fri, 27 Jan 2006 03:52:49 -0400 (AST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=hoKZgFEQWGg0RwRf4twN8IwVUZEbfZD7zjpfrqgqJXO05A9p5SCu/1xzAh4bjDpy; h=Received:Message-Id:X-Mailer:Date:To:From:Subject:Cc:In-Reply-To:References:Mime-Version:Content-Type:X-ELNK-Trace:X-Originating-IP; Received: from [70.22.189.241] (helo=ron-6d52adff2a6.earthlink.net) by smtpauth01.mail.atl.earthlink.net with asmtp (Exim 4.34) id 1F2OPZ-0002sa-B9; Fri, 27 Jan 2006 02:52:49 -0500 Message-Id: <7.0.1.0.2.20060126232407.03b2f418@earthlink.net> X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Date: Fri, 27 Jan 2006 02:52:45 -0500 To: "Craig A. James" , pgsql-performance@postgresql.org From: Ron Subject: Re: [GENERAL] Creation of tsearch2 index is very Cc: Tom Lane In-Reply-To: <43D99E04.4040109@modgraph-usa.com> References: <20060120213754.GG31908@svana.org> <7.0.1.0.2.20060120174141.039b03e8@earthlink.net> <6111.1137797436@sss.pgh.pa.us> <20060120225751.GA27230@uio.no> <6532.1137801157@sss.pgh.pa.us> <20060121000519.GA29755@uio.no> <6743.1137802990@sss.pgh.pa.us> <7.0.1.0.2.20060121064930.03aba810@earthlink.net> <18771.1137868073@sss.pgh.pa.us> <7.0.1.0.2.20060126190219.0388a918@earthlink.net> <20060127010054.GD13501@surnet.cl> <7.0.1.0.2.20060126202809.03838ab0@earthlink.net> <43D98582.1050501@modgraph-usa.com> <7.0.1.0.2.20060126221829.037961c8@earthlink.net> <43D99E04.4040109@modgraph-usa.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-ELNK-Trace: acd68a6551193be5d780f4a490ca69563f9fea00a6dd62bc0ada9bd12ab7177ad38faee61c9d66a3350badd9bab72f9c350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 70.22.189.241 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.442 required=5 tests=[AWL=-0.037, DNS_FROM_RFC_ABUSE=0.479] X-Spam-Score: 0.442 X-Spam-Level: X-Archive-Number: 200601/456 X-Sequence-Number: 16934 At 11:13 PM 1/26/2006, Craig A. James wrote: >Ron, > >I'll write to you privately, because these discussions can get messy >"in public". I'm responding to this missive publicly in an attempt to help the discussion along. It is not my usual practice to respond to private messages publicly, but this seems a good case for an exception. >>You seem to have missed my point. I just gave a very clear >>description of how to "decide which bitmaps go in each of the two >>buckets" by reformulating the question into "decide which bitmaps >>go in each of =four= buckets". > >Sorry to disagree, but here's the problem. It's not whether you put >them into two, or four, or N buckets. The problem is, how do you >categorize them to begin with, so that you have some reasonable >criterion for which item goes in which bucket? THAT is the hard >problem, not whether you have two or four buckets. Agreed. ...and I've given the answer to "how do you categorize them" using a general property of RD Trees which should result in "a reasonable criterion for which item goes in which bucket" when used for text searching. The definition of RD tree keys being either "atomic" (non decomposable) or "molecular" (containing the keys of their descendents) is the one source of our current problems figuring out how to split them and, if I'm correct, a hint as to how to solve the splitting problem in O(1) time while helping to foster high performance during seearches. >Earlier, you wrote: >>Traditional B-tree ordering methods can be used to define the >>ordering/placement of pages within each index, which will minimize >>head seeks to find the correct page to scan. >>Since the criteria for putting a key within a page or starting a >>new page is simple, performance for those tasks should be O(1). > >What are the "traditional B-tree ordering methods"? That's the >issue, right there. The problem is that bitmaps HAVE NO ORDERING >METHOD. You can't sort them numerically or alphabetically. The =bitmaps= have no ordering method. =Pages= of bitmaps MUST have an ordering method or we have no idea which page to look at when searching for a key. Treating the "root" bitmaps (those that may have descendents but have no parents) as numbers and ordering the pages using B tree creation methods that use those numbers as keys is a simple way to create a balanced data structure with high fan out. IOW, a recipe for finding the proper page(s) to scan using minimal seeks. >Take a crowd of people. It's easy to divide them in half by names: >just alphabetize and split the list in half. That's what your >solution would improve on. > >But imagine I gave you a group of people and told you to put them >into two rooms, such that when you are through, the people in each >room are maximally similar to each other and maximally dissimilar to >the people in the other room. How would you do it? > >First of all, you'd have to define what "different" and "same" >are. Is your measure based on skin color, hair color, age, height, >weight, girth, intelligence, speed, endurance, body odor, ... >? Suppose I tell you, "All of those". You have to sort the people >so that your two groups are separated such that the group >differences are maximized in this N-dimensional >space. Computationally, it's a nearly impossible problem. I'm =changing= the problem using the semantics of RD trees. Using an RD tree representation, we'd create and assign a key for each person that ranked them compared to everyone else for each of the metrics we decided to differentiate on. Then we start to form trees of keys to these people by creating "parent" keys as roots that contain the union of everyone with the same or possibly similar value for some quality. By iterating this process, we end up with a bottom up construction method for an RD tree whose root key will the union of all the keys representing these people. If this is one data structure, we end up with an efficient and effective way of answering not only Boolean but also ranking and similarity type queries. The problem comes when we have to split this monolithic DS into pieces for best performance. As many have noted, there is no simple way to decide how to do such a thing. OTOH, we =do= have the knowledge of how RD trees are built and what their keys represent, and we know that queries are going to tend strongly to either a) traverse the path from parent to child (depth first) or b) find all siblings with (dis)similar characteristics (breadth first), or c) contain a mixture of a) and b). So I'm suggesting that conceptually we clone the original RD tree and we split each clone according to two different methods. Method A results in pages that contain as many complete depth first paths from root to leave as possible on each page. Method B results in pages that contain as many siblings as possible per page. ...and we use the appropriate index during each type of query or query part. In return for using 2x as much space, we should have a general method that is O(1) for decomposing RD trees in such a way as to support high performance during searches. >Here's a much simpler version of the problem. Suppose I give you >1000 numbers, and tell you to divide them in half so that the two >groups have the smallest standard deviation within each group >possible, and the two average values of the groups of numbers are >the farthest apart possible. Pretty easy, right? > >Now do it where "distance" is evaluated modulo(10), that is, 1 and 9 >are closer together than 1 and 3. Now try it -- you'll find that >this problem is almost impossible to solve. This is orthogonal to the discussion at hand since the above is not akin to text searching nor best done with RD trees and that is exactly what this discussion is about. We don't have to solve a general problem for all domains. We only have to solve it for the specific domain of text search using the specific DS of RD trees. >The problem is that, as database designers, we're used to text and >numbers, which have an inherent order. Bitmaps have no ordering -- >you can't say one is "greater than" or "less than" the other. All >you can do is determine that A and B are "more similar" or "less >similar" than A and C. Text and numbers only have an order because we deem them to. There is even a very common default order we tend to use. But even in the trivial case of ranking we've all said that "1" is better than "2" in one situation and "2" is better than "1" in another. In the case of text searching, the bitmaps represent where to find legomena, AKA specific tokens. Particularly hapax legomena, AKA unique tokens. Hapax Legomena are particularly important because they are maximally efficient at driving the search needed to answer a query. While absolute hapax legomena are great for quickly pruning things within a document or document region, relative hapax legomena can do the same thing when searching among multiple documents or document regions. The two indexes I'm suggesting are designed to take advantage of this general property of text searching. Hopefully this clarifies things and motivates a better discussion? Ron From pgsql-performance-owner@postgresql.org Fri Jan 27 21:27:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8D9B09DCB92 for ; Fri, 27 Jan 2006 21:27:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36850-07 for ; Fri, 27 Jan 2006 21:27:35 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 826DB9DCB5E for ; Fri, 27 Jan 2006 21:27:30 -0400 (AST) Received: from dbeat.com (unknown [208.234.8.166]) by svr4.postgresql.org (Postfix) with ESMTP id 1EA935AF86B for ; Sat, 28 Jan 2006 01:27:34 +0000 (GMT) Received: from videobox (cpe-24-90-163-242.nj.res.rr.com [24.90.163.242]) by dbeat.com (8.12.10/8.11.6) with SMTP id k0S1RVFU005767 for ; Fri, 27 Jan 2006 20:27:31 -0500 Message-ID: <007101c623a9$82207c10$0200a8c0@videobox> From: "Mike Biamonte" To: Subject: Huge Data sets, simple queries Date: Fri, 27 Jan 2006 20:23:55 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/457 X-Sequence-Number: 16935 Does anyone have any experience with extremely large data sets? I'm mean hundreds of millions of rows. The queries I need to run on my 200 million transactions are relatively simple: select month, count(distinct(cardnum)) count(*), sum(amount) from transactions group by month; This query took 18 hours on PG 8.1 on a Dual Xeon, RHEL3, (2.4 Kernel) with RAID-10 (15K drives) and 12 GB Ram. I was expecting it to take about 4 hours - based on some experience with a similar dataset on a different machine (RH9, PG7.3 Dual Xeon, 4GB RAM, Raid-5 10K drives) This machine is COMPLETELY devoted to running these relatively simple queries one at a time. (No multi-user support needed!) I've been tooling with the various performance settings: effective_cache at 5GB, shared_buffers at 2 GB, workmem, sortmem at 1 GB each. ( Shared buffers puzzles me a it bit - my instinct says to set it as high as possible, but everything I read says that "too high" can hurt performance.) Any ideas for performance tweaking in this kind of application would be greatly appreciated. We've got indexes on the fields being grouped, and always vacuum analzye after building them. It's difficult to just "try" various ideas because each attempt takes a full day to test. Real experience is needed here! Thanks much, Mike From pgsql-performance-owner@postgresql.org Sat Jan 28 13:54:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D31D09DCA09 for ; Sat, 28 Jan 2006 13:54:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17677-10 for ; Sat, 28 Jan 2006 13:54:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46]) by postgresql.org (Postfix) with ESMTP id 055EF9DC9D6 for ; Sat, 28 Jan 2006 13:54:10 -0400 (AST) Received: from 172.16.1.148 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D2)); Sat, 28 Jan 2006 12:53:56 -0500 X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST02.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Sat, 28 Jan 2006 12:53:56 -0500 Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Sat, 28 Jan 2006 17:53:56 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Fri, 27 Jan 2006 19:05:04 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "Mike Biamonte" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYjqiD+PM+GCn6QRfyvn64Ut4tn7AADYGQY In-Reply-To: <007101c623a9$82207c10$0200a8c0@videobox> MIME-Version: 1.0 X-OriginalArrivalTime: 28 Jan 2006 17:53:56.0787 (UTC) FILETIME=[CF61E830:01C62433] X-WSS-ID: 6FC5703E3306121286-01-01 Content-Type: multipart/alternative; boundary=B_3221286835_1192920 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.766 required=5 tests=[AWL=-0.369, DATE_IN_PAST_12_24=0.881, HTML_MESSAGE=0.001, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.766 X-Spam-Level: * X-Archive-Number: 200601/462 X-Sequence-Number: 16940 > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3221286835_1192920 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Sounds like you are running into the limits of your disk subsystem. You ar= e scanning all of the data in the transactions table, so you will be limited by the disk bandwidth you have =AD and using RAID-10, you should divide the number of disk drives by 2 and multiply by their indiividual bandwidth (around 60MB/s) and that=B9s what you can expect in terms of performance. So= , if you have 8 drives, you should expect to get 4 x 60 MB/s =3D 240 MB/s in bandwidth. That means that if you are dealing with 24,000 MB of data in th= e =B3transactions=B2 table, then you will scan it in 100 seconds. With a workload like this, you are in the realm of business intelligence / data warehousing I think. You should check your disk performance, I would expect you=B9ll find it lacking, partly because you are running RAID10, but mostly because I expect you are using a hardware RAID adapter. - Luke On 1/27/06 5:23 PM, "Mike Biamonte" wrote: >=20 >=20 >=20 > Does anyone have any experience with extremely large data sets? > I'm mean hundreds of millions of rows. >=20 > The queries I need to run on my 200 million transactions are relatively > simple: >=20 > select month, count(distinct(cardnum)) count(*), sum(amount) from > transactions group by month; >=20 > This query took 18 hours on PG 8.1 on a Dual Xeon, RHEL3, (2.4 Kernel) wi= th > RAID-10 (15K drives) > and 12 GB Ram. I was expecting it to take about 4 hours - based on some > experience with a > similar dataset on a different machine (RH9, PG7.3 Dual Xeon, 4GB RAM, > Raid-5 10K drives) >=20 > This machine is COMPLETELY devoted to running these relatively simple > queries one at a > time. (No multi-user support needed!) I've been tooling with the vario= us > performance settings: > effective_cache at 5GB, shared_buffers at 2 GB, workmem, sortmem at 1 GB > each. > ( Shared buffers puzzles me a it bit - my instinct says to set it as high= as > possible, > but everything I read says that "too high" can hurt performance.) >=20 > Any ideas for performance tweaking in this kind of application would b= e > greatly appreciated. > We've got indexes on the fields being grouped, and always vacuum analzye > after building them. >=20 > It's difficult to just "try" various ideas because each attempt takes = a > full day to test. Real > experience is needed here! >=20 > Thanks much, >=20 > Mike >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings >=20 >=20 --B_3221286835_1192920 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Re: [PERFORM] Huge Data sets, simple queries Sound= s like you are running into the limits of your disk subsystem.  You are= scanning all of the data in the transactions table, so you will be limited = by the disk bandwidth you have – and using RAID-10, you should divide = the number of disk drives by 2 and multiply by their indiividual bandwidth (= around 60MB/s) and that’s what you can expect in terms of performance.=  So, if you have 8 drives, you should expect to get 4 x 60 MB/s =3D 240 = MB/s in bandwidth.  That means that if you are dealing with 24,000 MB o= f data in the “transactions” table, then you will scan  it = in 100 seconds.

With a workload like this, you are in the realm of business intelligence / = data warehousing I think.  You should check your disk performance, I wo= uld expect you’ll find it lacking, partly because you are running RAID= 10, but mostly because I expect you are using a hardware RAID adapter.

- Luke


On 1/27/06 5:23 PM, "Mike Biamonte" <mike@dbeat.com> wrote:=




Does anyone have any experience with extremely large data sets?
I'm mean hundreds of millions of rows.

The queries I need to run on my 200 million transactions are relatively
simple:

   select month, count(distinct(cardnum)) count(*), sum(amou= nt) from
transactions group by month;

This query took 18 hours on PG 8.1 on a Dual Xeon, RHEL3, (2.4 Kernel) with=
RAID-10 (15K drives)
and 12 GB Ram.  I was expecting it to take about 4 hours - based on so= me
experience with a
similar dataset on a different machine (RH9, PG7.3 Dual Xeon, 4GB RAM,
Raid-5 10K drives)

  This machine is COMPLETELY devoted to running these relatively = simple
queries one at a
time. (No multi-user support needed!)    I've been tooling w= ith the various
performance settings:
effective_cache at 5GB, shared_buffers at 2 GB, workmem, sortmem at 1 GB each.
( Shared buffers puzzles me a it bit - my instinct says to set it as high a= s
possible,
but everything I read says that "too high" can hurt performance.)=

   Any ideas for performance tweaking in this kind of applic= ation would be
greatly appreciated.
We've got indexes on the fields being grouped, and always vacuum analzye after building them.

   It's difficult to just "try" various ideas beca= use each attempt takes a
full day to test.  Real
experience is needed here!

Thanks much,

Mike


---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings



--B_3221286835_1192920-- From pgsql-performance-owner@postgresql.org Sat Jan 28 02:56:46 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 591839DC810 for ; Sat, 28 Jan 2006 02:56:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02665-04 for ; Sat, 28 Jan 2006 02:56:44 -0400 (AST) X-Greylist: delayed 00:06:40.875832 by SQLgrey- Received: from mail2.sea5.speakeasy.net (mail2.sea5.speakeasy.net [69.17.117.4]) by postgresql.org (Postfix) with ESMTP id B12639DC80C for ; Sat, 28 Jan 2006 02:56:41 -0400 (AST) Received: (qmail 2124 invoked from network); 28 Jan 2006 06:50:01 -0000 Received: from dsl081-060-184.sfo1.dsl.speakeasy.net (HELO noodles) (jwbaker@[64.81.60.184]) (envelope-sender ) by mail2.sea5.speakeasy.net (qmail-ldap-1.03) with RC4-MD5 encrypted SMTP for ; 28 Jan 2006 06:50:01 -0000 Subject: Re: Huge Data sets, simple queries From: "Jeffrey W. Baker" To: Mike Biamonte Cc: pgsql-performance@postgresql.org In-Reply-To: <007101c623a9$82207c10$0200a8c0@videobox> References: <007101c623a9$82207c10$0200a8c0@videobox> Content-Type: text/plain Date: Fri, 27 Jan 2006 22:50:00 -0800 Message-Id: <1138431000.8630.18.camel@noodles> Mime-Version: 1.0 X-Mailer: Evolution 2.5.4 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/458 X-Sequence-Number: 16936 On Fri, 2006-01-27 at 20:23 -0500, Mike Biamonte wrote: > > Does anyone have any experience with extremely large data sets? > I'm mean hundreds of millions of rows. Sure, I think more than a few of us do. Just today I built a summary table from a 25GB primary table with ~430 million rows. This took about 45 minutes. > The queries I need to run on my 200 million transactions are relatively > simple: > > select month, count(distinct(cardnum)) count(*), sum(amount) from > transactions group by month; > > This query took 18 hours on PG 8.1 on a Dual Xeon, RHEL3, (2.4 Kernel) with > RAID-10 (15K drives) > and 12 GB Ram. I was expecting it to take about 4 hours - based on some > experience with a > similar dataset on a different machine (RH9, PG7.3 Dual Xeon, 4GB RAM, > Raid-5 10K drives) Possibly the latter machine has a faster I/O subsystem. How large is the table on disk? > This machine is COMPLETELY devoted to running these relatively simple > queries one at a > time. (No multi-user support needed!) I've been tooling with the various > performance settings: > effective_cache at 5GB, shared_buffers at 2 GB, workmem, sortmem at 1 GB > each. > ( Shared buffers puzzles me a it bit - my instinct says to set it as high as > possible, > but everything I read says that "too high" can hurt performance.) > > Any ideas for performance tweaking in this kind of application would be > greatly appreciated. > We've got indexes on the fields being grouped, > and always vacuum analzye > after building them. Probably vacuum makes no difference. > It's difficult to just "try" various ideas because each attempt takes a > full day to test. Real > experience is needed here! Can you send us an EXPLAIN of the query? I believe what you're seeing here is probably: Aggregate +-Sort +-Sequential Scan or perhaps: Aggregate +-Index Scan I have a feeling that the latter will be much faster. If your table has been created over time, then it is probably naturally ordered by date, and therefore also ordered by month. You might expect a Sequential Scan to be the fastest, but the Sort step will be a killer. On the other hand, if your table is badly disordered by date, the Index Scan could also be very slow. Anyway, send us the query plan and also perhaps a sample of vmstat during the query. For what it's worth, I have: effective_cache_size | 700000 cpu_tuple_cost | 0.01 cpu_index_tuple_cost | 0.001 random_page_cost | 3 shared_buffers | 50000 temp_buffers | 1000 work_mem | 1048576 <= for this query only And here's a few lines from vmstat during the query: procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 2 1 76 43476 94916 7655148 0 0 78800 0 1662 788 68 12 0 20 1 1 76 45060 91196 7658088 0 0 78028 0 1639 712 71 11 0 19 2 0 76 44668 87624 7662960 0 0 78924 52 1650 736 69 12 0 19 2 0 76 45300 83672 7667432 0 0 83536 16 1688 768 71 12 0 18 1 1 76 45744 80652 7670712 0 0 84052 0 1691 796 70 12 0 17 That's about 80MB/sec sequential input, for comparison purposes. -jwb From pgsql-performance-owner@postgresql.org Sat Jan 28 11:55:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 313CD9DCA13 for ; Sat, 28 Jan 2006 11:55:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99091-01 for ; Sat, 28 Jan 2006 11:55:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1A6BD9DC825 for ; Sat, 28 Jan 2006 11:54:58 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0SFt2xE011815; Sat, 28 Jan 2006 10:55:02 -0500 (EST) To: "Mike Biamonte" cc: pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries In-reply-to: <007101c623a9$82207c10$0200a8c0@videobox> References: <007101c623a9$82207c10$0200a8c0@videobox> Comments: In-reply-to "Mike Biamonte" message dated "Fri, 27 Jan 2006 20:23:55 -0500" Date: Sat, 28 Jan 2006 10:55:02 -0500 Message-ID: <11814.1138463702@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/459 X-Sequence-Number: 16937 "Mike Biamonte" writes: > The queries I need to run on my 200 million transactions are relatively > simple: > select month, count(distinct(cardnum)) count(*), sum(amount) from > transactions group by month; count(distinct) is not "relatively simple", and the current implementation isn't especially efficient. Can you avoid that construct? Assuming that "month" means what it sounds like, the above would result in running twelve parallel sort/uniq operations, one for each month grouping, to eliminate duplicates before counting. You've got sortmem set high enough to blow out RAM in that scenario ... regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 28 13:08:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 299A99DC944 for ; Sat, 28 Jan 2006 13:08:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05166-10 for ; Sat, 28 Jan 2006 13:08:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail4.sea5.speakeasy.net (mail4.sea5.speakeasy.net [69.17.117.6]) by postgresql.org (Postfix) with ESMTP id D61B69DC81E for ; Sat, 28 Jan 2006 13:08:54 -0400 (AST) Received: (qmail 9438 invoked from network); 28 Jan 2006 17:08:54 -0000 Received: from dsl081-060-184.sfo1.dsl.speakeasy.net (HELO noodles) (jwbaker@[64.81.60.184]) (envelope-sender ) by mail4.sea5.speakeasy.net (qmail-ldap-1.03) with RC4-MD5 encrypted SMTP for ; 28 Jan 2006 17:08:54 -0000 Subject: Re: Huge Data sets, simple queries From: "Jeffrey W. Baker" To: Tom Lane Cc: pgsql-performance@postgresql.org In-Reply-To: <11814.1138463702@sss.pgh.pa.us> References: <007101c623a9$82207c10$0200a8c0@videobox> <11814.1138463702@sss.pgh.pa.us> Content-Type: text/plain Date: Sat, 28 Jan 2006 09:08:53 -0800 Message-Id: <1138468133.9336.5.camel@noodles> Mime-Version: 1.0 X-Mailer: Evolution 2.5.4 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/460 X-Sequence-Number: 16938 On Sat, 2006-01-28 at 10:55 -0500, Tom Lane wrote: > > Assuming that "month" means what it sounds like, the above would > result > in running twelve parallel sort/uniq operations, one for each month > grouping, to eliminate duplicates before counting. You've got sortmem > set high enough to blow out RAM in that scenario ... Hrmm, why is it that with a similar query I get a far simpler plan than you describe, and relatively snappy runtime? select date , count(1) as nads , sum(case when premium then 1 else 0 end) as npremium , count(distinct(keyword)) as nwords , count(distinct(advertiser)) as nadvertisers from data group by date order by date asc QUERY PLAN ----------------------------------------------------------------------------------------------- GroupAggregate (cost=0.00..14452743.09 rows=721 width=13) -> Index Scan using data_date_idx on data (cost=0.00..9075144.27 rows=430206752 width=13) (2 rows) =# show server_version; server_version ---------------- 8.1.2 (1 row) -jwb From pgsql-performance-owner@postgresql.org Sat Jan 28 13:37:07 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5EDC79DC834 for ; Sat, 28 Jan 2006 13:37:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11321-08 for ; Sat, 28 Jan 2006 13:37:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 86B5C9DC81E for ; Sat, 28 Jan 2006 13:37:03 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0SHb0Ce018416; Sat, 28 Jan 2006 12:37:00 -0500 (EST) To: "Jeffrey W. Baker" cc: pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries In-reply-to: <1138468133.9336.5.camel@noodles> References: <007101c623a9$82207c10$0200a8c0@videobox> <11814.1138463702@sss.pgh.pa.us> <1138468133.9336.5.camel@noodles> Comments: In-reply-to "Jeffrey W. Baker" message dated "Sat, 28 Jan 2006 09:08:53 -0800" Date: Sat, 28 Jan 2006 12:37:00 -0500 Message-ID: <18415.1138469820@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/461 X-Sequence-Number: 16939 "Jeffrey W. Baker" writes: > On Sat, 2006-01-28 at 10:55 -0500, Tom Lane wrote: >> Assuming that "month" means what it sounds like, the above would result >> in running twelve parallel sort/uniq operations, one for each month >> grouping, to eliminate duplicates before counting. You've got sortmem >> set high enough to blow out RAM in that scenario ... > Hrmm, why is it that with a similar query I get a far simpler plan than > you describe, and relatively snappy runtime? You can't see the sort operations in the plan, because they're invoked implicitly by the GroupAggregate node. But they're there. Also, a plan involving GroupAggregate is going to run the "distinct" sorts sequentially, because it's dealing with only one grouping value at a time. In the original case, the planner probably realizes there are only 12 groups and therefore prefers a HashAggregate, which will try to run all the sorts in parallel. Your "group by date" isn't a good approximation of the original conditions because there will be a lot more groups. (We might need to tweak the planner to discourage selecting HashAggregate in the presence of DISTINCT aggregates --- I don't remember whether it accounts for the sortmem usage in deciding whether the hash will fit in memory or not ...) regards, tom lane From pgsql-performance-owner@postgresql.org Sat Jan 28 14:55:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 853FA9DCA13 for ; Sat, 28 Jan 2006 14:55:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44242-01 for ; Sat, 28 Jan 2006 14:55:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4EAEA9DC9D6 for ; Sat, 28 Jan 2006 14:55:09 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0SIt84O018926; Sat, 28 Jan 2006 13:55:08 -0500 (EST) To: "Jeffrey W. Baker" , pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries In-reply-to: <18415.1138469820@sss.pgh.pa.us> References: <007101c623a9$82207c10$0200a8c0@videobox> <11814.1138463702@sss.pgh.pa.us> <1138468133.9336.5.camel@noodles> <18415.1138469820@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sat, 28 Jan 2006 12:37:00 -0500" Date: Sat, 28 Jan 2006 13:55:08 -0500 Message-ID: <18925.1138474508@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/463 X-Sequence-Number: 16941 I wrote: > (We might need to tweak the planner to discourage selecting > HashAggregate in the presence of DISTINCT aggregates --- I don't > remember whether it accounts for the sortmem usage in deciding > whether the hash will fit in memory or not ...) Ah, I take that all back after checking the code: we don't use HashAggregate at all when there are DISTINCT aggregates, precisely because of this memory-blow-out problem. For both your group-by-date query and the original group-by-month query, the plan of attack is going to be to read the original input in grouping order (either via sort or indexscan, with sorting probably preferred unless the table is pretty well correlated with the index) and then sort/uniq on the DISTINCT value within each group. The OP is probably losing on that step compared to your test because it's over much larger groups than yours, forcing some spill to disk. And most likely he's not got an index on month, so the first sort is in fact a sort and not an indexscan. Bottom line is that he's probably doing a ton of on-disk sorting where you're not doing any. This makes me think Luke's theory about inadequate disk horsepower may be on the money. regards, tom lane From pgsql-performance-owner@postgresql.org Sun Jan 29 07:25:26 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 921F89DC865 for ; Sun, 29 Jan 2006 07:25:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61130-03 for ; Sun, 29 Jan 2006 07:25:26 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.203]) by postgresql.org (Postfix) with ESMTP id 7680D9DC843 for ; Sun, 29 Jan 2006 07:25:22 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 13so977216nzn for ; Sun, 29 Jan 2006 03:25:25 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=FbSaHH4rZRTcztd9tQf2REGyD0N0KMqE9FMYYtKGkOyYnPiw5fFhZTfg0XW59ERjDZ9Q5n8f3B3D8JuF/85IfVoxDrWU6AY4k+3IwERekyxVdD9zJVMGvsYw5ZrH823IwTcYAP0Px3VFaq0BruYaG98W3XMvNnQnPCkQPtwMSPQ= Received: by 10.65.197.1 with SMTP id z1mr1183950qbp; Sun, 29 Jan 2006 03:25:23 -0800 (PST) Received: by 10.65.254.12 with HTTP; Sun, 29 Jan 2006 03:25:23 -0800 (PST) Message-ID: <9e4684ce0601290325p4f284c57ndeaae13e6ce58fd7@mail.gmail.com> Date: Sun, 29 Jan 2006 12:25:23 +0100 From: hubert depesz lubaczewski To: Luke Lonergan Subject: Re: Huge Data sets, simple queries Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <007101c623a9$82207c10$0200a8c0@videobox> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.206 required=5 tests=[AWL=0.206] X-Spam-Score: 0.206 X-Spam-Level: X-Archive-Number: 200601/464 X-Sequence-Number: 16942 On 1/28/06, Luke Lonergan wrote: > You should check your disk performance, I would > expect you'll find it lacking, partly because you are running RAID10, but > mostly because I expect you are using a hardware RAID adapter. hmm .. do i understand correctly that you're suggesting that using raid 10 and/or hardware raid adapter might hurt disc subsystem performance? could you elaborate on the reasons, please? it's not that i'm against the idea - i'm just curious as this is very "against-common-sense". and i always found it interesting when somebody states something that uncommon... best regards depesz From pgsql-performance-owner@postgresql.org Sun Jan 29 11:43:25 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 43DB49DC883 for ; Sun, 29 Jan 2006 11:43:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19584-09 for ; Sun, 29 Jan 2006 11:43:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by postgresql.org (Postfix) with ESMTP id 9236F9DC80A for ; Sun, 29 Jan 2006 11:43:22 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0ITV00DS12CEXNWI@vms046.mailsrvcs.net> for pgsql-performance@postgresql.org; Sun, 29 Jan 2006 09:43:27 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id 1E5BC6E5D4 for ; Sun, 29 Jan 2006 10:43:26 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 09900-02 for ; Sun, 29 Jan 2006 10:43:25 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 0ED986EA13; Sun, 29 Jan 2006 10:43:24 -0500 (EST) Date: Sun, 29 Jan 2006 10:43:24 -0500 From: Michael Stone Subject: Re: Huge Data sets, simple queries In-reply-to: <9e4684ce0601290325p4f284c57ndeaae13e6ce58fd7@mail.gmail.com> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060129154323.GA9976@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us References: <007101c623a9$82207c10$0200a8c0@videobox> <9e4684ce0601290325p4f284c57ndeaae13e6ce58fd7@mail.gmail.com> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.108 required=5 tests=[AWL=0.108] X-Spam-Score: 0.108 X-Spam-Level: X-Archive-Number: 200601/465 X-Sequence-Number: 16943 On Sun, Jan 29, 2006 at 12:25:23PM +0100, hubert depesz lubaczewski wrote: >hmm .. do i understand correctly that you're suggesting that using >raid 10 and/or hardware raid adapter might hurt disc subsystem >performance? could you elaborate on the reasons, please? I think it's been fairly well beaten to death that the low-end hardware raid adapters have lousy performance. It's not until you get into the range of battery-backed disk caches with 512M+ and multiple I/O channels that hardware raid becomes competitive with software raid. Mike Stone From pgsql-performance-owner@postgresql.org Sun Jan 29 14:46:41 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A08CE9DCBD3 for ; Sun, 29 Jan 2006 14:46:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61511-03 for ; Sun, 29 Jan 2006 14:46:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id 8F6AB9DCA7D for ; Sun, 29 Jan 2006 14:46:37 -0400 (AST) Received: from 172.16.1.110 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Sun, 29 Jan 2006 13:46:34 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Sun, 29 Jan 2006 13:46:34 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Subject: Re: Huge Data sets, simple queries Date: Sun, 29 Jan 2006 13:44:08 -0500 Message-ID: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYkyRpoG0gZ6jTvQhyW+xEvJhxA1wAOVEsg From: "Luke Lonergan" To: "hubert depesz lubaczewski" cc: pgsql-performance@postgresql.org X-OriginalArrivalTime: 29 Jan 2006 18:46:34.0275 (UTC) FILETIME=[53CE1730:01C62504] X-WSS-ID: 6FC3D20032K126766-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.046 required=5 tests=[AWL=0.046] X-Spam-Score: 0.046 X-Spam-Level: X-Archive-Number: 200601/466 X-Sequence-Number: 16944 Depesz, > [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20 > hubert depesz lubaczewski > Sent: Sunday, January 29, 2006 3:25 AM > > hmm .. do i understand correctly that you're suggesting that=20 > using raid 10 and/or hardware raid adapter might hurt disc=20 > subsystem performance? could you elaborate on the reasons,=20 > please? it's not that i'm against the idea - i'm just curious=20 > as this is very "against-common-sense". and i always found it=20 > interesting when somebody states something that uncommon... See previous postings on this list - often when someone is reporting a performance problem with large data, the answer comes back that their I/O setup is not performing well. Most times, people are trusting that when they buy a hardware RAID adapter and set it up, that the performance will be what they expect and what is theoretically correct for the number of disk drives. In fact, in our testing of various host-based SCSI RAID adapters (LSI, Dell PERC, Adaptec, HP SmartArray), we find that *all* of them underperform, most of them severely. Some produce results slower than a single disk drive. We've found that some external SCSI RAID adapters, those built into the disk chassis, often perform better. I think this might be due to the better drivers and perhaps a different marketplace for the higher end solutions driving performance validation. The important lesson we've learned is to always test the I/O subsystem performance - you can do so with a simple test like: time bash -c "dd if=3D/dev/zero of=3Dbigfile bs=3D8k count=3D4000000 = && sync" time dd if=3Dbigfile of=3D/dev/null bs=3D8k If the answer isn't something close to the theoretical rate, you are likely limited by your RAID setup. You might be shocked to find a severe performance problem. If either is true, switching to software RAID using a simple SCSI adapter will fix the problem. BTW - we've had very good experiences with the host-based SATA adapters from 3Ware. The Areca controllers are also respected. Oh - and about RAID 10 - for large data work it's more often a waste of disk performance-wise compared to RAID 5 these days. RAID5 will almost double the performance on a reasonable number of drives. - Luke From pgsql-performance-owner@postgresql.org Sun Jan 29 17:04:03 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D0CC19DC80C for ; Sun, 29 Jan 2006 17:04:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01792-05 for ; Sun, 29 Jan 2006 17:04:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail8.sea5.speakeasy.net (mail8.sea5.speakeasy.net [69.17.117.10]) by postgresql.org (Postfix) with ESMTP id 1A8C39DC853 for ; Sun, 29 Jan 2006 17:03:59 -0400 (AST) Received: (qmail 12788 invoked from network); 29 Jan 2006 21:04:01 -0000 Received: from dsl081-060-184.sfo1.dsl.speakeasy.net (HELO noodles) (jwbaker@[64.81.60.184]) (envelope-sender ) by mail8.sea5.speakeasy.net (qmail-ldap-1.03) with RC4-MD5 encrypted SMTP for ; 29 Jan 2006 21:04:01 -0000 Subject: Re: Huge Data sets, simple queries From: "Jeffrey W. Baker" To: Luke Lonergan Cc: pgsql-performance@postgresql.org In-Reply-To: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> References: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> Content-Type: text/plain Date: Sun, 29 Jan 2006 13:04:01 -0800 Message-Id: <1138568641.10923.6.camel@noodles> Mime-Version: 1.0 X-Mailer: Evolution 2.5.4 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/467 X-Sequence-Number: 16945 On Sun, 2006-01-29 at 13:44 -0500, Luke Lonergan wrote: > Depesz, > > > [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of > > hubert depesz lubaczewski > > Sent: Sunday, January 29, 2006 3:25 AM > > > > hmm .. do i understand correctly that you're suggesting that > > using raid 10 and/or hardware raid adapter might hurt disc > > subsystem performance? could you elaborate on the reasons, > > please? it's not that i'm against the idea - i'm just curious > > as this is very "against-common-sense". and i always found it > > interesting when somebody states something that uncommon... > Oh - and about RAID 10 - for large data work it's more often a waste of > disk performance-wise compared to RAID 5 these days. RAID5 will almost > double the performance on a reasonable number of drives. I think you might want to be more specific here. I would agree with you for data warehousing, decision support, data mining, and similar read-mostly non-transactional loads. For transactional loads RAID-5 is, generally speaking, a disaster due to the read-before-write problem. While we're on the topic, I just installed another one of those Areca ARC-1130 controllers with 1GB cache. It's ludicrously fast: 250MB/sec burst writes, CPU-limited reads. I can't recommend them highly enough. -jwb PS: Could you look into fixing your mailer? Your messages sometimes don't contain In-Reply-To headers, and therefore don't thread properly. From pgsql-performance-owner@postgresql.org Sun Jan 29 20:32:18 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 54F679DC833 for ; Sun, 29 Jan 2006 20:32:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35249-08 for ; Sun, 29 Jan 2006 20:32:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail1.panix.com (mail1.panix.com [166.84.1.72]) by postgresql.org (Postfix) with ESMTP id 15C1C9DC82E for ; Sun, 29 Jan 2006 20:32:15 -0400 (AST) Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mail1.panix.com (Postfix) with ESMTP id 1FC0D588A0; Sun, 29 Jan 2006 19:32:18 -0500 (EST) Received: (from adler@localhost) by panix2.panix.com (8.11.6p3/8.8.8/PanixN1.1) id k0U0WIp17092; Sun, 29 Jan 2006 19:32:18 -0500 (EST) Date: Sun, 29 Jan 2006 19:32:15 -0500 From: Michael Adler To: Mike Biamonte Cc: pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries Message-ID: <20060130003215.GA20269@pobox.com> References: <007101c623a9$82207c10$0200a8c0@videobox> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <007101c623a9$82207c10$0200a8c0@videobox> X-PGP-Key-ID: 0xFA0F8E88 X-PGP-Key-Fingerprint: B40D 7C75 C44A 443D 8216 29B8 4B82 2C04 FA0F 8E88 X-PGP-Key-URL: User-Agent: Mutt/1.5.10i X-Hashcash: 1:20:060130:mike@dbeat.com::kKJRtZlcudE+h3ZR:0004MUH X-Hashcash: 1:20:060130:pgsql-performance@postgresql.org::QF46YqlT5i0d1bj1:00000 00000000000000000000000053UM X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.096 required=5 tests=[AWL=0.096] X-Spam-Score: 0.096 X-Spam-Level: X-Archive-Number: 200601/468 X-Sequence-Number: 16946 On Fri, Jan 27, 2006 at 08:23:55PM -0500, Mike Biamonte wrote: > This query took 18 hours on PG 8.1 on a Dual Xeon, RHEL3, (2.4 > Kernel) with RAID-10 (15K drives) and 12 GB Ram. I was expecting it > to take about 4 hours - based on some experience with a similar > dataset on a different machine (RH9, PG7.3 Dual Xeon, 4GB RAM, > Raid-5 10K drives) > > It's difficult to just "try" various ideas because each attempt > takes a full day to test. Real experience is needed here! It seems like you are changing multiple variables at the same time. I think you need to first compare the query plans with EXPLAIN SELECT to see if they are significantly different. Your upgrade from 7.3 to 8.1 may have resulted in a less optimal plan. Second, you should monitor your IO performance during the query execution and test it independent of postgres. Then compare the stats between the two systems. As a side note, if you have many disks and you are concerned about bottlenecks on read operations, RAID 5 may perform better than RAID 10. -Mike From pgsql-performance-owner@postgresql.org Sun Jan 29 23:24:26 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 683479DC9A8 for ; Sun, 29 Jan 2006 23:24:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73563-06 for ; Sun, 29 Jan 2006 23:24:29 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-68-15-5-150.sd.sd.cox.net [68.15.5.150]) by postgresql.org (Postfix) with ESMTP id 283409DC9A2 for ; Sun, 29 Jan 2006 23:24:22 -0400 (AST) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k0U2QHXA003079; Sun, 29 Jan 2006 18:26:17 -0800 Message-ID: <43DD85D2.5020207@modgraph-usa.com> Date: Sun, 29 Jan 2006 19:19:46 -0800 From: "Craig A. James" User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Mike Biamonte CC: pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries References: <007101c623a9$82207c10$0200a8c0@videobox> In-Reply-To: <007101c623a9$82207c10$0200a8c0@videobox> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.092 required=5 tests=[AWL=0.092] X-Spam-Score: 0.092 X-Spam-Level: X-Archive-Number: 200601/469 X-Sequence-Number: 16947 Mike Biamonte wrote: > Does anyone have any experience with extremely large data sets? > I'm mean hundreds of millions of rows. > > The queries I need to run on my 200 million transactions are relatively > simple: > > select month, count(distinct(cardnum)) count(*), sum(amount) from > transactions group by month; This may be heretical to post to a relational-database group, but sometimes a problem can be better solved OUTSIDE of the relational system. I had a similar problem recently: I have a set of about 100,000 distinct values, each of which occurs one to several million times in the database, with an aggregate total of several hundred million occurances in the database. Sorting this into distinct lists ("Which rows contain this value?") proved quite time consuming (just like your case), but on reflection, I realized that it was dumb to expect a general-purpose sorting algorithm to sort a list about which I had specialized knowledge. General-purpose sorting usually takes O(N*log(N)), but if you have a small number of distinct values, you can use "bucket sorting" and sort in O(N) time, a huge improvement. In my case, it was even more specialized -- there was a very small number of the lists that contained thousands or millions of items, but about 95% of the lists only had a few items. Armed with this knowledge, it took me couple weeks to write a highly-specialized sorting system that used a combination of Postgres, in-memory and disk caching, and algorithms dredged up from Knuth. The final result ran in about four hours. The thing to remember about relational databases is that the designers are constrained by the need for generality, reliability and SQL standards. Given any particular well-defined task where you have specialized knowledge about the data, and/or you don't care about transactional correctness, and/or you're not concerned about data loss, a good programmer can always write a faster solution. Of course, there's a huge penalty. You lose support, lose of generality, the application takes on complexity that should be in the database, and on and on. A hand-crafted solution should be avoided unless there's simply no other way. A relational database is a tool. Although powerful, like any tool it has limitations. Use the tool where it's useful, and use other tools when necessary. Craig From pgsql-performance-owner@postgresql.org Sun Jan 29 23:50:56 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0AA5F9DC993 for ; Sun, 29 Jan 2006 23:50:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76442-06 for ; Sun, 29 Jan 2006 23:51:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id D76BA9DC9A3 for ; Sun, 29 Jan 2006 23:50:53 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0U3oww5025262; Sun, 29 Jan 2006 22:50:58 -0500 (EST) To: Jen Sale cc: pgsql-performance@postgresql.org Subject: Re: Desperate: View not using indexes (very slow) In-reply-to: <200601251109.25876.js@slipt.net> References: <200601251109.25876.js@slipt.net> Comments: In-reply-to Jen Sale message dated "Wed, 25 Jan 2006 11:09:25 -0500" Date: Sun, 29 Jan 2006 22:50:58 -0500 Message-ID: <25261.1138593058@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.101 required=5 tests=[AWL=0.101] X-Spam-Score: 0.101 X-Spam-Level: X-Archive-Number: 200601/472 X-Sequence-Number: 16950 Jen Sale writes: > can someone please tell me what we did wrong? Joins against union subqueries aren't handled very well at the moment. (As it happens, I'm working on that exact problem right now for 8.2, but that won't help you today.) The plan indicates that you are using UNION rather than UNION ALL, which is not helping any. Do you really need duplicate elimination in that view? regards, tom lane From pgsql-performance-owner@postgresql.org Mon Jan 30 01:35:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A096A9DC850 for ; Mon, 30 Jan 2006 01:35:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93428-08 for ; Mon, 30 Jan 2006 01:35:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.bway.net (xena.bway.net [216.220.96.26]) by postgresql.org (Postfix) with ESMTP id 2590F9DC843 for ; Mon, 30 Jan 2006 01:35:09 -0400 (AST) Received: (qmail 93872 invoked by uid 0); 30 Jan 2006 05:35:09 -0000 Received: from unknown (HELO ?192.168.0.41?) (spork@bway.net@216.220.116.154) by smtp.bway.net with (DHE-RSA-AES256-SHA encrypted) SMTP; 30 Jan 2006 05:35:09 -0000 Date: Mon, 30 Jan 2006 00:35:12 -0500 (EST) From: Charles Sprickman X-X-Sender: spork@spork-book.local To: Luke Lonergan cc: hubert depesz lubaczewski , pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries In-Reply-To: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> Message-ID: References: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.096 required=5 tests=[AWL=0.096] X-Spam-Score: 0.096 X-Spam-Level: X-Archive-Number: 200601/473 X-Sequence-Number: 16951 On Sun, 29 Jan 2006, Luke Lonergan wrote: > In fact, in our testing of various host-based SCSI RAID adapters (LSI, > Dell PERC, Adaptec, HP SmartArray), we find that *all* of them > underperform, most of them severely. [snip] > The important lesson we've learned is to always test the I/O subsystem > performance - you can do so with a simple test like: > time bash -c "dd if=/dev/zero of=bigfile bs=8k count=4000000 && sync" > time dd if=bigfile of=/dev/null bs=8k I'm curious about this since we're shopping around for something new... I do want to get some kind of baseline to compare new products to. Areca sent me stats on their SCSI->SATA controller and it looks like it maxes out around 10,000 IOPS. I'd like to see how our existing stuff compares to this. I'd especially like to see it in graph form such as the docs Areca sent (IOPS on one axis, block size on the other, etc.). Looking at the venerable Bonnie, it doesn't really seem to focus so much on the number of read/write operations per second, but on big bulky transfers. What are you folks using to measure your arrays? I've been considering using some of our data and just basically benchmarking postgres on various hardware with that, but I cannot compare that to any manufacturer tests. Sorry to meander a bit off topic, but I've been getting frustrated with this little endeavour... Thanks, Charles > - Luke > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > From pgsql-performance-owner@postgresql.org Mon Jan 30 03:25:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E7F4B9DCA59 for ; Mon, 30 Jan 2006 03:25:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18594-04-3 for ; Mon, 30 Jan 2006 03:25:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46]) by postgresql.org (Postfix) with ESMTP id 02D3D9DCA32 for ; Mon, 30 Jan 2006 03:25:29 -0400 (AST) Received: from 172.16.1.112 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D2)); Mon, 30 Jan 2006 02:25:22 -0500 X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP02.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 30 Jan 2006 02:25:22 -0500 Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Mon, 30 Jan 2006 07:25:22 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Sun, 29 Jan 2006 23:25:22 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "Charles Sprickman" cc: "hubert depesz lubaczewski" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYlXvYzEFUVJEA+TBKMsmNFpJsgdAAD14+A In-Reply-To: MIME-Version: 1.0 X-OriginalArrivalTime: 30 Jan 2006 07:25:22.0773 (UTC) FILETIME=[54E79050:01C6256E] X-WSS-ID: 6FC360E82XS295913-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.348 required=5 tests=[AWL=0.095, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.348 X-Spam-Level: * X-Archive-Number: 200601/474 X-Sequence-Number: 16952 Charles, On 1/29/06 9:35 PM, "Charles Sprickman" wrote: > What are you folks using to measure your arrays? Bonnie++ measures random I/Os, numbers we find are typically in the 500/s range, the best I've seen is 1500/s on a large Fibre Channel RAID0 (at http://www.wlug.org.nz/HarddiskBenchmarks). - Luke From pgsql-performance-owner@postgresql.org Mon Jan 30 20:36:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7A65B9DC9C1 for ; Mon, 30 Jan 2006 20:36:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13386-04 for ; Mon, 30 Jan 2006 20:36:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 191119DC944 for ; Mon, 30 Jan 2006 20:36:09 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id D09984102A9; Tue, 31 Jan 2006 01:21:11 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id E2813FF30; Mon, 30 Jan 2006 09:25:45 +0000 (GMT) Message-ID: <43DDDB99.2090607@archonet.com> Date: Mon, 30 Jan 2006 09:25:45 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: arnaulist@andromeiberica.com Cc: pgsql-performance@postgresql.org Subject: Re: Where is my bottleneck? References: <43D67496.2020203@androme.es> In-Reply-To: <43D67496.2020203@androme.es> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.549 required=5 tests=[AWL=-0.332, DATE_IN_PAST_12_24=0.881] X-Spam-Score: 0.549 X-Spam-Level: X-Archive-Number: 200601/485 X-Sequence-Number: 16963 Arnau Rebassa Villalonga wrote: > > The configuration of postgresql is the default, I tried to tune the > postgresql.conf and the results where disappointing, so I left again the > default values. That's the first thing to fix. Go to the page below and read through the "Performance Tuning" article. http://www.varlena.com/varlena/GeneralBits/Tidbits/index.php -- Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Mon Jan 30 07:00:57 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 858049DC98C for ; Mon, 30 Jan 2006 07:00:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 58708-03 for ; Mon, 30 Jan 2006 07:00:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from vms044pub.verizon.net (vms044pub.verizon.net [206.46.252.44]) by postgresql.org (Postfix) with ESMTP id 2ADDB9DC9E1 for ; Mon, 30 Jan 2006 07:00:53 -0400 (AST) Received: from osgiliath.mathom.us ([70.108.47.21]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0ITW000ZMJXGX450@vms044.mailsrvcs.net> for pgsql-performance@postgresql.org; Mon, 30 Jan 2006 05:00:53 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by osgiliath.mathom.us (Postfix) with ESMTP id C77216EA7D for ; Mon, 30 Jan 2006 06:00:50 -0500 (EST) Received: from osgiliath.mathom.us ([127.0.0.1]) by localhost (osgiliath.home.mathom.us [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 17253-08-2 for ; Mon, 30 Jan 2006 06:00:49 -0500 (EST) Received: by osgiliath.mathom.us (Postfix, from userid 1000) id 7857D6EA13; Mon, 30 Jan 2006 06:00:49 -0500 (EST) Date: Mon, 30 Jan 2006 06:00:49 -0500 From: Michael Stone Subject: Re: Where is my bottleneck? In-reply-to: <43D67496.2020203@androme.es> To: pgsql-performance@postgresql.org Mail-followup-to: pgsql-performance@postgresql.org Message-id: <20060130110047.GB9976@mathom.us> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-disposition: inline X-Pgp-Fingerprint: 53 FF 38 00 E7 DD 0A 9C 84 52 84 C5 EE DF 7C 88 X-Virus-Scanned: Debian amavisd-new at mathom.us References: <43D67496.2020203@androme.es> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.109 required=5 tests=[AWL=0.109] X-Spam-Score: 0.109 X-Spam-Level: X-Archive-Number: 200601/475 X-Sequence-Number: 16953 On Tue, Jan 24, 2006 at 07:40:22PM +0100, Arnau Rebassa Villalonga wrote: > I have a performance problem and I don't know where is my bottleneck. [snip] > Most of the time the idle value is even higher than 60%. It's generally a fairly safe bet that if you are running slow and your cpu is idle, your i/o isn't fast enough. Mike Stone From pgsql-performance-owner@postgresql.org Mon Jan 30 12:58:08 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 41A959DC848 for ; Mon, 30 Jan 2006 12:58:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22333-02 for ; Mon, 30 Jan 2006 12:58:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id D4E569DC86F for ; Mon, 30 Jan 2006 12:58:05 -0400 (AST) Received: from 172.16.1.110 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Mon, 30 Jan 2006 11:57:56 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 30 Jan 2006 11:57:55 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Mon, 30 Jan 2006 16:57:53 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Mon, 30 Jan 2006 08:49:04 -0800 Subject: Re: Where is my bottleneck? From: "Luke Lonergan" To: arnaulist@andromeiberica.com, pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Where is my bottleneck? Thread-Index: AcYlTXJlmh467zVYQt+IukMO5Z5s6wAb6GIY In-Reply-To: <43D67496.2020203@androme.es> MIME-Version: 1.0 X-OriginalArrivalTime: 30 Jan 2006 16:57:55.0439 (UTC) FILETIME=[50B067F0:01C625BE] X-WSS-ID: 6FC09A1B32K768491-02-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.292 required=5 tests=[AWL=0.039, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.292 X-Spam-Level: * X-Archive-Number: 200601/476 X-Sequence-Number: 16954 Arnau, On 1/24/06 10:40 AM, "Arnau Rebassa Villalonga" wrote: > I know it's a problem with a very big scope, but could you give me a > hint about where I should look to? Try this: time bash -c "dd if=/dev/zero of=bigfile bs=8k count=2000000 && sync" time dd if=bigfile of=/dev/null bs=8k And report the results back here. If it takes too long to complete (more than a couple of minutes), bring up another window and run "vmstat 1" then report the values in the columns "bi" and "bo". - Luke From pgsql-performance-owner@postgresql.org Mon Jan 30 13:53:35 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6EE649DC9FA for ; Mon, 30 Jan 2006 13:53:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31189-05 for ; Mon, 30 Jan 2006 13:53:33 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.195]) by postgresql.org (Postfix) with ESMTP id 3EE759DC855 for ; Mon, 30 Jan 2006 13:53:32 -0400 (AST) Received: by zproxy.gmail.com with SMTP id i11so1036440nzh for ; Mon, 30 Jan 2006 09:53:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=GCwigbljgxwYqW1i73nX4cl35DmPXGkgretItS7q3tFIsxg2zI1OvmwT3vmzQ5LnsqKkWt7oe+z3PurukzURtBKUjkz66cgi8+kFTc7Nd5ee+3WOxVX4cF1/opV3ucZDlTK3SqVpBfTLdQhOAsagGTJ2vu//sGb7YMj6T0sHpmk= Received: by 10.64.150.1 with SMTP id x1mr395697qbd; Mon, 30 Jan 2006 09:53:29 -0800 (PST) Received: by 10.65.254.12 with HTTP; Mon, 30 Jan 2006 09:53:29 -0800 (PST) Message-ID: <9e4684ce0601300953kdb9f812h12820410cc3d5580@mail.gmail.com> Date: Mon, 30 Jan 2006 18:53:29 +0100 From: hubert depesz lubaczewski To: Luke Lonergan Subject: Re: Huge Data sets, simple queries Cc: pgsql-performance@postgresql.org In-Reply-To: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <3E37B936B592014B978C4415F90D662D023F28D9@MI8NYCMAIL06.Mi8.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.201 required=5 tests=[AWL=0.201] X-Spam-Score: 0.201 X-Spam-Level: X-Archive-Number: 200601/477 X-Sequence-Number: 16955 On 1/29/06, Luke Lonergan wrote: > Oh - and about RAID 10 - for large data work it's more often a waste of > disk performance-wise compared to RAID 5 these days. RAID5 will almost > double the performance on a reasonable number of drives. how many is reasonable? depesz From pgsql-performance-owner@postgresql.org Mon Jan 30 15:49:16 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D59379DCB6D for ; Mon, 30 Jan 2006 15:49:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64854-03 for ; Mon, 30 Jan 2006 15:49:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46]) by postgresql.org (Postfix) with ESMTP id A823A9DC98B for ; Mon, 30 Jan 2006 15:49:12 -0400 (AST) Received: from 172.16.1.26 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D2)); Mon, 30 Jan 2006 14:49:07 -0500 X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST01.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 30 Jan 2006 14:49:05 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Mon, 30 Jan 2006 19:48:50 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Mon, 30 Jan 2006 11:48:49 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "hubert depesz lubaczewski" cc: pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYl1jBJbwQQzpHJEdqBvAANk63kWA== In-Reply-To: <9e4684ce0601300953kdb9f812h12820410cc3d5580@mail.gmail.com> MIME-Version: 1.0 X-OriginalArrivalTime: 30 Jan 2006 19:49:05.0567 (UTC) FILETIME=[3A2992F0:01C625D6] X-WSS-ID: 6FC0B2392XS789756-02-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.296 required=5 tests=[AWL=0.043, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.296 X-Spam-Level: * X-Archive-Number: 200601/478 X-Sequence-Number: 16956 Depesz, On 1/30/06 9:53 AM, "hubert depesz lubaczewski" wrote: >> double the performance on a reasonable number of drives. > > how many is reasonable? What I mean by that is: given a set of disks N, the read performance of RAID will be equal to the drive read rate A times the number of drives used for reading by the RAID algorithm. In the case of RAID5, that number is (N-1), so the read rate is A x (N-1). In the case of RAID10, that number is N/2, so the read rate is A x (N/2). So, the ratio of read performance RAID5/RAID10 is (N-1)/(N/2) = 2 x (N-1)/N. For numbers of drives, this ratio looks like this: N RAID5/RAID10 3 1.33 6 1.67 8 1.75 14 1.86 So - I think reasonable would be 6-8, which are common disk configurations. - Luke From pgsql-performance-owner@postgresql.org Mon Jan 30 16:10:42 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E19959DC984 for ; Mon, 30 Jan 2006 16:10:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64042-09 for ; Mon, 30 Jan 2006 16:10:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 50D9A9DC9F8 for ; Mon, 30 Jan 2006 16:10:39 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id A0C3739841; Mon, 30 Jan 2006 14:10:25 -0600 (CST) Date: Mon, 30 Jan 2006 14:10:25 -0600 From: "Jim C. Nasby" To: arnaulist@andromeiberica.com Cc: pgsql-performance@postgresql.org Subject: Re: Where is my bottleneck? Message-ID: <20060130201025.GA3920@pervasive.com> References: <43D67496.2020203@androme.es> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43D67496.2020203@androme.es> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/479 X-Sequence-Number: 16957 On Tue, Jan 24, 2006 at 07:40:22PM +0100, Arnau Rebassa Villalonga wrote: > Hi all, > > I have a performance problem and I don't know where is my bottleneck. > I have postgresql 7.4.2 running on a debian server with kernel You should really upgrade to the latest 7.4 version. You're probably vulnerable to some data-loss issues. > 2.4.26-1-686-smp with two Xeon(TM) at 2.80GHz and 4GB of RAM and a RAID > 5 made with SCSI disks. Maybe its not the latest hardware but I think Generally speaking, databases (or anything else that does a lot of random writes) don't like RAID5. > My problem is that the general performance is not good enough and I > don't know where is the bottleneck. It could be because the queries are > not optimized as they should be, but I also think it can be a postgresql > configuration problem or hardware problem (HDs not beeing fast enough, > not enough RAM, ... ) What kind of performance are you expecting? What are you actually seeing? > The configuration of postgresql is the default, I tried to tune the > postgresql.conf and the results where disappointing, so I left again the > default values. Probably not so good... you'll most likely want to tune shared_buffers, sort_mem and effective_cache_size at a minimum. Granted, that might not be your current bottleneck, but it would probably be your next. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Mon Jan 30 16:25:26 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C44EF9DCA4F for ; Mon, 30 Jan 2006 16:25:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 68896-10 for ; Mon, 30 Jan 2006 16:25:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 5E2729DC98B for ; Mon, 30 Jan 2006 16:25:23 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id B19A639842; Mon, 30 Jan 2006 14:25:24 -0600 (CST) Date: Mon, 30 Jan 2006 14:25:24 -0600 From: "Jim C. Nasby" To: Luke Lonergan Cc: Mike Biamonte , pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries Message-ID: <20060130202524.GB3920@pervasive.com> References: <007101c623a9$82207c10$0200a8c0@videobox> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.099 required=5 tests=[AWL=0.099] X-Spam-Score: 0.099 X-Spam-Level: X-Archive-Number: 200601/480 X-Sequence-Number: 16958 On Fri, Jan 27, 2006 at 07:05:04PM -0800, Luke Lonergan wrote: > Sounds like you are running into the limits of your disk subsystem. You are > scanning all of the data in the transactions table, so you will be limited > by the disk bandwidth you have ? and using RAID-10, you should divide the > number of disk drives by 2 and multiply by their indiividual bandwidth > (around 60MB/s) and that?s what you can expect in terms of performance. So, > if you have 8 drives, you should expect to get 4 x 60 MB/s = 240 MB/s in > bandwidth. That means that if you are dealing with 24,000 MB of data in the > ?transactions? table, then you will scan it in 100 seconds. Why divide by 2? A good raid controller should be able to send read requests to both drives out of the mirrored set to fully utilize the bandwidth. Of course, that probably won't come into play unless the OS decides that it's going to read-ahead fairly large chunks of the table at a time... Also, some vmstat output would certainly help clarify where the bottleneck is... -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Mon Jan 30 18:57:23 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7CB9A9DCA86 for ; Mon, 30 Jan 2006 18:57:22 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98821-02 for ; Mon, 30 Jan 2006 18:57:18 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 947529DCA66 for ; Mon, 30 Jan 2006 18:57:14 -0400 (AST) Received: from rose.easter-eggs.fr (coquelicot-sdsl.easter-eggs.com [213.215.37.94]) by svr4.postgresql.org (Postfix) with ESMTP id A757E5AF08A for ; Mon, 30 Jan 2006 22:57:17 +0000 (GMT) Received: from pavot.easter-eggs.fr (pavot.easter-eggs.fr [10.0.0.26]) by rose.easter-eggs.fr (Postfix) with ESMTP id EC68DBB for ; Mon, 30 Jan 2006 23:57:14 +0100 (CET) Received: by pavot.easter-eggs.fr (Postfix, from userid 1013) id 527335BAF3; Mon, 30 Jan 2006 23:57:12 +0100 (CET) Date: Mon, 30 Jan 2006 23:57:11 +0100 From: Emmanuel Lacour To: pgsql-performance@postgresql.org Subject: Query planner issue Message-ID: <20060130225711.GE1320@easter-eggs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/481 X-Sequence-Number: 16959 Hi everybody, I have the following problem, on a test server, if I do a fresh import of production data then run 'explain analyze select count(*) from mandats;' I get this result: Aggregate (cost=6487.32..6487.32 rows=1 width=0) (actual time=607.61..607.61 rows=1 loops=1) -> Seq Scan on mandats (cost=0.00..6373.26 rows=45626 width=0) (actual time=0.14..496.20 rows=45626 loops=1) Total runtime: 607.95 msec On the production server, if I do the same (without other use of the server), I get: Aggregate (cost=227554.33..227554.33 rows=1 width=0) (actual time=230705.79..230705.79 rows=1 loops=1) -> Seq Scan on mandats (cost=0.00..227440.26 rows=45626 width=0) (actual time=0.03..230616.64 rows=45760 loops=1) Total runtime: 230706.08 msec Is there anyone having an idea on how yo solve this poor performances? I think it is caused by many delete/insert on this table every day, but how to solve it, I need to run this qury each hour :(. I run vacuum each night, postgresql is unfortunatly 7.2.1 :( (no upgrade before 2 or 3 months). -- Emmanuel Lacour ------------------------------------ Easter-eggs 44-46 rue de l'Ouest - 75014 Paris - France - M�tro Gait� Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 41 35 00 76 mailto:elacour@easter-eggs.com - http://www.easter-eggs.com From pgsql-performance-owner@postgresql.org Mon Jan 30 19:26:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 49CF39DC9C1 for ; Mon, 30 Jan 2006 19:26:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00597-08 for ; Mon, 30 Jan 2006 19:26:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id 12A3D9DC98B for ; Mon, 30 Jan 2006 19:26:21 -0400 (AST) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 30 Jan 2006 15:26:23 -0800 Subject: Re: Query planner issue From: Mark Lewis To: Emmanuel Lacour Cc: pgsql-performance@postgresql.org In-Reply-To: <20060130225711.GE1320@easter-eggs.com> References: <20060130225711.GE1320@easter-eggs.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Mon, 30 Jan 2006 15:26:23 -0800 Message-Id: <1138663583.28241.96.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-22) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.120, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200601/482 X-Sequence-Number: 16960 You have lots of dead rows. Do a vacuum full to get it under control, then run VACUUM more frequently and/or increase your FSM settings to keep dead rows in check. In 7.2 vacuum is pretty intrusive; it will be much better behaved once you can upgrade to a more recent version. You really, really want to upgrade as soon as possible, and refer to the on-line docs about what to do with your FSM settings. -- Mark Lewis On Mon, 2006-01-30 at 23:57 +0100, Emmanuel Lacour wrote: > Hi everybody, > > I have the following problem, on a test server, if I do a fresh import > of production data then run > 'explain analyze select count(*) from mandats;' > > I get this result: > > Aggregate (cost=6487.32..6487.32 rows=1 width=0) (actual time=607.61..607.61 rows=1 loops=1) > -> Seq Scan on mandats (cost=0.00..6373.26 rows=45626 width=0) (actual time=0.14..496.20 rows=45626 loops=1) > Total runtime: 607.95 msec > > > On the production server, if I do the same (without other use of the server), I get: > > Aggregate (cost=227554.33..227554.33 rows=1 width=0) (actual time=230705.79..230705.79 rows=1 loops=1) > -> Seq Scan on mandats (cost=0.00..227440.26 rows=45626 width=0) (actual time=0.03..230616.64 rows=45760 loops=1) > Total runtime: 230706.08 msec > > > > Is there anyone having an idea on how yo solve this poor performances? I > think it is caused by many delete/insert on this table every day, but > how to solve it, I need to run this qury each hour :(. I run > vacuum each night, postgresql is unfortunatly 7.2.1 :( (no upgrade > before 2 or 3 months). > From pgsql-performance-owner@postgresql.org Mon Jan 30 19:37:31 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 30D789DCA86 for ; Mon, 30 Jan 2006 19:37:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04493-04 for ; Mon, 30 Jan 2006 19:37:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from amanda.contactbda.com (ipn36372-f65123.cidr.lightship.net [216.204.66.227]) by postgresql.org (Postfix) with ESMTP id 376AA9DC9FA for ; Mon, 30 Jan 2006 19:37:27 -0400 (AST) Received: from amanda.contactbda.com (amanda.contactbda.com [192.168.1.2]) by amanda.contactbda.com (8.12.11/8.12.11/Debian-3) with ESMTP id k0UNbM4K004301; Mon, 30 Jan 2006 18:37:22 -0500 From: "Jim Buttafuoco" To: Emmanuel Lacour , pgsql-performance@postgresql.org Reply-To: jim@contactbda.com Subject: Re: Query planner issue Date: Mon, 30 Jan 2006 18:37:22 -0500 Message-Id: <20060130233550.M83895@contactbda.com> In-Reply-To: <20060130225711.GE1320@easter-eggs.com> References: <20060130225711.GE1320@easter-eggs.com> X-Mailer: Open WebMail 2.41 20040926 X-OriginatingIP: 192.168.1.1 (jim) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.131 required=5 tests=[AWL=0.131] X-Spam-Score: 0.131 X-Spam-Level: X-Archive-Number: 200601/483 X-Sequence-Number: 16961 with Postgresql 7.2.1 you will need to do BOTH vacuum and reindex and with a table that gets many updates/deletes, you should run vacuum more than daily. Both issues have been solved in 8.1. Jim ---------- Original Message ----------- From: Emmanuel Lacour To: pgsql-performance@postgresql.org Sent: Mon, 30 Jan 2006 23:57:11 +0100 Subject: [PERFORM] Query planner issue > Hi everybody, > > I have the following problem, on a test server, if I do a fresh import > of production data then run > 'explain analyze select count(*) from mandats;' > > I get this result: > > Aggregate (cost=6487.32..6487.32 rows=1 width=0) (actual time=607.61..607.61 rows=1 loops=1) > -> Seq Scan on mandats (cost=0.00..6373.26 rows=45626 width=0) (actual time=0.14..496.20 rows=45626 > loops=1) Total runtime: 607.95 msec > > On the production server, if I do the same (without other use of the server), I get: > > Aggregate (cost=227554.33..227554.33 rows=1 width=0) (actual time=230705.79..230705.79 rows=1 loops=1) > -> Seq Scan on mandats (cost=0.00..227440.26 rows=45626 width=0) (actual time=0.03..230616.64 rows=45760 > loops=1) Total runtime: 230706.08 msec > > Is there anyone having an idea on how yo solve this poor performances? I > think it is caused by many delete/insert on this table every day, but > how to solve it, I need to run this qury each hour :(. I run > vacuum each night, postgresql is unfortunatly 7.2.1 :( (no upgrade > before 2 or 3 months). > > -- > Emmanuel Lacour ------------------------------------ Easter-eggs > 44-46 rue de l'Ouest - 75014 Paris - France - M�tro Gait� > Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 41 35 00 76 > mailto:elacour@easter-eggs.com - http://www.easter-eggs.com > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend ------- End of Original Message ------- From pgsql-performance-owner@postgresql.org Mon Jan 30 20:27:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 77F8C9DC944 for ; Mon, 30 Jan 2006 20:27:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10925-07 for ; Mon, 30 Jan 2006 20:27:25 -0400 (AST) X-Greylist: delayed 01:30:08.788645 by SQLgrey- Received: from rose.easter-eggs.fr (coquelicot-sdsl.easter-eggs.com [213.215.37.94]) by postgresql.org (Postfix) with ESMTP id DD9469DC86A for ; Mon, 30 Jan 2006 20:27:20 -0400 (AST) Received: from pavot.easter-eggs.fr (pavot.easter-eggs.fr [10.0.0.26]) by rose.easter-eggs.fr (Postfix) with ESMTP id 67E1EBB for ; Tue, 31 Jan 2006 01:27:23 +0100 (CET) Received: by pavot.easter-eggs.fr (Postfix, from userid 1013) id EB67E5BAF3; Tue, 31 Jan 2006 01:27:25 +0100 (CET) Date: Tue, 31 Jan 2006 01:27:25 +0100 From: Emmanuel Lacour To: pgsql-performance@postgresql.org Subject: Re: Query planner issue Message-ID: <20060131002725.GF1320@easter-eggs.com> References: <20060130225711.GE1320@easter-eggs.com> <1138663583.28241.96.camel@archimedes> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1138663583.28241.96.camel@archimedes> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.08 required=5 tests=[AWL=0.080] X-Spam-Score: 0.08 X-Spam-Level: X-Archive-Number: 200601/484 X-Sequence-Number: 16962 On Mon, Jan 30, 2006 at 03:26:23PM -0800, Mark Lewis wrote: > You have lots of dead rows. Do a vacuum full to get it under control, > then run VACUUM more frequently and/or increase your FSM settings to > keep dead rows in check. In 7.2 vacuum is pretty intrusive; it will be > much better behaved once you can upgrade to a more recent version. > > You really, really want to upgrade as soon as possible, and refer to the > on-line docs about what to do with your FSM settings. > Thanks! Vacuum full did it. I will now play with fsm settings to avoid running a full vacuum daily... -- Emmanuel Lacour ------------------------------------ Easter-eggs 44-46 rue de l'Ouest - 75014 Paris - France - M�tro Gait� Phone: +33 (0) 1 43 35 00 37 - Fax: +33 (0) 1 41 35 00 76 mailto:elacour@easter-eggs.com - http://www.easter-eggs.com From pgsql-performance-owner@postgresql.org Mon Jan 30 21:55:55 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D67499DC837 for ; Mon, 30 Jan 2006 21:55:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28710-06 for ; Mon, 30 Jan 2006 21:55:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 861159DC805 for ; Mon, 30 Jan 2006 21:55:52 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0V1trji027708; Mon, 30 Jan 2006 20:55:53 -0500 (EST) To: Mark Lewis cc: Emmanuel Lacour , pgsql-performance@postgresql.org Subject: Re: Query planner issue In-reply-to: <1138663583.28241.96.camel@archimedes> References: <20060130225711.GE1320@easter-eggs.com> <1138663583.28241.96.camel@archimedes> Comments: In-reply-to Mark Lewis message dated "Mon, 30 Jan 2006 15:26:23 -0800" Date: Mon, 30 Jan 2006 20:55:53 -0500 Message-ID: <27707.1138672553@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.101 required=5 tests=[AWL=0.101] X-Spam-Score: 0.101 X-Spam-Level: X-Archive-Number: 200601/486 X-Sequence-Number: 16964 Mark Lewis writes: > You really, really want to upgrade as soon as possible, No, sooner than that. Show your boss the list of known data-loss-causing bugs in 7.2.1, and refuse to take responsibility if the database eats all your data before the "in good time" upgrade. The release note pages starting here: http://developer.postgresql.org/docs/postgres/release-7-2-8.html mention the problems we found while 7.2 was still supported. It's likely that some of the 7.3 bugs found later than 2005-05-09 also apply to 7.2. regards, tom lane From pgsql-performance-owner@postgresql.org Tue Jan 31 12:24:40 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 745A09DCCBD for ; Tue, 31 Jan 2006 12:24:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93259-06 for ; Tue, 31 Jan 2006 12:24:37 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 925469DCCBB for ; Tue, 31 Jan 2006 12:24:36 -0400 (AST) Received: from mailstore.csita.unige.it (mbox2.csita.unige.it [130.251.21.23]) by svr4.postgresql.org (Postfix) with ESMTP id 21CFF5AF189 for ; Tue, 31 Jan 2006 16:24:35 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mailstore.csita.unige.it (Postfix) with ESMTP id B550536355 for ; Tue, 31 Jan 2006 17:24:31 +0100 (CET) Received: from mailstore.csita.unige.it ([127.0.0.1]) by localhost (mbox2 [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 12864-01-32 for ; Tue, 31 Jan 2006 17:24:31 +0100 (CET) Received: from 130.251.21.7 (webmail.unige.it [130.251.21.7]) by mailstore.csita.unige.it (Postfix) with ESMTP id 9C3173632F for ; Tue, 31 Jan 2006 17:24:31 +0100 (CET) Received: from selene.educ.disi.unige.it (selene.educ.disi.unige.it [130.251.152.1]) by webmail.studenti.unige.it (IMP) with HTTP for <2386429@mail.unige.it>; Tue, 31 Jan 2006 17:24:30 +0100 Message-ID: <1138724670.43df8f3e30019@webmail.studenti.unige.it> Date: Tue, 31 Jan 2006 17:24:30 +0100 From: 2386429@studenti.unige.it To: pgsql-performance@postgresql.org Subject: Delete me MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) 3.2.8 X-Virus-Scanned: by amavisd-new at unige.it (mbox2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=4.006 required=5 tests=[FROM_ALL_NUMS=1.92, FROM_STARTS_WITH_NUMS=0.283, NO_REAL_NAME=0.55, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 4.006 X-Spam-Level: **** X-Archive-Number: 200601/487 X-Sequence-Number: 16965 Can you delete me from the mail list Please? From pgsql-performance-owner@postgresql.org Tue Jan 31 13:01:01 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 04E609DC82A for ; Tue, 31 Jan 2006 13:01:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01200-04 for ; Tue, 31 Jan 2006 13:00:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id EA0329DC800 for ; Tue, 31 Jan 2006 13:00:53 -0400 (AST) Received: from 172.16.1.25 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Tue, 31 Jan 2006 12:00:46 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 31 Jan 2006 12:00:36 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Tue, 31 Jan 2006 17:00:31 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Tue, 31 Jan 2006 09:00:30 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "Jim C. Nasby" cc: "Mike Biamonte" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYmh9c6Fdnw4JJ7EdqBvAANk63kWA== In-Reply-To: <20060130202524.GB3920@pervasive.com> MIME-Version: 1.0 X-OriginalArrivalTime: 31 Jan 2006 17:00:36.0683 (UTC) FILETIME=[DB3609B0:01C62687] X-WSS-ID: 6FC1483732K1571066-04-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.3 required=5 tests=[AWL=0.047, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.3 X-Spam-Level: * X-Archive-Number: 200601/488 X-Sequence-Number: 16966 Jim, On 1/30/06 12:25 PM, "Jim C. Nasby" wrote: > Why divide by 2? A good raid controller should be able to send read > requests to both drives out of the mirrored set to fully utilize the > bandwidth. Of course, that probably won't come into play unless the OS > decides that it's going to read-ahead fairly large chunks of the table > at a time... I've not seen one that does, nor would it work in the general case IMO. In RAID1 writes are duplicated and reads come from one of the copies. You could alternate read service requests to minimize rotational latency, but you can't improve bandwidth. - Luke From pgsql-performance-owner@postgresql.org Tue Jan 31 13:39:13 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E07F49DC826 for ; Tue, 31 Jan 2006 13:39:12 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06256-07 for ; Tue, 31 Jan 2006 13:39:11 -0400 (AST) X-Greylist: delayed 00:05:00.750326 by SQLgrey- Received: from rwcrmhc14.comcast.net (rwcrmhc14.comcast.net [216.148.227.154]) by postgresql.org (Postfix) with ESMTP id BBEC69DC801 for ; Tue, 31 Jan 2006 13:39:10 -0400 (AST) Received: from [192.168.0.52] (c-24-8-249-24.hsd1.co.comcast.net[24.8.249.24]) by comcast.net (rwcrmhc14) with ESMTP id <20060131172907m1400lostse>; Tue, 31 Jan 2006 17:29:07 +0000 Message-ID: <43DF9D93.3030602@drule.org> Date: Tue, 31 Jan 2006 10:25:39 -0700 From: Kevin User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/489 X-Sequence-Number: 16967 Luke Lonergan wrote: > Jim, > > On 1/30/06 12:25 PM, "Jim C. Nasby" wrote: > > >> Why divide by 2? A good raid controller should be able to send read >> requests to both drives out of the mirrored set to fully utilize the >> bandwidth. Of course, that probably won't come into play unless the OS >> decides that it's going to read-ahead fairly large chunks of the table >> at a time... >> > > I've not seen one that does, nor would it work in the general case IMO. In > RAID1 writes are duplicated and reads come from one of the copies. You > could alternate read service requests to minimize rotational latency, but > you can't improve bandwidth. > > - Luke > > For Solaris's software raid, the default settings for raid-1 sets is: round-robin read, parallel write. I assumed this mean't it would give similar read performance to raid-0, but I've never benchmarked it. -Kevin From pgsql-performance-owner@postgresql.org Tue Jan 31 14:33:18 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 045C29DC83C for ; Tue, 31 Jan 2006 14:33:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17227-08 for ; Tue, 31 Jan 2006 14:33:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id CA9839DC88E for ; Tue, 31 Jan 2006 14:33:15 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 11ADD426548; Tue, 31 Jan 2006 18:33:15 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 9120715F11; Tue, 31 Jan 2006 18:33:14 +0000 (GMT) Message-ID: <43DFAD6A.8000206@archonet.com> Date: Tue, 31 Jan 2006 18:33:14 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: 2386429@studenti.unige.it Cc: pgsql-performance@postgresql.org Subject: Re: Delete me References: <1138724670.43df8f3e30019@webmail.studenti.unige.it> In-Reply-To: <1138724670.43df8f3e30019@webmail.studenti.unige.it> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.114 required=5 tests=[AWL=0.114] X-Spam-Score: 0.114 X-Spam-Level: X-Archive-Number: 200601/490 X-Sequence-Number: 16968 2386429@studenti.unige.it wrote: > Can you delete me from the mail list Please? Go to the website. Click "community" Click "mailing lists" On the left-hand side click "Subscribe" Fill in the form, changing action to "unsubscribe" HTH -- Richard Huxton Archonet Ltd From pgsql-performance-owner@postgresql.org Tue Jan 31 15:21:47 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6FF019DC950 for ; Tue, 31 Jan 2006 15:21:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31619-07 for ; Tue, 31 Jan 2006 15:21:47 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 0793E9DC827 for ; Tue, 31 Jan 2006 15:21:44 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id E96013983E; Tue, 31 Jan 2006 13:21:45 -0600 (CST) Date: Tue, 31 Jan 2006 13:21:45 -0600 From: "Jim C. Nasby" To: Luke Lonergan Cc: Mike Biamonte , pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries Message-ID: <20060131192145.GU95850@pervasive.com> References: <20060130202524.GB3920@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/491 X-Sequence-Number: 16969 On Tue, Jan 31, 2006 at 09:00:30AM -0800, Luke Lonergan wrote: > Jim, > > On 1/30/06 12:25 PM, "Jim C. Nasby" wrote: > > > Why divide by 2? A good raid controller should be able to send read > > requests to both drives out of the mirrored set to fully utilize the > > bandwidth. Of course, that probably won't come into play unless the OS > > decides that it's going to read-ahead fairly large chunks of the table > > at a time... > > I've not seen one that does, nor would it work in the general case IMO. In > RAID1 writes are duplicated and reads come from one of the copies. You > could alternate read service requests to minimize rotational latency, but > you can't improve bandwidth. (BTW, I did some testing that seems to confirm this) Why couldn't you double the bandwidth? If you're doing a largish read you should be able to do something like have drive a read the first track, drive b the second, etc. Of course that means that the controller or OS would have to be able to stitch things back together. As for software raid, I'm wondering how well that works if you can't use a BBU to allow write caching/re-ordering... -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 31 15:23:24 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AFF7D9DC827 for ; Tue, 31 Jan 2006 15:23:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35471-03 for ; Tue, 31 Jan 2006 15:23:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 4DFFD9DC819 for ; Tue, 31 Jan 2006 15:23:20 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id A1B1A39841; Tue, 31 Jan 2006 13:23:21 -0600 (CST) Date: Tue, 31 Jan 2006 13:23:21 -0600 From: "Jim C. Nasby" To: Richard Huxton Cc: 2386429@studenti.unige.it, pgsql-performance@postgresql.org Subject: Re: Delete me Message-ID: <20060131192321.GV95850@pervasive.com> References: <1138724670.43df8f3e30019@webmail.studenti.unige.it> <43DFAD6A.8000206@archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43DFAD6A.8000206@archonet.com> X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/492 X-Sequence-Number: 16970 On Tue, Jan 31, 2006 at 06:33:14PM +0000, Richard Huxton wrote: > 2386429@studenti.unige.it wrote: > >Can you delete me from the mail list Please? > > Go to the website. > Click "community" > Click "mailing lists" > On the left-hand side click "Subscribe" > Fill in the form, changing action to "unsubscribe" Or take a look at the header that's included with every single message sent to the list... List-Unsubscribe: -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 31 16:04:02 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6D6479DC827 for ; Tue, 31 Jan 2006 16:04:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41713-09 for ; Tue, 31 Jan 2006 16:04:02 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 6C6569DC819 for ; Tue, 31 Jan 2006 16:04:00 -0400 (AST) Received: from gghcwest.com (adsl-71-128-90-172.dsl.pltn13.pacbell.net [71.128.90.172]) by svr4.postgresql.org (Postfix) with ESMTP id 043D15AF025 for ; Tue, 31 Jan 2006 20:04:01 +0000 (GMT) Received: from toonses.gghcwest.com (toonses.gghcwest.com [192.168.168.115]) by gghcwest.com (8.12.10/8.12.9) with ESMTP id k0VK3vmd015782 for ; Tue, 31 Jan 2006 12:03:58 -0800 Received: from jwb by toonses.gghcwest.com with local (Exim 4.52) id 1F41jL-0001UU-4j for pgsql-performance@postgresql.org; Tue, 31 Jan 2006 12:03:59 -0800 Subject: Re: Huge Data sets, simple queries From: "Jeffrey W. Baker" To: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Tue, 31 Jan 2006 12:03:58 -0800 Message-Id: <1138737838.5648.4.camel@toonses.gghcwest.com> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.072 required=5 tests=[AWL=0.072] X-Spam-Score: 0.072 X-Spam-Level: X-Archive-Number: 200601/493 X-Sequence-Number: 16971 On Tue, 2006-01-31 at 09:00 -0800, Luke Lonergan wrote: > Jim, > > On 1/30/06 12:25 PM, "Jim C. Nasby" wrote: > > > Why divide by 2? A good raid controller should be able to send read > > requests to both drives out of the mirrored set to fully utilize the > > bandwidth. Of course, that probably won't come into play unless the OS > > decides that it's going to read-ahead fairly large chunks of the table > > at a time... > > I've not seen one that does, nor would it work in the general case IMO. In > RAID1 writes are duplicated and reads come from one of the copies. You > could alternate read service requests to minimize rotational latency, but > you can't improve bandwidth. Then you've not seen Linux. Linux does balanced reads on software mirrors. I'm not sure why you think this can't improve bandwidth. It does improve streaming bandwidth as long as the platter STR is more than the bus STR. -jwb From pgsql-performance-owner@postgresql.org Tue Jan 31 16:47:51 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 151D99DC819 for ; Tue, 31 Jan 2006 16:47:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50506-02 for ; Tue, 31 Jan 2006 16:47:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.mi8.com (d01gw02.mi8.com [63.240.6.46]) by postgresql.org (Postfix) with ESMTP id 968A39DC861 for ; Tue, 31 Jan 2006 16:47:48 -0400 (AST) Received: from 172.16.1.112 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D2)); Tue, 31 Jan 2006 15:47:15 -0500 X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP02.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 31 Jan 2006 15:47:12 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.105]) with Microsoft Exchange Server HTTP-DAV ; Tue, 31 Jan 2006 20:47:12 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Tue, 31 Jan 2006 12:47:10 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "Jeffrey W. Baker" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYmoZRRye2e6Jm6SeWLJpF4I0uRxwABe0kU In-Reply-To: <1138737838.5648.4.camel@toonses.gghcwest.com> MIME-Version: 1.0 X-OriginalArrivalTime: 31 Jan 2006 20:47:12.0640 (UTC) FILETIME=[83087000:01C626A7] X-WSS-ID: 6FC1135A2XS1658211-02-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.303 required=5 tests=[AWL=0.050, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.303 X-Spam-Level: * X-Archive-Number: 200601/494 X-Sequence-Number: 16972 Jeffrey, On 1/31/06 12:03 PM, "Jeffrey W. Baker" wrote: > Then you've not seen Linux. :-D > Linux does balanced reads on software > mirrors. I'm not sure why you think this can't improve bandwidth. It > does improve streaming bandwidth as long as the platter STR is more than > the bus STR. ... Prove it. - Luke From pgsql-performance-owner@postgresql.org Tue Jan 31 18:53:15 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CE14C9DCB81 for ; Tue, 31 Jan 2006 18:53:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77501-03 for ; Tue, 31 Jan 2006 18:53:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id 7FC899DCBB4 for ; Tue, 31 Jan 2006 18:53:12 -0400 (AST) Received: from 172.16.1.112 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Tue, 31 Jan 2006 17:53:02 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP02.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 31 Jan 2006 17:52:59 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.106]) with Microsoft Exchange Server HTTP-DAV ; Tue, 31 Jan 2006 22:52:58 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Tue, 31 Jan 2006 14:52:57 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "Jim C. Nasby" cc: "Mike Biamonte" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYmm5tNPfhKvWQlRXSop7/73TxCzAAHXiHG In-Reply-To: <20060131192145.GU95850@pervasive.com> MIME-Version: 1.0 X-OriginalArrivalTime: 31 Jan 2006 22:52:59.0393 (UTC) FILETIME=[153F8F10:01C626B9] X-WSS-ID: 6FC135C032K1817801-02-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.306 required=5 tests=[AWL=0.053, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.306 X-Spam-Level: * X-Archive-Number: 200601/495 X-Sequence-Number: 16973 Jim, On 1/31/06 11:21 AM, "Jim C. Nasby" wrote: > (BTW, I did some testing that seems to confirm this) > > Why couldn't you double the bandwidth? If you're doing a largish read > you should be able to do something like have drive a read the first > track, drive b the second, etc. Of course that means that the controller > or OS would have to be able to stitch things back together. It's because your alternating reads are skipping in chunks across the platter. Disks work at their max internal rate when reading sequential data, and the cache is often built to buffer a track-at-a-time, so alternating pieces that are not contiguous has the effect of halving the max internal sustained bandwidth of each drive - the total is equal to one drive's sustained internal bandwidth. This works differently for RAID0, where the chunks are allocated to each drive and laid down contiguously on each, so that when they're read back, each drive runs at it's sustained sequential throughput. The alternating technique in mirroring might improve rotational latency for random seeking - a trick that Tandem exploited, but it won't improve bandwidth. > As for software raid, I'm wondering how well that works if you can't use > a BBU to allow write caching/re-ordering... Works great with standard OS write caching. - Luke From pgsql-performance-owner@postgresql.org Tue Jan 31 19:10:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B83849DCA64 for ; Tue, 31 Jan 2006 19:10:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77940-10 for ; Tue, 31 Jan 2006 19:10:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id 5375F9DCA5E for ; Tue, 31 Jan 2006 19:10:14 -0400 (AST) Received: (qmail 16073 invoked from network); 1 Feb 2006 00:11:06 +0100 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 1 Feb 2006 00:11:06 +0100 To: "Luke Lonergan" , "Jeffrey W. Baker" , pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries References: Message-ID: Date: Wed, 01 Feb 2006 00:11:05 +0100 From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200601/496 X-Sequence-Number: 16974 >> Linux does balanced reads on software >> mirrors. I'm not sure why you think this can't improve bandwidth. It >> does improve streaming bandwidth as long as the platter STR is more than >> the bus STR. > > ... Prove it. > (I have a software RAID1 on this desktop machine) It's a lot faster than a single disk for random reads when more than 1 thread hits the disk, because it distributes reads to both disks. Thus, applications start faster, and the machine is more reactive even when the disk is thrashing. Cron starting a "updatedb" is less painful. It's cool for desktop use (and of course it's more reliable). However large reads (dd-style) are just the same speed as 1 drive. I guess you'd need a humongous readahead in order to read from both disks. From pgsql-performance-owner@postgresql.org Tue Jan 31 19:12:27 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C6F159DCB81 for ; Tue, 31 Jan 2006 19:12:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80044-07-2 for ; Tue, 31 Jan 2006 19:12:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id ABDCA9DCBB7 for ; Tue, 31 Jan 2006 19:12:24 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id BA88A39849; Tue, 31 Jan 2006 17:12:27 -0600 (CST) Date: Tue, 31 Jan 2006 17:12:27 -0600 From: "Jim C. Nasby" To: Luke Lonergan Cc: Mike Biamonte , pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries Message-ID: <20060131231227.GP95850@pervasive.com> References: <20060131192145.GU95850@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.104 required=5 tests=[AWL=0.104] X-Spam-Score: 0.104 X-Spam-Level: X-Archive-Number: 200601/497 X-Sequence-Number: 16975 On Tue, Jan 31, 2006 at 02:52:57PM -0800, Luke Lonergan wrote: > It's because your alternating reads are skipping in chunks across the > platter. Disks work at their max internal rate when reading sequential > data, and the cache is often built to buffer a track-at-a-time, so > alternating pieces that are not contiguous has the effect of halving the max > internal sustained bandwidth of each drive - the total is equal to one > drive's sustained internal bandwidth. > > This works differently for RAID0, where the chunks are allocated to each > drive and laid down contiguously on each, so that when they're read back, > each drive runs at it's sustained sequential throughput. > > The alternating technique in mirroring might improve rotational latency for > random seeking - a trick that Tandem exploited, but it won't improve > bandwidth. Or just work in multiples of tracks, which would greatly reduce the impact of delays from seeking. > > As for software raid, I'm wondering how well that works if you can't use > > a BBU to allow write caching/re-ordering... > > Works great with standard OS write caching. Well, the only problem with that is if the machine crashes for any reason you risk having the database corrupted (or at best losing some committed transactions). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461 From pgsql-performance-owner@postgresql.org Tue Jan 31 19:13:17 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B16669DC861 for ; Tue, 31 Jan 2006 19:13:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83325-05 for ; Tue, 31 Jan 2006 19:13:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id 6A6819DC827 for ; Tue, 31 Jan 2006 19:13:14 -0400 (AST) Received: from 172.16.1.110 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Tue, 31 Jan 2006 18:13:12 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 31 Jan 2006 18:13:12 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.106]) with Microsoft Exchange Server HTTP-DAV ; Tue, 31 Jan 2006 23:13:11 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Tue, 31 Jan 2006 15:13:10 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "PFC" , "Jeffrey W. Baker" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYmu+bTJSLNLJKvEdqBvAANk63kWA== In-Reply-To: MIME-Version: 1.0 X-OriginalArrivalTime: 31 Jan 2006 23:13:12.0227 (UTC) FILETIME=[E8275730:01C626BB] X-WSS-ID: 6FC1308232K1830268-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.309 required=5 tests=[AWL=0.056, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.309 X-Spam-Level: * X-Archive-Number: 200601/498 X-Sequence-Number: 16976 PFC, On 1/31/06 3:11 PM, "PFC" wrote: >> ... Prove it. >> > > (I have a software RAID1 on this desktop machine) > > It's a lot faster than a single disk for random reads when more than 1 > thread hits the disk, because it distributes reads to both disks. Thus, > applications start faster, and the machine is more reactive even when the > disk is thrashing. Cron starting a "updatedb" is less painful. It's cool > for desktop use (and of course it's more reliable). Exactly - improved your random seeks. > However large reads (dd-style) are just the same speed as 1 drive. I > guess you'd need a humongous readahead in order to read from both disks. Nope - won't help. - Luke From pgsql-performance-owner@postgresql.org Tue Jan 31 19:20:05 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7D6839DCB9E for ; Tue, 31 Jan 2006 19:20:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83977-09 for ; Tue, 31 Jan 2006 19:20:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by postgresql.org (Postfix) with ESMTP id 8AFB39DCAA6 for ; Tue, 31 Jan 2006 19:19:57 -0400 (AST) Received: from 172.16.1.148 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Tue, 31 Jan 2006 18:19:42 -0500 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01HOST02.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 31 Jan 2006 18:19:40 -0500 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.106]) with Microsoft Exchange Server HTTP-DAV ; Tue, 31 Jan 2006 23:19:39 +0000 User-Agent: Microsoft-Entourage/11.2.1.051004 Date: Tue, 31 Jan 2006 15:19:38 -0800 Subject: Re: Huge Data sets, simple queries From: "Luke Lonergan" To: "Jim C. Nasby" cc: "Mike Biamonte" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Huge Data sets, simple queries Thread-Index: AcYmvM4XDGFWGpKwEdqBvAANk63kWA== In-Reply-To: <20060131231227.GP95850@pervasive.com> MIME-Version: 1.0 X-OriginalArrivalTime: 31 Jan 2006 23:19:40.0844 (UTC) FILETIME=[CFC996C0:01C626BC] X-WSS-ID: 6FC12F0732K1834077-02-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.312 required=5 tests=[AWL=0.059, RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.312 X-Spam-Level: * X-Archive-Number: 200601/499 X-Sequence-Number: 16977 Jim, On 1/31/06 3:12 PM, "Jim C. Nasby" wrote: >> The alternating technique in mirroring might improve rotational latency for >> random seeking - a trick that Tandem exploited, but it won't improve >> bandwidth. > > Or just work in multiples of tracks, which would greatly reduce the > impact of delays from seeking. So, having rediscovered the facts underlying the age-old RAID10 versus RAID5 debate we're back to the earlier points. RAID10 is/was the best option when latency / random seek was the predominant problem to be solved, RAID5/50 is best where read bandwidth is needed. Modern developments in fast CPUs for write checksumming have made RAID5/50 a viable alternative to RAID10 even when there is moderate write / random seek workloads and fast read is needed. >> >> Works great with standard OS write caching. > > Well, the only problem with that is if the machine crashes for any > reason you risk having the database corrupted (or at best losing some > committed transactions). So, do you routinely turn off Linux write caching? If not, then there's no difference. - Luke From pgsql-performance-owner@postgresql.org Tue Jan 31 19:51:33 2006 X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 117EB9DC8AB for ; Tue, 31 Jan 2006 19:51:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92638-04 for ; Tue, 31 Jan 2006 19:51:35 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id B770D9DC861 for ; Tue, 31 Jan 2006 19:26:28 -0400 (AST) Received: from mailserver.sandvine.com (sandvine.com [199.243.201.138]) by svr4.postgresql.org (Postfix) with ESMTP id 1C8C65AF835 for ; Tue, 31 Jan 2006 23:26:32 +0000 (GMT) X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: partitioning and locking problems Date: Tue, 31 Jan 2006 18:25:01 -0500 Message-ID: <2BCEB9A37A4D354AA276774EE13FB8C263B3DE@mailserver.sandvine.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: partitioning and locking problems Thread-Index: AcYmvcI/wJEcTqj/SumMC+ZFsd4mVQ== From: "Marc Morin" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/500 X-Sequence-Number: 16978 We have a large database system designed around partitioning. Our application is characterized with =20 - terabytes of data - billions of rows in dozens of base tables (and 100s of paritions) - 24x7 insert load of new data that cannot be stopped, data is time sensitive. - periodic reports that can have long running queries with query times measured in hours =20 We have 2 classes of "maintenance" activities that are causing us problems: - periodically we need to change an insert rule on a view to point to a different partition. - periodically we need to delete data that is no longer needed. Performed via truncate. =20 Under both these circumstances (truncate and create / replace rule) the locking behaviour of these commands can cause locking problems for us. The scenario is best illustrated as a series of steps: =20 1- long running report is running on view 2- continuous inserters into view into a table via a rule 3- truncate or rule change occurs, taking an exclusive lock. Must wait for #1 to finish. 4- new reports and inserters must now wait for #3. 5- now everyone is waiting for a single query in #1. Results in loss of insert data granularity (important for our application). =20 Would like to understand the implications of changing postgres' code/locking for rule changes and truncate to not require locking out select statements? =20 =20 The following is a simplified schema to help illustrate the problem. =20 create table a_1 ( pkey int primary key ); create table a_2 ( pkey int primary key ); =20 create view a as select * from a_1 union all select * from a_2; =20 create function change_rule(int) returns void as ' begin execute ''create or replace rule insert as on insert to a do instead insert into a_''||$1||''(pkey) values(NEW.pkey)''; end; ' language plpgsql; =20 -- change rule, execute something like the following periodically select change_rule(1); =20 We've looked at the code and the rule changes appear "easy" but we are concerned about the required changes for truncate. =20 Thanks Marc