From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Israel Brewster <ijbrewster@alaska.edu>
Cc: Mark Zellers <markz@adaptiveinsights.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: UPDATE many records
Date: Tue, 7 Jan 2020 13:57:44 -0800
Message-ID: <90aae1ff-02a6-22b4-ae5f-c99b0b56a56f@aklaver.com> (raw)
In-Reply-To: <A7813C13-3B77-4F22-87F1-7B1A94751EB1@alaska.edu>
References: <97518FCA-F286-4A6A-803F-46A109196C71@alaska.edu>
<CY4PR0601MB3763A96602AE90077A6DC060D53F0@CY4PR0601MB3763.namprd06.prod.outlook.com>
<BB3FB79A-8172-43E2-A731-0D42B78FB569@alaska.edu>
<4c7f993f-f233-dfb6-29b8-98fdf24ec033@aklaver.com>
<F4040495-D045-4BCE-AB24-6E0B4D1F5717@alaska.edu>
<8cb3358a-caaf-8442-a38c-dbea18f546b7@aklaver.com>
<A7813C13-3B77-4F22-87F1-7B1A94751EB1@alaska.edu>
On 1/7/20 1:43 PM, Israel Brewster wrote:
>> On Jan 7, 2020, at 12:21 PM, Adrian Klaver <adrian.klaver@aklaver.com
>> <mailto:adrian.klaver@aklaver.com>> wrote:
>>
>> On 1/7/20 1:10 PM, Israel Brewster wrote:
>>>> On Jan 7, 2020, at 12:01 PM, Adrian Klaver
>>>> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> 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 <http://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 <mailto:adrian.klaver@aklaver.com>
>>
>>
>> --
>> Adrian Klaver
>> adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, ijbrewster@alaska.edu, markz@adaptiveinsights.com
Subject: Re: UPDATE many records
In-Reply-To: <90aae1ff-02a6-22b4-ae5f-c99b0b56a56f@aklaver.com>
References: <97518FCA-F286-4A6A-803F-46A109196C71@alaska.edu> <CY4PR0601MB3763A96602AE90077A6DC060D53F0@CY4PR0601MB3763.namprd06.prod.outlook.com> <BB3FB79A-8172-43E2-A731-0D42B78FB569@alaska.edu> <4c7f993f-f233-dfb6-29b8-98fdf24ec033@aklaver.com> <F4040495-D045-4BCE-AB24-6E0B4D1F5717@alaska.edu> <8cb3358a-caaf-8442-a38c-dbea18f546b7@aklaver.com> <A7813C13-3B77-4F22-87F1-7B1A94751EB1@alaska.edu> <90aae1ff-02a6-22b4-ae5f-c99b0b56a56f@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox