pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Auto create partition with declarative partitioning
5+ messages / 4 participants
[nested] [flat]

* Auto create partition with declarative partitioning
@ 2018-10-19 20:52  Jorge Torralba <jorge.torralba@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Jorge Torralba @ 2018-10-19 20:52 UTC (permalink / raw)
  To: pgsql-admin

Trying to make this work but am having difficulties.

I have created a table with a timestamp column that i wish to partition by
range using the timestamp column.

My objective is to test if a partition exists for the date range and create
it if it does not.

In the past I have had a before insert trigger which I would send to a
create partition function. Extract the info from NEW.createdate, and use
some logic to create the partition if it did not exists for the create date.

However, now, with the partition by range, I get the error :

Partitioned tables cannot have BEFORE / FOR EACH ROW triggers.

Therefore I cannot call the function to check if the partition exists.

Other than creating a bunch of partitions in advance, what are my options?

-- 
Thanks,

Jorge Torralba
----------------------------

Note: This communication may contain privileged or other confidential
information. If you are not the intended recipient, please do not print,
copy, retransmit, disseminate or otherwise use the information. Please
indicate to the sender that you have received this email in error and
delete the copy you received. Thank You.

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

* Re: Auto create partition with declarative partitioning
@ 2018-10-19 20:57  Scott Ribe <scott_ribe@elevated-dev.com>
  parent: Jorge Torralba <jorge.torralba@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Scott Ribe @ 2018-10-19 20:57 UTC (permalink / raw)
  To: Jorge Torralba <jorge.torralba@gmail.com>; +Cc: pgsql-admin

> On Oct 19, 2018, at 2:52 PM, Jorge Torralba <jorge.torralba@gmail.com> wrote:
> 
> Partitioned tables cannot have BEFORE / FOR EACH ROW triggers.

I believe 11 fixes this?




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

* Re: Auto create partition with declarative partitioning
@ 2018-10-19 21:01  Jorge Torralba <jorge.torralba@gmail.com>
  parent: Scott Ribe <scott_ribe@elevated-dev.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Jorge Torralba @ 2018-10-19 21:01 UTC (permalink / raw)
  To: Scott Ribe <scott_ribe@elevated-dev.com>; +Cc: pgsql-admin

I am doing this on 11 :(

On Fri, Oct 19, 2018 at 1:57 PM Scott Ribe <scott_ribe@elevated-dev.com>
wrote:

> > On Oct 19, 2018, at 2:52 PM, Jorge Torralba <jorge.torralba@gmail.com>
> wrote:
> >
> > Partitioned tables cannot have BEFORE / FOR EACH ROW triggers.
>
> I believe 11 fixes this?
>


-- 
Thanks,

Jorge Torralba
----------------------------

Note: This communication may contain privileged or other confidential
information. If you are not the intended recipient, please do not print,
copy, retransmit, disseminate or otherwise use the information. Please
indicate to the sender that you have received this email in error and
delete the copy you received. Thank You.

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

* Re: Auto create partition with declarative partitioning
@ 2018-10-19 21:09  Keith Fiske <keith.fiske@crunchydata.com>
  parent: Jorge Torralba <jorge.torralba@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Keith Fiske @ 2018-10-19 21:09 UTC (permalink / raw)
  To: jorge.torralba@gmail.com; +Cc: scott_ribe@elevated-dev.com; pgsql-admin

On Fri, Oct 19, 2018 at 5:02 PM Jorge Torralba <jorge.torralba@gmail.com>
wrote:

> I am doing this on 11 :(
>
> On Fri, Oct 19, 2018 at 1:57 PM Scott Ribe <scott_ribe@elevated-dev.com>
> wrote:
>
>> > On Oct 19, 2018, at 2:52 PM, Jorge Torralba <jorge.torralba@gmail.com>
>> wrote:
>> >
>> > Partitioned tables cannot have BEFORE / FOR EACH ROW triggers.
>>
>> I believe 11 fixes this?
>>
>
>
> --
> Thanks,
>
> Jorge Torralba
> ----------------------------
>
> Note: This communication may contain privileged or other confidential
> information. If you are not the intended recipient, please do not print,
> copy, retransmit, disseminate or otherwise use the information. Please
> indicate to the sender that you have received this email in error and
> delete the copy you received. Thank You.
>



It is not recommended that you create partitions with triggers, either at
the time they are needed or even future ones. This can cause contention
when even the slightly write load is on that partition set and 1 or more
transactions require the creation of a new child table. All following
transactions will be put into a wait state until the new table is created.

I would recommend a separate process that pre-creates the tables in enough
time before they are needed. The pg_partman tool that I've been working on
can do all this for you if you're able to install third-party extensions.
As of version 4.0.0, it has full support of all the new features in 11.

https://github.com/pgpartman/pg_partman

-- 
Keith Fiske
Senior Database Engineer
Crunchy Data - http://crunchydata.com

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

* Re: Auto create partition with declarative partitioning
@ 2018-10-22 14:49  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Jorge Torralba <jorge.torralba@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Alvaro Herrera @ 2018-10-22 14:49 UTC (permalink / raw)
  To: Jorge Torralba <jorge.torralba@gmail.com>; +Cc: pgsql-admin

On 2018-Oct-19, Jorge Torralba wrote:

> In the past I have had a before insert trigger which I would send to a
> create partition function. Extract the info from NEW.createdate, and use
> some logic to create the partition if it did not exists for the create date.
> 
> However, now, with the partition by range, I get the error :
> 
> Partitioned tables cannot have BEFORE / FOR EACH ROW triggers.

Interesting.  I don't think this was ever mentioned as a possible use
case for BEFORE triggers on partitioned tables, during the pg11
development.  Basically we forbade BEFORE triggers on partitioned
tables.  (You can find the reasons for that in the thread that discussed
row trigger development).

> Other than creating a bunch of partitions in advance, what are my options?

Create *one* partition in advance?

Another option would be to contribute the feature of automatically
creating the partitions for Postgres 12 :-)

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




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


end of thread, other threads:[~2018-10-22 14:49 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 20:52 Auto create partition with declarative partitioning Jorge Torralba <jorge.torralba@gmail.com>
2018-10-19 20:57 ` Scott Ribe <scott_ribe@elevated-dev.com>
2018-10-19 21:01   ` Jorge Torralba <jorge.torralba@gmail.com>
2018-10-19 21:09     ` Keith Fiske <keith.fiske@crunchydata.com>
2018-10-22 14:49 ` Alvaro Herrera <alvherre@2ndquadrant.com>

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