Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fz89p-0004Ak-Vw for pgsql-performance@arkaria.postgresql.org; Sun, 09 Sep 2018 22:26:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fz89o-0001yp-Bg for pgsql-performance@arkaria.postgresql.org; Sun, 09 Sep 2018 22:26:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fz89o-0001yi-1o for pgsql-performance@lists.postgresql.org; Sun, 09 Sep 2018 22:26:16 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fz89l-0003s7-9I for pgsql-performance@postgresql.org; Sun, 09 Sep 2018 22:26:15 +0000 Received: by mail-pf1-x444.google.com with SMTP id i26-v6so9447031pfo.12 for ; Sun, 09 Sep 2018 15:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=M6F31P2n7yA8yL9Zs5GBsY+kGJ0Mei//eTyaerBpB68=; b=EhJv4BOtAM/8qnS3TWhLbaTSty5ZP/IM2/WEU0rQJYLTb4f1ciInkKZIuWD4+rdVVy LWuzNeQKuU0727zApathnCbG2N+uic6H353XCKN9NKJ0D3g9g+bE04/MrHCNVoLNoWLD GzXvVuoxKVfdNZ+xYwWRDEZUun2526DU2PRM5/x9f7d81wbQnisYTUGNHSsrTpYcdgmY EcYP73D7JzVnEKnlR+qVMz0QjCYtFPbXZC/4p9BfbSjsxtW6eI2wQfMXOi8LXTVIgDhz Wm0RFB3qrMg2ZXqCbhmeD20N49xNAUg9kgDrBahLlFmu1jTLCMf9dIinn8puw3G9aVw7 KPTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=M6F31P2n7yA8yL9Zs5GBsY+kGJ0Mei//eTyaerBpB68=; b=jSAiFjDczc3MS7q6DZc20oTblXgqxIubg7cgLbwCItZrdMUNuHesJj83IjIyJq5DaL z6afb5n1SN7dqUhNzd4yYLjYbb10dDBwCa3IUuf/svUhamrg59VVSB7UhN25ecjO6xpa wWN1g43OCwDCW8MueX/wNYyGLnq8W5oYtUObxZV2soAvurpvV2E0zvO71A3ZkUYZfin9 lh93rxQ5nabG4ty9iDt3L4DHpxsBDPO/gVvauuEU1AEgUqUNCQDwOyrZUlFDLbQEsRim 3Mg9MM6u/iuNEaP3TyqYg3hjChA33gMJLhukLSi8n31vq2KZH02bmbVP97NPCPXtf+RP 65hQ== X-Gm-Message-State: APzg51CucOgYsDXmpI8vzQ21CZntgB7VNJg25Fv2J92+bIiMk/UmVYjX MeRPHtnh8d4+EU4YaumafWiN1KuG X-Google-Smtp-Source: ANB0Vda48rlRsM8NluzYL4G65toOsURaY6bk643l0QicPV/HBoy8HV077yQEu+DCwbER9Yz4MAL9SA== X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr19776526pgu.259.1536531970420; Sun, 09 Sep 2018 15:26:10 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-a08f-a7a4-568b-94e7.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:a08f:a7a4:568b:94e7]) by smtp.gmail.com with ESMTPSA id s9-v6sm19118157pgc.16.2018.09.09.15.26.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Sep 2018 15:26:09 -0700 (PDT) References: <1536339842382-0.post@n3.nabble.com> <8736uk6eh5.fsf@gmail.com> <1536385261054-0.post@n3.nabble.com> User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: padusuma Cc: pgsql-performance@postgresql.org Subject: Re: Performance of INSERT into temporary tables using psqlODBC driver In-reply-to: <1536385261054-0.post@n3.nabble.com> Date: Mon, 10 Sep 2018 08:26:06 +1000 Message-ID: <87zhwq48ap.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk padusuma writes: >>We are inserting large numbers (millions) of rows into a postgres >>database from a Javascript application and found using the COPY command >>was much, much faster than doing regular inserts (even with multi-insert >>commit). If you can do this using the driver you are using, that will >>give you the largest performance boost. > > The data to be inserted into temporary tables is obtained from one or more > queries run earlier and the data is available as a vector of strings. If I > need to use COPY FROM command, then the application would need to create a > file with the data to be inserted and the file needs to be readable by the > user running database server process, which may not be always possible > unless the application is running on the same host. I think this approach > may not be feasible for our application. > OK, that does make a difference. If your data is already in the database, COPY is not going to help you much. > I have increased the value for /temp_buffers/ server parameter from the > default 8 MB to 128 MB. However, this change did not affect the INSERT time > for temporary tables. It isn't clear why you create vectors of strings rather than just select into or something similar. There are no 'quick fixes' which can be applied without real analysis of the system. However, based on the limited information available, you may want to consider - - Increase work_mem to reduce use of temp files. Need it to be 2 to 3 times largest temp file (but use common sense) - Tweak wal checkpoint parameters to prevent wal checkpoints occurring too frequently. Note that there is a play off here between frequency of checkpoints and boot time after a crash. Fewer wal checkpoints will usually improve performance, but recovery time is longer. - Verify your inserts into temporary tables is the bottleneck and not the select from existing data (explain plan etc and adjust indexes accordingly). How effectively you can increase insert times will depend on what the memory and cpu profile of the system is. More memory, less use of temp files, faster system, so spend a bit of time to make sure your system is configured to squeeze as much out of that RAM as you can! -- Tim Cross