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.89) (envelope-from ) id 1iowrK-0007PL-0H for pgsql-general@arkaria.postgresql.org; Tue, 07 Jan 2020 21:57:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iowrI-00020m-Ln for pgsql-general@arkaria.postgresql.org; Tue, 07 Jan 2020 21:57:52 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iowrI-0001zc-BM for pgsql-general@lists.postgresql.org; Tue, 07 Jan 2020 21:57:52 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iowrF-0006WA-B8 for pgsql-general@lists.postgresql.org; Tue, 07 Jan 2020 21:57:51 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id CCF5A3E8; Tue, 7 Jan 2020 16:57:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 07 Jan 2020 16:57:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=T t0B2WTi6HpQFkksiZjJFzJ2jTZWRObRgQIBeHBsWTw=; b=igt1I4syVUBk8lio7 sknDJrdsILcndi7xcpdk5as0WvYU81q6ZtrUGImuIp/wgcTnfDAQqZrlWOasitG9 yoQG7VYVYIESwWJqOvI/S53jndmjS/3TSjifekPlS/4Bbnfzf2bM0aPNK6CtPQsc 2adxvndH16KQPXTxbjoHBwa64Ek5xdrMCwMa3sU5Hyu/dPfKVSmn+QozVdJrns4q OEcGAaFQHJ6BoGzwX9ECTCUdXB0XeKf9u44FxYfAA5GrR+YSaq0GB772pxjAoQWq GMWkHuurAQeLrMacfBmjtRC4acY2WSRVm8W7rSoRDwk891Bnd2r0DjPlALGH8bFw zVnGA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Tt0B2WTi6HpQFkksiZjJFzJ2jTZWRObRgQIBeHBsW Tw=; b=L55OxJp804VskOxNokBUz4crQ8KZ9VicYAl5w4tqLcnBHUbS/jnVNFeFr aGgwd/XI7jF3fXH6OmfkvVyQvAEHJGEdfZDJkjLnc0uGysjZVyqafNe9L1w1zS/m lQOEnPVowdnZvA/GeaP4R4HECYOFhuGIzQpFt5LW+3hC7oKR8PvMFeQlEP4oceSR axPM+CcYQFRUBZSe2uNhaSPAQyt9sP/nUfnSFyhb8msoHkDZLTAM8dDjoJdAx1t6 4HKnvZCwOfV/FQGjlTT9NVtdEo/AYTBk/OhsLXRbjBk9JDmQSipzW/jDeHt4o3v3 8RpErZLQ5tEoh0R+2VXyACmIvPmGA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdehiedgfeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinheptghhrghnghgvpghtrggslhgvrdhiugdpphhoshhtghhrvghs qhhlrdhorhhgnecukfhppeejuddrvdduvddruddvledrudelfeenucfrrghrrghmpehmrg hilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucev lhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id 6729E8005A; Tue, 7 Jan 2020 16:57:45 -0500 (EST) Subject: Re: UPDATE many records To: Israel Brewster Cc: Mark Zellers , "pgsql-general@lists.postgresql.org" References: <97518FCA-F286-4A6A-803F-46A109196C71@alaska.edu> <4c7f993f-f233-dfb6-29b8-98fdf24ec033@aklaver.com> <8cb3358a-caaf-8442-a38c-dbea18f546b7@aklaver.com> From: Adrian Klaver Message-ID: <90aae1ff-02a6-22b4-ae5f-c99b0b56a56f@aklaver.com> Date: Tue, 7 Jan 2020 13:57:44 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/7/20 1:43 PM, Israel Brewster wrote: >> On Jan 7, 2020, at 12:21 PM, Adrian Klaver > > wrote: >> >> On 1/7/20 1:10 PM, Israel Brewster wrote: >>>> On Jan 7, 2020, at 12:01 PM, Adrian Klaver >>>> > wrote: >>>> >>>> On 1/7/20 12:47 PM, Israel Brewster wrote: >>>>> One potential issue I just thought of with this approach: disk >>>>> space. Will I be doubling the amount of space used while both >>>>> tables exist? If so, that would prevent this from working - I don’t >>>>> have that much space available at the moment. >>>> >>>> It will definitely increase the disk space by at least the data in >>>> the new table. How much relative to the old table is going to depend >>>> on how aggressive the AUTOVACUUM/VACUUM is. >>>> >>>> A suggestion for an alternative approach: >>>> >>>> 1) Create a table: >>>> >>>> create table change_table(id int, changed_fld some_type) >>>> >>>> where is is the PK from the existing table. >>>> >>>> 2) Run your conversion function against existing table with change >>>> to have it put new field value in change_table keyed to id/PK. >>>> Probably do this in batches. >>>> >>>> 3) Once all the values have been updated, do an UPDATE set >>>> changed_field = changed_fld from change_table where >>>> existing_table.pk = change_table.id ; >>> Makes sense. Use the fast SELECT to create/populate the other table, >>> then the update can just be setting a value, not having to call any >>> functions. From what you are saying about updates though, I may still >>> need to batch the UPDATE section, with occasional VACUUMs to maintain >>> disk space. Unless I am not understanding the concept of “tuples that >>> are obsoleted by an update”, which is possible. >> >> You are not. For a more thorough explanation see: >> >> https://www.postgresql.org/docs/12/routine-vacuuming.html#VACUUM-BASICS >> >> How much space do you have to work with? >> >> To get an idea of the disk space currently used by table see; >> >> https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT > > Oh, ok, I guess I was being overly paranoid on this front. Those > functions would indicate that the table is only 7.5 GB, with another > 8.7GB of indexes, for a total of around 16GB. So not a problem after all > - I have around 100GB available. > > Of course, that now leaves me with the mystery of where my other 500GB > of disk space is going, since it is apparently NOT going to my DB as I > had assumed, but solving that can wait. Assuming you are on some form of Linux: sudo du -h -d 1 / Then you can drill down into the output of above. > > Thanks again for all the good information and suggestions! > --- > Israel Brewster > Software Engineer > Alaska Volcano Observatory > Geophysical Institute - UAF > 2156 Koyukuk Drive > Fairbanks AK 99775-7320 > Work: 907-474-5172 > cell:  907-328-9145 >> >>>> >>>>> --- >>>>> Israel Brewster >>>>> Software Engineer >>>>> Alaska Volcano Observatory >>>>> Geophysical Institute - UAF >>>>> 2156 Koyukuk Drive >>>>> Fairbanks AK 99775-7320 >>>>> Work: 907-474-5172 >>>>> cell:  907-328-9145 >>>> >>>> >>>> -- >>>> Adrian Klaver >>>> adrian.klaver@aklaver.com >> >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com