Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZzJ9-0003lu-BH for pgsql-performance@arkaria.postgresql.org; Wed, 17 Aug 2016 11:46:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bZzJ8-0002wE-U7 for pgsql-performance@arkaria.postgresql.org; Wed, 17 Aug 2016 11:46:54 +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.84_2) (envelope-from ) id 1bZzHS-00013U-Vd for pgsql-performance@postgresql.org; Wed, 17 Aug 2016 11:45:11 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZzHO-0005D8-6N for pgsql-performance@postgresql.org; Wed, 17 Aug 2016 11:45:09 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 641252EF66F7 for ; Wed, 17 Aug 2016 04:45:01 -0700 (PDT) Date: Wed, 17 Aug 2016 04:45:03 -0700 (MST) From: pinker To: pgsql-performance@postgresql.org Message-ID: <1471434303741-5916781.post@n5.nabble.com> Subject: Big data INSERT optimization - ExclusiveLock on extension of the table MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi, the problem I'm dealing with is long holding locks during extensions of table: process xxx still waiting for ExclusiveLock on extension of relation xxx of database xxx after 3000.158 ms My application is write intensive, in one round I need to insert about 1M rows. The general scheme of the process looks as follows: 1. rename table t01 to t02 2. insert into t02 1M rows in chunks for about 100k 3. from t01 (previously loaded table) insert data through stored procedure to b01 - this happens parallel in over a dozen sessions 4. truncate t01 Some data: PostgreSQL version 9.5 commit_delay | 0 | Sets the delay in microseconds between transaction commit and flushing WAL to disk. checkpoint_completion_target | 0.9 | Time spent flushing dirty buffers during checkpoint, as fraction of checkpoint interval maintenance_work_mem | 2GB | Sets the maximum memory to be used for maintenance operations. shared_buffers | 2GB wal_block_size | 8192 | Shows the block size in the write ahead log. wal_buffers | 16MB | Sets the number of disk-page buffers in shared memory for WAL. wal_compression | off | Compresses full-page writes written in WAL file. wal_keep_segments | 0 | Sets the number of WAL files held for standby servers. wal_level | minimal | Set the level of information written to the WAL. wal_log_hints | off | Writes full pages to WAL when first modified after a checkpoint, even for a non-critical modifications. wal_receiver_status_interval | 10s | Sets the maximum interval between WAL receiver status reports to the primary. wal_receiver_timeout | 1min | Sets the maximum wait time to receive data from the primary. wal_retrieve_retry_interval | 5s | Sets the time to wait before retrying to retrieve WAL after a failed attempt. wal_segment_size | 16MB | Shows the number of pages per write ahead log segment. wal_sender_timeout | 1min | Sets the maximum time to wait for WAL replication. wal_sync_method | fdatasync | Selects the method used for forcing WAL updates to disk. wal_writer_delay | 200ms | WAL writer sleep time between WAL flushes. work_mem | 32MB | Sets the maximum memory to be used for query workspaces. Checkpoints occur every ~ 30sec. Following the advices from this mailing list shared buffers size was changed from 12 to 2GB but nothing has changed. I'm not sure or my bottleneck is the I/O subsystem or there is anything else I can do to make it faster? What I came up with is (but I'm not sure if any of this makes sense): * change settings for bgwriter/wal? * make sure huge pages are in use by changing huge_pages parameter to on * replace truncate with DROP/CREATE command? * turning off fsync for loading? * increase commit_delay value? * move temporary tables to a different tablespace Your advice or suggestions will be much appreciated. -- View this message in context: http://postgresql.nabble.com/Big-data-INSERT-optimization-ExclusiveLock-on-extension-of-the-table-tp5916781.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance