Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNdWX-0004ws-FG for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 13:51:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNdWV-00011F-JH for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 13:51:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNdWV-00010V-8X for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 13:51:31 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNdWO-0001J7-Dd for pgsql-general@postgresql.org; Thu, 24 Oct 2019 13:51:30 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46zTDV30W1z1501; Thu, 24 Oct 2019 09:51:22 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46zTDV150Nz1ZVn; Thu, 24 Oct 2019 09:51:22 -0400 (EDT) Date: Thu, 24 Oct 2019 09:51:21 -0400 From: stan To: Ron Cc: pgsql-general@postgresql.org Subject: Re: A very puzzling backup/restore problem Message-ID: <20191024135121.GA16268@panix.com> References: <20191024105227.GA13265@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Oct 24, 2019 at 07:57:14AM -0500, Ron wrote: > Why did you do "\i task_instance.dump" instead of "pg_restore"? Ah, that may be the root of my problem. I had in the back of my mind that the result of a pg_dump was a free standing SQL script, but that my be exactly what is going on. I will try to use pg_restore, and make certain that resolves my issue. In the meantime, I found that if I deleted all the SET lines from the dump I could restore with psql. But that is probably not the right way to do this. >=20 > On 10/24/19 5:52 AM, stan wrote: > >=20 > > I have a very confusing isse. I am trying to backup and restre a signle > > table . > >=20 > > first I dump the table. > >=20 > >=20 > > Script started on 2019-10-24 06:29:12-0400 > > =1B]0;stan@smokey: ~=07stan@smokey:~$ pg_dump -a --table task_instance = > task_instance.dump > >=20 > > Then I connect to the db, and verify that things are as expected. > >=20 > > =1B]0;stan@smokey: ~=07stan@smokey:~$ psql > > psql (11.5 (Ubuntu 11.5-3.pgdg18.04+1)) > > Type "help" for help. > >=20 > > =1B[1m[local] stan@stan=3D=1B[0m> \dt > > List of relations > > Schema | Name | Type | Owner > > --------+--------------------------+-------+------- > > public | biz_constants | table | stan > > public | bom_item | table | stan > > public | costing_unit | table | stan > > public | customer | table | stan > > public | earthquake | table | stan > > public | employee | table | stan > > public | expense_report_instance | table | stan > > public | gl_code | table | stan > > public | mfg | table | stan > > public | mfg_part | table | stan > > public | mfg_vendor_relationship | table | stan > > public | permitted_work | table | stan > > public | phone_number_test | table | stan > > public | project | table | stan > > public | project_budget_component | table | stan > > public | project_cost_category | table | stan > > public | rate | table | stan > > public | salary | table | stan > > public | task_instance | table | stan > > public | vendor | table | stan > > public | work_type | table | stan > > (21 rows) > >=20 > > =1B[1m[local] stan@stan=3D=1B[0m> \d task_instance > > =1B[?1049h=1B[22;0;0t=1B[?1h=1B=3D = Table "public.task_instance" > > Column | Type | Collation | Nullable | = =08 Default > > ---------------+--------------------------+-----------+----------+-----= --------- =08--------------------------------- > > task_instance | integer | | not null | nex= tval('task =08_instance_key_serial'::regclass) > > project_key | integer | | not null | > > employee_key | integer | | not null | > > work_type_key | integer | | not null | > > hours | numeric(5,2) | | not null | > > work_start | timestamp with time zone | | not null | > > work_end | timestamp with time zone | | not null | > > modtime | timestamp with time zone | | not null | CUR= RENT_TIMES =08TAMP > > lock | boolean | | | true > > descrip | character varying | | | > > Indexes: > > "task_instance_pkey" PRIMARY KEY, btree (task_instance) > > "task_constraint" UNIQUE CONSTRAINT, btree (employee_key, work_typ= e_key, pro =08ject_key, work_start, work_end) > > Foreign-key constraints: > > "task_instance_employee_key_fkey" FOREIGN KEY (employee_key) REFER= ENCES empl =08:=1B[K=1B[K=1B[?1l=1B>=1B[?1049l=1B[23;0;0t=1B[1m[local] stan= @stan=3D=1B[0m> \d permitted_work > > =1B[?1049h=1B[22;0;0t=1B[?1h=1B=3D Table "pu= blic.permitted_work" > > Column | Type | Collation | Nullable | = Default =08 > > ---------------+--------------------------+-----------+----------+-----= --------- =08----- > > employee_key | integer | | not null | > > work_type_key | integer | | not null | > > permit | boolean | | not null | fal= se > > modtime | timestamp with time zone | | not null | CUR= RENT_TIMES =08TAMP > > Indexes: > > "permit_constraint" UNIQUE CONSTRAINT, btree (employee_key, work_t= ype_key) > > Foreign-key constraints: > > "permitted_work_employee_key_fkey" FOREIGN KEY (employee_key) REFE= RENCES emp =08loyee(employee_key) ON DELETE RESTRICT > > "permitted_work_work_type_key_fkey" FOREIGN KEY (work_type_key) RE= FERENCES w =08ork_type(work_type_key) ON DELETE RESTRICT > >=20 > > Then I delete the rows from the table. > >=20 > > =1B[7m(END)=1B[27m=1B[K=1B[K=1B[?1l=1B>=1B[?1049l=1B[23;0;0t=1B[1m[loca= l] stan@stan=3D=1B[0m> delete from task_instance ; > > DELETE 31 > >=20 > > Then I try to restore from the dump file. > >=20 > > =1B[1m[local] stan@stan=3D=1B[0m> \i task_instance.dump > > SET > > SET > > SET > > SET > > SET > > set_config > > ------------ > > (1 row) > >=20 > > SET > > SET > > SET > > SET > > psql:task_instance.dump:55: ERROR: relation "permitted_work" does not = exist > > LINE 3: permitted_work > > ^ > > QUERY: SELECT > > permit FROM > > permitted_work > > WHERE > > NEW.employee_key =3D permitted_work.employee_key > > AND > > NEW.work_type_key =3D permitted_work.work_type_key > > CONTEXT: PL/pgSQL function public.check_permission() line 4 at SQL sta= tement > > COPY task_instance, line 1: "1 1 1 8 17.50 2019-02-01 00:00:00-05 2019-= 02-08 00:00:00-05 2019-10-24 06:28:44.502699-04 t Drawings..." > >=20 > > After that error, U cannot see any objects in the table > >=20 > > =1B[1m[local] stan@stan=3D=1B[0m> \dt > > Did not find any relations. > > =1B[1m[local] stan@stan=3D=1B[0m> \q > > =1B]0;stan@smokey: ~=07stan@smokey:~$ exit > >=20 > > Script done on 2019-10-24 06:30:48-0400 > >=20 > > quiting psql and reconecting shows that the obkects ARE there, with the > > taks)instance table empty. > >=20 > > What am I doing wrong? >=20 > --=20 > Angular momentum makes the world go 'round. --=20 "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin