Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tO406-003rHI-3s for pgsql-general@arkaria.postgresql.org; Thu, 19 Dec 2024 00:02:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tO405-003z3n-Ci for pgsql-general@arkaria.postgresql.org; Thu, 19 Dec 2024 00:02:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tO405-003z3e-08 for pgsql-general@lists.postgresql.org; Thu, 19 Dec 2024 00:02:44 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tO401-000Ug9-SY for pgsql-general@lists.postgresql.org; Thu, 19 Dec 2024 00:02:43 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-540201cfedbso145854e87.3 for ; Wed, 18 Dec 2024 16:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734566561; x=1735171361; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=aUJPRQc36pIngnoXrOXFsXn70oWyPjxiczVsa5US8IQ=; b=MYxaz/NhOZwDiFlAwDsDwU7v+tYUWt0koaxqqXUy7ekLHZRplNRyypn9+Ou18f+irR JUUQ2f/iaTkfmzvLp/mGmgIjxakx9AzU0qNfiu3bJUStTcSKUgOw5I7chKC72GI4NJfN 28sH0HXIxNMuaJkBoRue1paA2czZALXVKOa9JR+XM+sE1WymxoitPDPhojsprRS3zTFg GeaNh6uLwY8lUcdoHY9WYEhrjOKzoWZT4GQKGmOYglsQa4T6hrW3mYnz6IZRB31aguA9 1dfocxx4iKsMEQlmbRGjkj6069mdz1nuZgGx6C0OpuJMyH7BdV7yrcN6/DwSdCt5/LtV 5HYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734566561; x=1735171361; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aUJPRQc36pIngnoXrOXFsXn70oWyPjxiczVsa5US8IQ=; b=W0bnFM7rPnKfgJcPbc8in1MG2niHKufBFtImA6IhycImxLDeo17LfmsCKVFm/fBctF J/LBSYrIkADWL5BQVpIgfeRb0EFwWbQuf9YTxHOkxBn+GaDqnrZ24vAAAroM2Ykias/E ceOMcZYM/3XojuC7X65aI2snGMjocJRWQzmXJBM1L3dzKVif/nU2ZuGlDAIvx58d8er4 +7Za+/gn2w2/LXrbtwtEEgUbxtRom7fOhTL0NcbvKkec9jMAmxgr6S+dqd3ZE+TqZ370 n5Mw77kBxaoEMTeMOI3Os5vCwiayXcQp6w2ile2RJjDKtaF9F/wfW6aqtZZ8cEtNjx6D ykzA== X-Gm-Message-State: AOJu0Yx9yMLqyADfJpIQX1aurTtgzTjanKHd5sn/c/KFeGiQadmwAIJG z9dOy3P/LsJ9Vc/Q8KwNRt47h+gky+VUMQYy9MYOP3ZMo5Utw+SMKuWgRRwShsYfRNmXYoWaYML +c27CrtdIyfcaCiJku9L7tcRfteDBOuBdtFQ= X-Gm-Gg: ASbGncuKTIvWMIAuAROfPhs19qcvJBC2ksqRtMys/Vv3gqQ70YK5WXODcBC2afWblnp HqEJ3yER/DiSuCNP4GxloKYr9KFAGjmrWUIF3lmM= X-Google-Smtp-Source: AGHT+IGtyLp/zO9vO92bND9KPNg9FxmRGIMsGoPGgnH1GYq7dDPapWHNlSi17Yq5zFdyi5YoU3TNf6KvncNzv5JtARk= X-Received: by 2002:a05:6512:239b:b0:53e:3ac2:9c01 with SMTP id 2adb3069b0e04-541e67473b2mr2078179e87.16.1734566560886; Wed, 18 Dec 2024 16:02:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Saul Perdomo Date: Wed, 18 Dec 2024 19:02:30 -0500 Message-ID: Subject: Re: How to deal with dangling files after aborted `pg_restore`? To: Ivan Kurnosov Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000b3795b0629943f0e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b3795b0629943f0e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Genuine question: Why are you looking to recover from this half-cooked state instead of restarting the restore process from the beginning? On Tue, Dec 17, 2024, 1:10=E2=80=AFa.m. Ivan Kurnosov w= rote: > The scenario: > > 1. There is a postgresql 17 server running > 2. Restore dump with `--single-transaction` flag > 3. For whatever reason the server goes away (eg: we kill the process) > 4. Now `base` directory is filled with abandoned table files which > postgresql know nothing about > > Playground: > > Terminal 1: > Start server: `docker run --rm -it -e POSTGRES_HOST_AUTH_METHOD=3Dtrust -= v > $PWD/postgres:/var/lib/postgresql/data postgres:17.2` > > Terminal 2: > 1. Start container with recent pg_restore: `docker run --rm -it -v > $PWD:/app -w /app postgres:17.2 bash` > 2. Start dump recovery: `pg_restore -h 172.17.0.2 -U postgres -d postgres > --single-transaction -v -Fc --no-owner dump.sql` > > Terminal 3: > 1. Find what container is the server: `docker ps` > 2. Kill it: `docker kill d7ecf6e66c1d` > > Terminal 1: > Start the server again, with the same command > > Terminal 3: > Check there are abandoned large files: > ``` > # ls -la /home/ivan/postgres/base/5 > > -rw------- 1 systemd-coredump systemd-coredump 342884352 Dec 17 18:58 163= 99 > -rw------- 1 systemd-coredump systemd-coredump 11149312 Dec 17 18:58 164= 04 > -rw------- 1 systemd-coredump systemd-coredump 188416 Dec 17 18:58 > 16403_fsm > -rw------- 1 systemd-coredump systemd-coredump 686145536 Dec 17 18:58 164= 03 > ``` > > Terminal 2: > 1. Confirm those OIDs are not accounted: > ``` > psql -h 172.17.0.2 -U postgres -c 'select * from pg_class'|grep 16404 > psql -h 172.17.0.2 -U postgres -c 'select * from pg_class'|grep 16403 > psql -h 172.17.0.2 -U postgres -c 'select * from pg_class'|grep 16399 > ``` > > Hence a question: am I doing something wrong? Is it expected behaviour? I= f > so - how would one recover from this scenario now WITHOUT dropping entire > database? > > -- > With best regards, Ivan Kurnosov > --000000000000b3795b0629943f0e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Genuine question: Why are you looking to recover from this h= alf-cooked state instead of restarting the restore process from the beginni= ng?


On Tue, Dec 17, 2024, 1:10=E2=80=AFa.m. Ivan Kurnosov <<= a href=3D"mailto:zerkms@zerkms.com">zerkms@zerkms.com> wrote:
The scenario:
=

1. There is a postgresql 17 server running
2.= Restore dump with `--single-transaction` flag
3. For whatever re= ason the server goes away (eg: we kill the process)
4. Now `base`= directory is filled with abandoned table files which postgresql know nothi= ng about

Playground:

Term= inal 1:
Start server: `docker run --rm -it -e POSTGRES_HOST_AUTH_= METHOD=3Dtrust -v $PWD/postgres:/var/lib/postgresql/data postgres:17.2`

Terminal 2:
1. Start container with recent = pg_restore: `docker run --rm -it -v $PWD:/app -w /app postgres:17.2 bash`
2. Start dump recovery: `pg_restore -h 172.17.0.2 -U postgres -d p= ostgres --single-transaction -v -Fc --no-owner dump.sql`

Terminal 3:
1. Find what container is the server: `docker = ps`
2. Kill it: `docker kill d7ecf6e66c1d`

Terminal 1:
Start the server again, with the same command

Terminal 3:
Check there are abandoned large = files:
```
# ls -la=C2=A0/home/ivan/postgres/base/5
<truncated>
-rw------- 1 systemd-coredump systemd-co= redump 342884352 Dec 17 18:58 16399
-rw------- 1 systemd-coredump system= d-coredump =C2=A011149312 Dec 17 18:58 16404
-rw------- 1 systemd-coredu= mp systemd-coredump =C2=A0 =C2=A0188416 Dec 17 18:58 16403_fsm
-rw------= - 1 systemd-coredump systemd-coredump 686145536 Dec 17 18:58 16403
```

Terminal 2:
1. Confirm those OIDs = are not accounted:=C2=A0
```
psql -h 172.17.0.2 -U post= gres -c 'select * from pg_class'|grep 16404
psql -h 172.1= 7.0.2 -U postgres -c 'select * from pg_class'|grep 16403
= psql -h 172.17.0.2 -U postgres -c 'select * from pg_class'|grep 163= 99
```

Hence a question: am I doing some= thing wrong? Is it expected behaviour? If so - how would one recover from t= his scenario now WITHOUT dropping entire database?

--
With best regards, Ivan= Kurnosov
--000000000000b3795b0629943f0e--