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.98.2) (envelope-from ) id 1xASLK-00000002ek9-1fAE for pgsql-bugs@arkaria.postgresql.org; Sat, 26 Sep 2026 13:21:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xASKK-00000004HjV-1vnm for pgsql-bugs@arkaria.postgresql.org; Sat, 26 Sep 2026 13:20:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x9qwG-0000000EsKF-2Q2f for pgsql-bugs@lists.postgresql.org; Thu, 24 Sep 2026 21:25:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x9qwD-000000015yC-0PsV for pgsql-bugs@lists.postgresql.org; Thu, 24 Sep 2026 21:25:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=wt+muCUUtVpq4lvCwilJfz2Ww3uVmo9g+qqr7a8LuqA=; b=d3Fk1NNu2gN9flJdfCqYicem2O nSmYo9gkaHxiiH1xvP4zgxm4axama2V+WcxudPAwINphmMlOP2ab+iH+m3S41bwK9l8dWfem4wYNM O28jLMFMsli5/3xX++2ubuiWLLRkTzcFxm1doO9Sij6w9oTaHb3sXyhodAzDKajkpxvIhsE1pRVL9 bpnKBWjHF71Ma/MH0woxCeiAvnZ9wvJcTglh/O+75pTmk6YBumOramboHvCUSpOrSMclpNpRlHYla pSfj+R0HqasOKtx2Tz2pwTUj0V7utTQpUgD6TxSMXLE6+zzIwBbaAPP35LWJvBnb/HVOtaNae2s07 tfKT9y8g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x9qwD-003Ecc-0m for pgsql-bugs@lists.postgresql.org; Thu, 24 Sep 2026 21:25:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x9qwB-00000009Irj-0hFN for pgsql-bugs@lists.postgresql.org; Thu, 24 Sep 2026 21:25:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19718: pg_dump -Ft: restore.sql gets "\unrestrict (null)"/"\restrict (null)", so psql skips \i data files To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: pkopylov@cloudlinux.com Reply-To: pkopylov@cloudlinux.com, pgsql-bugs@lists.postgresql.org Date: Thu, 24 Sep 2026 21:24:46 +0000 Message-ID: <19718-7e945d0ff9b5a589@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19718 Logged by: Pavel Kopylov Email address: pkopylov@cloudlinux.com PostgreSQL version: 17.11 Operating system: Debian 13 Description: =20 Since commit 71ea0d6795 ("Restrict psql meta-commands in plain-text dumps"), ```c _reconnectToDB() in src/bin/pg_dump/pg_backup_archiver.c writes ahprintf(AH, "\\unrestrict %s\n", ropt->restrict_key); ... ahprintf(AH, "\\restrict %s\n\n", ropt->restrict_key); ``` without checking ropt->restrict_key. RestoreArchive() emits the same markers only "if (ropt->restrict_key)". pg_dump generates a restrict key only for --format=3Dplain. The tar format, however, still writes a plain-text restore.sql through RestoreArchive() in _CloseArchive() (pg_backup_tar.c), using a copy of the dump's RestoreOptions, where restrict_key is NULL. pg_dump always sets outputCreateDB for non-plain formats, so the DATABASE TOC entry always reaches _reconnectToDB(), and every tar-format restore.sql contains: ``` \unrestrict (null) \connect srcdb \restrict (null) ``` When the script is run with "psql -f restore.sql", the first line fails with "\unrestrict: not currently in restricted mode". psql then enters restricted mode with the key "(null)" and rejects every later meta-command. With pg_dump -Ft --inserts the table data is loaded through "\i $$PATH$$/NNNN.dat", so no table data is restored at all. Reproduced on 18.6 and 17.11 (official Docker images). The code on master is the same. The logged output run on the official Docker image is: ``` $ cat repro-debian13.log ### Debian GNU/Linux 13 (trixie), postgresql-15-pllua postgresql-17 17.11-0+deb13u1postgresql-17-jit-llvm postgresql-17-pllua postgresql-9.1 + createdb srcdb + psql -Xq srcdb -c 'CREATE TABLE t(i int); INSERT INTO t SELECT generate_series(1,10)' + mkdir /tmp/x + cd /tmp/x + pg_dump -Ft --inserts srcdb -f d.tar + tar xf d.tar + sed -i 's|[$][$]PATH[$][$]|/tmp/x|g' restore.sql + dropdb srcdb + createdb srcdb + psql -X -d srcdb -f restore.sql + grep -i restrict psql:restore.sql:37: error: \unrestrict: not currently in restricted mode psql:restore.sql:72: error: backslash commands are restricted; only \unrestrict is allowed + psql -XAt -d srcdb -c 'SELECT count(*) FROM t' 0 ``` The expected output number MUST be 10 instead of 0.