Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist

Lists: pgsql-bugspgsql-hackers
From: autarch(at)urth(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-13 20:22:43
Message-ID: E1U5iqp-0000nA-Uh@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

The following bug has been logged on the website:

Bug reference: 7873
Logged by: Dave Rolsky
Email address: autarch(at)urth(dot)org
PostgreSQL version: 9.2.3
Operating system: Linux
Description:

When you pass the --clean option to pg_restore it tries to drop tables
without checking if they exist. This results in lots of error output. If
you're running pg_restore via an automated process it's very hard to
distinguish between these "ok" errors and real errors.

It should be using "DROP TABLE IF EXISTS" and the equivalent for
constraints.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: autarch(at)urth(dot)org
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-15 20:32:05
Message-ID: 20130215203205.GC12030@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Wed, Feb 13, 2013 at 08:22:43PM +0000, autarch(at)urth(dot)org wrote:
> The following bug has been logged on the website:
>
> Bug reference: 7873
> Logged by: Dave Rolsky
> Email address: autarch(at)urth(dot)org
> PostgreSQL version: 9.2.3
> Operating system: Linux
> Description:
>
> When you pass the --clean option to pg_restore it tries to drop tables
> without checking if they exist. This results in lots of error output. If
> you're running pg_restore via an automated process it's very hard to
> distinguish between these "ok" errors and real errors.
>
> It should be using "DROP TABLE IF EXISTS" and the equivalent for
> constraints.

Well, I think the question is whether you want error feedback for things
that don't exist. I don't really know the answer.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Dave Rolsky <autarch(at)urth(dot)org>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-15 22:06:12
Message-ID: alpine.DEB.2.00.1302151604450.13270@urth.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, 15 Feb 2013, Bruce Momjian wrote:

> On Wed, Feb 13, 2013 at 08:22:43PM +0000, autarch(at)urth(dot)org wrote:
>> The following bug has been logged on the website:
>>
>> Bug reference: 7873
>> Logged by: Dave Rolsky
>> Email address: autarch(at)urth(dot)org
>> PostgreSQL version: 9.2.3
>> Operating system: Linux
>> Description:
>>
>> When you pass the --clean option to pg_restore it tries to drop tables
>> without checking if they exist. This results in lots of error output. If
>> you're running pg_restore via an automated process it's very hard to
>> distinguish between these "ok" errors and real errors.
>>
>> It should be using "DROP TABLE IF EXISTS" and the equivalent for
>> constraints.
>
> Well, I think the question is whether you want error feedback for things
> that don't exist. I don't really know the answer.

Fair enough. It should probably an option to add "if exists", at least. I
can't imagine I'm the only using this tool to ship database updates around
to different machines, some of which may not have new tables. I'd really
like to be able to know when the restore fails versus when it succeeds but
is noisy.

Cheers,

-dave

/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Dave Rolsky <autarch(at)urth(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-15 23:46:37
Message-ID: 20130215234637.GH12030@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, Feb 15, 2013 at 04:06:12PM -0600, Dave Rolsky wrote:
> On Fri, 15 Feb 2013, Bruce Momjian wrote:
>
> >On Wed, Feb 13, 2013 at 08:22:43PM +0000, autarch(at)urth(dot)org wrote:
> >>The following bug has been logged on the website:
> >>
> >>Bug reference: 7873
> >>Logged by: Dave Rolsky
> >>Email address: autarch(at)urth(dot)org
> >>PostgreSQL version: 9.2.3
> >>Operating system: Linux
> >>Description:
> >>
> >>When you pass the --clean option to pg_restore it tries to drop tables
> >>without checking if they exist. This results in lots of error output. If
> >>you're running pg_restore via an automated process it's very hard to
> >>distinguish between these "ok" errors and real errors.
> >>
> >>It should be using "DROP TABLE IF EXISTS" and the equivalent for
> >>constraints.
> >
> >Well, I think the question is whether you want error feedback for things
> >that don't exist. I don't really know the answer.
>
> Fair enough. It should probably an option to add "if exists", at
> least. I can't imagine I'm the only using this tool to ship database
> updates around to different machines, some of which may not have new
> tables. I'd really like to be able to know when the restore fails
> versus when it succeeds but is noisy.

All I can say is I don't remember anyone asking for this in the past.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Dave Rolsky <autarch(at)urth(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-16 16:35:01
Message-ID: 11257.1361032501@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> On Fri, Feb 15, 2013 at 04:06:12PM -0600, Dave Rolsky wrote:
>> Fair enough. It should probably an option to add "if exists", at
>> least. I can't imagine I'm the only using this tool to ship database
>> updates around to different machines, some of which may not have new
>> tables. I'd really like to be able to know when the restore fails
>> versus when it succeeds but is noisy.

> All I can say is I don't remember anyone asking for this in the past.

I think it has come up before. I wouldn't object to a pg_dump option to
add IF EXISTS to all the drop commands (though changing the default
behavior would be more controversial). Don't intend to spend my own
time on it though ...

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-16 17:47:31
Message-ID: CAFj8pRBihcCEK-bcQEgCqLdLjQQ+J5PUyeZTekXHi_hoaEkoBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/2/16 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>> On Fri, Feb 15, 2013 at 04:06:12PM -0600, Dave Rolsky wrote:
>>> Fair enough. It should probably an option to add "if exists", at
>>> least. I can't imagine I'm the only using this tool to ship database
>>> updates around to different machines, some of which may not have new
>>> tables. I'd really like to be able to know when the restore fails
>>> versus when it succeeds but is noisy.
>
>> All I can say is I don't remember anyone asking for this in the past.
>
> I think it has come up before. I wouldn't object to a pg_dump option to
> add IF EXISTS to all the drop commands (though changing the default
> behavior would be more controversial). Don't intend to spend my own
> time on it though ...

we use this feature more than one year.

I'll send patch at Monday

Regards

Pavel Stehule

>
> regards, tom lane
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-19 13:00:07
Message-ID: CAFj8pRDwqTXnc+rEUAVc4H5Hx1F_0hKNA-9F+2FgCu18aXtY4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/2/16 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
> 2013/2/16 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>>> On Fri, Feb 15, 2013 at 04:06:12PM -0600, Dave Rolsky wrote:
>>>> Fair enough. It should probably an option to add "if exists", at
>>>> least. I can't imagine I'm the only using this tool to ship database
>>>> updates around to different machines, some of which may not have new
>>>> tables. I'd really like to be able to know when the restore fails
>>>> versus when it succeeds but is noisy.
>>
>>> All I can say is I don't remember anyone asking for this in the past.
>>
>> I think it has come up before. I wouldn't object to a pg_dump option to
>> add IF EXISTS to all the drop commands (though changing the default
>> behavior would be more controversial). Don't intend to spend my own
>> time on it though ...
>
> we use this feature more than one year.
>
> I'll send patch at Monday

here is patch, that we use about one year - originally for 9.1 - I did
port to 9.3

Regards

Pavel

>
> Regards
>
> Pavel Stehule
>
>
>
>>
>> regards, tom lane
>>
>>
>> --
>> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-bugs

Attachment Content-Type Size
conditional-drops.patch application/octet-stream 25.2 KB

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-21 02:28:42
Message-ID: CAK3UJRFimHstfo5KDqhfDS+1Oq7ji0SLWF-JGRye_LvkKQ8spw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Feb 19, 2013 at 6:00 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> 2013/2/16 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>> 2013/2/16 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>>> I think it has come up before. I wouldn't object to a pg_dump option to
>>> add IF EXISTS to all the drop commands (though changing the default
>>> behavior would be more controversial). Don't intend to spend my own
>>> time on it though ...

FYI, it was proposed here:
http://www.postgresql.org/message-id/507AD08C.5020603@dalibo.com

> here is patch, that we use about one year - originally for 9.1 - I did
> port to 9.3

dropdb and dropuser both support a similar option named --if-exists. I
suggest --if-exists instead of --conditional-drops for consistency.
I've only glanced at the patch, but if it makes no sense to use
--conditional-drops (or --if-exists, whatever it ends up being called)
without --clean, then attempting to do so should raise an error.

Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-02-23 21:51:31
Message-ID: CAFj8pRB8wvrMz57hR5YJ-QFe6AmMp6r7TXLmJL64PxBawPmweA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/2/21 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> On Tue, Feb 19, 2013 at 6:00 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> 2013/2/16 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>>> 2013/2/16 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>>>> I think it has come up before. I wouldn't object to a pg_dump option to
>>>> add IF EXISTS to all the drop commands (though changing the default
>>>> behavior would be more controversial). Don't intend to spend my own
>>>> time on it though ...
>
> FYI, it was proposed here:
> http://www.postgresql.org/message-id/507AD08C.5020603@dalibo.com
>
>> here is patch, that we use about one year - originally for 9.1 - I did
>> port to 9.3
>
> dropdb and dropuser both support a similar option named --if-exists. I
> suggest --if-exists instead of --conditional-drops for consistency.
> I've only glanced at the patch, but if it makes no sense to use
> --conditional-drops (or --if-exists, whatever it ends up being called)
> without --clean, then attempting to do so should raise an error.

so

* --conditional-drops replaced by --if-exists
* -- additional check, available only with -c option
* fix bug with dump custom functions

Regards

Pavel

>
> Josh

Attachment Content-Type Size
conditional-drops.patch application/octet-stream 30.4 KB

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-03-07 23:44:36
Message-ID: CAK3UJRG__4=+f46XaMiqA80f_-BQhJcpFwyp8g8fpSPqj-JSzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

[Moving to -hackers]

On Sat, Feb 23, 2013 at 2:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> so
>
> * --conditional-drops replaced by --if-exists

Thanks for the fixes, I played around with the patch a bit. I was sort
of expecting this example to work (after setting up the regression
database with `make installcheck`)

pg_dump --clean --if-exists -Fp -d regression --file=regression.sql
createdb test
psql -v ON_ERROR_STOP=1 --single-transaction -d test -f regression.sql

But it fails, first at:
...
DROP TRIGGER IF EXISTS tsvectorupdate ON public.test_tsvector;
ERROR: relation "public.test_tsvector" does not exist

This seems like a shortcoming of DROP TRIGGER ... IF EXISTS, and it
looks like DROP RULE ... IF EXISTS has the same problem. I recall DROP
... IF EXISTS being fixed recently for not to error out if the schema
specified for the object does not exist, and ISTM the same arguments
could be made in favor of fixing DROP TRIGGER/TABLE ... IF EXISTS not
to error out if the table doesn't exist.

Working further through the dump of the regression database, these
also present problems for --clean --if-exists dumps:

DROP CAST IF EXISTS (text AS public.casttesttype);
ERROR: type "public.casttesttype" does not exist

DROP OPERATOR IF EXISTS public.<% (point, widget);
ERROR: type "widget" does not exist

DROP FUNCTION IF EXISTS public.pt_in_widget(point, widget);
ERROR: type "widget" does not exist

I'm not sure whether DROP CAST/OPERATOR/FUNCTION IF EXISTS should be
more tolerant of nonexistent types, of if the mess could perhaps be
avoided by dump reordering.

Note, this usability problem affects unpatched head as well:

pg_dump -Fc -d regression --file=regression.dump
pg_restore --clean -1 -d regression regression.dump
...
pg_restore: [archiver (db)] could not execute query: ERROR: type
"widget" does not exist
Command was: DROP FUNCTION public.widget_out(widget);

(The use here is a little different than the first example above, but
I would still expect this case to work.) The above problems with IF
EXISTS aren't really a problem of the patch per se, but IMO it would
be nice to straighten all the issues out together for 9.4.

> * -- additional check, available only with -c option

Cool. I think it would also be useful to check that --clean may only
be used with --format=p to avoid any confusion there. (This issue
could be addressed in a separate patch if you'd rather not lard this
patch.)

Some comments on the changes:

1. There is at least one IF EXISTS check missing from pg_dump.c, see
for example this statement from a dump of the regression database with
--if-exists:

ALTER TABLE public.nv_child_2010 DROP CONSTRAINT nv_child_2010_d_check;

2. Shouldn't pg_restore get --if-exists as well?

3.
+ printf(_(" --if-exists don't report error if
cleaned object doesn't exist\n"));

This help output bleeds just over our de facto 80-character limit.
Also contractions seem to be avoided elsewhere. It's a little hard to
squeeze a decent explanation into one line, but perhaps:

Use IF EXISTS when dropping objects

would be better. The sgml changes could use some wordsmithing and
grammar fixes. I could clean these up for you in a later version if
you'd like.

4. There seem to be spurious whitespace changes to the function
prototype and declaration for _printTocEntry.

That's all I've had time for so far...

Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-03-08 09:23:29
Message-ID: CAFj8pRBX_+z2XbUSORZA+dv6rk38wvMnM5V8DROGFVrh2ETKjg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> [Moving to -hackers]
>
> On Sat, Feb 23, 2013 at 2:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>> so
>>
>> * --conditional-drops replaced by --if-exists
>
> Thanks for the fixes, I played around with the patch a bit. I was sort
> of expecting this example to work (after setting up the regression
> database with `make installcheck`)
>
> pg_dump --clean --if-exists -Fp -d regression --file=regression.sql
> createdb test
> psql -v ON_ERROR_STOP=1 --single-transaction -d test -f regression.sql
>
> But it fails, first at:
> ...
> DROP TRIGGER IF EXISTS tsvectorupdate ON public.test_tsvector;
> ERROR: relation "public.test_tsvector" does not exist
>
> This seems like a shortcoming of DROP TRIGGER ... IF EXISTS, and it
> looks like DROP RULE ... IF EXISTS has the same problem. I recall DROP
> ... IF EXISTS being fixed recently for not to error out if the schema
> specified for the object does not exist, and ISTM the same arguments
> could be made in favor of fixing DROP TRIGGER/TABLE ... IF EXISTS not
> to error out if the table doesn't exist.
>
> Working further through the dump of the regression database, these
> also present problems for --clean --if-exists dumps:
>
> DROP CAST IF EXISTS (text AS public.casttesttype);
> ERROR: type "public.casttesttype" does not exist
>
> DROP OPERATOR IF EXISTS public.<% (point, widget);
> ERROR: type "widget" does not exist
>
> DROP FUNCTION IF EXISTS public.pt_in_widget(point, widget);
> ERROR: type "widget" does not exist
>
> I'm not sure whether DROP CAST/OPERATOR/FUNCTION IF EXISTS should be
> more tolerant of nonexistent types, of if the mess could perhaps be
> avoided by dump reordering.
>
> Note, this usability problem affects unpatched head as well:
>
> pg_dump -Fc -d regression --file=regression.dump
> pg_restore --clean -1 -d regression regression.dump
> ...
> pg_restore: [archiver (db)] could not execute query: ERROR: type
> "widget" does not exist
> Command was: DROP FUNCTION public.widget_out(widget);
>
> (The use here is a little different than the first example above, but
> I would still expect this case to work.) The above problems with IF
> EXISTS aren't really a problem of the patch per se, but IMO it would
> be nice to straighten all the issues out together for 9.4.

ok

>
>> * -- additional check, available only with -c option
>
> Cool. I think it would also be useful to check that --clean may only
> be used with --format=p to avoid any confusion there. (This issue
> could be addressed in a separate patch if you'd rather not lard this
> patch.)

no

some people - like we in our company would to use this feature for
quiet and strict mode for plain text format too.

enabling this feature has zero overhead so there are no reason block
it anywhere.

>
> Some comments on the changes:
>
> 1. There is at least one IF EXISTS check missing from pg_dump.c, see
> for example this statement from a dump of the regression database with
> --if-exists:
>
> ALTER TABLE public.nv_child_2010 DROP CONSTRAINT nv_child_2010_d_check;
>
> 2. Shouldn't pg_restore get --if-exists as well?
>
> 3.
> + printf(_(" --if-exists don't report error if
> cleaned object doesn't exist\n"));
>
> This help output bleeds just over our de facto 80-character limit.
> Also contractions seem to be avoided elsewhere. It's a little hard to
> squeeze a decent explanation into one line, but perhaps:
>
> Use IF EXISTS when dropping objects
>
> would be better. The sgml changes could use some wordsmithing and
> grammar fixes. I could clean these up for you in a later version if
> you'd like.
>
> 4. There seem to be spurious whitespace changes to the function
> prototype and declaration for _printTocEntry.

I'll send updated version in next months

Thank you for review

Regards

Pavel

>
> That's all I've had time for so far...
>
> Josh


From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-03-08 15:58:57
Message-ID: CAK3UJRGEmtV477gu8Rvh+TUcRQHQcsHc=c0Ynu=3KDdV+Vxarw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, Mar 8, 2013 at 2:23 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> 2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:

>> Cool. I think it would also be useful to check that --clean may only
>> be used with --format=p to avoid any confusion there. (This issue
>> could be addressed in a separate patch if you'd rather not lard this
>> patch.)
>
> no
>
> some people - like we in our company would to use this feature for
> quiet and strict mode for plain text format too.
>
> enabling this feature has zero overhead so there are no reason block
> it anywhere.

I'm not sure I understand what you're getting at, but maybe my
proposal wasn't so clear. Right now, you can specify --clean along
with -Fc to pg_dump, and pg_dump will not complain even though this
combination is nonsense. I am proposing that pg_dump error out in this
case, i.e.

$ pg_dump -Fc --file=test.dump --clean -d test
pg_dump: option --clean only valid with plain format dump

Although this lack of an error a (IMO) misfeature of existing pg_dump,
so if you'd rather leave this issue aside for your patch, that is
fine.

Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-03-08 16:58:42
Message-ID: CAFj8pRBmHAh997SKC1W0GFXWbdSdYebV9g1vM5LLGVLvu3MbLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> On Fri, Mar 8, 2013 at 2:23 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> 2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
>
>>> Cool. I think it would also be useful to check that --clean may only
>>> be used with --format=p to avoid any confusion there. (This issue
>>> could be addressed in a separate patch if you'd rather not lard this
>>> patch.)
>>
>> no
>>
>> some people - like we in our company would to use this feature for
>> quiet and strict mode for plain text format too.
>>
>> enabling this feature has zero overhead so there are no reason block
>> it anywhere.
>
> I'm not sure I understand what you're getting at, but maybe my
> proposal wasn't so clear. Right now, you can specify --clean along
> with -Fc to pg_dump, and pg_dump will not complain even though this
> combination is nonsense. I am proposing that pg_dump error out in this
> case, i.e.
>
> $ pg_dump -Fc --file=test.dump --clean -d test
> pg_dump: option --clean only valid with plain format dump
>
> Although this lack of an error a (IMO) misfeature of existing pg_dump,
> so if you'd rather leave this issue aside for your patch, that is
> fine.

I'll see - please, stay tuned to 9.4 first commitfest

Regards

Pavel

>
> Josh


From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-06-17 12:47:13
Message-ID: CAK3UJRHKmhgTfaHu0PuDPr2HEmR3SJCz-1gZJuW19xN8+ZCZZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, Mar 8, 2013 at 11:58 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> I'll see - please, stay tuned to 9.4 first commitfest

Hi Pavel,
Just a reminder, I didn't see this patch in the current commitfest. I
would be happy to spend some more time reviewing if you wish to pursue
the patch.

Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-06-19 07:33:42
Message-ID: CAFj8pRCn9N9bB0EAgjDXTUn5D31m4kH3N8LmmH6osmuTXEVFmw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/6/17 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> On Fri, Mar 8, 2013 at 11:58 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>> I'll see - please, stay tuned to 9.4 first commitfest
>
> Hi Pavel,
> Just a reminder, I didn't see this patch in the current commitfest. I
> would be happy to spend some more time reviewing if you wish to pursue
> the patch.

Hello

yes, I hadn't free time for finalization of last patch. I hope so I
can do final version next month to next commitfest.

Regards and thank you

Pavel

>
> Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-02 09:39:50
Message-ID: CAFj8pRBswhH0n-Yr4hvvO93p35DTY_te313VGBb_Gkpmi9Vz8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> On Fri, Mar 8, 2013 at 2:23 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> 2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
>
>>> Cool. I think it would also be useful to check that --clean may only
>>> be used with --format=p to avoid any confusion there. (This issue
>>> could be addressed in a separate patch if you'd rather not lard this
>>> patch.)
>>
>> no
>>
>> some people - like we in our company would to use this feature for
>> quiet and strict mode for plain text format too.
>>
>> enabling this feature has zero overhead so there are no reason block
>> it anywhere.
>
> I'm not sure I understand what you're getting at, but maybe my
> proposal wasn't so clear. Right now, you can specify --clean along
> with -Fc to pg_dump, and pg_dump will not complain even though this
> combination is nonsense. I am proposing that pg_dump error out in this
> case, i.e.
>
> $ pg_dump -Fc --file=test.dump --clean -d test
> pg_dump: option --clean only valid with plain format dump
>
> Although this lack of an error a (IMO) misfeature of existing pg_dump,
> so if you'd rather leave this issue aside for your patch, that is
> fine.
>

I tested last patch and I am thinking so this patch has sense for
custom format too

[postgres(at)localhost ~]$ /usr/local/pgsql/bin/pg_dump --clean -t a
-Fc postgres > dump
[postgres(at)localhost ~]$ psql -c "drop table a"
DROP TABLE
[postgres(at)localhost ~]$ pg_restore --clean -d postgres dump
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 171; 1259 16462 TABLE
a postgres
pg_restore: [archiver (db)] could not execute query: ERROR: table "a"
does not exist
Command was: DROP TABLE public.a;

WARNING: errors ignored on restore: 1

[postgres(at)localhost ~]$ /usr/local/pgsql/bin/pg_dump --if-exist
--clean -t a -Fc postgres > dump
[postgres(at)localhost ~]$ psql -c "drop table a"
DROP TABLE
[postgres(at)localhost ~]$ pg_restore --clean -d postgres dump

So limit for plain format is not too strict

Regards

Pavel

> Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-02 11:05:36
Message-ID: CAFj8pRA-8yvR_=oj6OKxSDHUfGmQam5cJP+8LCeYY6qZUGffzg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> [Moving to -hackers]
>
> On Sat, Feb 23, 2013 at 2:51 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>> so
>>
>> * --conditional-drops replaced by --if-exists
>
> Thanks for the fixes, I played around with the patch a bit. I was sort
> of expecting this example to work (after setting up the regression
> database with `make installcheck`)
>
> pg_dump --clean --if-exists -Fp -d regression --file=regression.sql
> createdb test
> psql -v ON_ERROR_STOP=1 --single-transaction -d test -f regression.sql
>
> But it fails, first at:
> ...
> DROP TRIGGER IF EXISTS tsvectorupdate ON public.test_tsvector;
> ERROR: relation "public.test_tsvector" does not exist
>
> This seems like a shortcoming of DROP TRIGGER ... IF EXISTS, and it
> looks like DROP RULE ... IF EXISTS has the same problem. I recall DROP
> ... IF EXISTS being fixed recently for not to error out if the schema
> specified for the object does not exist, and ISTM the same arguments
> could be made in favor of fixing DROP TRIGGER/TABLE ... IF EXISTS not
> to error out if the table doesn't exist.

yes, I am thinking so it is probably best solution. Without it I
should to generate a DO statement with necessary conditions. :(

I'll prepare patch and proposal.

>
> Working further through the dump of the regression database, these
> also present problems for --clean --if-exists dumps:
>
> DROP CAST IF EXISTS (text AS public.casttesttype);
> ERROR: type "public.casttesttype" does not exist
>
> DROP OPERATOR IF EXISTS public.<% (point, widget);
> ERROR: type "widget" does not exist
>
> DROP FUNCTION IF EXISTS public.pt_in_widget(point, widget);
> ERROR: type "widget" does not exist

>
> I'm not sure whether DROP CAST/OPERATOR/FUNCTION IF EXISTS should be
> more tolerant of nonexistent types, of if the mess could perhaps be
> avoided by dump reordering.

we can raise a warning instead error ?

Regards

Pavel

>
> Note, this usability problem affects unpatched head as well:
>
> pg_dump -Fc -d regression --file=regression.dump
> pg_restore --clean -1 -d regression regression.dump
> ...
> pg_restore: [archiver (db)] could not execute query: ERROR: type
> "widget" does not exist
> Command was: DROP FUNCTION public.widget_out(widget);
>
> (The use here is a little different than the first example above, but
> I would still expect this case to work.) The above problems with IF
> EXISTS aren't really a problem of the patch per se, but IMO it would
> be nice to straighten all the issues out together for 9.4.
>
>> * -- additional check, available only with -c option
>
> Cool. I think it would also be useful to check that --clean may only
> be used with --format=p to avoid any confusion there. (This issue
> could be addressed in a separate patch if you'd rather not lard this
> patch.)
>
> Some comments on the changes:
>
> 1. There is at least one IF EXISTS check missing from pg_dump.c, see
> for example this statement from a dump of the regression database with
> --if-exists:
>
> ALTER TABLE public.nv_child_2010 DROP CONSTRAINT nv_child_2010_d_check;
>
> 2. Shouldn't pg_restore get --if-exists as well?
>
> 3.
> + printf(_(" --if-exists don't report error if
> cleaned object doesn't exist\n"));
>
> This help output bleeds just over our de facto 80-character limit.
> Also contractions seem to be avoided elsewhere. It's a little hard to
> squeeze a decent explanation into one line, but perhaps:
>
> Use IF EXISTS when dropping objects
>
> would be better. The sgml changes could use some wordsmithing and
> grammar fixes. I could clean these up for you in a later version if
> you'd like.
>
> 4. There seem to be spurious whitespace changes to the function
> prototype and declaration for _printTocEntry.
>
> That's all I've had time for so far...
>
> Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-02 11:47:07
Message-ID: CAFj8pRCk-1h_qHd0+u1iGniX4pemmqyYg--0FqEBZ0azf9+F=A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

remastered patch

still there is a issue with dependencies

Regards

Pavel Stehule

2013/6/17 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
> On Fri, Mar 8, 2013 at 11:58 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>> I'll see - please, stay tuned to 9.4 first commitfest
>
> Hi Pavel,
> Just a reminder, I didn't see this patch in the current commitfest. I
> would be happy to spend some more time reviewing if you wish to pursue
> the patch.
>
> Josh

Attachment Content-Type Size
conditional-drops.patch application/octet-stream 21.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-05 16:16:09
Message-ID: CAFj8pRCLmnA9B2ROnzmwjAjCBq--p-P_2Kq_21N21YX1Kdd8cA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

I am sending a patch that removes strict requirements for DROP IF
EXISTS statements. This behave is similar to our ALTER IF EXISTS
behave now.

postgres=# DROP CAST IF EXISTS (sss AS public.casttesttype);
NOTICE: types "sss" and "public.casttesttype" does not exist, skipping
DROP CAST
postgres=# DROP FUNCTION IF EXISTS public.pt_in_widget(point, widget);
NOTICE: function public.pt_in_widget(point,widget) does not exist, skipping
DROP FUNCTION
postgres=# DROP OPERATOR IF EXISTS public.<% (point, widget);
NOTICE: operator public.<% does not exist, skipping
DROP OPERATOR
postgres=# DROP TRIGGER test_trigger_exists ON no_such_table;
ERROR: relation "no_such_table" does not exist
postgres=# DROP TRIGGER IF EXISTS test_trigger_exists ON no_such_table;
NOTICE: trigger "test_trigger_exists" for table "no_such_table" does
not exist, skipping
DROP TRIGGER

This functionality is necessary for correct quite reload from dump
without possible warnings

Regards

Pavel

2013/7/2 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
> Hello
>
> remastered patch
>
> still there is a issue with dependencies
>
> Regards
>
> Pavel Stehule
>
>
>
>
> 2013/6/17 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
>> On Fri, Mar 8, 2013 at 11:58 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>
>>> I'll see - please, stay tuned to 9.4 first commitfest
>>
>> Hi Pavel,
>> Just a reminder, I didn't see this patch in the current commitfest. I
>> would be happy to spend some more time reviewing if you wish to pursue
>> the patch.
>>
>> Josh

Attachment Content-Type Size
drop-if-exists-no-double-check.patch application/octet-stream 18.6 KB

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-10 14:54:10
Message-ID: CAK3UJRH5CjEjaj1=7FZgrqwNQox_bfVQVr+UKyVFp+6mSujqyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, Jul 5, 2013 at 12:16 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> I am sending a patch that removes strict requirements for DROP IF
> EXISTS statements. This behave is similar to our ALTER IF EXISTS
> behave now.

+1 for this idea. But this patch should be treated as a separate issue
from the use of IF EXISTS in pg_dump/pg_restore, right? If so, I
suggest starting a new thread about this patch to make reviewing
easier.

Josh


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Dave Rolsky <autarch(at)urth(dot)org>, Bruce Momjian <bruce(at)momjian(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-10 15:06:18
Message-ID: CAFj8pRC+eaifgXvm9RmLZjuxxT72KZUAFm0yxki+3RcOP57r4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Yes, I wrote a separate patch for next commitfest.
Dne 10.7.2013 16:54 "Josh Kupershmidt" <schmiddy(at)gmail(dot)com> napsal(a):

> On Fri, Jul 5, 2013 at 12:16 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>
> > I am sending a patch that removes strict requirements for DROP IF
> > EXISTS statements. This behave is similar to our ALTER IF EXISTS
> > behave now.
>
> +1 for this idea. But this patch should be treated as a separate issue
> from the use of IF EXISTS in pg_dump/pg_restore, right? If so, I
> suggest starting a new thread about this patch to make reviewing
> easier.
>
> Josh
>


From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-10 15:17:06
Message-ID: CAK3UJRGzJLmjHG=e=By67H2qRB93MCvN-DZNj5BCPOyoitLWOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Jul 2, 2013 at 5:39 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:

> 2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
>> On Fri, Mar 8, 2013 at 2:23 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>> 2013/3/8 Josh Kupershmidt <schmiddy(at)gmail(dot)com>:
>>
>>>> Cool. I think it would also be useful to check that --clean may only
>>>> be used with --format=p to avoid any confusion there. (This issue
>>>> could be addressed in a separate patch if you'd rather not lard this
>>>> patch.)
>>>
>>> no
>>>
>>> some people - like we in our company would to use this feature for
>>> quiet and strict mode for plain text format too.
>>>
>>> enabling this feature has zero overhead so there are no reason block
>>> it anywhere.
>>
>> I'm not sure I understand what you're getting at, but maybe my
>> proposal wasn't so clear. Right now, you can specify --clean along
>> with -Fc to pg_dump, and pg_dump will not complain even though this
>> combination is nonsense. I am proposing that pg_dump error out in this
>> case, i.e.
>>
>> $ pg_dump -Fc --file=test.dump --clean -d test
>> pg_dump: option --clean only valid with plain format dump
>>
>> Although this lack of an error a (IMO) misfeature of existing pg_dump,
>> so if you'd rather leave this issue aside for your patch, that is
>> fine.
>>
>
> I tested last patch and I am thinking so this patch has sense for
> custom format too
>
> [postgres(at)localhost ~]$ /usr/local/pgsql/bin/pg_dump --clean -t a
> -Fc postgres > dump
> [postgres(at)localhost ~]$ psql -c "drop table a"
> DROP TABLE
> [postgres(at)localhost ~]$ pg_restore --clean -d postgres dump
> pg_restore: [archiver (db)] Error while PROCESSING TOC:
> pg_restore: [archiver (db)] Error from TOC entry 171; 1259 16462 TABLE
> a postgres
> pg_restore: [archiver (db)] could not execute query: ERROR: table "a"
> does not exist
> Command was: DROP TABLE public.a;
>
> WARNING: errors ignored on restore: 1
>
> [postgres(at)localhost ~]$ /usr/local/pgsql/bin/pg_dump --if-exist
> --clean -t a -Fc postgres > dump
> [postgres(at)localhost ~]$ psql -c "drop table a"
> DROP TABLE
> [postgres(at)localhost ~]$ pg_restore --clean -d postgres dump
>
> So limit for plain format is not too strict

I'm not sure I understand what you're proposing here, but for the
record I really don't think it's a good idea to encourage the use of
pg_dump -Fc --clean ...

Right now, we don't error out on this combination of command-line
options, but the --clean is effectively a no-op; you have to tell
pg_restore to use --clean. IMO, this is basically how it should be:
pg_dump, at least in custom-format, is preserving the contents of your
database with the understanding that you will use pg_restore wish to
restore from this dump in a variety of possible ways. Putting
restrictions like --clean into the custom-format dump file just makes
that dump file less useful overall.

Although it's still not clear to me why the examples you showed above
used *both* `pg_dump -Fc --clean ...` and `pg_restore --clean ...`
together. Surely the user should be specifying this preference in only
one place?

Josh


From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-07-10 21:42:33
Message-ID: CAK3UJREth9DVL5U7ewOLQYhXF7EcV5BABFE+pzPQjkPfqbW=vQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Jul 2, 2013 at 7:47 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello
>
> remastered patch
>
> still there is a issue with dependencies

Several of the issues from my last review [1] seem to still be present
in this patch, such as review notes #1 and #4.

And as discussed previously, I think that the --clean option belongs
solely with pg_restore for custom-format dumps. The way the patch
handles this is rather confusing, forcing the user to do:

$ pg_dump -Fc --clean --if-exists --file=backup.dump ...
and then:
$ pg_restore --clean ... backup.dump (without --if-exists)

to get the desired behavior.

Josh

[1] http://www.postgresql.org/message-id/CAK3UJRG__4=+f46XaMiqA80f_-BQhJcpFwyp8g8fpSPqj-JSzA@mail.gmail.com


From: Satoshi Nagayasu <snaga(at)uptime(dot)jp>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-09-16 07:19:55
Message-ID: 5236B11B.8040700@uptime.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

(2013/07/06 1:16), Pavel Stehule wrote:
> I am sending a patch that removes strict requirements for DROP IF
> EXISTS statements. This behave is similar to our ALTER IF EXISTS
> behave now.
>
>
> postgres=# DROP CAST IF EXISTS (sss AS public.casttesttype);
> NOTICE: types "sss" and "public.casttesttype" does not exist, skipping
> DROP CAST
> postgres=# DROP FUNCTION IF EXISTS public.pt_in_widget(point, widget);
> NOTICE: function public.pt_in_widget(point,widget) does not exist, skipping
> DROP FUNCTION
> postgres=# DROP OPERATOR IF EXISTS public.<% (point, widget);
> NOTICE: operator public.<% does not exist, skipping
> DROP OPERATOR
> postgres=# DROP TRIGGER test_trigger_exists ON no_such_table;
> ERROR: relation "no_such_table" does not exist
> postgres=# DROP TRIGGER IF EXISTS test_trigger_exists ON no_such_table;
> NOTICE: trigger "test_trigger_exists" for table "no_such_table" does
> not exist, skipping
> DROP TRIGGER
>
> This functionality is necessary for correct quite reload from dump
> without possible warnings

I'm looking at this patch, and I have a question here.

Should "DROP TRIGGER IF EXISTS" ignore error for non-existing trigger
and non-existing table? Or just only for non-existing trigger?

I've not understood the pg_restore issue precisely so far,
but IMHO "DROP TRIGGER IF EXISTS" means "if the _trigger_ exists",
not "if the _table_ exists".

Is this a correct and/or an expected behavior?

Sorry if I missed some consensus which we already made.

Any comments?

Regards,
--
Satoshi Nagayasu <snaga(at)uptime(dot)jp>
Uptime Technologies, LLC. http://www.uptime.jp


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Satoshi Nagayasu <snaga(at)uptime(dot)jp>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-09-19 22:12:01
Message-ID: CAFj8pRAyO-H5QQJ+853YsO_CZNeNrr7=Z9qjRuC4y5cmWtWyjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp>

> (2013/07/06 1:16), Pavel Stehule wrote:
>
>> I am sending a patch that removes strict requirements for DROP IF
>> EXISTS statements. This behave is similar to our ALTER IF EXISTS
>> behave now.
>>
>>
>> postgres=# DROP CAST IF EXISTS (sss AS public.casttesttype);
>> NOTICE: types "sss" and "public.casttesttype" does not exist, skipping
>> DROP CAST
>> postgres=# DROP FUNCTION IF EXISTS public.pt_in_widget(point, widget);
>> NOTICE: function public.pt_in_widget(point,**widget) does not exist,
>> skipping
>> DROP FUNCTION
>> postgres=# DROP OPERATOR IF EXISTS public.<% (point, widget);
>> NOTICE: operator public.<% does not exist, skipping
>> DROP OPERATOR
>> postgres=# DROP TRIGGER test_trigger_exists ON no_such_table;
>> ERROR: relation "no_such_table" does not exist
>> postgres=# DROP TRIGGER IF EXISTS test_trigger_exists ON no_such_table;
>> NOTICE: trigger "test_trigger_exists" for table "no_such_table" does
>> not exist, skipping
>> DROP TRIGGER
>>
>> This functionality is necessary for correct quite reload from dump
>> without possible warnings
>>
>
> I'm looking at this patch, and I have a question here.
>
> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing trigger
> and non-existing table? Or just only for non-existing trigger?
>

My opinion is so, both variants should be ignored - it should be fully
fault tolerant in this use case.

Regards

Pavel

>
> I've not understood the pg_restore issue precisely so far,
> but IMHO "DROP TRIGGER IF EXISTS" means "if the _trigger_ exists",
> not "if the _table_ exists".
>
> Is this a correct and/or an expected behavior?
>
> Sorry if I missed some consensus which we already made.
>
> Any comments?
>
> Regards,
> --
> Satoshi Nagayasu <snaga(at)uptime(dot)jp>
> Uptime Technologies, LLC. http://www.uptime.jp
>


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-10 16:54:23
Message-ID: 5256DBBF.8010605@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers


On 09/19/2013 06:12 PM, Pavel Stehule wrote:
>
>
> 2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp <mailto:snaga(at)uptime(dot)jp>>
>
>

>
> I'm looking at this patch, and I have a question here.
>
> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing trigger
> and non-existing table? Or just only for non-existing trigger?
>
>
> My opinion is so, both variants should be ignored - it should be fully
> fault tolerant in this use case.
>
>

This thread seems to have gone cold, but I'm inclined to agree with
Pavel. If the table doesn't exist, neither does the trigger, and the
whole point of the 'IF EXISTS' variants is to provide the ability to
issue DROP commands that don't fail if their target is missing.

cheers

andrew


From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-14 21:38:22
Message-ID: CAK3UJRFiscKy=DSv9Kv5FYP=E7jcz3A=WopVKM9=qR9fqn-wBg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Thu, Oct 10, 2013 at 12:54 PM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

> This thread seems to have gone cold, but I'm inclined to agree with Pavel.
> If the table doesn't exist, neither does the trigger, and the whole point of
> the 'IF EXISTS' variants is to provide the ability to issue DROP commands
> that don't fail if their target is missing.

+1 from me as well.

Also, Pavel, this patch is still listed as 'Needs Review' in the CF
app, but I haven't seen a response to the concerns in my last message.

Josh


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-14 21:44:21
Message-ID: 20131014214421.GE25013@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
>
> On 09/19/2013 06:12 PM, Pavel Stehule wrote:
> >
> >
> >2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp <mailto:snaga(at)uptime(dot)jp>>
> >
> >
>
>
> >
> > I'm looking at this patch, and I have a question here.
> >
> > Should "DROP TRIGGER IF EXISTS" ignore error for non-existing trigger
> > and non-existing table? Or just only for non-existing trigger?
> >
> >
> >My opinion is so, both variants should be ignored - it should be fully
> >fault tolerant in this use case.
> >
> >
>
>
> This thread seems to have gone cold, but I'm inclined to agree with Pavel.
> If the table doesn't exist, neither does the trigger, and the whole point of
> the 'IF EXISTS' variants is to provide the ability to issue DROP commands
> that don't fail if their target is missing.

-1, this seems to likely to just hide typos.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-14 21:59:25
Message-ID: 525C693D.3090105@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers


On 10/14/2013 05:44 PM, Andres Freund wrote:
> On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
>> On 09/19/2013 06:12 PM, Pavel Stehule wrote:
>>>
>>> 2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp <mailto:snaga(at)uptime(dot)jp>>
>>>
>>>
>>
>>> I'm looking at this patch, and I have a question here.
>>>
>>> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing trigger
>>> and non-existing table? Or just only for non-existing trigger?
>>>
>>>
>>> My opinion is so, both variants should be ignored - it should be fully
>>> fault tolerant in this use case.
>>>
>>>
>>
>> This thread seems to have gone cold, but I'm inclined to agree with Pavel.
>> If the table doesn't exist, neither does the trigger, and the whole point of
>> the 'IF EXISTS' variants is to provide the ability to issue DROP commands
>> that don't fail if their target is missing.
> -1, this seems to likely to just hide typos.
>

So if I say

DROP TRIGGER IF EXISTS foo ON bar;

you're ok with succeeding if foo is a typo, but not if bar is?

cheers

andrew


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-14 22:00:51
Message-ID: 20131014220051.GF25013@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-10-14 17:59:25 -0400, Andrew Dunstan wrote:
>
> On 10/14/2013 05:44 PM, Andres Freund wrote:
> >On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
> >>On 09/19/2013 06:12 PM, Pavel Stehule wrote:
> >>>
> >>>2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp <mailto:snaga(at)uptime(dot)jp>>
> >>>
> >>>
> >>
> >>> I'm looking at this patch, and I have a question here.
> >>>
> >>> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing trigger
> >>> and non-existing table? Or just only for non-existing trigger?
> >>>
> >>>
> >>>My opinion is so, both variants should be ignored - it should be fully
> >>>fault tolerant in this use case.
> >>>
> >>>
> >>
> >>This thread seems to have gone cold, but I'm inclined to agree with Pavel.
> >>If the table doesn't exist, neither does the trigger, and the whole point of
> >>the 'IF EXISTS' variants is to provide the ability to issue DROP commands
> >>that don't fail if their target is missing.
> >-1, this seems to likely to just hide typos.
> >
>
>
> So if I say
>
> DROP TRIGGER IF EXISTS foo ON bar;
>
> you're ok with succeeding if foo is a typo, but not if bar is?

Yes.

Normally you won't do DROP TRIGGER if you don't need the table in the
first place, in that case you can just DROP TABLE.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-14 22:23:15
Message-ID: 525C6ED3.9090701@fuzzy.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hi,

On 14.10.2013 23:44, Andres Freund wrote:
> On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
>> On 09/19/2013 06:12 PM, Pavel Stehule wrote:
>>> 2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp
>>> <mailto:snaga(at)uptime(dot)jp>>
>>>
>>> I'm looking at this patch, and I have a question here.
>>>
>>> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing
>>> trigger and non-existing table? Or just only for non-existing
>>> trigger?
>>>
>>> My opinion is so, both variants should be ignored - it should be
>>> fully fault tolerant in this use case.
>>
>> This thread seems to have gone cold, but I'm inclined to agree with
>> Pavel. If the table doesn't exist, neither does the trigger, and
>> the whole point of the 'IF EXISTS' variants is to provide the
>> ability to issue DROP commands that don't fail if their target is
>> missing.
>
> -1, this seems to likely to just hide typos.

Not sure I agree with your reasoning. Isn't that equally true for 'IF
EXISTS' clause with all commands in general? Why should we use "likely
to hide typos" argument in this case and not the others?

Or do you object only to extending DROP TRIGGER IF EXISTS to "if table
and trigger exists"? It seems natural to me that "no table" => "no
trigger" so I'm fine with this interpretation, just like Andrew.

The purpose of this patch was to add support for quiet "pg_restore
--clean" and pg_restore should not do typos (if it does, we're in much
deeper troubles I guess).

If you're concerned about users doing typos, they may as well do typos
in the trigger name with exactly the same result (trigger not dropped
without any kind of error message).

I see no reason to support DROP TRIGGER IF EXISTS but restrict the IF
EXISTS clause only to the trigger on the grounds of typos.

So +1 from me, both to the patch and graceful handling of missing table.

kind regards
Tomas


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tomas Vondra <tv(at)fuzzy(dot)cz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-14 22:28:00
Message-ID: 20131014222800.GH25013@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-10-15 00:23:15 +0200, Tomas Vondra wrote:
> Hi,
>
> On 14.10.2013 23:44, Andres Freund wrote:
> > On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
> >> On 09/19/2013 06:12 PM, Pavel Stehule wrote:
> >>> 2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp
> >>> <mailto:snaga(at)uptime(dot)jp>>
> >>>
> >>> I'm looking at this patch, and I have a question here.
> >>>
> >>> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing
> >>> trigger and non-existing table? Or just only for non-existing
> >>> trigger?
> >>>
> >>> My opinion is so, both variants should be ignored - it should be
> >>> fully fault tolerant in this use case.
> >>
> >> This thread seems to have gone cold, but I'm inclined to agree with
> >> Pavel. If the table doesn't exist, neither does the trigger, and
> >> the whole point of the 'IF EXISTS' variants is to provide the
> >> ability to issue DROP commands that don't fail if their target is
> >> missing.
> >
> > -1, this seems to likely to just hide typos.
>
> Not sure I agree with your reasoning. Isn't that equally true for 'IF
> EXISTS' clause with all commands in general? Why should we use "likely
> to hide typos" argument in this case and not the others?

Because there simply is no reason to issue a DROP TRIGGER IF EXISTS if
you don't need the contents of the table. In that case you can just
issue a DROP TABLE IF EXISTS and start anew.

> The purpose of this patch was to add support for quiet "pg_restore
> --clean" and pg_restore should not do typos (if it does, we're in much
> deeper troubles I guess).

Why does that even have to do anything for triggers? Emitting DROP TABLE
should be enough.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-23 01:37:13
Message-ID: CAK3UJRFHNrpsvpJWH4vs1dc8bWuqRhQu2mamrMpR642-QuROjQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Mon, Oct 14, 2013 at 5:38 PM, Josh Kupershmidt <schmiddy(at)gmail(dot)com> wrote:
> Also, Pavel, this patch is still listed as 'Needs Review' in the CF
> app, but I haven't seen a response to the concerns in my last message.

It looks like this patch has been imported into the 2013-11 CF [1] and
marked "Needs Review". I looked at the version of the patch pointed to
in that CF entry back in July, and noted [2] several problems that
still seemed to be present in the patch, for which I never saw a
followup from Pavel. IMO this patch should have gotten marked
"Returned with Feedback" pending a response from Pavel.

Josh

[1] https://commitfest.postgresql.org/action/patch_view?id=1174
[2] http://www.postgresql.org/message-id/CAK3UJREth9DVL5U7ewOLQYhXF7EcV5BABFE+pzPQjkPfqbW=vQ@mail.gmail.com


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-24 15:05:23
Message-ID: CA+TgmoZJT=0b_hUiVgBecCkFh9AqzkmcNmsJ=32YDFQCg7BTQw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Oct 22, 2013 at 9:37 PM, Josh Kupershmidt <schmiddy(at)gmail(dot)com> wrote:
> On Mon, Oct 14, 2013 at 5:38 PM, Josh Kupershmidt <schmiddy(at)gmail(dot)com> wrote:
>> Also, Pavel, this patch is still listed as 'Needs Review' in the CF
>> app, but I haven't seen a response to the concerns in my last message.
>
> It looks like this patch has been imported into the 2013-11 CF [1] and
> marked "Needs Review". I looked at the version of the patch pointed to
> in that CF entry back in July, and noted [2] several problems that
> still seemed to be present in the patch, for which I never saw a
> followup from Pavel. IMO this patch should have gotten marked
> "Returned with Feedback" pending a response from Pavel.

That sounds reasonable to me. Perhaps you should so mark it.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Satoshi Nagayasu <snaga(at)uptime(dot)jp>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Dave Rolsky <autarch(at)urth(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-10-24 15:36:37
Message-ID: CAFj8pRCJJmsnaKjY4oOAKBd3--hSCkeAHf=5e=D+ff2mDUi-2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/10/24 Robert Haas <robertmhaas(at)gmail(dot)com>

> On Tue, Oct 22, 2013 at 9:37 PM, Josh Kupershmidt <schmiddy(at)gmail(dot)com>
> wrote:
> > On Mon, Oct 14, 2013 at 5:38 PM, Josh Kupershmidt <schmiddy(at)gmail(dot)com>
> wrote:
> >> Also, Pavel, this patch is still listed as 'Needs Review' in the CF
> >> app, but I haven't seen a response to the concerns in my last message.
> >
> > It looks like this patch has been imported into the 2013-11 CF [1] and
> > marked "Needs Review". I looked at the version of the patch pointed to
> > in that CF entry back in July, and noted [2] several problems that
> > still seemed to be present in the patch, for which I never saw a
> > followup from Pavel. IMO this patch should have gotten marked
> > "Returned with Feedback" pending a response from Pavel.
>
> That sounds reasonable to me. Perhaps you should so mark it.
>

+1

Regards

Pavel

>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 21:28:27
Message-ID: 3210.1384118907@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

[ catching up on old email ]

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> On 2013-10-15 00:23:15 +0200, Tomas Vondra wrote:
>> On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
>>> This thread seems to have gone cold, but I'm inclined to agree with
>>> Pavel. If the table doesn't exist, neither does the trigger, and
>>> the whole point of the 'IF EXISTS' variants is to provide the
>>> ability to issue DROP commands that don't fail if their target is
>>> missing.

>> -1, this seems to likely to just hide typos.

> Because there simply is no reason to issue a DROP TRIGGER IF EXISTS if
> you don't need the contents of the table. In that case you can just
> issue a DROP TABLE IF EXISTS and start anew.

I think this is nonsense. It's only one step removed from "why do you
need IF EXISTS at all, you should know whether the object is there".
The entire point of this syntax is to not need to do detailed analysis
about whether the object is there.

The pg_dump --clean use-case is sufficient refutation for that, IMO.
You're suggesting that pg_dump should make a special case out of what it
emits for "cleaning" a trigger; which we could do I guess, but it would be
ugly and fragile. For instance, the special case would probably soon grow
some warts for partial-dump scenarios. Anyway, pg_dump is not the only tool
that might wish to use DROP IF EXISTS.

regards, tom lane


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 22:11:59
Message-ID: 20131110221159.GD32665@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-11-10 16:28:27 -0500, Tom Lane wrote:
> [ catching up on old email ]
>
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > On 2013-10-15 00:23:15 +0200, Tomas Vondra wrote:
> >> On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
> >>> This thread seems to have gone cold, but I'm inclined to agree with
> >>> Pavel. If the table doesn't exist, neither does the trigger, and
> >>> the whole point of the 'IF EXISTS' variants is to provide the
> >>> ability to issue DROP commands that don't fail if their target is
> >>> missing.
>
> >> -1, this seems to likely to just hide typos.
>
> > Because there simply is no reason to issue a DROP TRIGGER IF EXISTS if
> > you don't need the contents of the table. In that case you can just
> > issue a DROP TABLE IF EXISTS and start anew.
>
> I think this is nonsense. It's only one step removed from "why do you
> need IF EXISTS at all, you should know whether the object is there".
> The entire point of this syntax is to not need to do detailed analysis
> about whether the object is there.

Well, in my opinion the IF EXISTS refers to the object type being
dropped. I.e. with DROP TABLE it refers to the table not existing, with
DROP TRIGGER it refers to the trigger not existing.
Note how we also error out if you do something like:
ALTER TABLE nonexistant DROP COLUMN IF EXISTS bar;

> The pg_dump --clean use-case is sufficient refutation for that, IMO.
> You're suggesting that pg_dump should make a special case out of what it
> emits for "cleaning" a trigger; which we could do I guess, but it would be
> ugly and fragile. For instance, the special case would probably soon grow
> some warts for partial-dump scenarios.

ISTM the only way to get a DROP TRIGGER that actually is required is a
--section=post-data dump. In the other cases it will get dropped by the
DROP TABLE that's executed shortly afterwards. But in that case we'll
currently error out during the CREATE TRIGGER shortly afterwards if the
table doesn't exist...
Maybe the way to fix this properly is to not drop post-data objects that
are implicitly dropped by the object that owns them.

>Anyway, pg_dump is not the only tool that might wish to use DROP IF EXISTS.

Well, I am absolutely not arguing against DROP TRIGGER IF NOT EXISTS
(which we already have), just against it ignoring nonexistant tables
instead of just nonexistant triggers.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 23:16:16
Message-ID: 5459.1384125376@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> On 2013-11-10 16:28:27 -0500, Tom Lane wrote:
>> I think this is nonsense. It's only one step removed from "why do you
>> need IF EXISTS at all, you should know whether the object is there".
>> The entire point of this syntax is to not need to do detailed analysis
>> about whether the object is there.

> Well, in my opinion the IF EXISTS refers to the object type being
> dropped. I.e. with DROP TABLE it refers to the table not existing, with
> DROP TRIGGER it refers to the trigger not existing.

Then I take it you also think we should undo the changes that made
"DROP TABLE IF EXISTS foo.bar" not fail if schema foo doesn't exist?
Because after all, the schema is not the object being dropped.

regards, tom lane


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 23:23:55
Message-ID: 20131110232355.GG32665@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-11-10 18:16:16 -0500, Tom Lane wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > On 2013-11-10 16:28:27 -0500, Tom Lane wrote:
> >> I think this is nonsense. It's only one step removed from "why do you
> >> need IF EXISTS at all, you should know whether the object is there".
> >> The entire point of this syntax is to not need to do detailed analysis
> >> about whether the object is there.
>
> > Well, in my opinion the IF EXISTS refers to the object type being
> > dropped. I.e. with DROP TABLE it refers to the table not existing, with
> > DROP TRIGGER it refers to the trigger not existing.
>
> Then I take it you also think we should undo the changes that made
> "DROP TABLE IF EXISTS foo.bar" not fail if schema foo doesn't exist?
> Because after all, the schema is not the object being dropped.

No, not the same thing imo, although I find that change debatable.

Anyway, if we're going to change DROP TRIGGER at the very least ALTER
TABLE ... DROP CONSTRAINT also needs to be changed, otherwise we'll gain
nothing.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 23:26:26
Message-ID: 5647.1384125986@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> On 2013-11-10 18:16:16 -0500, Tom Lane wrote:
>> Then I take it you also think we should undo the changes that made
>> "DROP TABLE IF EXISTS foo.bar" not fail if schema foo doesn't exist?
>> Because after all, the schema is not the object being dropped.

> No, not the same thing imo, although I find that change debatable.

> Anyway, if we're going to change DROP TRIGGER at the very least ALTER
> TABLE ... DROP CONSTRAINT also needs to be changed, otherwise we'll gain
> nothing.

That would be a plausible next step, but I don't have a problem with
this patch not solving every case like this at once.

regards, tom lane


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 23:32:47
Message-ID: 20131110233247.GH32665@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-11-10 18:26:26 -0500, Tom Lane wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > On 2013-11-10 18:16:16 -0500, Tom Lane wrote:
> >> Then I take it you also think we should undo the changes that made
> >> "DROP TABLE IF EXISTS foo.bar" not fail if schema foo doesn't exist?
> >> Because after all, the schema is not the object being dropped.
>
> > No, not the same thing imo, although I find that change debatable.
>
> > Anyway, if we're going to change DROP TRIGGER at the very least ALTER
> > TABLE ... DROP CONSTRAINT also needs to be changed, otherwise we'll gain
> > nothing.
>
> That would be a plausible next step, but I don't have a problem with
> this patch not solving every case like this at once.

Well, there are relatively few tables without primary keys around that
have triggers. The dumps currently look like:
DROP TRIGGER foo ON public.foo;
ALTER TABLE ONLY public.foo DROP CONSTRAINT foo_pkey;
ALTER TABLE public.foo ALTER COLUMN id DROP DEFAULT;
DROP SEQUENCE public.foo_id_seq;
DROP TABLE public.foo;
So we'd get approximately one line further unless we fix this for DROP
DEFAULT and DROP CONSTRAINT as well.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 23:42:11
Message-ID: 5940.1384126931@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> ... So we'd get approximately one line further unless we fix this for DROP
> DEFAULT and DROP CONSTRAINT as well.

True. As far as pg_dump --clean is concerned, it'd undoubtedly be easier
if we did what you suggest and just eliminate the emitted DROP commands
for table components, relying on the assumption that there'll never be
a partial-dump mode that would allow dumping a table's components without
the table. However, the server-side approach has the benefit that it'll
likely make life easier for other applications besides pg_dump.

regards, tom lane


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-10 23:57:03
Message-ID: 20131110235703.GJ32665@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-11-10 18:42:11 -0500, Tom Lane wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > ... So we'd get approximately one line further unless we fix this for DROP
> > DEFAULT and DROP CONSTRAINT as well.

Turns out that's bogus - ALTER TABLE has two levels of NOT EXISTS.

Maybe we should just do the same for DROP TRIGGER?

DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE | RESTRICT ]

> However, the server-side approach has the benefit that it'll
> likely make life easier for other applications besides pg_dump.

I am unconvinced that that's the case when using the existing IF EXISTS
for DROP TRIGGER, but my complaints would be completely addressed by
making it a separate flag.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-11 01:13:05
Message-ID: 9280.1384132385@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> Turns out that's bogus - ALTER TABLE has two levels of NOT EXISTS.

> Maybe we should just do the same for DROP TRIGGER?

> DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE | RESTRICT ]

Works for me.

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-11 19:57:51
Message-ID: CAFj8pRA2PjdE32Y1QZV+i9shbD0_Gw_zBnkjduV+LhLbv_pXGQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

I can agree, so DROP TRIGGER doesn't need a IF EXISTS clause when it is
executed after DROP TABLE.

pg_dump -c produces:

DROP TRIGGER jjj ON public.foo;
DROP TABLE public.foo;
DROP FUNCTION public.f1();
DROP EXTENSION plpgsql;
DROP SCHEMA public;

Is there some reason why we use explicitly DROP TRIGGER there?

Regards

Pavel

2013/10/15 Andres Freund <andres(at)2ndquadrant(dot)com>

> On 2013-10-15 00:23:15 +0200, Tomas Vondra wrote:
> > Hi,
> >
> > On 14.10.2013 23:44, Andres Freund wrote:
> > > On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote:
> > >> On 09/19/2013 06:12 PM, Pavel Stehule wrote:
> > >>> 2013/9/16 Satoshi Nagayasu <snaga(at)uptime(dot)jp
> > >>> <mailto:snaga(at)uptime(dot)jp>>
> > >>>
> > >>> I'm looking at this patch, and I have a question here.
> > >>>
> > >>> Should "DROP TRIGGER IF EXISTS" ignore error for non-existing
> > >>> trigger and non-existing table? Or just only for non-existing
> > >>> trigger?
> > >>>
> > >>> My opinion is so, both variants should be ignored - it should be
> > >>> fully fault tolerant in this use case.
> > >>
> > >> This thread seems to have gone cold, but I'm inclined to agree with
> > >> Pavel. If the table doesn't exist, neither does the trigger, and
> > >> the whole point of the 'IF EXISTS' variants is to provide the
> > >> ability to issue DROP commands that don't fail if their target is
> > >> missing.
> > >
> > > -1, this seems to likely to just hide typos.
> >
> > Not sure I agree with your reasoning. Isn't that equally true for 'IF
> > EXISTS' clause with all commands in general? Why should we use "likely
> > to hide typos" argument in this case and not the others?
>
> Because there simply is no reason to issue a DROP TRIGGER IF EXISTS if
> you don't need the contents of the table. In that case you can just
> issue a DROP TABLE IF EXISTS and start anew.
>
> > The purpose of this patch was to add support for quiet "pg_restore
> > --clean" and pg_restore should not do typos (if it does, we're in much
> > deeper troubles I guess).
>
> Why does that even have to do anything for triggers? Emitting DROP TABLE
> should be enough.
>
> Greetings,
>
> Andres Freund
>
> --
> Andres Freund http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-11 20:07:56
Message-ID: CAFj8pRAt_Dp0n0yecmpiPyYeMHT8mcaPNe+UsLoGgd20ZXKY=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/11/11 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > Turns out that's bogus - ALTER TABLE has two levels of NOT EXISTS.
>
> > Maybe we should just do the same for DROP TRIGGER?
>
> > DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE |
> RESTRICT ]
>
> Works for me.
>

for me too

tomorrow I'll prepare patch

Regards

Pavel

>
> regards, tom lane
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-11 21:19:17
Message-ID: CAFj8pRCGfXOOsnwpL5vaYRW11XdwHw1KXRJ80uTdj3GPNLW4kg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/11/11 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>

>
>
>
> 2013/11/11 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
>
>> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
>> > Turns out that's bogus - ALTER TABLE has two levels of NOT EXISTS.
>>
>> > Maybe we should just do the same for DROP TRIGGER?
>>
>> > DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE |
>> RESTRICT ]
>>
>
This syntax is not consistent with other IF EXISTS.

should be (IF EXISTS is before name always)

DROP TRIGGER [ IF EXISTS ] name ON [ IF EXISTS ] table_name [ CASCADE |
RESTRICT ]

What do you think about?

Regards

Pavel

>
>> Works for me.
>>
>
> for me too
>
> tomorrow I'll prepare patch
>
> Regards
>
> Pavel
>
>
>>
>> regards, tom lane
>>
>>
>> --
>> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-hackers
>>
>
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-12 16:00:24
Message-ID: CAFj8pRBQOC4LZmYenGtpZAS=Vt+YTbc8s1UQXTEtcNmVegOv5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

here is patch with fault tolerant drop trigger and drop rule support

drop trigger [if exists] trgname on [if exists] tablename;
drop rule [if exists] trgname on [if exists] tablename;

Regards

Pavel

2013/11/11 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>

>
>
>
> 2013/11/11 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
>
>> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
>> > Turns out that's bogus - ALTER TABLE has two levels of NOT EXISTS.
>>
>> > Maybe we should just do the same for DROP TRIGGER?
>>
>> > DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE |
>> RESTRICT ]
>>
>> Works for me.
>>
>
> for me too
>
> tomorrow I'll prepare patch
>
> Regards
>
> Pavel
>
>
>>
>> regards, tom lane
>>
>>
>> --
>> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-hackers
>>
>
>

Attachment Content-Type Size
drop-trigger.patch text/x-patch 23.7 KB

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-19 08:53:04
Message-ID: CAEZATCXCOZDREmkjZtu4x5xFZ7rSZB_WtTBSaUH2fm8ocoqCKw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 12 November 2013 16:00, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello
>
> here is patch with fault tolerant drop trigger and drop rule support
>
> drop trigger [if exists] trgname on [if exists] tablename;
> drop rule [if exists] trgname on [if exists] tablename;
>
> Regards
>
> Pavel
>

Hi,

I have just started looking at this patch.

It applies cleanly to head, and appears to work as intended. I have a
question though about the syntax. Looking back over this thread, there
seem to have been 3 different possibilities discussed:

1). Keep the existing syntax:

DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];

but make it tolerate a non-existent table when "IF EXISTS" is specified.

2). Support 2 independent levels of "IF EXISTS" using the syntax:

DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE
| RESTRICT ]

There was some consensus for this, but then Pavel pointed out that it
is inconsistent with other DROP commands, which all have the "IF
EXISTS" before the object to which it refers.

3). Support 2 independent levels of "IF EXISTS" using the syntax:

DROP TRIGGER [ IF EXISTS ] name ON [ IF EXISTS ] table_name [ CASCADE
| RESTRICT ]

which is what the latest patch does.

The syntax in option (3) is certainly more consistent with other DROP
commands, but it feels pretty clunky from a grammar point-of-view. It
also feels overly complex for the use cases discussed.

Personally I would prefer option (1). The SQL standard syntax is
simply "DROP TRIGGER name". The only reason we have the "ON
table_name" part is that our trigger names aren't globally unique, so
"trigger_name ON table_name" is required to uniquely identify the
trigger to drop, which would seem to be directly analogous to
specifying a schema in DROP TABLE, and we've already made that
tolerate a non-existent schema if "IF EXISTS" is used.

This seems rather different from ALTER TABLE, which allows multiple
sub-commands on the same table, so naturally lends itself to multiple
independent DROP <objtype> [IF EXISTS] sub-commands underneath the
top-level ALTER TABLE [IF EXISTS], for example:

ALTER TABLE IF EXISTS table_name
DROP COLUMN IF EXISTS col_name,
DROP CONSTRAINT IF EXISTS constr_name;

