pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedPostgreSQL intenal scheduler?
9+ messages / 5 participants
[nested] [flat]
* PostgreSQL intenal scheduler?
@ 2018-09-05 15:06 Thiemo Kellner <thiemo@gelassene-pferde.biz>
0 siblings, 3 replies; 9+ messages in thread
From: Thiemo Kellner @ 2018-09-05 15:06 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Hi all
I am designing a framework for historisation implementation (SCD). One
feature I would like to provide is a table in that the actual state of
an entity is put and if this is complete, this history table is
"updated":
------------ -------------
==> | ENTITY_ACT | ==> | ENTITY_HIST |
------------ -------------
I plan to use instead-of-triggers on the hist table that read the
actual table and perfoms all necessary inserts und updates on the
history table. If I want the termination of a record version (actually
the record of a specific business key with a specific payload) to get
propagated up and/or down referential integrities (no overlapping
validities) I have to make sure that only one of those processes is
modifying a table. I was thinking of a scheduler queue where the
trigger would put a process request and PostgreSQL would work through.
Is there a scheduler within PostgreSQL? I read the documentation and
searched the web but could not find a hint. But before going another
road or implementing something myself, I ask. Maybe this design is no
good at all.
Kind regards
Thiemo
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-05 15:09 Tim Clarke <tim.clarke@minerva-analytics.info>
parent: Thiemo Kellner <thiemo@gelassene-pferde.biz>
2 siblings, 1 reply; 9+ messages in thread
From: Tim Clarke @ 2018-09-05 15:09 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 05/09/18 16:06, Thiemo Kellner wrote:
>
> Hi all
>
> I am designing a framework for historisation implementation (SCD). One
> feature I would like to provide is a table in that the actual state of
> an entity is put and if this is complete, this history table is
> "updated":
>
> ------------ -------------
> ==> | ENTITY_ACT | ==> | ENTITY_HIST |
> ------------ -------------
>
> I plan to use instead-of-triggers on the hist table that read the
> actual table and perfoms all necessary inserts und updates on the
> history table. If I want the termination of a record version (actually
> the record of a specific business key with a specific payload) to get
> propagated up and/or down referential integrities (no overlapping
> validities) I have to make sure that only one of those processes is
> modifying a table. I was thinking of a scheduler queue where the
> trigger would put a process request and PostgreSQL would work through.
> Is there a scheduler within PostgreSQL? I read the documentation and
> searched the web but could not find a hint. But before going another
> road or implementing something myself, I ask. Maybe this design is no
> good at all.
>
> Kind regards
>
> Thiemo
>
>
Why not just call your "do a scheduled run" code from cron?
Tim Clarke
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-05 15:31 Thomas Kellerer <spam_eater@gmx.net>
parent: Thiemo Kellner <thiemo@gelassene-pferde.biz>
2 siblings, 1 reply; 9+ messages in thread
From: Thomas Kellerer @ 2018-09-05 15:31 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Thiemo Kellner schrieb am 05.09.2018 um 17:06:
> I am designing a framework for historisation implementation (SCD).
> One feature I would like to provide is a table in that the actual
> state of an entity is put and if this is complete, this history table
> is "updated":
>
> ------------ -------------
> ==> | ENTITY_ACT | ==> | ENTITY_HIST |
> ------------ -------------
>
> I plan to use instead-of-triggers on the hist table that read the
> actual table and perfoms all necessary inserts und updates on the
> history table. If I want the termination of a record version
> (actually the record of a specific business key with a specific
> payload) to get propagated up and/or down referential integrities (no
> overlapping validities) I have to make sure that only one of those
> processes is modifying a table. I was thinking of a scheduler queue
> where the trigger would put a process request and PostgreSQL would
> work through. Is there a scheduler within PostgreSQL? I read the
> documentation and searched the web but could not find a hint. But
> before going another road or implementing something myself, I ask.
> Maybe this design is no good at all.
There is no built-in scheduler, but there is an extension that supplies that
https://github.com/citusdata/pg_cron
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-05 19:35 Thiemo Kellner <thiemo@gelassene-pferde.biz>
parent: Thomas Kellerer <spam_eater@gmx.net>
0 siblings, 1 reply; 9+ messages in thread
From: Thiemo Kellner @ 2018-09-05 19:35 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I have seen pg_cron but it is not what I am looking for. It schedules
tasks only by time. I am looking for a fifo queue. pg_cron neither
prevents from simultaneous runs I believe.
Quoting Thomas Kellerer <spam_eater@gmx.net>:
> There is no built-in scheduler, but there is an extension that supplies that
>
> https://github.com/citusdata/pg_cron
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-05 21:01 Ron <ronljohnsonjr@gmail.com>
parent: Thiemo Kellner <thiemo@gelassene-pferde.biz>
0 siblings, 1 reply; 9+ messages in thread
From: Ron @ 2018-09-05 21:01 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Maybe https://github.com/chanks/que is what you need.
On 09/05/2018 02:35 PM, Thiemo Kellner wrote:
> I have seen pg_cron but it is not what I am looking for. It schedules
> tasks only by time. I am looking for a fifo queue. pg_cron neither
> prevents from simultaneous runs I believe.
>
> Quoting Thomas Kellerer <spam_eater@gmx.net>:
>
>> There is no built-in scheduler, but there is an extension that supplies that
>>
>> https://github.com/citusdata/pg_cron
>
>
>
>
--
Angular momentum makes the world go 'round.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-05 22:03 Thiemo Kellner <thiemo@gelassene-pferde.biz>
parent: Ron <ronljohnsonjr@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Thiemo Kellner @ 2018-09-05 22:03 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
This is a queue but if I am not mistaken, it is outside PostgreSQL
where to go I am very reluctant. I will look at it in more depth.
Thanks!
Quoting Ron <ronljohnsonjr@gmail.com>:
> Maybe https://github.com/chanks/que is what you need.
>
> On 09/05/2018 02:35 PM, Thiemo Kellner wrote:
>> I have seen pg_cron but it is not what I am looking for. It
>> schedules tasks only by time. I am looking for a fifo queue.
>> pg_cron neither prevents from simultaneous runs I believe.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-05 22:04 Thiemo Kellner <thiemo@gelassene-pferde.biz>
parent: Tim Clarke <tim.clarke@minerva-analytics.info>
0 siblings, 0 replies; 9+ messages in thread
From: Thiemo Kellner @ 2018-09-05 22:04 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Because I am looking for a fifo queue and not for time schedule.
Thanks anyway.
Quoting Tim Clarke <tim.clarke@minerva-analytics.info>:
>
> Why not just call your "do a scheduled run" code from cron?
>
> Tim Clarke
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-06 05:17 Jeremy Finzel <finzelj@gmail.com>
parent: Thiemo Kellner <thiemo@gelassene-pferde.biz>
2 siblings, 1 reply; 9+ messages in thread
From: Jeremy Finzel @ 2018-09-06 05:17 UTC (permalink / raw)
To: Thiemo Kellner <thiemo@gelassene-pferde.biz>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
If I follow your use case, we have written something that just may fit your
scenario and plan to open source it rather soon.
It has several layers but let me boil it down. First we use an open sourced
auditing system to log changes to the source tables. This becomes your
queue. A postgres background worker will asynchronously process these
changes based on your configuration, which is highly configurable. It also
handles the concurrency you are questioning.
This allows you to build history tables without requiring you for example
to do it directly via a trigger. It also removes redundancy if you have the
same key updated multiple times. It assumes we are fine with the data built
not being 100% up to date data because these updates obviously don’t all
happen in the same transaction as the source data change.
Let me know if this interests you and I can share more.
Thanks,
Jeremy
On Wed, Sep 5, 2018 at 10:07 AM Thiemo Kellner <thiemo@gelassene-pferde.biz>
wrote:
>
> Hi all
>
> I am designing a framework for historisation implementation (SCD). One
> feature I would like to provide is a table in that the actual state of
> an entity is put and if this is complete, this history table is
> "updated":
>
> ------------ -------------
> ==> | ENTITY_ACT | ==> | ENTITY_HIST |
> ------------ -------------
>
> I plan to use instead-of-triggers on the hist table that read the
> actual table and perfoms all necessary inserts und updates on the
> history table. If I want the termination of a record version (actually
> the record of a specific business key with a specific payload) to get
> propagated up and/or down referential integrities (no overlapping
> validities) I have to make sure that only one of those processes is
> modifying a table. I was thinking of a scheduler queue where the
> trigger would put a process request and PostgreSQL would work through.
> Is there a scheduler within PostgreSQL? I read the documentation and
> searched the web but could not find a hint. But before going another
> road or implementing something myself, I ask. Maybe this design is no
> good at all.
>
> Kind regards
>
> Thiemo
>
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: PostgreSQL intenal scheduler?
@ 2018-09-06 06:28 Thiemo Kellner <thiemo@gelassene-pferde.biz>
parent: Jeremy Finzel <finzelj@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Thiemo Kellner @ 2018-09-06 06:28 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Thanks for the hint. Your solution seems to be good. However, I am
designing my framework for fun, to give back something to the
community and because I think it's time that historisation is not
reinvented and reimplemented again and again.
Having that said, I think I can get rid of the need to cascade changes
up and down the refential constraints by the following modelling. I am
aware that I would restrict the use of the framework to this model.
------------- --------------------
==> | ENTITY_HEAD |>--..| PARENT_ENTITIY_HEAD |
// ------------- --------------------
// |
------------ // |
==> | ENTITY_ACT | == |
------------ \\ |
\\ /|\
\\ -------------
==> | ENTITY_HIST |
-------------
The head table only contains the business key, the business surrogate
key and foreign key attributes to parent tables. Strictly, I can
contain also payload attributes that never ever ever ever ever ever
change their value. But who is to guarantee that? However, It is SCD0
so once a value is entered it never changes.
The history table contains all the other attributes the payload so to
speak and get the historisation. Version matching between related
entities could be done by a generated view so no one would have to
re-invent the wheel.
One could generate the head table from the business key in the actual
table and generate the hist table from the actual table without the
business key and a template table with history attributes. Can one
exclude attributes from inheritance?
Quoting Jeremy Finzel <finzelj@gmail.com>:
> If I follow your use case, we have written something that just may
> fit your scenario and plan to open source it rather soon.
>
>
> It has several layers but let me boil it down. First we use an
> open sourced auditing system to log changes to the source tables.
> This becomes your queue. A postgres background worker will
> asynchronously process these changes based on your configuration,
> which is highly configurable. It also handles the concurrency you
> are questioning.
>
> This allows you to build history tables without requiring you for
> example to do it directly via a trigger. It also removes redundancy
> if you have the same key updated multiple times. It assumes we are
> fine with the data built not being 100% up to date data because
> these updates obviously don’t all happen in the same transaction as
> the source data change.
>
> Let me know if this interests you and I can share more.
>
> Thanks,
> Jeremy
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2018-09-06 06:28 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-09-05 15:06 PostgreSQL intenal scheduler? Thiemo Kellner <thiemo@gelassene-pferde.biz>
2018-09-05 15:09 ` Tim Clarke <tim.clarke@minerva-analytics.info>
2018-09-05 22:04 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
2018-09-05 15:31 ` Thomas Kellerer <spam_eater@gmx.net>
2018-09-05 19:35 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
2018-09-05 21:01 ` Ron <ronljohnsonjr@gmail.com>
2018-09-05 22:03 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
2018-09-06 05:17 ` Jeremy Finzel <finzelj@gmail.com>
2018-09-06 06:28 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
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