pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
WAL logging of SELECT ... INTO command
21+ messages / 8 participants
[nested] [flat]

* WAL logging of SELECT ... INTO command
@ 2006-03-21 12:22  Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-21 12:22 UTC (permalink / raw)
  To: pgsql-performance

Currently, it appears that SELECT * INTO new_table FROM old_table logs
each page as it's written to WAL. Is this actually needed? Couldn't the
database simply log that the SELECT ... INTO statement was executed
instead? Doing so would likely result in a large performance improvement
in most installs. Is there no provision for writing anything but data
page changes (or whole pages) to WAL?
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-21 20:33  Simon Riggs <simon@2ndquadrant.com>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 2 replies; 21+ messages in thread

From: Simon Riggs @ 2006-03-21 20:33 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: pgsql-performance

On Tue, 2006-03-21 at 06:22 -0600, Jim C. Nasby wrote:
> Currently, it appears that SELECT * INTO new_table FROM old_table logs
> each page as it's written to WAL. Is this actually needed? Couldn't the
> database simply log that the SELECT ... INTO statement was executed
> instead? Doing so would likely result in a large performance improvement
> in most installs. Is there no provision for writing anything but data
> page changes (or whole pages) to WAL?

AFAIK it takes the same code path as CREATE TABLE AS SELECT, which
already does exactly what you suggest (except when using PITR).

Best Regards, Simon Riggs




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 06:20  Qingqing Zhou <zhouqq@cs.toronto.edu>
  parent: Simon Riggs <simon@2ndquadrant.com>
  1 sibling, 1 reply; 21+ messages in thread

From: Qingqing Zhou @ 2006-03-22 06:20 UTC (permalink / raw)
  To: pgsql-performance


"Simon Riggs" <simon@2ndquadrant.com> wrote
> On Tue, 2006-03-21 at 06:22 -0600, Jim C. Nasby wrote:
> > Currently, it appears that SELECT * INTO new_table FROM old_table logs
> > each page as it's written to WAL. Is this actually needed? Couldn't the
> > database simply log that the SELECT ... INTO statement was executed
> > instead? Doing so would likely result in a large performance improvement
> > in most installs. Is there no provision for writing anything but data
> > page changes (or whole pages) to WAL?
>
> AFAIK it takes the same code path as CREATE TABLE AS SELECT, which
> already does exactly what you suggest (except when using PITR).
>

As I read, they did take the same code path, but did they "simply log that
the SELECT ... INTO statement was executed"? If so, how can we rely on the
unreliable content of the old_table to do recovery?

Regards,
Qingqing





^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 12:47  Jim C. Nasby <jnasby@pervasive.com>
  parent: Simon Riggs <simon@2ndquadrant.com>
  1 sibling, 2 replies; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-22 12:47 UTC (permalink / raw)
  To: Simon Riggs <simon@2ndquadrant.com>; +Cc: pgsql-performance

On Tue, Mar 21, 2006 at 08:33:50PM +0000, Simon Riggs wrote:
> On Tue, 2006-03-21 at 06:22 -0600, Jim C. Nasby wrote:
> > Currently, it appears that SELECT * INTO new_table FROM old_table logs
> > each page as it's written to WAL. Is this actually needed? Couldn't the
> > database simply log that the SELECT ... INTO statement was executed
> > instead? Doing so would likely result in a large performance improvement
> > in most installs. Is there no provision for writing anything but data
> > page changes (or whole pages) to WAL?
> 
> AFAIK it takes the same code path as CREATE TABLE AS SELECT, which
> already does exactly what you suggest (except when using PITR).

Ok, I saw disk activity on the base directory and assumed it was pg_xlog
stuff. Turns out that both SELECT INTO and CREATE TABLE AS ignore
default_tablepsace and create the new tables in the base directory. I'm
guessing that's a bug... (this is on 8.1.2, btw).

