v12.4 pg_dump .sql fails to load data via psql

From: JED WALKER <jedwa(at)comcast(dot)net>
To: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Cc: "Jed(at)Home" <jedwa(at)comcast(dot)net>, "Jed(at)ICD" <jed(dot)walker(at)icd-tech(dot)com>
Subject: v12.4 pg_dump .sql fails to load data via psql
Date: 2021-10-11 22:26:17
Message-ID: 375102856.69594.1633991178400@connect.xfinity.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PostgreSQL v12.4 pg_dumpall output fails to load via "psql -f" load to empty instance/server.

This occurs using check constraints that reference a function using data in a table that is loaded later.

As a logical backup method this should be loadable into a clean database as-is.

Error:

psql:TestCase1.sql:286: ERROR: The schema/table/column cannot be found in a Domain Relation

CONTEXT: PL/pgSQL function frp_pkg_picklist.is_item_valid_for_column(character varying,character varying,character varying,character varying,boolean,boolean) line 19 at RAISE

COPY customer, line 1: "0 SHARED_DO_NOT_USE customer"

This can be remedied by manually modifying the pg_dumpall .sql file as a workaround

1. Move the tables referenced in the check constraint function, and place at the beginning of the COPY section
2. Disable the (or all) constraints on the affected tables and enable at the end.
3. Do not create the (or all) constraints on the affected tables and create them at the end.

All of these require changes to the output file (risk and work), but it should load cleanly without that.

==========

Test Case

----------

I've minimized the situation to a small test-set to show how it works (or doesn't).

See TestCase1.txt

Also see 202110load.txt for initial discovery information.

1. Create a fresh PostgreSQL database

1. Load instance with TestCase1BuildDB.sql
e.g. psql -f TestCase1BuildDB.sql

1. pg_dumpall instance
e.g. pg_dumpall -h0.0.0.0 -p5432 -Upostgres > TestCase1.sql

1. Create a fresh PostgreSQL database

1. Load databae from TestCase1.sql dumpall
e.g. psql -f TestCase1.sql

should fail with:

... ERROR: The schema/table/column cannot be found in a Domain Relation

... CONTEXT: PL/pgSQL function frp_pkg_picklist.is_item_valid_for_column(character varying,character varying,character varying,character varying,boolean,boolean) line 19 at RAISE

... COPY customer, line 1: "0 SHARED_DO_NOT_USE customer"

... COPY frp.customer (id, formal_name, accounting_period_scope) FROM stdin;

The check constraint on the table calls a function

and that functions makes a decision based on data in the picklist table

which has not been loaded yet, thus it fails the constraint check and does not load rows.

* Jed

Attachment Content-Type Size
TestCase1.sql application/octet-stream 10.0 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2021-10-11 22:48:13 Re: v12.4 pg_dump .sql fails to load data via psql
Previous Message Tom Lane 2021-10-11 21:59:31 Re: Epoch from age is incorrect