Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jGOqu-0000zq-TU for pgsql-general@arkaria.postgresql.org; Mon, 23 Mar 2020 15:18:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGOqt-0007u0-Pe for pgsql-general@arkaria.postgresql.org; Mon, 23 Mar 2020 15:18:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jGOqt-0007to-9p for pgsql-general@lists.postgresql.org; Mon, 23 Mar 2020 15:18:55 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jGOqq-0001zw-V2 for pgsql-general@lists.postgresql.org; Mon, 23 Mar 2020 15:18:54 +0000 Received: by mail-il1-x132.google.com with SMTP id r5so8743673ilq.6 for ; Mon, 23 Mar 2020 08:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=d+ouXcf1RB8byeHaC4S5O019GmzYM3kGc3iosEt63/M=; b=emp1ts+fuOG0W1XqNfS/Wo2LZtKp0RUqjlpBIVWkbytB0UaBXVVJ/UDn7vAjOKbNot LTWDXFm5ptKIA/eOzfCnc0XnsVtisx68wdNfnzdgJIhgSMfqwld19q3TmqV7POsst/I7 5wi9hcyZJ0RfP7wzsgEx0z5Xqqs+UdSE1oCzEzQtpHJlUJDBec0B2qWs7jzQWVm+c5ro MY98fs8v/5PoyXDi6DzK8Jfyy/es8gLN78aONzfaItSDkXRKMMGBcrVEejJywCGT4dkA lT7RSpKQtSc5K+hyaIU4A1DM2CL5vKRmmJNco4AarpKu/2kulIiUa2uIGm+D8HDB8V6Y wNSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=d+ouXcf1RB8byeHaC4S5O019GmzYM3kGc3iosEt63/M=; b=mylUT3fjOvY7NKeKXoM5amoSWkYpohLIhUY8up/ijTiox5WH9Jc5UmHWEU3OC+hB6g kd3MCxtwnfIcurxwCtVhlD+KfHPhmVHfJZFDkK6ATTiMlFq8Jvn0HifgoyshICbxVGWW vORqCgtlMnARDDCUSds/O9OBfWRyg2btasobtp9sNHmwxcDNwobc9YVF/wHVJsFan7jB 6Xl54UZf4/lSqoIJwna/qQkT4aNgBvzHvygXcHl69x3zPopgazD4T2M9PUuIDWhHaBLV hKdEcv2ZBqiflmzwA97n0z+UP4FXmZyoMtftwxN+R5jCTL47JKZeJNniWhLdunI9eSk1 yVaw== X-Gm-Message-State: ANhLgQ2D1ijceAYE5Kb0x9rNk+rk+XhACWSxEgZNWTPr+SV+ratmGBZt 0GffJDl4bKr3WoOcXhxpEvDuZ/Ih X-Google-Smtp-Source: ADFU+vt5FVo53catI9+qE0v9PAzHCLC4xcSoiy7WAJfVoqIRVrQEBis2UKwRcQt5dfUpgiQlrvWbSw== X-Received: by 2002:a92:48cb:: with SMTP id j72mr21707571ilg.162.1584976731148; Mon, 23 Mar 2020 08:18:51 -0700 (PDT) Received: from [172.16.12.101] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id y71sm5337056ilk.23.2020.03.23.08.18.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Mar 2020 08:18:50 -0700 (PDT) Subject: Re: Loading 500m json files to database To: pgsql-general@lists.postgresql.org References: <1584959088557-0.post@n3.nabble.com> From: Rob Sargent Message-ID: Date: Mon, 23 Mar 2020 09:16:40 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <1584959088557-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/23/20 4:24 AM, pinker wrote: > Hi, do you have maybe idea how to make loading process faster? > > I have 500 millions of json files (1 json per file) that I need to load to > db. > My test set is "only" 1 million files. > > What I came up with now is: > > time for i in datafiles/*; do > psql -c "\copy json_parts(json_data) FROM $i"& > done > > which is the fastest so far. But it's not what i expect. Loading 1m of data > takes me ~3h so loading 500 times more is just unacceptable. > > some facts: > * the target db is on cloud so there is no option to do tricks like turning > fsync off > * version postgres 11 > * i can spin up huge postgres instance if necessary in terms of cpu/ram > * i tried already hash partitioning (to write to 10 different tables instead > of 1) > > > Any ideas? > Most advanced languages have a bulk copy implementation. I've found this to be blindingly fast when the receiving table has no indices, constraints. It's not clear how large your files are, but you might take this time to "normalized" them: extract any id, datatype, etc into table attributes. > -- > Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > >