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 1smYXb-006l9W-Ef for pgsql-general@arkaria.postgresql.org; Fri, 06 Sep 2024 12:58:19 +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 1smYXY-00EMdF-84 for pgsql-general@arkaria.postgresql.org; Fri, 06 Sep 2024 12:58:16 +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 1smYXX-00EMd6-RN for pgsql-general@lists.postgresql.org; Fri, 06 Sep 2024 12:58:16 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1smYXV-000S1u-Ey for pgsql-general@lists.postgresql.org; Fri, 06 Sep 2024 12:58:15 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-374c180d123so1080901f8f.3 for ; Fri, 06 Sep 2024 05:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725627492; x=1726232292; 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=PHvwTmqGKGBTqHS8V4LhU0LqNDaKd2MbhCRqMhswkoY=; b=PDUI+GPMK0YptDIr0yOJrilW7PfA1DPb75Gc9WMdxHHsD2Z+OPK4R8KIGkNHu8CUeA 4IolBG0qDXbs+Mn72eXBIaxbIoJVRHvwglAP7CXP5h9gAzMSCwtFy5PbGXev4CX5iYne V4ov0pygTd2C2zr+iGpMq8LtHW1QIpG1knIPbUOoHswHfRkt3XQbrP8PlsxHE4KgubzC BPeeRtE4HLcc/tjH5blAyBdr28Ngd8RbKv0DnfjzPxeObCIAFU4xe1BALnoltAgQvD3k Rm5lgpv7q/qTGwo1/wBJOkn5oR5qT0WxlhfiI9BWkg2kVReqVo715ZPoh85DLs83u+qk Napw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725627492; x=1726232292; 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=PHvwTmqGKGBTqHS8V4LhU0LqNDaKd2MbhCRqMhswkoY=; b=spBIutQ4Doc0VoqJnfgIgWFrtQy5wvwvAUlWyMP0kms5dqaKJJA1zIhl/qljewlym0 mJ2U38D0MFfREzxBEpQ5otZIXhfi1u7uKfEcX+RbalXvxhNEdsE+PsQBHFFpC5Z7d8UA qd4QKgy0bj3oXFKYIri4s3T9E771U/YNU/ES20qHkmlJ4CAlIhifhSSK3AS6eDnKvGlb tClQEsCpz2ae/aTUEGQimK2A2XS54I11n682o6lqqUkFl3GJwWN2FntZ/JHKA3DL9Og5 EXEjecmBQkpZFL/2CuNl4T+MbtCw8ARg9lGogVEMTH5lsX1Z1PWmrCg+s4ubu70dkc9S 26hg== X-Forwarded-Encrypted: i=1; AJvYcCUpITBvSvZC+apNvlUtWd9axn9B8raSetxg4lND6zr2ZRi0/jddzWOFyyaPVOFyBj3SivDSTGyV/DryHyEh@lists.postgresql.org X-Gm-Message-State: AOJu0YxqFfeMmAYoE3EdvmTMYmFkue8ALdlwenwBKb2OWH+Pk10LBz1J fjZeUM+Q4QyOIA49rd9J3UFw2CnpSt8brcB2bj4M9MBNGVEPxP2izEQXUBDCCHtxCjLUJLdIRMd hJTKVKxoP7a8TntnPH0KBwQWVlQE= X-Google-Smtp-Source: AGHT+IEdSJUP9NLU7ro1IxHdjlLOnZ5F7lopPFYu97DPidmGIw/iQv1G16zn6F/I5tTGGVKDkrdwSKJUDkI5KG64giw= X-Received: by 2002:adf:e88b:0:b0:374:ba3f:ad08 with SMTP id ffacd0b85a97d-374ba3faf72mr12368055f8f.55.1725627491950; Fri, 06 Sep 2024 05:58:11 -0700 (PDT) MIME-Version: 1.0 References: <61af3fbe-40db-4900-9144-380a5b305c74@aklaver.com> In-Reply-To: <61af3fbe-40db-4900-9144-380a5b305c74@aklaver.com> From: Sam Son Date: Fri, 6 Sep 2024 18:28:00 +0530 Message-ID: Subject: Re: Issue with Restore dump with plpythonu, plpython3u installed on postgres16 To: Adrian Klaver Cc: Muhammad Usman Khan , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000ac2a80062172f53d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ac2a80062172f53d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks Adrian, I have tried your previous workaround and it worked fine. I will try this approach as well. Regards, Samson G On Thu, Sep 5, 2024 at 3:50=E2=80=AFAM Adrian Klaver wrote: > On 9/4/24 10:46, Sam Son wrote: > > Hi Adrian, > > > > Thanks for your suggestions. I will try your modifications and do > > benchmarking. > > I got to thinking and realized I missed an important part about > separating the schema and data restores using the -s and -a arguments. > This is best explained here: > > https://www.postgresql.org/docs/current/app-pgrestore.html > > --section=3Dsectionname > > Only restore the named section. The section name can be pre-data, > data, or post-data. This option can be specified more than once to > select multiple sections. The default is to restore all sections. > > The data section contains actual table data as well as large-object > definitions. Post-data items consist of definitions of indexes, > triggers, rules and constraints other than validated check constraints. > Pre-data items consist of all other data definition items. > > > With the modification I suggested the -s argument will result in: > > -s > --schema-only > > Restore only the schema (data definitions), not data, to the extent > that schema entries are present in the archive. > > This option is the inverse of --data-only. It is similar to, but > for historical reasons not identical to, specifying --section=3Dpre-data > --section=3Dpost-data. > > The issue being it includes post-data definitions as in: > > "Post-data items consist of definitions of indexes, triggers, rules and > constraints other than validated check constraints. " > > That means when you restore the output of pg_restore -a the above items > will be in place and will run. Among other things if there are trigger > functions using plpython3u and said functions are not Python3 valid they > will fail. You might also get warnings like: > > " > pg_dump: warning: there are circular foreign-key constraints on this tabl= e: > pg_dump: detail: equipment > pg_dump: hint: You might not be able to restore the dump without using > --disable-triggers or temporarily dropping the constraints. > pg_dump: hint: Consider using a full dump instead of a --data-only dump > to avoid this problem. > " > > You might be better off using something like: > > pg_restore ... --section=3Dpre-data -f ddl_defs.sql > Search/replace ddl_defs.sql > psql ... -f ddl_defs.sql > pg_restore ... --section=3Ddata > pg_restore ... --section=3Dpost-data > > > > > > > Thanks, > > Samson G > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > --000000000000ac2a80062172f53d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Adrian,=C2=A0

I have tried your = previous workaround and it worked fine. I will try this approach as well.

Regards,
Samson G

On Thu, Sep 5, 202= 4 at 3:50=E2=80=AFAM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 9/4/24 10:46, Sam Son wrote:
> Hi Adrian,
>
> Thanks for your suggestions. I will try your modifications and do
> benchmarking.

I got to thinking and realized I missed an important part about
separating the schema and data restores using the -s and -a arguments.
This is best explained here:

https://www.postgresql.org/docs/current/a= pp-pgrestore.html

--section=3Dsectionname

=C2=A0 =C2=A0 =C2=A0Only restore the named section. The section name can be= pre-data,
data, or post-data. This option can be specified more than once to
select multiple sections. The default is to restore all sections.

=C2=A0 =C2=A0 =C2=A0The data section contains actual table data as well as = large-object
definitions. Post-data items consist of definitions of indexes,
triggers, rules and constraints other than validated check constraints. Pre-data items consist of all other data definition items.


With the modification I suggested the -s argument will result in:

-s
--schema-only

=C2=A0 =C2=A0 =C2=A0Restore only the schema (data definitions), not data, t= o the extent
that schema entries are present in the archive.

=C2=A0 =C2=A0 =C2=A0This option is the inverse of --data-only. It is simila= r to, but
for historical reasons not identical to, specifying --section=3Dpre-data --section=3Dpost-data.

The issue being it includes post-data definitions as in:

"Post-data items consist of definitions of indexes, triggers, rules an= d
constraints other than validated check constraints. "

That means when you restore the output of pg_restore -a the above items will be in place and will run. Among other things if there are trigger
functions using plpython3u and said functions are not Python3 valid they will fail. You might also get warnings like:

"
pg_dump: warning: there are circular foreign-key constraints on this table:=
pg_dump: detail: equipment
pg_dump: hint: You might not be able to restore the dump without using
--disable-triggers or temporarily dropping the constraints.
pg_dump: hint: Consider using a full dump instead of a --data-only dump to avoid this problem.
"

You might be better off using something like:

pg_restore ... --section=3Dpre-data=C2=A0 -f ddl_defs.sql
Search/replace ddl_defs.sql
psql ... -f ddl_defs.sql
pg_restore ... --section=3Ddata
pg_restore ... --section=3Dpost-data



>
> Thanks,
> Samson G


--
Adrian Klaver
adrian.klave= r@aklaver.com

--000000000000ac2a80062172f53d--