Also, why do we log rows for CTAS/SELECT INTO when PITR is in use for
simple SELECTs (ones that don't call non-deterministic functions)? The
data should alread be available AFAICS...
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 13:08  Simon Riggs <simon@2ndquadrant.com>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  1 sibling, 1 reply; 21+ messages in thread

From: Simon Riggs @ 2006-03-22 13:08 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: pgsql-performance

On Wed, 2006-03-22 at 06:47 -0600, Jim C. Nasby wrote:

> Also, why do we log rows for CTAS/SELECT INTO when PITR is in use for
> simple SELECTs (ones that don't call non-deterministic functions)? The
> data should alread be available AFAICS...

Not sure what you're asking... SELECTs don't produce WAL.

PITR wants all changes. Without PITR we can optimise certain logging
actions.

Best Regards, Simon Riggs




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 13:19  Jim C. Nasby <jnasby@pervasive.com>
  parent: Simon Riggs <simon@2ndquadrant.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-22 13:19 UTC (permalink / raw)
  To: Simon Riggs <simon@2ndquadrant.com>; +Cc: pgsql-performance

On Wed, Mar 22, 2006 at 01:08:34PM +0000, Simon Riggs wrote:
> On Wed, 2006-03-22 at 06:47 -0600, Jim C. Nasby wrote:
> 
> > Also, why do we log rows for CTAS/SELECT INTO when PITR is in use for
> > simple SELECTs (ones that don't call non-deterministic functions)? The
> > data should alread be available AFAICS...
> 
> Not sure what you're asking... SELECTs don't produce WAL.

Yes, there'd have to be some special kind of WAL entry that specifies
what select statement was used in CTAS.

> PITR wants all changes. Without PITR we can optimise certain logging
> actions.

The only change here is that we're creating a new table based on the
results of a SELECT. If that SELECT doesn't use anything that's
non-deterministic, then the machine doing the recovery should already
have all the data it needs, provided that we log the SELECT that was
used in the CTAS.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 15:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Tom Lane @ 2006-03-22 15:06 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Simon Riggs <simon@2ndquadrant.com>; pgsql-performance

"Jim C. Nasby" <jnasby@pervasive.com> writes:
>> PITR wants all changes. Without PITR we can optimise certain logging
>> actions.

> The only change here is that we're creating a new table based on the
> results of a SELECT. If that SELECT doesn't use anything that's
> non-deterministic, then the machine doing the recovery should already
> have all the data it needs, provided that we log the SELECT that was
> used in the CTAS.

This is based on a fundamental misconception about the way PITR
log-shipping works.  We log actions at the physical level (put this
tuple here), not the logical here's-the-statement-we-executed level.
The two approaches cannot mix, because as soon as there's any physical
discrepancy at all, physical-level actions would be incorrectly applied
to the slave database.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 15:14  Jim C. Nasby <jnasby@pervasive.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-22 15:14 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Simon Riggs <simon@2ndquadrant.com>; pgsql-performance

On Wed, Mar 22, 2006 at 10:06:05AM -0500, Tom Lane wrote:
> "Jim C. Nasby" <jnasby@pervasive.com> writes:
> >> PITR wants all changes. Without PITR we can optimize certain logging
> >> actions.
> 
> > The only change here is that we're creating a new table based on the
> > results of a SELECT. If that SELECT doesn't use anything that's
> > non-deterministic, then the machine doing the recovery should already
> > have all the data it needs, provided that we log the SELECT that was
> > used in the CTAS.
> 
> This is based on a fundamental misconception about the way PITR
> log-shipping works.  We log actions at the physical level (put this
> tuple here), not the logical here's-the-statement-we-executed level.
> The two approaches cannot mix, because as soon as there's any physical
> discrepancy at all, physical-level actions would be incorrectly applied
> to the slave database.

Oh, so in other words, SELECT * INTO temp FROM table is inherently
non-deterministic at the physical level, so the only way to be able to
allow PITR to work is to duplicate all the physical changes. Darn.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 15:35  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Tom Lane @ 2006-03-22 15:35 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Simon Riggs <simon@2ndquadrant.com>; pgsql-performance

"Jim C. Nasby" <jnasby@pervasive.com> writes:
> Oh, so in other words, SELECT * INTO temp FROM table is inherently
> non-deterministic at the physical level, so the only way to be able to
> allow PITR to work is to duplicate all the physical changes. Darn.

Well, lemme put it this way: I'm not prepared to require that PG be
deterministic at the physical level.  One obvious source of
non-determinancy is the FSM, which is likely to hand out different free
space to different transactions depending on what else is going on at
the same time.  There are others, such as deliberately random
tie-breaking during btree index insertion.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 16:19  Csaba Nagy <nagy@ecircle-ag.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 21+ messages in thread

From: Csaba Nagy @ 2006-03-22 16:19 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Jim C. Nasby <jnasby@pervasive.com>; Simon Riggs <simon@2ndquadrant.com>; pgsql-performance

On Wed, 2006-03-22 at 16:35, Tom Lane wrote:
> "Jim C. Nasby" <jnasby@pervasive.com> writes:
> > Oh, so in other words, SELECT * INTO temp FROM table is inherently
> > non-deterministic at the physical level, so the only way to be able to
> > allow PITR to work is to duplicate all the physical changes. Darn.
> 
> Well, lemme put it this way: I'm not prepared to require that PG be
> deterministic at the physical level.  One obvious source of
> non-determinancy is the FSM, which is likely to hand out different free
> space to different transactions depending on what else is going on at
> the same time.  There are others, such as deliberately random
> tie-breaking during btree index insertion.

While you're at talking about WAL and PITR... I see from the aboce
discussion that PITR is already demanding special handling in the code
(I hope I got this one right, as the following are based on this).

What if the PITR logging would be disconnected from the WAL logging
completely ?

What I mean is to introduce a WAL subscription mechanism, which
basically means some incoming connections where we stream the log
records. We don't need to write them to disk at all in the normal case,
I guess usually PITR will store the records on some other machine so it
means network, not disk. And it doesn't need to be done synchronously,
it can lag behind the running transactions, and we can do it in batches
of WAL records.

It also would mean that the local WAL does not need to log the things
which are only needed for the PITR... that would likely mean some spared
WAL disk activity. Of course it also would mean that the local WAL and
PITR WAL are not the same, but that is not an issue I guess.

It would also permit immediate recycling of the WAL files if the current
archiving style is not used.

The drawbacks I can see (please add yours):
1) the need for the subscription management code with the added
complexity it implies;
2) problems if the WAL stream lags too much behind;
3) problems if the subscribed client's connection is interrupted;

