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 1gsxuo-0005Sn-OQ for pgsql-general@arkaria.postgresql.org; Sun, 10 Feb 2019 22:49:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gsxun-0002KW-Cq for pgsql-general@arkaria.postgresql.org; Sun, 10 Feb 2019 22:49:33 +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 1gsxun-0002KN-1c for pgsql-general@lists.postgresql.org; Sun, 10 Feb 2019 22:49:33 +0000 Received: from eik.handig-eekhoorn.at ([94.130.23.215] helo=hammy.handig-eekhoorn.at) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsxuj-0007L4-8i for pgsql-general@postgresql.org; Sun, 10 Feb 2019 22:49:31 +0000 Received: from hammy.handig-eekhoorn.at (localhost.localdomain [127.0.0.1]) by hammy.handig-eekhoorn.at (Proxmox) with ESMTP id 1AA0220A65; Sun, 10 Feb 2019 23:49:26 +0100 (CET) Received: from margarita.erven.at (80-109-180-71.cable.dynamic.surfer.at [80.109.180.71]) by hammy.handig-eekhoorn.at (Proxmox) with ESMTPS id D4D9420127; Sun, 10 Feb 2019 23:49:25 +0100 (CET) Received: from [192.168.27.172] (unknown [192.168.0.1]) by margarita.erven.at (Postfix) with ESMTPSA id DE83A7700154; Sun, 10 Feb 2019 23:49:24 +0100 (CET) Subject: Re: Unused files in the database directory after crashed VACUUM FULL To: pgsql-general Cc: Tom Lane References: <17143.1549813268@sss.pgh.pa.us> From: Hannes Erven Message-ID: <4ae62ff0-f33e-2a26-79ff-dcaa39ee92ff@erven.at> Date: Sun, 10 Feb 2019 23:49:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <17143.1549813268@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-AT Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi again, Am 10.02.19 um 16:41 schrieb Tom Lane: > Hannes Erven writes: >> I've just had a "VACUUM FULL " crash due to 100% disk usage. >> Clearly my fault, I was expecting the new table to be small enough. > > What do you mean by "crash" exactly? A normal transactional failure > should've cleaned up orphaned files. I suppose if the kernel decided to > kill -9 the vacuum process, that wouldn't happen --- but that's not > the usual response to out-of-disk-space. Here's the exact log (the pgadmin process was running the VACCUM FULL): 2019-02-09 23:44:53.516 CET [20341] @/ <> PANIC: could not write to file "pg_wal/xlogtemp.20341": No space left on device 2019-02-09 23:44:53.516 CET [19181] @/ <> LOG: WAL writer process (PID 20341) was terminated by signal 6: Aborted 2019-02-09 23:44:53.516 CET [19181] @/ <> LOG: terminating any other active server processes 2019-02-09 23:44:53.516 CET [20816] postgres@IP/db WARNING: terminating connection because of crash of another serve r process 2019-02-09 23:44:53.516 CET [20816] postgres@IP/db DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory. 2019-02-09 23:44:53.516 CET [20816] postgres@IP/db HINT: In a moment you should be able to reconnect to the database and repeat your command. 2019-02-09 23:44:53.597 CET [19181] @/ <> LOG: all server processes terminated; reinitializing 2019-02-09 23:44:53.679 CET [11686] @/ <> LOG: database system was interrupted; last known up at 2019-02-09 23:44:40 CET 2019-02-09 23:44:58.761 CET [11686] @/ <> LOG: database system was not properly shut down; automatic recovery in progress 2019-02-09 23:44:58.807 CET [11686] @/ <> LOG: redo starts at 1DA/B3400798 2019-02-09 23:44:58.811 CET [11686] @/ <> FATAL: could not extend file "base/16400/612716_fsm": No space left on device 2019-02-09 23:44:58.811 CET [11686] @/ <> HINT: Check free disk space. 2019-02-09 23:44:58.811 CET [11686] @/ <> CONTEXT: WAL redo at 1DA/B3406310 for Heap/INSERT: off 4 After freeing space and restarting: 2019-02-10 06:28:25.622 CET [14344] @/ <> LOG: database system was interrupted while in recovery at 2019-02-09 23:44:58 CET 2019-02-10 06:28:25.622 CET [14344] @/ <> HINT: This probably means that some data is corrupted and you will have to use the last backup for recovery. 2019-02-10 06:28:26.762 CET [14344] @/ <> LOG: database system was not properly shut down; automatic recovery in progress 2019-02-10 06:28:26.831 CET [14344] @/ <> LOG: redo starts at 1DA/B3400798 2019-02-10 06:28:27.624 CET [14344] @/ <> LOG: redo done at 1DA/D5FFF9D8 >> Is there a safe procedure how to >> check/clean up "unnecessary" files in the cluster directory? > > You just described it --- verify with pg_filenode_relation that the > file doesn't correspond to any pg_class entry, then manually delete. OK, I see. I came up with this: with d0 as ( select oid from pg_database where datname=current_database() ), d1 as ( select pg_ls_dir as fn, regexp_match(pg_ls_dir, '^([0-9]+)(.*)$') as match from d0, pg_ls_dir('base/'||d0.oid) order by 1 ), d2 as ( select fn, match[1] as base, match[2] as ext from d1 where (fn NOT ILIKE 'pg_%') ), d3 as ( select d.*, pg_filenode_relation(0, base::oid) as relation from d2 d ) select fn, pg_size_pretty((pg_stat_file('base/'||d0.oid||'/'||fn)).size) from d0, d3 where relation is null; fn | pg_size_pretty ------------+---------------- 612713 | 25 MB 612718 | 1024 MB 612718.1 | 1024 MB 612718.2 | 180 MB t11_621351 | 96 kB t11_621354 | 0 bytes t11_621356 | 8192 bytes t11_621357 | 160 kB t11_621360 | 0 bytes t11_621362 | 8192 bytes So there's still 612713 and 612718* left to clean up; judging from the numbers and timestamps, they probably belong to other VACUUM FULLs I manually canceled in the pgadmin UI during my experiments. Is this interesting enough to further investigate? If yes, I'll be happy to work on a test case. In any case, I've now learned (how) to check for orphaned files if a database cluster's on-disk size is way off from the sums of pg_total_relation_size() + WAL... Thanks again & best regards, -hannes