0

I am using postgres 10 db.

I am having Customers table consisting of following columns

custid (primary key),
name,
phonenumber,
email,
dateofbirth,
address,
city,
country,
status(boolean)
Join_Date(Date)

I have million of records in table. I want to partition table based on different months(Jan 2018 one partition, Feb 2018 one partition,..etc) by help of Join_Date and with help of Intermediate table.

I also want to write the automated script such that at the end of month the table have to get create another partition of last month

12
  • so what actually you want to do Commented Aug 9, 2018 at 11:24
  • i want to partition customer table with the help of intermediate(temp) table Commented Aug 9, 2018 at 11:25
  • like jan 2018 one partition, feb 2018 one partition Commented Aug 9, 2018 at 11:26
  • does it physical partition or logical? Commented Aug 9, 2018 at 11:28
  • logical partition Commented Aug 9, 2018 at 11:30

2 Answers 2

0

Try this method:

  1. First of all, create an additional column in customer table as you want to logical partition.
  2. Then update that columns using customer and intermediate table
  3. After updating truncate your table

For each month you can run this script and this will give you logical partitioning.

update customer set partition_column=to_char(Join_Date, 'YYYY-MM')
join intermediate_table on intermediate_table.custid=customer.custid
and  intermediate_table.Join_Date=customer.Join_Date

truncate table intermediate_table
Sign up to request clarification or add additional context in comments.

2 Comments

can you please eloborate your answer because i am very new to postgres
this applicable for all database not particularly postgres
0

There is an example for your problem in the Postgres documentation.

PostgreSQL: Documentation: 10: 5.10. Table Partitioning

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.