Nr. 2 could be solved by saving the PITR WAL separately if the lag grows
over a threshold, and issue a warning. This could still be acceptable,
as the writing doesn't have to be synchronous and can be made in
relatively large blocks.
There could be a second bigger lag threshold which completely cancels
the subscription. All these thresholds should be configurable, as it
depends on the application what's more important, to have the standby
available all the time or have the primary faster if loaded...

Nr. 3. can be solved by either canceling the subscription on connection
drop, or by allowing a certain amount of time after which the
subscription is canceled. The client can reconnect before this timeout
expires. In the meantime the primary can store the PITR WAL on disk as
mentioned above...

Cheers,
Csaba.





^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-22 19:37  Kris Jurka <books@ejurka.com>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  1 sibling, 1 reply; 21+ messages in thread

From: Kris Jurka @ 2006-03-22 19:37 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Simon Riggs <simon@2ndquadrant.com>; pgsql-performance



On Wed, 22 Mar 2006, Jim C. Nasby wrote:

> Ok, I saw disk activity on the base directory and assumed it was pg_xlog
> stuff. Turns out that both SELECT INTO and CREATE TABLE AS ignore
> default_tablepsace and create the new tables in the base directory. I'm
> guessing that's a bug... (this is on 8.1.2, btw).

This has been fixed in CVS HEAD as part of a patch to allow additional 
options to CREATE TABLE AS.

