2. Fast and cheap tables: partitions, clusters and nested data
2.5 Expiry and storage cost: do not pay for old data
Highlights & notes
Select lesson text to highlight it, or tap Add note.
Bookmarks
Bookmark a lesson to see it here.
Queries are one half of the bill. Storage is the other half, and it grows quietly every day. Two habits keep it under control.
- Expiry: tell BigQuery to delete data you no longer need. A whole table can expire, or the old partitions of a table.
- Long-term storage: a table or partition that has not been changed for 90 days is charged at about half price, automatically.
Expiry is ideal for bronze tables with a legal keep-time, and for scratch tables that people forget to delete.
Expiry deletes data for good after the time travel window. Agree the keep-time with the business before you set it on a real table.
Keep only 90 days of partitions
One setting on a partitioned table.
SQL
ALTER TABLE sales.orders_pSET OPTIONS (partition_expiration_days = 90);
Result
partitions: the last 90 days older partitions: deleted automatically
Quick check
What does partition_expiration_days = 90 do?
A scratch table that cleans itself up
Good manners for test tables.
SQL
CREATE TABLE sales.scratch_testOPTIONS ( expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)) ASSELECT * FROM sales.orders;
Result
sales.scratch_test: 6 rows, expires in 7 days
Quick check
A partition has not been modified for 90 days. What happens to its storage price?
Try it yourself
1. Create a scratch table with an expiry, as in the second walkthrough.
2. Open its Details tab and find the line Table expiration. In the sandbox every table already expires after 60 days.
Question 1 · Easy
What are the two halves of a BigQuery bill?
Question 2 · Medium
Which tables are good candidates for an expiry time?
Question 3 · Hard
Law says raw data may be kept for one year only. What do you set on the daily-partitioned bronze table?
Key takeaways
Storage is half the bill. Set expiry on scratch tables and on old partitions, and remember that unchanged data becomes cheaper after 90 days.
Save your progress
Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.
Start free Log in