X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 519C3D1D643; Tue, 27 Jan 2004 03:14:18 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 54649-04; Mon, 26 Jan 2004 23:13:51 -0400 (AST) Received: from bralar.on.ca (bralar1meg.1meg.golden.net [209.183.141.194]) by svr1.postgresql.org (Postfix) with ESMTP id 1D8AED1D30E; Mon, 26 Jan 2004 23:13:45 -0400 (AST) Received: from BRALAR10 (authenticated user bgawne@bralar.on.ca) by bralar.on.ca (MDaemon.PRO.v6.8.5.R) with ESMTP id 59-md50000000009.tmp; Mon, 26 Jan 2004 22:15:12 -0500 From: "Brad Gawne" To: , Subject: Re: Insert Times Date: Mon, 26 Jan 2004 22:15:09 -0500 Organization: Bralar Software Inc. MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 In-Reply-To: Thread-Index: AcPkT+dDsDKtVmFGR2yR3AFFUQSefwADqr0A X-Authenticated-Sender: bgawne@bralar.on.ca X-Spam-Processed: MAIL.BRALAR.ON.CA, Mon, 26 Jan 2004 22:15:12 -0500 (not processed: message from valid local sender) X-Return-Path: bgawne@bralar.on.ca Reply-To: bgawne@bralar.on.ca Message-ID: X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=BAYES_20, FORGED_MUA_OUTLOOK, IN_REP_TO, MISSING_OUTLOOK_NAME, RCVD_IN_NJABL, X_NJABL_OPEN_PROXY X-Spam-Level: X-Archive-Number: 200401/277 X-Sequence-Number: 5451 Drew, Just a guess because I don't know PostGres that well, but it could be the SQL parse time and once the statement is parsed, it may be pinned in parse cache for subsequent calls. Regards, Brad Gawne -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of PC Drew Sent: January 26, 2004 16:00 To: pgsql-performance@postgresql.org Subject: [PERFORM] Insert Times I'm trying to track down some performance issues where time (in milliseconds) is critical. One thing that I've noticed is that it seems like the first insert takes an inordinate amount of time. Inserts after the first one are acceptable. My production environment is like this: Solaris 9 JBoss Java 1.4.2 PostgreSQL 7.3 JDBC drivers PostgreSQL 7.3.2 database I've isolated the problem in order to more accurately recreate it by using the following table definition and insert statement: gregqa=# \d one Table "public.one" Column | Type | Modifiers --------+------------------------+----------- id | integer | msg | character varying(255) | explain analyze insert into one (id, msg) values (1, 'blah'); I'm currently using Jython (Python written in Java) and the JDBC drivers to recreate the problem with this code: from java.sql import * from java.lang import Class Class.forName("org.postgresql.Driver") db = DriverManager.getConnection("jdbc:postgresql://localhost:5432/blah", "blah", "") for i in range(5): query = "EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah');" print query st = db.createStatement() rs = st.executeQuery(query) rsmd = rs.getMetaData() cols = rsmd.getColumnCount() cols_range = range(1, cols + 1) while rs.next(): for col in cols_range: print rs.getString(col) rs.close() st.close() db.close() When I run this code (which will execute the query 5 times before finishing), here's the output I get: [bert:~/tmp] > env CLASSPATH=pg73jdbc3.jar jython dbquery.py EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.02..0.02 rows=1 loops=1) Total runtime: 0.59 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.02..0.02 rows=1 loops=1) Total runtime: 0.17 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.01 rows=1 loops=1) Total runtime: 0.12 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.01 rows=1 loops=1) Total runtime: 0.12 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.01 rows=1 loops=1) Total runtime: 0.12 msec [bert:~/tmp] > env CLASSPATH=pg73jdbc3.jar jython dbquery.py EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.02..0.02 rows=1 loops=1) Total runtime: 0.55 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.02..0.02 rows=1 loops=1) Total runtime: 0.15 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.01 rows=1 loops=1) Total runtime: 0.13 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.02 rows=1 loops=1) Total runtime: 0.13 msec EXPLAIN ANALYZE INSERT INTO one (id, msg) VALUES (1, 'blah'); Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.02 rows=1 loops=1) Total runtime: 0.17 msec (I ran it twice to show that it is consistently repeatable) Now, of course this query isn't very interesting and shouldn't take very long, but it does illustrate the time difference between the first query and the last four. On my bigger insert query, it's taking 79msec for the first query and ~0.9msec for the last four. Any ideas as to why the first query would take so long? I can provide more information if necessary, but I think the example is pretty simple as is. -- PC Drew ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html