http://archives.postgresql.org/pgsql-patches/2006-02/msg00211.php

Kris Jurka




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-24 10:05  Jim C. Nasby <jnasby@pervasive.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-24 10:05 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Simon Riggs <simon@2ndquadrant.com>; pgsql-performance

On Wed, Mar 22, 2006 at 02:37:28PM -0500, Kris Jurka wrote:
> 
> 
> On Wed, 22 Mar 2006, Jim C. Nasby wrote:
> 
> >Ok, I saw disk activity on the base directory and assumed it was pg_xlog
> >stuff. Turns out that both SELECT INTO and CREATE TABLE AS ignore
> >default_tablepsace and create the new tables in the base directory. I'm
> >guessing that's a bug... (this is on 8.1.2, btw).
> 
> This has been fixed in CVS HEAD as part of a patch to allow additional 
> options to CREATE TABLE AS.
> 
> http://archives.postgresql.org/pgsql-patches/2006-02/msg00211.php

I'll argue that the current behavior is still a bug and should be fixed.
Would it be difficult to patch 8.1 (and 8.0 if there were tablespaces
then...) to honor default_tablespace?
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-24 10:07  Jim C. Nasby <jnasby@pervasive.com>
  parent: Qingqing Zhou <zhouqq@cs.toronto.edu>
  0 siblings, 1 reply; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-24 10:07 UTC (permalink / raw)
  To: Qingqing Zhou <zhouqq@cs.toronto.edu>; +Cc: pgsql-performance

On Wed, Mar 22, 2006 at 02:20:39PM +0800, Qingqing Zhou wrote:
> 
> "Simon Riggs" <simon@2ndquadrant.com> wrote
> > On Tue, 2006-03-21 at 06:22 -0600, Jim C. Nasby wrote:
> > > Currently, it appears that SELECT * INTO new_table FROM old_table logs
> > > each page as it's written to WAL. Is this actually needed? Couldn't the
> > > database simply log that the SELECT ... INTO statement was executed
> > > instead? Doing so would likely result in a large performance improvement
> > > in most installs. Is there no provision for writing anything but data
> > > page changes (or whole pages) to WAL?
> >
> > AFAIK it takes the same code path as CREATE TABLE AS SELECT, which
> > already does exactly what you suggest (except when using PITR).
> >
> 
> As I read, they did take the same code path, but did they "simply log that
> the SELECT ... INTO statement was executed"? If so, how can we rely on the
> unreliable content of the old_table to do recovery?

Why would the content of the old_table be unreliable? If we've replayed
logs up to the point of the CTAS then any data that would be visible to
the CTAS should be fine, no?

Though, the way Tom put it in one of his replies it sounds like WAL
doesn't do any kind of statement logging, only data logging. If that's
the case I'm not sure that the CTAS would actually get replayed. But I
suspect I'm just misunderstanding...
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-24 12:39  Alvaro Herrera <alvherre@commandprompt.com>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Alvaro Herrera @ 2006-03-24 12:39 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Qingqing Zhou <zhouqq@cs.toronto.edu>; pgsql-performance

Jim C. Nasby wrote:

> Why would the content of the old_table be unreliable? If we've replayed
> logs up to the point of the CTAS then any data that would be visible to
> the CTAS should be fine, no?
> 
> Though, the way Tom put it in one of his replies it sounds like WAL
> doesn't do any kind of statement logging, only data logging. If that's
> the case I'm not sure that the CTAS would actually get replayed. But I
> suspect I'm just misunderstanding...

The CTAS doesn't get logged (nor replayed obviously).  What happens is
that the involved files are fsync'ed before transaction commit, AFAIR.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-24 13:01  Jim C. Nasby <jnasby@pervasive.com>
  parent: Alvaro Herrera <alvherre@commandprompt.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-24 13:01 UTC (permalink / raw)
  To: Qingqing Zhou <zhouqq@cs.toronto.edu>; pgsql-performance

On Fri, Mar 24, 2006 at 08:39:02AM -0400, Alvaro Herrera wrote:
> Jim C. Nasby wrote:
> 
> > Why would the content of the old_table be unreliable? If we've replayed
> > logs up to the point of the CTAS then any data that would be visible to
> > the CTAS should be fine, no?
> > 
> > Though, the way Tom put it in one of his replies it sounds like WAL
> > doesn't do any kind of statement logging, only data logging. If that's
> > the case I'm not sure that the CTAS would actually get replayed. But I
> > suspect I'm just misunderstanding...
> 
> The CTAS doesn't get logged (nor replayed obviously).  What happens is
> that the involved files are fsync'ed before transaction commit, AFAIR.

Ahh, yes, that sounds right. Might be a nice gain to be had if there was
some way to log the statement, but I suspect getting WAL to support that
would be extremely non-trivial.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-24 13:47  Alvaro Herrera <alvherre@commandprompt.com>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 1 reply; 21+ messages in thread

From: Alvaro Herrera @ 2006-03-24 13:47 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Qingqing Zhou <zhouqq@cs.toronto.edu>; pgsql-performance

Jim C. Nasby wrote:
> On Fri, Mar 24, 2006 at 08:39:02AM -0400, Alvaro Herrera wrote:
> > Jim C. Nasby wrote:
> > 
> > > Why would the content of the old_table be unreliable? If we've replayed
> > > logs up to the point of the CTAS then any data that would be visible to
> > > the CTAS should be fine, no?
> > > 
> > > Though, the way Tom put it in one of his replies it sounds like WAL
> > > doesn't do any kind of statement logging, only data logging. If that's
> > > the case I'm not sure that the CTAS would actually get replayed. But I
> > > suspect I'm just misunderstanding...
> > 
> > The CTAS doesn't get logged (nor replayed obviously).  What happens is
> > that the involved files are fsync'ed before transaction commit, AFAIR.
> 
> Ahh, yes, that sounds right. Might be a nice gain to be had if there was
> some way to log the statement, but I suspect getting WAL to support that
> would be extremely non-trivial.

None at all, at least in the current incarnation, I think, because said
query execution is dependent on the contents of the FSM, which is itself
dependent on the timing of VACUUM and other stuff.  Such an action,
running with a different FSM content, can very trivially cause data
corruption.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-03-24 13:59  Jim C. Nasby <jnasby@pervasive.com>
  parent: Alvaro Herrera <alvherre@commandprompt.com>
  0 siblings, 0 replies; 21+ messages in thread

From: Jim C. Nasby @ 2006-03-24 13:59 UTC (permalink / raw)
  To: Qingqing Zhou <zhouqq@cs.toronto.edu>; pgsql-performance

On Fri, Mar 24, 2006 at 09:47:20AM -0400, Alvaro Herrera wrote:
> Jim C. Nasby wrote:
> > On Fri, Mar 24, 2006 at 08:39:02AM -0400, Alvaro Herrera wrote:
> > > Jim C. Nasby wrote:
> > > 
> > > > Why would the content of the old_table be unreliable? If we've replayed
> > > > logs up to the point of the CTAS then any data that would be visible to
> > > > the CTAS should be fine, no?
> > > > 
> > > > Though, the way Tom put it in one of his replies it sounds like WAL
> > > > doesn't do any kind of statement logging, only data logging. If that's
> > > > the case I'm not sure that the CTAS would actually get replayed. But I
> > > > suspect I'm just misunderstanding...
> > > 
> > > The CTAS doesn't get logged (nor replayed obviously).  What happens is
> > > that the involved files are fsync'ed before transaction commit, AFAIR.
> > 
> > Ahh, yes, that sounds right. Might be a nice gain to be had if there was
> > some way to log the statement, but I suspect getting WAL to support that
> > would be extremely non-trivial.
> 
> None at all, at least in the current incarnation, I think, because said
> query execution is dependent on the contents of the FSM, which is itself
> dependent on the timing of VACUUM and other stuff.  Such an action,
> running with a different FSM content, can very trivially cause data
> corruption.

Oh, duh, because subsiquent operations will depend on the heap being in
a very specific state. Oh well.
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: [PERFORM] WAL logging of SELECT ... INTO command
@ 2006-03-24 18:09  Kris Jurka <books@ejurka.com>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 2 replies; 21+ messages in thread

From: Kris Jurka @ 2006-03-24 18:09 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Simon Riggs <simon@2ndquadrant.com>; pgsql-performance; pgsql-patches@postgresql.org



On Fri, 24 Mar 2006, Jim C. Nasby wrote:

> On Wed, Mar 22, 2006 at 02:37:28PM -0500, Kris Jurka wrote:
>>
>> On Wed, 22 Mar 2006, Jim C. Nasby wrote:
>>
>>> Ok, I saw disk activity on the base directory and assumed it was pg_xlog
>>> stuff. Turns out that both SELECT INTO and CREATE TABLE AS ignore
>>> default_tablepsace and create the new tables in the base directory. I'm
>>> guessing that's a bug... (this is on 8.1.2, btw).
>>
>> This has been fixed in CVS HEAD as part of a patch to allow additional
>> options to CREATE TABLE AS.
>>
>> http://archives.postgresql.org/pgsql-patches/2006-02/msg00211.php
>
> I'll argue that the current behavior is still a bug and should be fixed.
> Would it be difficult to patch 8.1 (and 8.0 if there were tablespaces
> then...) to honor default_tablespace?

Here are patches that fix this for 8.0 and 8.1.

Kris Jurka

Attachments: download all (2 files, .tar.gz)

ctas_default_tablespace_80.patch (text/plain, 1.9K) download Index: src/backend/executor/execMain.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/executor/execMain.c,v retrieving revision 1.241.4.2 diff -c -r1.241.4.2 execMain.c *** src/backend/executor/execMain.c 12 Jan 2006 21:49:17 -0000 1.241.4.2 --- src/backend/executor/execMain.c 24 Mar 2006 18:05:53 -0000 *************** *** 36,41 **** --- 36,42 ---- #include "catalog/heap.h" #include "catalog/namespace.h" #include "commands/tablecmds.h" + #include "commands/tablespace.h" #include "commands/trigger.h" #include "executor/execdebug.h" #include "executor/execdefs.h" *************** *** 731,736 **** --- 732,738 ---- { char *intoName; Oid namespaceId; + Oid tablespaceId; AclResult aclresult; Oid intoRelationId; TupleDesc tupdesc; *************** *** 747,752 **** --- 749,764 ---- aclcheck_error(aclresult, ACL_KIND_NAMESPACE, get_namespace_name(namespaceId)); + tablespaceId = GetDefaultTablespace(); + if (OidIsValid(tablespaceId)) { + aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), + ACL_CREATE); + + if (aclresult != ACLCHECK_OK) + aclcheck_error(aclresult, ACL_KIND_TABLESPACE, + get_tablespace_name(tablespaceId)); + } + /* * have to copy tupType to get rid of constraints */ *************** *** 754,760 **** intoRelationId = heap_create_with_catalog(intoName, namespaceId, ! InvalidOid, tupdesc, RELKIND_RELATION, false, --- 766,772 ---- intoRelationId = heap_create_with_catalog(intoName, namespaceId, ! tablespaceId, tupdesc, RELKIND_RELATION, false,
ctas_default_tablespace_81.patch (text/plain, 1.9K) download Index: src/backend/executor/execMain.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/executor/execMain.c,v retrieving revision 1.256.2.5 diff -c -r1.256.2.5 execMain.c *** src/backend/executor/execMain.c 12 Jan 2006 21:49:06 -0000 1.256.2.5 --- src/backend/executor/execMain.c 24 Mar 2006 17:57:11 -0000 *************** *** 37,42 **** --- 37,43 ---- #include "catalog/heap.h" #include "catalog/namespace.h" #include "commands/tablecmds.h" + #include "commands/tablespace.h" #include "commands/trigger.h" #include "executor/execdebug.h" #include "executor/execdefs.h" *************** *** 737,742 **** --- 738,744 ---- { char *intoName; Oid namespaceId; + Oid tablespaceId; AclResult aclresult; Oid intoRelationId; TupleDesc tupdesc; *************** *** 753,758 **** --- 755,770 ---- aclcheck_error(aclresult, ACL_KIND_NAMESPACE, get_namespace_name(namespaceId)); + tablespaceId = GetDefaultTablespace(); + if (OidIsValid(tablespaceId)) { + aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), + ACL_CREATE); + + if (aclresult != ACLCHECK_OK) + aclcheck_error(aclresult, ACL_KIND_TABLESPACE, + get_tablespace_name(tablespaceId)); + } + /* * have to copy tupType to get rid of constraints */ *************** *** 760,766 **** intoRelationId = heap_create_with_catalog(intoName, namespaceId, ! InvalidOid, InvalidOid, GetUserId(), tupdesc, --- 772,778 ---- intoRelationId = heap_create_with_catalog(intoName, namespaceId, ! tablespaceId, InvalidOid, GetUserId(), tupdesc,
^ permalink raw reply [nested|flat] 21+ messages in thread

