Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-07 Thread Robert Haas
On Thu, Dec 6, 2012 at 3:34 PM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: I think we need to be solving that problem when we implement new firing points for event trigger. The 'table_rewrite' event needs to fire at a time when the code can cope with it. That's the main difficulty in

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-07 Thread Dimitri Fontaine
Robert Haas robertmh...@gmail.com writes: is needed there, or we may need to move some things from the exec phase to the prep phase to make it all work out. I think it's totally doable, but it's not going to be a 50-line patch. If you want to work on it, please be my guest :) Regards, --

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Simon Riggs
On 6 December 2012 00:46, Robert Haas robertmh...@gmail.com wrote: On Wed, Dec 5, 2012 at 6:45 PM, Simon Riggs si...@2ndquadrant.com wrote: Yes, but it is also the trigger writers problem. Maybe to some degree. I don't think that a server crash or something like a block-read error is ever

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Andres Freund
On 2012-12-06 18:21:09 +, Simon Riggs wrote: On 6 December 2012 00:46, Robert Haas robertmh...@gmail.com wrote: On Wed, Dec 5, 2012 at 6:45 PM, Simon Riggs si...@2ndquadrant.com wrote: Yes, but it is also the trigger writers problem. Maybe to some degree. I don't think that a server

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Simon Riggs
On 6 December 2012 18:31, Andres Freund and...@2ndquadrant.com wrote: On 2012-12-06 18:21:09 +, Simon Riggs wrote: On 6 December 2012 00:46, Robert Haas robertmh...@gmail.com wrote: On Wed, Dec 5, 2012 at 6:45 PM, Simon Riggs si...@2ndquadrant.com wrote: Yes, but it is also the trigger

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Andres Freund
On 2012-12-06 18:42:22 +, Simon Riggs wrote: On 6 December 2012 18:31, Andres Freund and...@2ndquadrant.com wrote: On 2012-12-06 18:21:09 +, Simon Riggs wrote: On 6 December 2012 00:46, Robert Haas robertmh...@gmail.com wrote: On Wed, Dec 5, 2012 at 6:45 PM, Simon Riggs

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Petr Jelinek
TABLE ... NOREWRITE option I don't see any difference between an event trigger and these statements... BEGIN; ALTER TABLE x ...; SELECT somefunction(); ALTER TABLE y ...; COMMIT; Event triggers get called *during* the ALTER TABLE. So if were not careful they see something thats

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Andres Freund
; pgsql-hackers@postgresql.org Subject: Re: [HACKERS] ALTER TABLE ... NOREWRITE option I don't see any difference between an event trigger and these statements... BEGIN; ALTER TABLE x ...; SELECT somefunction(); ALTER TABLE y ...; COMMIT; Event triggers get called *during

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Petr Jelinek
Subject: Re: [HACKERS] ALTER TABLE ... NOREWRITE option Event triggers get called *during* the ALTER TABLE. So if were not careful they see something thats not easy to handle. I thought the point of this was to call the trigger *before* anything happens. Just because the rewrite hasn't

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-06 Thread Dimitri Fontaine
Andres Freund and...@2ndquadrant.com writes: On 2012-12-06 18:42:22 +, Simon Riggs wrote: in-between state means what? And what danger do you see? For example during table rewrites we have a temporary pg_class entry thats a full copy of the table, with a separate oid, relfilenode and

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 00:16, Josh Berkus j...@agliodbs.com wrote: Sure, and the DevOps staff would be using the EXPLAIN feature (if we had it). After which they could do little anyway except complain to the ORM authors, who might or might not give a damn. I don't see that there's enough

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread John R Pierce
On 12/5/2012 1:42 AM, Simon Riggs wrote: I think we need a parameter called schema_change_reporting = off (default) | on [USERSET] which displays relevant statistics/reports about the actions taken by DDL statements. That will also highlight locks and the need to reduce their lock levels.

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Petr Jelinek
-Original Message- From: pgsql-hackers-ow...@postgresql.org [mailto:pgsql-hackers- ow...@postgresql.org] On Behalf Of Josh Berkus Sent: 05 December 2012 01:17 To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: [HACKERS] ALTER TABLE ... NOREWRITE option However, as I said

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 09:46, John R Pierce pie...@hogranch.com wrote: On 12/5/2012 1:42 AM, Simon Riggs wrote: I think we need a parameter called schema_change_reporting = off (default) | on [USERSET] which displays relevant statistics/reports about the actions taken by DDL statements. That

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Tom Lane
John R Pierce pie...@hogranch.com writes: On 12/5/2012 1:42 AM, Simon Riggs wrote: I think we need a parameter called schema_change_reporting = off (default) | on [USERSET] which displays relevant statistics/reports about the actions taken by DDL statements. That will also highlight

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Dimitri Fontaine
Simon Riggs si...@2ndquadrant.com writes: On 5 December 2012 09:46, John R Pierce pie...@hogranch.com wrote: On 12/5/2012 1:42 AM, Simon Riggs wrote: I think we need a parameter called schema_change_reporting = off (default) | on [USERSET] which displays relevant statistics/reports about

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 15:01, Tom Lane t...@sss.pgh.pa.us wrote: John R Pierce pie...@hogranch.com writes: On 12/5/2012 1:42 AM, Simon Riggs wrote: I think we need a parameter called schema_change_reporting = off (default) | on [USERSET] which displays relevant statistics/reports about the

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Tom Lane
Simon Riggs si...@2ndquadrant.com writes: On 5 December 2012 15:01, Tom Lane t...@sss.pgh.pa.us wrote: And perhaps more to the point, what's the advantage compared to good old log_statement = ddl? That logs DDL statements for the whole system and isn't user settable. Not true; you can set it

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Josh Berkus
Simon, And anything which assumes the *absence* of a manual script is also leaving out a large class of users. ORMs are very important, but not the only thing we serve. Yes. In the long run, we'll probably need two solutions. An interactive EXPLAIN, and something which logs or aborts for

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Robert Haas
On Wed, Dec 5, 2012 at 1:41 PM, Josh Berkus j...@agliodbs.com wrote: That's why we need a mechanism which either logs, or aborts on specific actions. From the perspective of the DevOps staff, abort is possibly the better option, but there may be issues with it on our end. That was the

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Josh Berkus
You know, event triggers seem like an awfully good solution to this problem. All we'd need is a new event called table_rewrite: CREATE EVENT TRIGGER my_event_trigger ON table_rewrite EXECUTE PROCEDURE consider_whether_to_throw_an_error(); Oh, wow, that would be perfect. That

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 19:15, Robert Haas robertmh...@gmail.com wrote: On Wed, Dec 5, 2012 at 1:41 PM, Josh Berkus j...@agliodbs.com wrote: That's why we need a mechanism which either logs, or aborts on specific actions. From the perspective of the DevOps staff, abort is possibly the better

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Dimitri Fontaine
Simon Riggs si...@2ndquadrant.com writes: CREATE EVENT TRIGGER my_event_trigger ON table_rewrite EXECUTE PROCEDURE consider_whether_to_throw_an_error(); +1, I was just thinking that myself. +1, and I think that can happen for 9.3, as soon as we agree on the list of code points where

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 22:21, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs si...@2ndquadrant.com writes: CREATE EVENT TRIGGER my_event_trigger ON table_rewrite EXECUTE PROCEDURE consider_whether_to_throw_an_error(); +1, I was just thinking that myself. +1, and I think

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Dimitri Fontaine
Simon Riggs si...@2ndquadrant.com writes: On 5 December 2012 22:21, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs si...@2ndquadrant.com writes: CREATE EVENT TRIGGER my_event_trigger ON table_rewrite EXECUTE PROCEDURE consider_whether_to_throw_an_error(); +1, I was just

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Andres Freund
On 2012-12-05 22:41:21 +, Simon Riggs wrote: On 5 December 2012 22:21, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs si...@2ndquadrant.com writes: CREATE EVENT TRIGGER my_event_trigger ON table_rewrite EXECUTE PROCEDURE consider_whether_to_throw_an_error();

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Robert Haas
On Wed, Dec 5, 2012 at 5:56 PM, Andres Freund and...@2ndquadrant.com wrote: On 2012-12-05 22:41:21 +, Simon Riggs wrote: On 5 December 2012 22:21, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs si...@2ndquadrant.com writes: CREATE EVENT TRIGGER my_event_trigger ON

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 22:49, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs si...@2ndquadrant.com writes: On 5 December 2012 22:21, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs si...@2ndquadrant.com writes: CREATE EVENT TRIGGER my_event_trigger ON table_rewrite

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Simon Riggs
On 5 December 2012 23:34, Robert Haas robertmh...@gmail.com wrote: On Wed, Dec 5, 2012 at 5:56 PM, Andres Freund and...@2ndquadrant.com wrote: On 2012-12-05 22:41:21 +, Simon Riggs wrote: On 5 December 2012 22:21, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Simon Riggs

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-05 Thread Robert Haas
On Wed, Dec 5, 2012 at 6:45 PM, Simon Riggs si...@2ndquadrant.com wrote: Yes, but it is also the trigger writers problem. Maybe to some degree. I don't think that a server crash or something like a block-read error is ever tolerable though, no matter how silly the user is with their event

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-04 Thread Josh Berkus
However, for a very large user group -- users with ORMs which do their own DDL migrations -- we could also use a way to log or WARN for table rewrites. Since the ORMs are not gonna do an EXPLAIN. An ORM is also quite unlikely to pay attention to a warning, much less a postmaster log entry

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-04 Thread Tom Lane
Josh Berkus j...@agliodbs.com writes: However, for a very large user group -- users with ORMs which do their own DDL migrations -- we could also use a way to log or WARN for table rewrites. Since the ORMs are not gonna do an EXPLAIN. An ORM is also quite unlikely to pay attention to a

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-04 Thread Simon Riggs
On 4 December 2012 22:30, Tom Lane t...@sss.pgh.pa.us wrote: Josh Berkus j...@agliodbs.com writes: However, for a very large user group -- users with ORMs which do their own DDL migrations -- we could also use a way to log or WARN for table rewrites. Since the ORMs are not gonna do an

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-04 Thread Josh Berkus
Sure, and the DevOps staff would be using the EXPLAIN feature (if we had it). After which they could do little anyway except complain to the ORM authors, who might or might not give a damn. I don't see that there's enough value-added from what you suggest to justify the development time.

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-03 Thread Dimitri Fontaine
Noah Misch n...@leadboat.com writes: Acquiring the lock could still take an unpredictable amount of time. I think there's a new GUC brewing about setting the lock timeout separately from the statement timeout, right? being said, I share Tom's doubts. The DEBUG1 messages are a sorry excuse for

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-03 Thread Josh Berkus
EXPLAIN ALTER TABLE would be the next step I guess. I discovered plenty of magic tricks when working on the rewriting support for that command, and I think exposing them in the EXPLAIN output would go a long way towards reducing some POLA violations. I think this would be cool on its own

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-03 Thread Tom Lane
Josh Berkus j...@agliodbs.com writes: EXPLAIN ALTER TABLE would be the next step I guess. I discovered plenty of magic tricks when working on the rewriting support for that command, and I think exposing them in the EXPLAIN output would go a long way towards reducing some POLA violations. I

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-03 Thread Noah Misch
On Mon, Dec 03, 2012 at 11:37:17AM +0100, Dimitri Fontaine wrote: Noah Misch n...@leadboat.com writes: Acquiring the lock could still take an unpredictable amount of time. I think there's a new GUC brewing about setting the lock timeout separately from the statement timeout, right? Yes.

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-03 Thread Hannu Krosing
On 12/02/2012 03:07 AM, Noah Misch wrote: On Sat, Dec 01, 2012 at 07:34:51PM +0100, Andres Freund wrote: On 2012-12-01 18:27:08 +, Simon Riggs wrote: On 1 December 2012 16:38, Tom Lane t...@sss.pgh.pa.us wrote: Simon Riggs si...@2ndquadrant.com writes: It's hard to know whether your

[HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Simon Riggs
It's hard to know whether your tables will be locked for long periods when implementing DDL changes. The NOREWRITE option would cause an ERROR if the table would be rewritten by the command. This would allow testing to highlight long running statements before code hits production. -- Simon

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Tom Lane
Simon Riggs si...@2ndquadrant.com writes: It's hard to know whether your tables will be locked for long periods when implementing DDL changes. The NOREWRITE option would cause an ERROR if the table would be rewritten by the command. This would allow testing to highlight long running

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Simon Riggs
On 1 December 2012 16:38, Tom Lane t...@sss.pgh.pa.us wrote: Simon Riggs si...@2ndquadrant.com writes: It's hard to know whether your tables will be locked for long periods when implementing DDL changes. The NOREWRITE option would cause an ERROR if the table would be rewritten by the

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Andres Freund
On 2012-12-01 18:27:08 +, Simon Riggs wrote: On 1 December 2012 16:38, Tom Lane t...@sss.pgh.pa.us wrote: Simon Riggs si...@2ndquadrant.com writes: It's hard to know whether your tables will be locked for long periods when implementing DDL changes. The NOREWRITE option would cause

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Josh Berkus
I'm not thrilled about inventing YA keyword for this. If you have a problem with that sort of scenario, why aren't you testing your DDL on a test server before you do it on production? *I* do test my DDL. However, there are literally hundreds of thousands of Rails, Django and Hibernate

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Andres Freund
On 2012-12-01 12:24:57 -0800, Josh Berkus wrote: I'm not thrilled about inventing YA keyword for this. If you have a problem with that sort of scenario, why aren't you testing your DDL on a test server before you do it on production? *I* do test my DDL. However, there are literally

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Josh Berkus
If you have a framework and you want to test for this you can just compare relfilenodes before/after. You're targeting the wrong users. This feature isn't for helping you or me. It's for helping the Rails users. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Andres Freund
On 2012-12-01 12:35:15 -0800, Josh Berkus wrote: If you have a framework and you want to test for this you can just compare relfilenodes before/after. You're targeting the wrong users. This feature isn't for helping you or me. It's for helping the Rails users. I am not targeting

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Petr Jelinek
-Original Message- From: pgsql-hackers-ow...@postgresql.org [mailto:pgsql-hackers- ow...@postgresql.org] On Behalf Of Andres Freund Sent: 01 December 2012 21:40 To: Josh Berkus Cc: pgsql-hackers@postgresql.org Subject: Re: [HACKERS] ALTER TABLE ... NOREWRITE option On 2012-12-01

Re: [HACKERS] ALTER TABLE ... NOREWRITE option

2012-12-01 Thread Noah Misch
On Sat, Dec 01, 2012 at 07:34:51PM +0100, Andres Freund wrote: On 2012-12-01 18:27:08 +, Simon Riggs wrote: On 1 December 2012 16:38, Tom Lane t...@sss.pgh.pa.us wrote: Simon Riggs si...@2ndquadrant.com writes: It's hard to know whether your tables will be locked for long periods