So what we currently have can be summarised as 2 classes of
commands/sub-commands to which "IF EXISTS" applies:

ALTER <objtype> [IF EXISTS] ...
DROP <objtype> [IF EXISTS] ...

We don't yet have multiple levels of "IF EXISTS" within the same DROP,
and I don't think it is necessary. For example, no one seems to be
asking for

DROP TABLE [IF EXISTS] table_name IN [IF EXISTS] schema_name

Anyway, that's just my opinion. Clearly there is at least one person
with a different opinion. What do other people think?

Regards,
Dean


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-19 12:08:39
Message-ID: CAFj8pRAXwmOp4Bx=U+W3Hahq1mu3ASYE3wDVptDp=9BtCGpCFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

I am thinking so @2 is not good idea. Using well known idiom "IF EXISTS"
once before table name and second after table name can be difficult and
messy for users. If you like it, use different idiom or different keyword,
please.

My person favourite is @1 - fault tolerant version - but I understand to
objection (what was reason, why I wrote a last version @3) - @1 and @3 are
good decision.

Regards

Pavel

2013/11/19 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 12 November 2013 16:00, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> > Hello
> >
> > here is patch with fault tolerant drop trigger and drop rule support
> >
> > drop trigger [if exists] trgname on [if exists] tablename;
> > drop rule [if exists] trgname on [if exists] tablename;
> >
> > Regards
> >
> > Pavel
> >
>
> Hi,
>
> I have just started looking at this patch.
>
> It applies cleanly to head, and appears to work as intended. I have a
> question though about the syntax. Looking back over this thread, there
> seem to have been 3 different possibilities discussed:
>
>
> 1). Keep the existing syntax:
>
> DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];
>
> but make it tolerate a non-existent table when "IF EXISTS" is specified.
>
>
> 2). Support 2 independent levels of "IF EXISTS" using the syntax:
>
> DROP TRIGGER [ IF EXISTS ] name ON table_name [ IF EXISTS ] [ CASCADE
> | RESTRICT ]
>
> There was some consensus for this, but then Pavel pointed out that it
> is inconsistent with other DROP commands, which all have the "IF
> EXISTS" before the object to which it refers.
>
>
> 3). Support 2 independent levels of "IF EXISTS" using the syntax:
>
> DROP TRIGGER [ IF EXISTS ] name ON [ IF EXISTS ] table_name [ CASCADE
> | RESTRICT ]
>
> which is what the latest patch does.
>
>
> The syntax in option (3) is certainly more consistent with other DROP
> commands, but it feels pretty clunky from a grammar point-of-view. It
> also feels overly complex for the use cases discussed.
>
> Personally I would prefer option (1). The SQL standard syntax is
> simply "DROP TRIGGER name". The only reason we have the "ON
> table_name" part is that our trigger names aren't globally unique, so
> "trigger_name ON table_name" is required to uniquely identify the
> trigger to drop, which would seem to be directly analogous to
> specifying a schema in DROP TABLE, and we've already made that
> tolerate a non-existent schema if "IF EXISTS" is used.
>
> This seems rather different from ALTER TABLE, which allows multiple
> sub-commands on the same table, so naturally lends itself to multiple
> independent DROP <objtype> [IF EXISTS] sub-commands underneath the
> top-level ALTER TABLE [IF EXISTS], for example:
>
> ALTER TABLE IF EXISTS table_name
> DROP COLUMN IF EXISTS col_name,
> DROP CONSTRAINT IF EXISTS constr_name;
>
> So what we currently have can be summarised as 2 classes of
> commands/sub-commands to which "IF EXISTS" applies:
>
> ALTER <objtype> [IF EXISTS] ...
> DROP <objtype> [IF EXISTS] ...
>
> We don't yet have multiple levels of "IF EXISTS" within the same DROP,
> and I don't think it is necessary. For example, no one seems to be
> asking for
>
> DROP TABLE [IF EXISTS] table_name IN [IF EXISTS] schema_name
>
> Anyway, that's just my opinion. Clearly there is at least one person
> with a different opinion. What do other people think?
>
> Regards,
> Dean
>


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-19 17:27:41
Message-ID: CA+Tgmoa4g3To_K+K-6oinXzpZHTGttkFC1kwopink90+umHUQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Tue, Nov 19, 2013 at 3:53 AM, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
> 1). Keep the existing syntax:
>
> DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];
>
> but make it tolerate a non-existent table when "IF EXISTS" is specified.

