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 1iNl7W-0007fv-KC for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 21:58:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNl7V-0005su-8E for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 21:58:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNl7U-0005sm-S1 for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 21:58:13 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iNl7Q-0004CH-Rn for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 21:58:11 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46zh272QF6zxTS; Thu, 24 Oct 2019 17:58:07 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46zh270ykJz1ZVj; Thu, 24 Oct 2019 17:58:07 -0400 (EDT) Date: Thu, 24 Oct 2019 17:58:06 -0400 From: stan To: Adrian Klaver Cc: pgsql-general@lists.postgresql.org Subject: Re: A very puzzling backup/restore problem Message-ID: <20191024215806.GA7146@panix.com> References: <20191024105227.GA13265@panix.com> <4fc52554-6dad-b833-c800-7f91172c7cf1@aklaver.com> <20191024143253.GA16590@panix.com> <42316356-9409-3908-5a13-9f20c1f5b04f@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <42316356-9409-3908-5a13-9f20c1f5b04f@aklaver.com> 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:40:29AM -0700, Adrian Klaver wrote: > On 10/24/19 7:32 AM, stan wrote: > > On Thu, Oct 24, 2019 at 07:04:11AM -0700, Adrian Klaver wrote: > > > On 10/24/19 3:52 AM, stan wrote: > > > >=20 > > > >=20 > > > > I have a very confusing isse. I am trying to backup and restre a si= gnle > > > > table . > > > >=20 > > > > first I dump the table. > > >=20 > > > Actually you are just dumping the table data. > > >=20 > > > More below. > > > >=20 > > > >=20 > > > > Script started on 2019-10-24 06:29:12-0400 > > > > =1B]0;stan@smokey: ~=07stan@smokey:~$ pg_dump -a --table task_insta= nce > 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 = | nextval('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 = | CURRENT_TIMES =08TAMP > > > > lock | boolean | | = | true > > > > descrip | character varying | | | > > > > Indexes: > > > > "task_instance_pkey" PRIMARY KEY, btree (task_instance) > > > > "task_constraint" UNIQUE CONSTRAINT, btree (employee_key, wor= k_type_key, pro =08ject_key, work_start, work_end) > > > > Foreign-key constraints: > > > > "task_instance_employee_key_fkey" FOREIGN KEY (employee_key) = REFERENCES 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= "public.permitted_work" > > > > Column | Type | Collation | Nullable = | Default =08 > > > > ---------------+--------------------------+-----------+----------+-= ------------- =08----- > > > > employee_key | integer | | not null | > > > > work_type_key | integer | | not null | > > > > permit | boolean | | not null = | false > > > > modtime | timestamp with time zone | | not null = | CURRENT_TIMES =08TAMP > > > > Indexes: > > > > "permit_constraint" UNIQUE CONSTRAINT, btree (employee_key, w= ork_type_key) > > > > Foreign-key constraints: > > > > "permitted_work_employee_key_fkey" FOREIGN KEY (employee_key)= REFERENCES emp =08loyee(employee_key) ON DELETE RESTRICT > > > > "permitted_work_work_type_key_fkey" FOREIGN KEY (work_type_ke= y) REFERENCES 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[= local] 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 > > > > ^ > > >=20 > > > In your \d task_instance above I do not see a trigger that calls > > > public.check_permission(). Does one exist or was it cut off the outpu= t you > > > pasted? > >=20 > > It exists. Perhaps I am using a different /dt format? I am not accustom= ed > > to seeing the triggers when I do it. > >=20 > > >=20 > > > Also look in the dump file. Given that you are using 11.5 I'm going to > > > assume it is resetting the search_path and that the unqualified sche= ma name > > > of permitted_work below is your issue. > >=20 > > That makes sense. If I delete all the SET lines things do work. > >=20 > > Is this a known bug on version 11.5? Or am I doing something incorrectl= y? > > BTW 11.5 is the latest package for Ubuntu, I believe. >=20 > Not a bug, a security fix: >=20 > https://www.postgresql.org/about/news/1834/ > PostgreSQL 10.3, 9.6.8, 9.5.12, 9.4.17, and 9.3.22 released! >=20 > https://wiki.postgresql.org/wiki/A_Guide_to_CVE-2018-1058%3A_Protect_Your= _Search_Path >=20 > All versions greater then and equal to those mentioned above have the fix. >=20 > >=20 > > Should I start always specifying the schema? Seems to add confusion to = me. >=20 > Yes. See CVE link for why that is important. >=20 > >=20 > > Thanks for the education here. > >=20 > > >=20 > > > > 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= statement > > > > COPY task_instance, line 1: "1 1 1 8 17.50 2019-02-01 00:00:00-05 2= 019-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 And I thought we were done with this :-( So, I created a schema for the project. Gave all the users permissions on t= hat schema, recreated all the object in the new schema, verified that everything, inclu= ding the functions are in that schema, and I when I dump a table, and try to restore it I get = the original error. I see this line in the dump: SELECT pg_catalog.set_config('search_path', '', false); So, it appears that this means that the function cannot be found, even if i= t is in the new (default) schema. Oh yes, I did make the new schema the first thing in the search path define= d in the system-wide postgresql.conf file. Surely this cant be the intended behavior. --=20 "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin