Unix Technical Forum

Postgresql partitioning

This is a discussion on Postgresql partitioning within the Pgsql General forums, part of the PostgreSQL category; --> Hey, Suppose I have a table with the following fields: CREATE TABLE distributors ( id DECIMAL(3) PRIMARY KEY, name ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:22 AM
Ram Ravichandran
 
Posts: n/a
Default Postgresql partitioning

Hey,

Suppose I have a table with the following fields:

CREATE TABLE distributors (
id DECIMAL(3) PRIMARY KEY,
name VARCHAR(40),
status INTEGER
);

I would ike to partition this table based on status which can be [0,1,2,3,4].

I was wondering if the records can change their status. i.e. If I did
UPDATE distributors SET status = 4 WHERE id = 231122;

would POSTGRESQL automatically change the record from the current
partition (say partition where status = 3) to the partition where
status = 4?
Or would I have to explicitly delete it from one partition table, and
reinsert it in the other?

Thanks,

Ram

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:22 AM
Erik Jones
 
Posts: n/a
Default Re: Postgresql partitioning

On Mar 21, 2008, at 7:15 PM, Ram Ravichandran wrote:

> Hey,
>
> Suppose I have a table with the following fields:
>
> CREATE TABLE distributors (
> id DECIMAL(3) PRIMARY KEY,
> name VARCHAR(40),
> status INTEGER
> );
>
> I would ike to partition this table based on status which can be
> [0,1,2,3,4].
>
> I was wondering if the records can change their status. i.e. If I did
> UPDATE distributors SET status = 4 WHERE id = 231122;
>
> would POSTGRESQL automatically change the record from the current
> partition (say partition where status = 3) to the partition where
> status = 4?


No. Assuming you have CHECK constraints on you partition tables and
constraint_exclusion=on postgres will emit an error on an update like
that.

> Or would I have to explicitly delete it from one partition table, and
> reinsert it in the other?


Yes. Also, note that this can't be done in an ON UPDATE trigger as
CHECK constraints are checked before any triggers are run.

Erik Jones

DBA | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com




--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 12:22 AM
Ram Ravichandran
 
Posts: n/a
Default Re: Postgresql partitioning

Thanks for the quick response. And I assume that primary key
uniqueness is not tested across tables. Right?

Thanks,
Ram

On Fri, Mar 21, 2008 at 8:59 PM, Erik Jones <erik@myemma.com> wrote:
> On Mar 21, 2008, at 7:15 PM, Ram Ravichandran wrote:
>
> > Hey,
> >
> > Suppose I have a table with the following fields:
> >
> > CREATE TABLE distributors (
> > id DECIMAL(3) PRIMARY KEY,
> > name VARCHAR(40),
> > status INTEGER
> > );
> >
> > I would ike to partition this table based on status which can be
> > [0,1,2,3,4].
> >
> > I was wondering if the records can change their status. i.e. If I did
> > UPDATE distributors SET status = 4 WHERE id = 231122;
> >
> > would POSTGRESQL automatically change the record from the current
> > partition (say partition where status = 3) to the partition where
> > status = 4?

>
> No. Assuming you have CHECK constraints on you partition tables and
> constraint_exclusion=on postgres will emit an error on an update like
> that.
>
>
> > Or would I have to explicitly delete it from one partition table, and
> > reinsert it in the other?

>
> Yes. Also, note that this can't be done in an ON UPDATE trigger as
> CHECK constraints are checked before any triggers are run.
>
> Erik Jones
>
> DBA | Emma(R)
> erik@myemma.com
> 800.595.4401 or 615.292.5888
> 615.292.0777 (fax)
>
> Emma helps organizations everywhere communicate & market in style.
> Visit us online at http://www.myemma.com
>
>
>
>


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 12:22 AM
Reece Hart
 
Posts: n/a
Default Re: Postgresql partitioning

On Fri, 2008-03-21 at 23:00 -0400, Ram Ravichandran wrote:
> I assume that primary key
> uniqueness is not tested across tables. Right?


That's correct. It's on the TODOs:
Inheritance
* Allow inherited tables to inherit indexes, UNIQUE constraints,
and primary/foreign keys
(at http://www.postgresql.org/docs/faqs.TODO.html )


I wonder whether you might be able to achieve the benefits of
partitioning and the simplicity of a single-table updates by using a
view with an update rule. This would allow you to embed the logic for
moving rows between partitions when the partition criterion changes into
the database. I've not done this myself, so I'm, um, not speaking from
experience.

-Reece

--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 12:22 AM
Robert Treat
 
Posts: n/a
Default Re: Postgresql partitioning

On Saturday 22 March 2008 09:39, Reece Hart wrote:
> On Fri, 2008-03-21 at 23:00 -0400, Ram Ravichandran wrote:
> > I assume that primary key
> > uniqueness is not tested across tables. Right?

>
> That's correct. It's on the TODOs:
> Inheritance
> * Allow inherited tables to inherit indexes, UNIQUE constraints,
> and primary/foreign keys
> (at http://www.postgresql.org/docs/faqs.TODO.html )
>
>
> I wonder whether you might be able to achieve the benefits of
> partitioning and the simplicity of a single-table updates by using a
> view with an update rule. This would allow you to embed the logic for
> moving rows between partitions when the partition criterion changes into
> the database. I've not done this myself, so I'm, um, not speaking from
> experience.
>


Actually you can add an update rule to the parent table itself, rewriting
into a set of insert, delete statements. (or call a function to manage it
which is probably better on a larger number of partitions)
--
Robert Treat
Build A Brighter LAMP :: Linux Apache {middleware} PostgreSQL

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:26 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com