I don't love this option, but I like it better than the other proposals.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-21 07:35:35
Message-ID: CAFj8pRBtY8ayyVYKLhSFJHL68-QdDJxFAFQ_Cm7H+3AN663RnQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/11/19 Robert Haas <robertmhaas(at)gmail(dot)com>

> On Tue, Nov 19, 2013 at 3:53 AM, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
> wrote:
> > 1). Keep the existing syntax:
> >
> > DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];
> >
> > but make it tolerate a non-existent table when "IF EXISTS" is specified.
>
> I don't love this option, but I like it better than the other proposals.
>

we are in agreement, so we want this feature. How we can decide about
syntax?

I am feeling, so almost all people prefer

DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];

Can we live with it?

Regards

Pavel

> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-21 22:14:17
Message-ID: 528E85B9.2070200@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 11/21/13, 2:35 AM, Pavel Stehule wrote:
> I am feeling, so almost all people prefer
>
> DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];
>
> Can we live with it?

Fine with me.

I think it helps if you consider IF EXISTS an attribute of the command,
not an attribute of the command parameters.

Now we should be aware that this sort of sets a precedent for ALTER
TABLE IF EXISTS ... DROP ANYTHING ... and similar composite commands.

If might be worth checking other SQL databases. We stole the IF EXISTS
from somewhere, I believe.


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-21 22:16:31
Message-ID: 20131121221631.GH27838@alap2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2013-11-21 17:14:17 -0500, Peter Eisentraut wrote:
> On 11/21/13, 2:35 AM, Pavel Stehule wrote:
> > I am feeling, so almost all people prefer
> >
> > DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];
> >
> > Can we live with it?
>
> Fine with me.
>
> I think it helps if you consider IF EXISTS an attribute of the command,
> not an attribute of the command parameters.
>
> Now we should be aware that this sort of sets a precedent for ALTER
> TABLE IF EXISTS ... DROP ANYTHING ... and similar composite commands.

