Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meGLa-0008Kl-8X for pgsql-general@arkaria.postgresql.org; Sat, 23 Oct 2021 12:42:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1meGL2-0004wK-9V for pgsql-general@arkaria.postgresql.org; Sat, 23 Oct 2021 12:41:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meGL1-0004tU-TN for pgsql-general@lists.postgresql.org; Sat, 23 Oct 2021 12:41:27 +0000 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1meGKu-0003Qu-9Z for pgsql-general@lists.postgresql.org; Sat, 23 Oct 2021 12:41:27 +0000 Received: by mail-qt1-x832.google.com with SMTP id c28so5972666qtv.11 for ; Sat, 23 Oct 2021 05:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=1I3FnDfewI7ZbNrJ+AnITHXznZ+9VEJwG50mpnviS7I=; b=P2G1ycrhTEd6lq1bkJVo7rnClZmMBmB0a0tJw8SFGvdRNYoo3SSWtUkGs1Ip9FFwgU nJi5c0rjmK6uehfFkgmKTnZi02tq9m+GdKUd6ExI0QPLIXOn8ddfXr854MFHRzQgLeM2 xrNQD3lfmC4EF2e/pzLsmYzi/Bs7kq4j4i1FIj9DsGyzi/4RbX7iKrnvFOz8hiW5Pucv TXYi1cFG4JEGsKewwIPqHSOfUA/BvKpFE5e9EnayFXH9u4ZT1Kdo4BcCeiTofDxKuCFo 0NKljhkR/Dw+7yTFqWXgXCJSyqyjyPvObs/V8rx613A+Uw82fJ8hKM5Ez2Bt5mWU4LK/ e7gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=1I3FnDfewI7ZbNrJ+AnITHXznZ+9VEJwG50mpnviS7I=; b=E9OSibMrS4qY81gV3LjB9h4Hg7JM3A7R+NL0fBFP4KzruuC+8G/y4wz9UEdRVjRBL+ cg0pqrlTmtTlLEv0yetUd0+R+fyaySpU6a1TBgUzOUIAYr9WjW9hYe/Ra9maS1hGn8wE ENG+R3YdChIiBxd3c74ufs+tJJ/3O6hYLhdbbQez4BUE1yOzNDlL48UZ9AwwH8y1poiO oiSn6K1L/hyjduJ0O+va5sRTqOLfZLz6K+iYDte+5okUCpMgvU/NRGdK4svbuLMBrEum agYBW+X+Djqon6bBs3AmS7IDcpD8REcXl9peCTo5xQ/CBilvY6SpIxwnnwGG/SvVKTWD +qGQ== X-Gm-Message-State: AOAM530KuuIsoWoIhXgN3/khGQgiZdrl6kFo2HrtV7eBfTUZEblHwumn /NRQFqXMV9Ge2IPioobfloyWrXUhbWa57g== X-Google-Smtp-Source: ABdhPJxjyO06dXYpBWxLZmawBN4pXewhIfG6tq6kwpqE8ceaoANaCENEITvXJlfroT1E+5sKH21I+w== X-Received: by 2002:ac8:5707:: with SMTP id 7mr6191797qtw.397.1634992877657; Sat, 23 Oct 2021 05:41:17 -0700 (PDT) Received: from [192.168.2.100] (pool-72-79-19-93.nwrknj.east.verizon.net. [72.79.19.93]) by smtp.gmail.com with ESMTPSA id i13sm6621402qko.70.2021.10.23.05.41.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 23 Oct 2021 05:41:17 -0700 (PDT) Message-ID: Date: Sat, 23 Oct 2021 08:41:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: WAL streaming and dropping a large table Content-Language: en-US To: pgsql-general@lists.postgresql.org References: From: Mladen Gogala In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/21/21 16:23, Rory Falloon wrote: > Hi, > > My postgres server setup is thus: a production database, which is > using WAL streaming (hot standby) to four other hosts of various > latencies. I Have a table that is ~200GB which has been backed up, and > now I Want to remove it. The table is not in use, it is a child table > to a parent table that _is_ in use but I foresee no issues here. The > total DB size is roughly 300GB.  The main reason for needing to remove > it is to recover the space back on the partition which is humming away > at 88% usage, and the table I wish to drop is better off in an archive > somewhere. > > I just removed around 10% of it with  'delete from', which of course > cascaded to the replication hosts. This increased the size of my > pg_xlog folder (from ~3GB to ~6.5GB) which of course increased my > partition usage. Obviously this is expected, but I wonder what would > happen if I had issued the 'drop table'? > > I expect the nature of enabling max_replication_slots would mean the > database would retain the wal segments until all have caught up; it > could take quite a long time to 'catch up' after the 'drop table' > command? It took about 10 minutes before the pg_xlog folder size had > 'settled down' to what I normally see as default which is ~3GB. > > > wal_keep_segments is defined as 128, > > wal_max_size is not defined, > > max_replication_slots is enabled > > I'd prefer to use 'drop table' as it would recover the data > immediately, but not if it will impact the production database in a > way that the partition will become full, which defeats the purpose. Is > it advisable to move the pg_xlog folder to another volume on the > system with more space (which I have) and symlink - obviously a stop & > start of the db required - and then let the WAL archives fill up as > need be? Or am I missing something obvious (likely) > > Thanks > Well, the difference between "drop table" and "delete" is that "drop table" is transaction on the data dictionary. PostgreSQL has transactional DDL, which means that "drop table" can be rolled back, so that transaction has to be protected by WAL, but it is just the log of the dictionary tables. There is the 3rd option, called "truncate" which is also a DDL which creates a new empty table with the same description and discards the old files.  Both 'drop" and "truncate" will not generate much WAL logs. On the other hand, "delete" is a regular DML transaction which will generate logs needed to recover the 200GB table. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com