* Re: [PERFORM] WAL logging of SELECT ... INTO command
@ 2006-04-21 23:11  Simon Riggs <simon@2ndquadrant.com>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 0 replies; 21+ messages in thread

From: Simon Riggs @ 2006-04-21 23:11 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Kris Jurka <books@ejurka.com>; Jim C. Nasby <jnasby@pervasive.com>; pgsql-performance; pgsql-patches@postgresql.org

On Fri, 2006-04-21 at 19:56 -0400, Bruce Momjian wrote:
> Your patch has been added to the PostgreSQL unapplied patches list at:
> 
> 	http://momjian.postgresql.org/cgi-bin/pgpatches
> 
> It will be applied as soon as one of the PostgreSQL committers reviews
> and approves it.

This patch should now be referred to as 
	allow CREATE TABLE AS/SELECT INTO to use default_tablespace
or something similar.

The name of the original thread no longer bears any resemblance to the
intention of this patch as submitted in its final form.

I've no objection to the patch, which seems to fill a functional
gap/bug.

-- 
  Simon Riggs
  EnterpriseDB          http://www.enterprisedb.com/




^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: WAL logging of SELECT ... INTO command
@ 2006-04-21 23:56  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Kris Jurka <books@ejurka.com>
  1 sibling, 1 reply; 21+ messages in thread

From: Bruce Momjian @ 2006-04-21 23:56 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Jim C. Nasby <jnasby@pervasive.com>; Simon Riggs <simon@2ndquadrant.com>; pgsql-performance; pgsql-patches@postgresql.org


Your patch has been added to the PostgreSQL unapplied patches list at:

	http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------


Kris Jurka wrote:
> 
> 
> On Fri, 24 Mar 2006, Jim C. Nasby wrote:
> 
> > On Wed, Mar 22, 2006 at 02:37:28PM -0500, Kris Jurka wrote:
> >>
> >> On Wed, 22 Mar 2006, Jim C. Nasby wrote:
> >>
> >>> Ok, I saw disk activity on the base directory and assumed it was pg_xlog
> >>> stuff. Turns out that both SELECT INTO and CREATE TABLE AS ignore
> >>> default_tablepsace and create the new tables in the base directory. I'm
> >>> guessing that's a bug... (this is on 8.1.2, btw).
> >>
> >> This has been fixed in CVS HEAD as part of a patch to allow additional
> >> options to CREATE TABLE AS.
> >>
> >> http://archives.postgresql.org/pgsql-patches/2006-02/msg00211.php
> >
> > I'll argue that the current behavior is still a bug and should be fixed.
> > Would it be difficult to patch 8.1 (and 8.0 if there were tablespaces
> > then...) to honor default_tablespace?
> 
> Here are patches that fix this for 8.0 and 8.1.
> 
> Kris Jurka

Content-Description: 

[ Attachment, skipping... ]

Content-Description: 

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +



^ permalink  raw  reply  [nested|flat] 21+ messages in thread

* Re: [PERFORM] WAL logging of SELECT ... INTO command
@ 2006-04-26 23:02  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 21+ messages in thread

From: Bruce Momjian @ 2006-04-26 23:02 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Jim C. Nasby <jnasby@pervasive.com>; Simon Riggs <simon@2ndquadrant.com>; pgsql-performance; pgsql-patches@postgresql.org


Backpatched to 8.0.X and 8.1.X.

---------------------------------------------------------------------------

Kris Jurka wrote:
> 
> 
> On Fri, 24 Mar 2006, Jim C. Nasby wrote:
> 
> > On Wed, Mar 22, 2006 at 02:37:28PM -0500, Kris Jurka wrote:
> >>
> >> On Wed, 22 Mar 2006, Jim C. Nasby wrote:
> >>
> >>> Ok, I saw disk activity on the base directory and assumed it was pg_xlog
> >>> stuff. Turns out that both SELECT INTO and CREATE TABLE AS ignore
> >>> default_tablepsace and create the new tables in the base directory. I'm
> >>> guessing that's a bug... (this is on 8.1.2, btw).
> >>
> >> This has been fixed in CVS HEAD as part of a patch to allow additional
> >> options to CREATE TABLE AS.
> >>
> >> http://archives.postgresql.org/pgsql-patches/2006-02/msg00211.php
> >
> > I'll argue that the current behavior is still a bug and should be fixed.
> > Would it be difficult to patch 8.1 (and 8.0 if there were tablespaces
> > then...) to honor default_tablespace?
> 
> Here are patches that fix this for 8.0 and 8.1.
> 
> Kris Jurka

Content-Description: 

[ Attachment, skipping... ]

Content-Description: 

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian   http://candle.pha.pa.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +



^ permalink  raw  reply  [nested|flat] 21+ messages in thread


end of thread, other threads:[~2006-04-26 23:02 UTC | newest]

Thread overview: 21+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-21 12:22 WAL logging of SELECT ... INTO command Jim C. Nasby <jnasby@pervasive.com>
2006-03-21 20:33 ` Simon Riggs <simon@2ndquadrant.com>
2006-03-22 06:20   ` Qingqing Zhou <zhouqq@cs.toronto.edu>
2006-03-24 10:07     ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-24 12:39       ` Alvaro Herrera <alvherre@commandprompt.com>
2006-03-24 13:01         ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-24 13:47           ` Alvaro Herrera <alvherre@commandprompt.com>
2006-03-24 13:59             ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-22 12:47   ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-22 13:08     ` Simon Riggs <simon@2ndquadrant.com>
2006-03-22 13:19       ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-22 15:06         ` Tom Lane <tgl@sss.pgh.pa.us>
2006-03-22 15:14           ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-22 15:35             ` Tom Lane <tgl@sss.pgh.pa.us>
2006-03-22 16:19               ` Csaba Nagy <nagy@ecircle-ag.com>
2006-03-22 19:37     ` Kris Jurka <books@ejurka.com>
2006-03-24 10:05       ` Jim C. Nasby <jnasby@pervasive.com>
2006-03-24 18:09         ` Kris Jurka <books@ejurka.com>
2006-04-21 23:56           ` Bruce Momjian <pgman@candle.pha.pa.us>
2006-04-21 23:11             ` Simon Riggs <simon@2ndquadrant.com>
2006-04-26 23:02           ` Bruce Momjian <pgman@candle.pha.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox