From: Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: atomically replace partition of range partitioned table
Date: Mon, 25 Feb 2019 15:03:26 -0800
Message-ID: <3a929946-5a7d-fed5-c252-d23dd0925513@gmail.com> (raw)
i have a range partitioned table with a brin index that i am using for
"Internet-of-Things" kind of data (essentially timeseries data about
some entities). the partition key is a timestamp. data is only loaded to
the "current" partition and data is never modified. older partitions are
static. the index key is the entity identifier. my problem is that the
brin index on the current partition does not perform well (because
summarization is not immediate) so i also include a b-tree index on the
current partition. when the current partition is "full", i create a new
partition.
i then want to optimize the previous current partition by (1) clustering
the partition on the index key to give me a correlation of 1 and (2)
dropping the b-tree index to reclaim its storage space. i want to do
this atomically so that querying over the full table is not interrupted.
of course, the cluster command is not usable because it takes an
exclusive lock. so, i do the following.
1. create a new partition table by copying the old partition table,
ordered by index key. both tables will have the same partition key range.
2. create a brin index on the new table.
3. detach the old partition table from the parent and drop it.
4. attach the new partition table to the parent.
what i need is for steps 3-4 to be atomic or quick. but, step 4 takes
tens of seconds, sometimes almost a minute. i tried adding a check
constraint to the new table so that it would not be scanned when
attached but that does not help. is there any way to do want i want?
thanks,
kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: w.kevin.wilkinson@gmail.com
Subject: Re: atomically replace partition of range partitioned table
In-Reply-To: <3a929946-5a7d-fed5-c252-d23dd0925513@gmail.com>
References: <3a929946-5a7d-fed5-c252-d23dd0925513@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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