That already has 2 independent IF EXISTS, so I think the precedence
argument goes the other way round.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-24 19:28:14
Message-ID: CAFj8pRBg8i6HP6Uv_sPOihzS7Xy6DdgfFOnbLThys46v3gtgFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/11/21 Peter Eisentraut <peter_e(at)gmx(dot)net>

> On 11/21/13, 2:35 AM, Pavel Stehule wrote:
> > I am feeling, so almost all people prefer
> >
> > DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];
> >
> > Can we live with it?
>
> Fine with me.
>
> I think it helps if you consider IF EXISTS an attribute of the command,
> not an attribute of the command parameters.
>
> Now we should be aware that this sort of sets a precedent for ALTER
> TABLE IF EXISTS ... DROP ANYTHING ... and similar composite commands.
>
> If might be worth checking other SQL databases. We stole the IF EXISTS
> from somewhere, I believe.
>
>
I did some searching:

So DROP TRIGGER IF EXISTS is supported by

SQL anywhere, MySQL

Doesn't support:

MS SQL server (conditional drops is by T-SQL IF EXISTS() statement),
Oracle, DB2,

But significant difference between PostgreSQL and other databases is
requirement to specify table in DROP statement. So in SQL anywhere or in
MySQL DROP TRIGGER IF EXISTS is fully fault tolerant, there are not
possibility to specify table.

Note: DROP TRIGGER ON tablename is PostgreSQL feature - no other databases
(without PostgreSQL forks) uses this syntax - so we don't need thinking
what is in (or what will be) in ANSI standard (or what other databases
does). In this moment syntax of DROP TRIGGER is non standard. So if we can
adopt design (idea) in SQL anywhere or MySQL, then DROP TRIGGER IF EXISTS
should be enough. In our implementation there are two conditions, but we
should not to check if target table exists (from statement purpose).

So now, +1 for using "DROP TRIGGER IF EXISTS name ON tablename" without
requirement for tablename

Regards

Pavel


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-26 19:54:11
Message-ID: 5294FC63.2090401@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 11/24/13, 2:28 PM, Pavel Stehule wrote:
> Note: DROP TRIGGER ON tablename is PostgreSQL feature - no other
> databases (without PostgreSQL forks) uses this syntax - so we don't need
> thinking what is in (or what will be) in ANSI standard (or what other
> databases does). In this moment syntax of DROP TRIGGER is non standard.
> So if we can adopt design (idea) in SQL anywhere or MySQL, then DROP
> TRIGGER IF EXISTS should be enough. In our implementation there are two
> conditions, but we should not to check if target table exists (from
> statement purpose).

Right, we might as well consider 'trigger ON tablename' to be the full
name of the trigger and just treat it like a unit.

But then a single IF EXISTS clause is still inconsistent with DROP TABLE
nonexistent.foo, which fails if the schema does not exist. In other
words, the IF EXISTS clause only applies to the end of an name chain.


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-26 23:56:41
Message-ID: CAEZATCVZS6PdAOgb5Fuv8moNi4krj4MNigPDB5JfLF08tx4GZw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 26 November 2013 19:54, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> On 11/24/13, 2:28 PM, Pavel Stehule wrote:
>> Note: DROP TRIGGER ON tablename is PostgreSQL feature - no other
>> databases (without PostgreSQL forks) uses this syntax - so we don't need
>> thinking what is in (or what will be) in ANSI standard (or what other
>> databases does). In this moment syntax of DROP TRIGGER is non standard.
>> So if we can adopt design (idea) in SQL anywhere or MySQL, then DROP
>> TRIGGER IF EXISTS should be enough. In our implementation there are two
>> conditions, but we should not to check if target table exists (from
>> statement purpose).
>
> Right, we might as well consider 'trigger ON tablename' to be the full
> name of the trigger and just treat it like a unit.
>

Yeah, that's how I would view it.

> But then a single IF EXISTS clause is still inconsistent with DROP TABLE
> nonexistent.foo, which fails if the schema does not exist. In other
> words, the IF EXISTS clause only applies to the end of an name chain.
>

Actually the IF EXISTS in DROP TABLE now applies to the schema as
well. Unfortunately there is currently no consistency across the
various DROP commands --- some tolerate a non-existent schema, while
others error out. Also amongst those that tolerate a non-existent
schema, the resulting notices are not consistent --- some report the
schema-qualified object name, while others just report the local
object name.

Here is the current state of HEAD:

DROP AGGREGATE IF EXISTS no_such_schema.foo(int);
ERROR: schema "no_such_schema" does not exist

DROP CAST IF EXISTS (no_such_schema.foo AS no_such_schema.bar);
ERROR: schema "no_such_schema" does not exist

DROP COLLATION IF EXISTS no_such_schema.foo;
NOTICE: collation "no_such_schema.foo" does not exist, skipping
DROP COLLATION

DROP CONVERSION IF EXISTS no_such_schema.foo;
NOTICE: conversion "no_such_schema.foo" does not exist, skipping
DROP CONVERSION

DROP DOMAIN IF EXISTS no_such_schema.foo;
ERROR: schema "no_such_schema" does not exist

DROP FOREIGN TABLE IF EXISTS no_such_schema.foo;
NOTICE: foreign table "foo" does not exist, skipping
DROP FOREIGN TABLE

DROP FUNCTION IF EXISTS no_such_schema.foo();
ERROR: schema "no_such_schema" does not exist

DROP INDEX IF EXISTS no_such_schema.foo;
NOTICE: index "foo" does not exist, skipping
DROP INDEX

DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;
NOTICE: materialized view "foo" does not exist, skipping
DROP MATERIALIZED VIEW

DROP OPERATOR IF EXISTS no_such_schema.+ (int, int);
ERROR: schema "no_such_schema" does not exist

DROP OPERATOR CLASS IF EXISTS no_such_schema.widget_ops USING btree;
ERROR: schema "no_such_schema" does not exist

DROP OPERATOR FAMILY IF EXISTS no_such_schema.float_ops USING btree;
ERROR: schema "no_such_schema" does not exist

DROP RULE IF EXISTS foo ON no_such_schema.bar;
ERROR: schema "no_such_schema" does not exist

DROP SEQUENCE IF EXISTS no_such_schema.foo;
NOTICE: sequence "foo" does not exist, skipping
DROP SEQUENCE

DROP TABLE IF EXISTS no_such_schema.foo;
NOTICE: table "foo" does not exist, skipping
DROP TABLE

DROP TEXT SEARCH CONFIGURATION IF EXISTS no_such_schema.foo;
NOTICE: text search configuration "no_such_schema.foo" does not exist, skipping
DROP TEXT SEARCH CONFIGURATION

DROP TEXT SEARCH DICTIONARY IF EXISTS no_such_schema.foo;
NOTICE: text search dictionary "no_such_schema.foo" does not exist, skipping
DROP TEXT SEARCH DICTIONARY

DROP TEXT SEARCH PARSER IF EXISTS no_such_schema.foo;
NOTICE: text search parser "no_such_schema.foo" does not exist, skipping
DROP TEXT SEARCH PARSER

DROP TEXT SEARCH TEMPLATE IF EXISTS no_such_schema.foo;
NOTICE: text search template "no_such_schema.foo" does not exist, skipping
DROP TEXT SEARCH TEMPLATE

DROP TRIGGER IF EXISTS foo ON no_such_schema.bar;
ERROR: schema "no_such_schema" does not exist

DROP TYPE IF EXISTS no_such_schema.foo;
ERROR: schema "no_such_schema" does not exist

DROP VIEW IF EXISTS no_such_schema.foo;
NOTICE: view "foo" does not exist, skipping
DROP VIEW

That's a lot of inconsistency --- 10 errors vs 12 notices (6 with
schema-qualified names and 6 with only local names).

Regards,
Dean


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-27 00:01:38
Message-ID: 1329.1385510498@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> Actually the IF EXISTS in DROP TABLE now applies to the schema as
> well. Unfortunately there is currently no consistency across the
> various DROP commands --- some tolerate a non-existent schema, while
> others error out.

Yeah. I think now that we've had this discussion, we should make them
all tolerate a non-existent schema. I'm fine with having that happen
over a series of patches rather than all at once though.

> Also amongst those that tolerate a non-existent
> schema, the resulting notices are not consistent --- some report the
> schema-qualified object name, while others just report the local
> object name.

Less excited about this part, but on the whole I'd vote for the "schema
"no_such_schema" does not exist" wording in cases where the schema isn't
there. The other way is less specific for no very good reason.

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-27 12:32:45
Message-ID: CAFj8pRBnVWmaWnNQTOQQjWHEC=bW=xQgMmuHbkAdntD5hubWdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

I'll prepare patch

2013/11/27 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> > Actually the IF EXISTS in DROP TABLE now applies to the schema as
> > well. Unfortunately there is currently no consistency across the
> > various DROP commands --- some tolerate a non-existent schema, while
> > others error out.
>
> Yeah. I think now that we've had this discussion, we should make them
> all tolerate a non-existent schema. I'm fine with having that happen
> over a series of patches rather than all at once though.
>
> > Also amongst those that tolerate a non-existent
> > schema, the resulting notices are not consistent --- some report the
> > schema-qualified object name, while others just report the local
> > object name.
>
> Less excited about this part, but on the whole I'd vote for the "schema
> "no_such_schema" does not exist" wording in cases where the schema isn't
> there. The other way is less specific for no very good reason.
>
> regards, tom lane
>


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-28 07:44:23
Message-ID: CAFj8pRDygU89vSbXUic+i9S_qcCufy85TEMeRUbqC6EL+YrJTg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/11/27 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> > Actually the IF EXISTS in DROP TABLE now applies to the schema as
> > well. Unfortunately there is currently no consistency across the
> > various DROP commands --- some tolerate a non-existent schema, while
> > others error out.
>
> Yeah. I think now that we've had this discussion, we should make them
> all tolerate a non-existent schema. I'm fine with having that happen
> over a series of patches rather than all at once though.
>
> > Also amongst those that tolerate a non-existent
> > schema, the resulting notices are not consistent --- some report the
> > schema-qualified object name, while others just report the local
> > object name.
>
> Less excited about this part, but on the whole I'd vote for the "schema
> "no_such_schema" does not exist" wording in cases where the schema isn't
> there. The other way is less specific for no very good reason.
>

can be used this behave (see attached patch, please)?

if it is correct, I'll work on second patch, that unify check and notices
for other DROP IF EXISTS statements.

Regards

Pavel

>
> regards, tom lane
>

Attachment Content-Type Size
drop-trigger-if-exists.patch text/x-patch 8.3 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-29 08:06:05
Message-ID: CAFj8pRAY-29cuAVKauq=4_martW4H1UHG986MuHqTG++ZY_OtQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

attached patch implement unified behave for DROP IF EXISTS statements as
was discussed

Regards

Pavel

2013/11/27 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 26 November 2013 19:54, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > On 11/24/13, 2:28 PM, Pavel Stehule wrote:
> >> Note: DROP TRIGGER ON tablename is PostgreSQL feature - no other
> >> databases (without PostgreSQL forks) uses this syntax - so we don't need
> >> thinking what is in (or what will be) in ANSI standard (or what other
> >> databases does). In this moment syntax of DROP TRIGGER is non standard.
> >> So if we can adopt design (idea) in SQL anywhere or MySQL, then DROP
> >> TRIGGER IF EXISTS should be enough. In our implementation there are two
> >> conditions, but we should not to check if target table exists (from
> >> statement purpose).
> >
> > Right, we might as well consider 'trigger ON tablename' to be the full
> > name of the trigger and just treat it like a unit.
> >
>
> Yeah, that's how I would view it.
>
> > But then a single IF EXISTS clause is still inconsistent with DROP TABLE
> > nonexistent.foo, which fails if the schema does not exist. In other
> > words, the IF EXISTS clause only applies to the end of an name chain.
> >
>
> Actually the IF EXISTS in DROP TABLE now applies to the schema as
> well. Unfortunately there is currently no consistency across the
> various DROP commands --- some tolerate a non-existent schema, while
> others error out. Also amongst those that tolerate a non-existent
> schema, the resulting notices are not consistent --- some report the
> schema-qualified object name, while others just report the local
> object name.
>
> Here is the current state of HEAD:
>
> DROP AGGREGATE IF EXISTS no_such_schema.foo(int);
> ERROR: schema "no_such_schema" does not exist
>
> DROP CAST IF EXISTS (no_such_schema.foo AS no_such_schema.bar);
> ERROR: schema "no_such_schema" does not exist
>
> DROP COLLATION IF EXISTS no_such_schema.foo;
> NOTICE: collation "no_such_schema.foo" does not exist, skipping
> DROP COLLATION
>
> DROP CONVERSION IF EXISTS no_such_schema.foo;
> NOTICE: conversion "no_such_schema.foo" does not exist, skipping
> DROP CONVERSION
>
> DROP DOMAIN IF EXISTS no_such_schema.foo;
> ERROR: schema "no_such_schema" does not exist
>
> DROP FOREIGN TABLE IF EXISTS no_such_schema.foo;
> NOTICE: foreign table "foo" does not exist, skipping
> DROP FOREIGN TABLE
>
> DROP FUNCTION IF EXISTS no_such_schema.foo();
> ERROR: schema "no_such_schema" does not exist
>
> DROP INDEX IF EXISTS no_such_schema.foo;
> NOTICE: index "foo" does not exist, skipping
> DROP INDEX
>
> DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;
> NOTICE: materialized view "foo" does not exist, skipping
> DROP MATERIALIZED VIEW
>
> DROP OPERATOR IF EXISTS no_such_schema.+ (int, int);
> ERROR: schema "no_such_schema" does not exist
>
> DROP OPERATOR CLASS IF EXISTS no_such_schema.widget_ops USING btree;
> ERROR: schema "no_such_schema" does not exist
>
> DROP OPERATOR FAMILY IF EXISTS no_such_schema.float_ops USING btree;
> ERROR: schema "no_such_schema" does not exist
>
> DROP RULE IF EXISTS foo ON no_such_schema.bar;
> ERROR: schema "no_such_schema" does not exist
>
> DROP SEQUENCE IF EXISTS no_such_schema.foo;
> NOTICE: sequence "foo" does not exist, skipping
> DROP SEQUENCE
>
> DROP TABLE IF EXISTS no_such_schema.foo;
> NOTICE: table "foo" does not exist, skipping
> DROP TABLE
>
> DROP TEXT SEARCH CONFIGURATION IF EXISTS no_such_schema.foo;
> NOTICE: text search configuration "no_such_schema.foo" does not exist,
> skipping
> DROP TEXT SEARCH CONFIGURATION
>
> DROP TEXT SEARCH DICTIONARY IF EXISTS no_such_schema.foo;
> NOTICE: text search dictionary "no_such_schema.foo" does not exist,
> skipping
> DROP TEXT SEARCH DICTIONARY
>
> DROP TEXT SEARCH PARSER IF EXISTS no_such_schema.foo;
> NOTICE: text search parser "no_such_schema.foo" does not exist, skipping
> DROP TEXT SEARCH PARSER
>
> DROP TEXT SEARCH TEMPLATE IF EXISTS no_such_schema.foo;
> NOTICE: text search template "no_such_schema.foo" does not exist, skipping
> DROP TEXT SEARCH TEMPLATE
>
> DROP TRIGGER IF EXISTS foo ON no_such_schema.bar;
> ERROR: schema "no_such_schema" does not exist
>
> DROP TYPE IF EXISTS no_such_schema.foo;
> ERROR: schema "no_such_schema" does not exist
>
> DROP VIEW IF EXISTS no_such_schema.foo;
> NOTICE: view "foo" does not exist, skipping
> DROP VIEW
>
> That's a lot of inconsistency --- 10 errors vs 12 notices (6 with
> schema-qualified names and 6 with only local names).
>
> Regards,
> Dean
>

Attachment Content-Type Size
drop-if-exists.patch text/x-patch 37.2 KB

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-11-30 21:07:11
Message-ID: 1385845631.27340.22.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, 2013-11-29 at 09:06 +0100, Pavel Stehule wrote:

> attached patch implement unified behave for DROP IF EXISTS statements
> as was discussed

src/backend/catalog/namespace.c:1743: indent with spaces.
src/backend/commands/dropcmds.c:322: indent with spaces.
src/backend/commands/dropcmds.c:323: indent with spaces.
src/backend/commands/dropcmds.c:331: indent with spaces.
src/backend/commands/dropcmds.c:332: indent with spaces.
src/backend/commands/tablecmds.c:702: indent with spaces.
src/backend/commands/tablecmds.c:859: indent with spaces.
src/backend/parser/parse_func.c:1065: trailing whitespace.
src/backend/parser/parse_func.c:1066: indent with spaces.
src/backend/parser/parse_type.c:60: indent with spaces.
src/include/parser/parse_type.h:25: indent with spaces.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Fwd: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-01 07:32:58
Message-ID: CAFj8pRDUAj1C_DdQRbi1zTMGe5v9xax8hLUQiVicnxf6PhYN9w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/11/30 Peter Eisentraut <peter_e(at)gmx(dot)net>

> trailing whitespace

fixed,

Peter, what application do you use for this check?

Regards

Pavel

Attachment Content-Type Size
drop-if-exists-consistency.patch text/x-patch 37.3 KB

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-01 20:40:18
Message-ID: CAEZATCVbjDhoTFbKY1+O_Rdt=gs=7GpKVUpKBbZKK0aZCW1agA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 1 December 2013 07:32, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>
>
> 2013/11/30 Peter Eisentraut <peter_e(at)gmx(dot)net>
>>
>> trailing whitespace
>
>
> fixed,
>

Hi,

I've been looking at this and I think it's mostly in good shape, but I
spotted a few minor issues:

* There's a typo in the notice text in a couple of places --- "does
not exists, skipping" should be "does not exist, skipping".

* In does_not_exist_skipping(), the schema existence checks for
extensions and foreign data wrappers are not necessary, since I don't
think they can be schema-qualified.

* Also in does_not_exist_skipping(), in the block for casts, it is no
longer safe to use format_type_be() because it is now possible for the
types to not exist at this point. So I think it needs to use
TypeNameToString() there instead, otherwise it might raise a no such
type ERROR while trying to issue the NOTICE.

* In DropErrorMsgNonExistent(), I think the ERROR text should report
no such schema in the same way as the NOTICE text when the schema
doesn't exist for consistency with the other ERRORs and NOTICEs.

* Some more code is needed to make DROP OPERATOR FAMILY IF EXISTS
tolerate a non-existent schema.

Attached is an updated patch for those issues. I also tried to tidy up
the code in dropcmds.c a bit, removing some duplicated code, and
making parent_does_not_exist_skipping() have the same signature as
schema_does_not_exist_skipping(). This makes the code in
does_not_exist_skipping() a little neater, and means that
parent_does_not_exist_skipping() can just call
schema_does_not_exist_skipping() to check for the existence of the
parent relation's schema.

I hope those changes are all OK.

Regards,
Dean

Attachment Content-Type Size
drop-if-exists-consistency-v2.patch application/octet-stream 37.4 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-02 04:55:51
Message-ID: CAFj8pRBvpCoyaB3i3di9YPtuarJPgod51FPxjMei2n=82yzsAQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

it looks well, thank you

Regards

Pavel

2013/12/1 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 1 December 2013 07:32, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> >
> >
> >
> > 2013/11/30 Peter Eisentraut <peter_e(at)gmx(dot)net>
> >>
> >> trailing whitespace
> >
> >
> > fixed,
> >
>
> Hi,
>
> I've been looking at this and I think it's mostly in good shape, but I
> spotted a few minor issues:
>
> * There's a typo in the notice text in a couple of places --- "does
> not exists, skipping" should be "does not exist, skipping".
>
> * In does_not_exist_skipping(), the schema existence checks for
> extensions and foreign data wrappers are not necessary, since I don't
> think they can be schema-qualified.
>
> * Also in does_not_exist_skipping(), in the block for casts, it is no
> longer safe to use format_type_be() because it is now possible for the
> types to not exist at this point. So I think it needs to use
> TypeNameToString() there instead, otherwise it might raise a no such
> type ERROR while trying to issue the NOTICE.
>
> * In DropErrorMsgNonExistent(), I think the ERROR text should report
> no such schema in the same way as the NOTICE text when the schema
> doesn't exist for consistency with the other ERRORs and NOTICEs.
>
> * Some more code is needed to make DROP OPERATOR FAMILY IF EXISTS
> tolerate a non-existent schema.
>
> Attached is an updated patch for those issues. I also tried to tidy up
> the code in dropcmds.c a bit, removing some duplicated code, and
> making parent_does_not_exist_skipping() have the same signature as
> schema_does_not_exist_skipping(). This makes the code in
> does_not_exist_skipping() a little neater, and means that
> parent_does_not_exist_skipping() can just call
> schema_does_not_exist_skipping() to check for the existence of the
> parent relation's schema.
>
> I hope those changes are all OK.
>
> Regards,
> Dean
>


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-02 19:37:18
Message-ID: 20131202193718.GC5731@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Dean Rasheed escribió:

> +/*
> + * If a schema was explicitly specified, test if it exists. If it does not,
> + * report the schema as missing rather than the child object.
> + */
> +static bool
> +schema_does_not_exist_skipping(List *objname,
> + const char **msg,
> + char **name)
> +{
> + RangeVar *rel;
> +
> + rel = makeRangeVarFromNameList(objname);
> +
> + if (rel->schemaname != NULL &&
> + !OidIsValid(LookupNamespaceNoError(rel->schemaname)))
> + {
> + *msg = gettext_noop("schema \"%s\" does not exist, skipping");
> + *name = rel->schemaname;
> +
> + return true;
> + }
> +
> + return false;
> +}

In success cases, are we leaking a lot of memory? In the error case I
guess it doesn't matter that the RangeVar is getting leaked (we're
aborting anyway), but if we're called and everything turns out to work,
are things cleaned up timely?

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-02 20:15:11
Message-ID: CAEZATCUDDXc9eAAjXO0Kd6o_y1B9JxEZqtzy6USgTKMWeSqh6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2 December 2013 19:37, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> Dean Rasheed escribió:
>
>> +/*
>> + * If a schema was explicitly specified, test if it exists. If it does not,
>> + * report the schema as missing rather than the child object.
>> + */
>> +static bool
>> +schema_does_not_exist_skipping(List *objname,
>> + const char **msg,
>> + char **name)
>> +{
>> + RangeVar *rel;
>> +
>> + rel = makeRangeVarFromNameList(objname);
>> +
>> + if (rel->schemaname != NULL &&
>> + !OidIsValid(LookupNamespaceNoError(rel->schemaname)))
>> + {
>> + *msg = gettext_noop("schema \"%s\" does not exist, skipping");
>> + *name = rel->schemaname;
>> +
>> + return true;
>> + }
>> +
>> + return false;
>> +}
>
> In success cases, are we leaking a lot of memory? In the error case I
> guess it doesn't matter that the RangeVar is getting leaked (we're
> aborting anyway), but if we're called and everything turns out to work,
> are things cleaned up timely?
>

I think that memory gets freed at the end of the DROP command, so I
don't think this is a concern. In any case, that RangeVar is only of
order 50 bytes. If we were concerned about memory leakage here, a
bigger concern would be the calling code in does_not_exist_skipping(),
which is using NameListToString() which allocates at least 1024 bytes
for the name of the non-existent object without freeing it.

Regards,
Dean


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-02 20:28:01
Message-ID: 20131202202801.GD5731@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Dean Rasheed escribió:

> I think that memory gets freed at the end of the DROP command, so I
> don't think this is a concern. In any case, that RangeVar is only of
> order 50 bytes. If we were concerned about memory leakage here, a
> bigger concern would be the calling code in does_not_exist_skipping(),
> which is using NameListToString() which allocates at least 1024 bytes
> for the name of the non-existent object without freeing it.

Fair enough.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fwd: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-02 21:52:12
Message-ID: 529D010C.1070304@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 12/1/13, 2:32 AM, Pavel Stehule wrote:
> trailing whitespace
>
>
> fixed,
>
> Peter, what application do you use for this check?

git diff --check


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-04 08:56:15
Message-ID: CAEZATCVEZFCTkhr2k96cy5WDnq6B8iTh1tkVTZLdrw17Aedc4Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 2 December 2013 04:55, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello
>
> it looks well, thank you
>
> Regards
>
> Pavel
>

I've been thinking about this some more, and there's another case that
concerns me slightly. We're now making some of the DROP...IF EXISTS
commands tolerate non-existent types as well as non-existent schemas
--- functions, aggregates, casts and operators all have type names in
their specifications. Of course it's possible that the type is missing
because it was in a schema that was dropped, so this change seems to
be in spirit of what was discussed, but it seems like a change that
might catch some people out.

I think that, on balance, it is a sensible change, since if the type
doesn't exist, the dependent object can't exist either, so DROP...IF
EXISTS shouldn't be raising an error. However, I wonder if we should
be issuing a more specific NOTICE in this case too --- i.e., check for
non-existent types in the same way as we check for non-existent parent
objects --- type_does_not_exist_skipping() and
type_list_does_not_exist_skipping().

Regards,
Dean


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-04 15:02:41
Message-ID: CAFj8pRC=rJE8dg28+KMgG4eDunQVz8isV1GoqNqWA_cUkNdraQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/12/4 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 2 December 2013 04:55, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> > Hello
> >
> > it looks well, thank you
> >
> > Regards
> >
> > Pavel
> >
>
> I've been thinking about this some more, and there's another case that
> concerns me slightly. We're now making some of the DROP...IF EXISTS
> commands tolerate non-existent types as well as non-existent schemas
> --- functions, aggregates, casts and operators all have type names in
> their specifications. Of course it's possible that the type is missing
> because it was in a schema that was dropped, so this change seems to
> be in spirit of what was discussed, but it seems like a change that
> might catch some people out.
>
> I think that, on balance, it is a sensible change, since if the type
> doesn't exist, the dependent object can't exist either, so DROP...IF
> EXISTS shouldn't be raising an error. However, I wonder if we should
> be issuing a more specific NOTICE in this case too --- i.e., check for
> non-existent types in the same way as we check for non-existent parent
> objects --- type_does_not_exist_skipping() and
> type_list_does_not_exist_skipping().
>

+1

Pavel

>
> Regards,
> Dean
>


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-05 01:33:07
Message-ID: 1386207187.13848.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Can someone in this thread clarify the commit fest situation? I see two
entries that appear to be the same:

https://commitfest.postgresql.org/action/patch_view?id=1174
https://commitfest.postgresql.org/action/patch_view?id=1175

I think the first one is a duplicate or obsolete.


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-05 06:22:59
Message-ID: CAEZATCVLAeRZoNCwS--00OnhSjCbtaP+viWyOMOFV69S4AnRYQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 5 December 2013 01:33, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> Can someone in this thread clarify the commit fest situation? I see two
> entries that appear to be the same:
>
> https://commitfest.postgresql.org/action/patch_view?id=1174
> https://commitfest.postgresql.org/action/patch_view?id=1175
>
> I think the first one is a duplicate or obsolete.
>

#1174 looks to be a separate feature. I don't think it's dependent on
#1175 from a code standpoint, but it probably needs it to work
properly in all situations.

I think #1175 is close to being ready for commit. Pavel, will you
produce an updated patch based on our last discussion? I'll set this
patch to waiting on author.

Regards,
Dean


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-05 10:03:35
Message-ID: CAFj8pRD9n9O_jtu9msvieqN8g-cKy-zdc88+4kKxSx1YDo5chQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/12/5 Peter Eisentraut <peter_e(at)gmx(dot)net>

> Can someone in this thread clarify the commit fest situation? I see two
> entries that appear to be the same:
>
> https://commitfest.postgresql.org/action/patch_view?id=1174
> https://commitfest.postgresql.org/action/patch_view?id=1175
>
> I think the first one is a duplicate or obsolete.
>

no, both are valid, and every solve different issue.

https://commitfest.postgresql.org/action/patch_view?id=1175

it implements fully fault tolerant DROP IF EXISTS statements. This patch is
prerequisite for second patch

https://commitfest.postgresql.org/action/patch_view?id=1174

This is a implementation of new pg_dump option --if-exists. This option
ensure using fault tolerant DROPs statement by dump.

Regards

Pavel


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-05 10:06:22
Message-ID: CAFj8pRAgm6n35vZ5pJ0Nq=YoRNzmmyC-CD_EVkdhjBNwMA2zzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/12/5 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 5 December 2013 01:33, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > Can someone in this thread clarify the commit fest situation? I see two
> > entries that appear to be the same:
> >
> > https://commitfest.postgresql.org/action/patch_view?id=1174
> > https://commitfest.postgresql.org/action/patch_view?id=1175
> >
> > I think the first one is a duplicate or obsolete.
> >
>
> #1174 looks to be a separate feature. I don't think it's dependent on
> #1175 from a code standpoint, but it probably needs it to work
> properly in all situations.
>
> I think #1175 is close to being ready for commit. Pavel, will you
> produce an updated patch based on our last discussion? I'll set this
> patch to waiting on author.
>

I expected so your version was a final. I have no problem to do other
enhancing (by me) , but I don't fully understand to your last proposal. Can
you specify it more, please?

Regards

Pavel

>
> Regards,
> Dean
>


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-05 20:54:56
Message-ID: CAEZATCX9idgfH5Z0Qi42WGivM9XCzk_3Ff9ND1wmU1wg6QC-Dg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 5 December 2013 10:06, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> I think #1175 is close to being ready for commit. Pavel, will you
>> produce an updated patch based on our last discussion? I'll set this
>> patch to waiting on author.
>
>
> I expected so your version was a final. I have no problem to do other
> enhancing (by me) , but I don't fully understand to your last proposal. Can
> you specify it more, please?
>

Well I was basically proposing that does_not_exist_skipping() be
enhanced to report on non-existent types that form part of the object
specification. I think this would affect the CAST, FUNCTION, AGGREGATE
and OPERATOR cases, but should be a fairly trivial extension to the
code that you've already added.

It should be possible to make the notice text from DROP...IF EXISTS
consistent with the error text from a plain DROP. For example consider
cases like func_name(no_such_schema.typename) and
func_name(existing_schema.no_such_type).

Regards,
Dean


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-07 21:34:00
Message-ID: CAFj8pRAG+y7PEVsbTmec4UZZSEQKMiU0BcT=wZTzGmLS-npDeA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2013/12/5 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 5 December 2013 10:06, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> >> I think #1175 is close to being ready for commit. Pavel, will you
> >> produce an updated patch based on our last discussion? I'll set this
> >> patch to waiting on author.
> >
> >
> > I expected so your version was a final. I have no problem to do other
> > enhancing (by me) , but I don't fully understand to your last proposal.
> Can
> > you specify it more, please?
> >
>
> Well I was basically proposing that does_not_exist_skipping() be
> enhanced to report on non-existent types that form part of the object
> specification. I think this would affect the CAST, FUNCTION, AGGREGATE
> and OPERATOR cases, but should be a fairly trivial extension to the
> code that you've already added.
>

ok, updated patch is in attachment

>
> It should be possible to make the notice text from DROP...IF EXISTS
> consistent with the error text from a plain DROP. For example consider
> cases like func_name(no_such_schema.typename) and
> func_name(existing_schema.no_such_type).
>

yes, it is possible, but I wouldn't enhance a scope of this patch, if it is
possible, please. I would to finish a --if-exist option for pg_dump a
pg_restore before (in this release cycle).

We can continue in cleaning DROP obj messages in next release, or maybe in
last commitfest - this functionality is not critical and is not complex.

Regards

Pavel

>
> Regards,
> Dean
>

Attachment Content-Type Size
drop-if-exists-consistency-v3.patch text/x-patch 40.6 KB

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-08 18:51:04
Message-ID: CAEZATCVHBqeobQMop-AMuNp6XnaD6+mGK26O=2eL=-afevwytg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 7 December 2013 21:34, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> Well I was basically proposing that does_not_exist_skipping() be
>> enhanced to report on non-existent types that form part of the object
>> specification. I think this would affect the CAST, FUNCTION, AGGREGATE
>> and OPERATOR cases, but should be a fairly trivial extension to the
>> code that you've already added.
>
>
> ok, updated patch is in attachment
>

Cool. This looks good to me, except I found a corner case --- the type
name for an operator may be "NONE", in which case the typeName in the
list will be NULL, so that needs to be guarded against. Updated patch
attached.

I think this is a good patch. It makes all the DROP...IF EXISTS
commands consistently fault-tolerant, instead of the current 50/50
mix, and all the resulting NOTICEs give useful information about why
objects don't exist and are being skipped.

I think this is now ready for committer.

Nice work!

Regards,
Dean

Attachment Content-Type Size
drop-if-exists-consistency-v4.patch text/x-diff 39.9 KB

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2013-12-08 18:54:57
Message-ID: CAFj8pRCqFG3SrUkUW=h4-PKnLmb4A=meYYSGLQjb+3m0R=i+dw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2013/12/8 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 7 December 2013 21:34, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> >> Well I was basically proposing that does_not_exist_skipping() be
> >> enhanced to report on non-existent types that form part of the object
> >> specification. I think this would affect the CAST, FUNCTION, AGGREGATE
> >> and OPERATOR cases, but should be a fairly trivial extension to the
> >> code that you've already added.
> >
> >
> > ok, updated patch is in attachment
> >
>
> Cool. This looks good to me, except I found a corner case --- the type
> name for an operator may be "NONE", in which case the typeName in the
> list will be NULL, so that needs to be guarded against. Updated patch
> attached.
>
> I think this is a good patch. It makes all the DROP...IF EXISTS
> commands consistently fault-tolerant, instead of the current 50/50
> mix, and all the resulting NOTICEs give useful information about why
> objects don't exist and are being skipped.
>
> I think this is now ready for committer.
>

thank you :)

Pavel

>
> Nice work!
>
> Regards,
> Dean
>


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2014-01-21 22:28:51
Message-ID: 20140121222851.GL10723@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

I have been mulling over this patch, and I can't seem to come to terms
with it. I first started making it look nicer here and there, thinking
it was all mostly okay, but eventually arrived at the idea that it seems
wrong to do what this does: basically, get_object_address() tries to
obtain an object address, and if that fails, return InvalidOid; then, in
RemoveObjects, we try rather hard to figure out why that failed, and
construct an error message.

It seems to me that it would make more sense to have get_object_address
somehow return a code indicating what failed; then we don't have to go
all over through the parser code once more. Perhaps, for example, when
missing_ok is given as true to get_object_address it also needs to get a
pointer to ObjectType and a string; if some object does not exist then
fill the ObjectType with the failing object and the string with the
failing name. Then RemoveObjects can construct a string more easily.
Not sure how workable this exact idea is; maybe there is a better way.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2014-01-22 07:46:29
Message-ID: CAEZATCXW-BaG0n+PAio5f2ex-sO_JdBgB0EfP6mjv0Mo66SaaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On 21 January 2014 22:28, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> I have been mulling over this patch, and I can't seem to come to terms
> with it. I first started making it look nicer here and there, thinking
> it was all mostly okay, but eventually arrived at the idea that it seems
> wrong to do what this does: basically, get_object_address() tries to
> obtain an object address, and if that fails, return InvalidOid; then, in
> RemoveObjects, we try rather hard to figure out why that failed, and
> construct an error message.
>
> It seems to me that it would make more sense to have get_object_address
> somehow return a code indicating what failed; then we don't have to go
> all over through the parser code once more. Perhaps, for example, when
> missing_ok is given as true to get_object_address it also needs to get a
> pointer to ObjectType and a string; if some object does not exist then
> fill the ObjectType with the failing object and the string with the
> failing name. Then RemoveObjects can construct a string more easily.
> Not sure how workable this exact idea is; maybe there is a better way.
>

Yeah, when I initially started reviewing this patch I had a very
similar thought. But when I looked more deeply at the code beneath
get_object_address, I started to doubt whether it could be done
without rather extensive changes all over the place. Also
get_object_address is itself called from a lot of places (not
necessarily all in our code) and all the other places (in our code, at
least) pass missing_ok=false. So it seemed rather ugly to change its
signature and force a matching change in all those other places, which
actually don't care about missing objects. Perhaps the answer would be
to have a separate get_object_address_if_exists function, and remove
the missing_ok flag from get_object_address, but that all felt like a
much larger patch.

In the end, I felt that Pavel's approach wasn't adding that much new
code, and it's all localised in the one place that does actually
tolerate missing objects.

I admit though, that I didn't explore the other approach very deeply,
so perhaps it might fall out more neatly than I feared.

Regards,
Dean


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2014-01-22 14:57:07
Message-ID: CAFj8pRD_bSy0rBRWrb1-ueay4E9Ae7=aP-hy8O10COkNHZtaxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Hello

2014/1/22 Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>

> On 21 January 2014 22:28, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> > I have been mulling over this patch, and I can't seem to come to terms
> > with it. I first started making it look nicer here and there, thinking
> > it was all mostly okay, but eventually arrived at the idea that it seems
> > wrong to do what this does: basically, get_object_address() tries to
> > obtain an object address, and if that fails, return InvalidOid; then, in
> > RemoveObjects, we try rather hard to figure out why that failed, and
> > construct an error message.
> >
> > It seems to me that it would make more sense to have get_object_address
> > somehow return a code indicating what failed; then we don't have to go
> > all over through the parser code once more. Perhaps, for example, when
> > missing_ok is given as true to get_object_address it also needs to get a
> > pointer to ObjectType and a string; if some object does not exist then
> > fill the ObjectType with the failing object and the string with the
> > failing name. Then RemoveObjects can construct a string more easily.
> > Not sure how workable this exact idea is; maybe there is a better way.
> >
>
> Yeah, when I initially started reviewing this patch I had a very
> similar thought. But when I looked more deeply at the code beneath
> get_object_address, I started to doubt whether it could be done
> without rather extensive changes all over the place. Also
> get_object_address is itself called from a lot of places (not
> necessarily all in our code) and all the other places (in our code, at
> least) pass missing_ok=false. So it seemed rather ugly to change its
> signature and force a matching change in all those other places, which
> actually don't care about missing objects. Perhaps the answer would be
> to have a separate get_object_address_if_exists function, and remove
> the missing_ok flag from get_object_address, but that all felt like a
> much larger patch.
>
> In the end, I felt that Pavel's approach wasn't adding that much new
> code, and it's all localised in the one place that does actually
> tolerate missing objects.
>

I though about it too. But I didn't continue - reasons was named by Dean -
and RemoveObjects are not difficult code - lot of code is mechanical - and
it is not on critical path.

Regards

Pavel

>
> I admit though, that I didn't explore the other approach very deeply,
> so perhaps it might fall out more neatly than I feared.
>
> Regards,
> Dean
>


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist
Date: 2014-01-23 17:48:29
Message-ID: 20140123174829.GS10723@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Pavel Stehule escribió:

> I though about it too. But I didn't continue - reasons was named by Dean -
> and RemoveObjects are not difficult code - lot of code is mechanical - and
> it is not on critical path.

I have pushed it after some editorialization.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services