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 1m2xTk-0005eU-Ke for pgsql-general@arkaria.postgresql.org; Mon, 12 Jul 2021 15:04:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m2xTj-0006bM-Ki for pgsql-general@arkaria.postgresql.org; Mon, 12 Jul 2021 15:04:15 +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 1m2wDP-0005jL-7k for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 13:43:19 +0000 Received: from zimbabwe.chezphil.org ([34.255.138.49]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2wDN-0002eI-32 for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 13:43:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=chezphil.org mappendix.com; s=20171026; h=Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Date:To:From:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=5AqhwSewNgE7i0hFdt0vLy6qM5IqyPiLeDmjQqDjgNQ=; b=vDtckDF6ePAm6iH7kWDcLs29w DJmFMou+wc72i8VCdR7PlxBipfsuyIDTkMLs09e8znfNN56KU+YyrDN13pvgdvEZluFCUwocvItVI qKZ14g78NaPzruJd9hpxAOx4Eg0d4A5q7qN3ulWK8ZnTdSUcvwjh5Ccw20HWbkXXfP/XQ=; Received: from localhost ([127.0.0.1] helo=chezphil.org) by zimbabwe.chezphil.org with esmtp (Exim 4.92) (envelope-from ) id 1m2wDL-0001id-M9 for pgsql-general@lists.postgresql.org; Mon, 12 Jul 2021 14:43:15 +0100 Received: from localhost ([::ffff:127.0.0.1]) by zimbabwe with smtp (dmsmtpd 0.00001); Mon, 12 Jul 2021 14:43:15 +0100 From: "Phil Endecott" To: Date: Mon, 12 Jul 2021 14:43:15 +0100 Subject: Re: Why can't I drop a tablespace? Message-ID: <1626097395360@dmwebmail.dmwebmail.chezphil.org> In-Reply-To: References: X-Mailer: Decimail Webmail 3alpha16 MIME-Version: 1.0 Content-Type: text/plain; format="flowed"; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe wrote: > On Fri, 2021-07-09 at 20:04 +0100, Phil Endecott wrote: >> =# create tablespace tempspace location "/db_temp"; >> =# alter table requests set tablespace tempspace; >> >> That didn't work; I think disk space had actually reached zero: >> >> PANIC: could not write to file "pg_wal/xlogtemp.19369": No space left on device >> STATEMENT: alter table requests set tablespace tempspace; >> >> So I shut down the database and resolved the problem in a more conventional >> way by resizing the filesystem. It is now (apparently) functioning normally. >> >> BUT: I am unable to drop the tablespace that I created: >> >> =# drop tablespace tempspace; >> ERROR: tablespace "tempspace" is not empty >> >> On inspection /db_temp does contain a few GB of data that looks >> consistent with my table "requests" that I had tried to move. >> >> postgres:/db_temp/PG_11_201809051$ ls -l 17829/ >> total 2894972 >> -rw------- 1 postgres postgres 32137216 Jul 8 18:35 486095 >> -rw------- 1 postgres postgres 37240832 Jul 8 18:57 494286 >> -rw------- 1 postgres postgres 1073741824 Jul 8 19:02 502478 >> -rw------- 1 postgres postgres 1073741824 Jul 8 19:03 502478.1 >> -rw------- 1 postgres postgres 747577344 Jul 8 19:03 502478.2 >> >> I can't find what is using it: > > These files don't get cleaned up after a crash, so they may well be > leftovers you can remove. Thanks Laurenz. I was looking at the source for "alter table set tablespace" yesterday trying to work out what is supposed to happen. There is a comment at tablecmds.c line 3989: "Thanks to the magic of MVCC, an error anywhere along the way rolls back the whole operation; we don't have to do anything special to clean up." But I guess that creating an entirely new file on a different filesystem is an exception to that. > Use \dt+ and \di+ to determine if the table or any of its indexes > actually resides in the new tablespace. Don't forget the TOAST table. "select distinct(reltablespace) from pg_class" gives only pg_global and null. Is that including TOAST tables etc.? > If they are all still in the original tablespace as they should be > on account of the transactional guarantees, go ahead and manually > remove the files. My plan is to wait for a couple of days to see if there are any other opinions here, and then do that. Thanks again, Phil.