Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4uQk-0006Sn-3D for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Oct 2017 19:55:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e4uQi-0001qM-Te for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Oct 2017 19:55:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e4uQh-0001pI-Kj for pgsql-hackers@postgresql.org; Wed, 18 Oct 2017 19:55:03 +0000 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1e4uQa-0001xL-VE for pgsql-hackers@postgresql.org; Wed, 18 Oct 2017 19:55:02 +0000 Received: by mail-it0-x242.google.com with SMTP id 72so7328879itk.3 for ; Wed, 18 Oct 2017 12:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to:user-agent; bh=dN2HqQI5STVu8jNV/ISNk9R0k8/QaKp7xm7WwH9KuNg=; b=onAkH53Fxa5yxNJWpfKhlI4txVmy2actD39jL9iEkvQ0I/0y7FzTUaasht7xE9Q64n xeZmMwOBVZ8Gcunt3WxpTOV3wgh6dJvpWJvpfZzoiDuLp7e2yZ2oECWo1ldKy7SWQ5gm ZAky/l2n4goIzDUNSYY+p5nqISacw0mTdFDlT4BDlxvlRCPX5BHnoMrIWUVzPOY3Qjct 0wQJFFikINfkHm8iVCjib9STk9MokULcEhgjIyLVONfBdQqWio5XoVU7+1Md+pZQf7uk DrGfHdLRrFmPhZkgzf/8gfiP5yncWz6c4/Ex9dAMXW6nNV5/ZcGL6sBABmD0p67SfVp0 U5hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=dN2HqQI5STVu8jNV/ISNk9R0k8/QaKp7xm7WwH9KuNg=; b=JE5XqzIMs2PQcNaF95x1+ZFBxdproObKGzw0y8N1LoKqPtLfnDWJRokY91/d3hdpTl hGXEQr/aNkbcoTBH9PJMOFuBwjIEK78HvVLTA4JR62Gu8S1FGf1MSBmVBbll9jfFJhVV tI6zsOabSyvoMDZ22+217+hQ8QmeqBXMhZSP5UWqNtbGJsu/SZ3YYkhRc1wfHzrSH3ZJ CMr9l3pMhFQNS6sWuqUD2r9BEcrdyE+8cAznQaoYvkVAnMtWZrkRdXgikL8AloXnCz1r Y+DU7iEpd/GdNdKuIM45jlg4QDo32WpDSNmZHi1LlG+3cvggD0EokelPjH6OmhkfFBkl bRGw== X-Gm-Message-State: AMCzsaU2duUD+JLxNRQvuTXud8H6QNH3dEi6wPiWCFg7NpgYK8W0veKf Oc+5qycz+X0nYICtZAHO5uXlfg== X-Google-Smtp-Source: ABhQp+SpRbsw0apI7cWn6od9Aoc4tvI4L4jWq0Y6/7CUrKAqjlEgylezhQpVqPVXafw6hKfgpfRFQQ== X-Received: by 10.36.205.198 with SMTP id l189mr370161itg.125.1508356495523; Wed, 18 Oct 2017 12:54:55 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 78sm3544972ioo.37.2017.10.18.12.54.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Oct 2017 12:54:55 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 5933F80129D; Wed, 18 Oct 2017 14:54:54 -0500 (CDT) Date: Wed, 18 Oct 2017 14:54:54 -0500 From: Justin Pryzby To: Tom Lane Cc: Simon Riggs , Craig Ringer , Greg Stark , Amit Langote , pgsql-hackers@postgreSQL.org Subject: Re: [GENERAL] huge RAM use in multi-command ALTER of table heirarchy Message-ID: <20171018195454.GI17895@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <946544e1-a4d7-12b5-60c6-c2b5f956ec6a@lab.ntt.co.jp> <6051.1500556750@sss.pgh.pa.us> <31269.1500420390@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, I just ran into this again in another context (see original dicussion, quoted below). Some time ago, while initially introducting non-default stats target, I set our non-filtering columns to "STATISTICS 10", lower than default, to minimize the size of pg_statistic, which (at least at one point) I perceived to have become bloated and causing issue (partially due to having an excessive number of "daily" granularity partitions, a problem I've since mitigated). The large number of columns with non-default stats target was (I think) causing pg_dump --section=pre-data to take 10+ minutes, which makes pg_upgrade more disruptive than necessary, so now I'm going back and fixing it. [pryzbyj@database ~]$ time sed '/SET STATISTICS 10;$/!d; s//SET STATISTICS -1;/' /srv/cdrperfbackup/ts/2017-10-17/pg_dump-section\=pre-data |psql -1q ts server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. connection to server was lost [pryzbyj@database ~]$ dmesg |tail -n2 Out of memory: Kill process 6725 (postmaster) score 550 or sacrifice child Killed process 6725, UID 26, (postmaster) total-vm:13544792kB, anon-rss:8977764kB, file-rss:8kB So I'm hoping to encourage someone to commit the change contemplated earlier. Thanks in advance. Justin On Tue, Jul 18, 2017 at 07:26:30PM -0400, Tom Lane wrote: > Justin Pryzby writes: > > I've seen this before while doing SET STATISTICS on a larger number of columns > > using xargs, but just came up while doing ADD of a large number of columns. > > Seems to be roughly linear in number of children but superlinear WRT columns. > > I think having to do with catalog update / cache invalidation with many > > ALTERs*children*columns? > > I poked into this a bit. The operation is necessarily roughly O(N^2) in > the number of columns, because we rebuild the affected table's relcache > entry after each elementary ADD COLUMN operation, and one of the principal > components of that cost is reading all the pg_attribute entries. However, > that should only be a time cost not a space cost. Eventually I traced the > O(N^2) space consumption to RememberToFreeTupleDescAtEOX, which seems to > have been introduced in Simon's commit e5550d5fe, and which strikes me as > a kluge of the first magnitude. Unless I am missing something, that > function's design concept can fairly be characterized as "let's leak > memory like there's no tomorrow, on the off chance that somebody somewhere > is ignoring basic coding rules". > > I tried ripping that out, and the peak space consumption of your example > (with 20 child tables and 1600 columns) decreased from ~3GB to ~200MB. > Moreover, the system still passes make check-world, so it's not clear > to me what excuse this code has to live. > > It's probably a bit late in the v10 cycle to be taking any risks in > this area, but I'd vote for ripping out RememberToFreeTupleDescAtEOX > as soon as the v11 cycle opens, unless someone can show an example > of non-broken coding that requires it. (And if so, there ought to > be a regression test incorporating that.) -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers