Configure garbage collection
This page shows you how to view, set, and update garbage collection policies in Bigtable. Before you read this page, you should be familiar with garbage collection.
Before you use the
cbt
CLI
, follow the setup instructions, including the steps to create a .cbtrc
file.
View current garbage collection policies
You can use either the Google Cloud console or the
cbt
CLI
to view a
column family's garbage collection policies.
Console
To view the current garbage collection policy for a column family:
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit in the table's row.Click
Open next to the column family that you want to view.When you are finished viewing the garbage collection policy, click Cancel to exit.
cbt
You can look up the current garbage collection policies for a given
table by running the following command, substituting a valid table ID for
TABLE_ID
:
cbt ls TABLE_ID
Set garbage collection policies
You can set garbage collection policies using the Google Cloud console, the
cbt
CLI
, or the Cloud Bigtable
client libraries.
Garbage collection based on age
The following section shows how to set the maximum age for data in a column family.
Console
To set an expiration time for cells in a column family:
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit.Click
Open next to the column family that you want to edit.Select Age based policy.
Enter the age by entering a number in the Max age field and using the Unit drop-down to select the unit of time.
For example, to retain a column family's data for 30 minutes, enter 30 and choose minutes.
Click Save.
cbt
This example creates a column family named cf1
, then sets the maximum age
for data in the column family to five days. This tells Bigtable
to remove all data with timestamps older than five days in all columns in this
column family.
cbt createfamily your-table cf1
cbt setgcpolicy your-table cf1 maxage=5d
Go
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C#
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C++
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
PHP
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Ruby
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Garbage collection based on the number of versions
The following section shows how to create a column family with a garbage collection policy that states the number of versions of the data, or number of cells, to keep.
Console
To set the number of cells, or versions, to retain in a column family:
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit in the table's row.Click
Open next to the column family that you want to edit.Select Version based policy.
Enter the number of cells to retain in every column in the column family.
Click Save.
cbt
This example creates a column family named cf2
, then sets the number of
versions to keep in the column family to two. This tells
Bigtable to remove all but the two most recent cells in all
columns in this column family.
cbt createfamily your-table cf2
cbt setgcpolicy your-table cf2 maxversions=2
This example sets a policy to remove all cells except the newest one.
cbt setgcpolicy your-table cf2 maxversions=1
Go
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C#
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C++
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
PHP
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Ruby
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Garbage collection based on multiple criteria
The following section demonstrate how to create a column family with an intersection garbage collection policy.
Console
To set an intersection garbage collection policy for cells in a column family:
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit in the table's row.Click
Open next to the column family that you want to edit.Select Custom policy.
Enter a garbage collection rule in the text area, setting values for
maxage
,maxversions
, or both. Acceptable age units are ms, s, m, h, and d, which stand for milliseconds, seconds, minutes, hours, and days.For example, to remove cells that are older than five days and older than the two most recent cells, enter the following. Cells must meet both criteria to be removed.
maxage=5d and maxversions=2
Click Save.
cbt
This example creates a column family named cf4
, then sets a garbage
collection policy that removes cells that are older than five days and
older than the two most recent cells for all columns in the column family.
Cells must meet both criteria to be removed.
cbt createfamily your-table cf4
cbt setgcpolicy your-table cf4 maxage=5d and maxversions=2
This example sets a policy that removes all cells more than 14 days old except the newest one.
cbt setgcpolicy your-table cf4 maxage=14d and maxversions=1
Go
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C#
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C++
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
PHP
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Ruby
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
The following section shows how to create a column family that has a union garbage collection policy.
Console
To set a union garbage collection policy for cells in a column family:
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit in the table's row.Click
Open next to the column family that you want to edit.Select Custom policy.
Enter a garbage collection rule in the text area, setting values for
maxage
,maxversions
, or both. Acceptable age units are ms, s, m, h, and d, which stand for milliseconds, seconds, minutes, hours, and days.For example, to remove cells that are more than five days old or are older than the two most recent cells, enter the following. Cells must meet either criteria to be removed.
maxage=5d or maxversions=2
Click Save.
cbt
This example creates a column family named cf3
, then sets a garbage
collection policy that removes cells that are more than five days old or
are older than the two most recent cells. Cells must meet either conditions
to be removed.
cbt createfamily your-table cf3
cbt setgcpolicy your-table cf3 maxage=5d or maxversions=2
This example sets a policy that removes all cell values except the newest one, but removes even the newest cell if it is more than one second old.
cbt setgcpolicy your-table cf3 maxversions=1 or maxage=1s
Go
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C#
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C++
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
PHP
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Ruby
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
The following section shows how to create a column family that has a nested garbage collection policy. A nested garbage collection policy has a combination of union and intersection rules.
Console
To set a nested garbage collection policy for cells in a column family:
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit in the table's row.Click
Open next to the column family that you want to edit.Select Custom policy.
Enter a garbage collection rule in the text area, setting values for
maxage
,maxversions
, or both. Acceptable age units are ms, s, m, h, and d, which stand for milliseconds, seconds, minutes, hours, and days.For example, to keep the two newest cells even if they are more than one minute old, or keep the ten newest cells as long as they are less than one minute old, enter the following:
(maxage=1m and maxversions=2) or maxversions=10
Click Save.
cbt
This example creates a column family named cf5
, then sets a garbage
collection policy that removes cells in the column family that meet
either of the following conditions:
- Older than the ten most recent cells
- More than one minute old and older than the two most recent cells
In other words, this policy keeps the two newest cells even if they are more than one minute old, or keeps the ten newest cells as long as they are less than one minute old.
cbt createfamily your-table cf5
cbt setgcpolicy your-table cf5 "(maxage=1m and maxversions=2) or
maxversions=10"
Go
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C#
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C++
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
PHP
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Ruby
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Update a garbage collection policy
The following section demonstrates how to modify an existing garbage collection policy.
To increase the retention period for a column family in a table that uses replication, you must acknowledge a warning about the potential for your clusters to become out of sync. The new value must be no more than 90 days more than the current value. For details, see Changing age-based policies.
Console
To update the garbage collection policy for a column family, follow these steps.
Open the list of Bigtable instances in the Google Cloud console.
Click the instance whose tables you want to view.
Click Tables in the left pane.
The Tables page displays a list of tables in the instance.
Click
Edit in the table's row.Click
Open next to the column family that you want to edit.Click Save.
cbt
cbt setgcpolicy your-table cf1 maxage=1d
If you increase the value of maxage
in a replicated table, you must use
the optional force
flag. The new value must be no more than 90 days
more than the current value.
Java
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C#
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
C++
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Node.js
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
PHP
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Ruby
To learn how to install and use the client library for Bigtable, see Bigtable client libraries.
To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
What's next
- Look at additional code samples.
- Explore strategies to simulate cell-level TTL.
- Read about how timestamps that are sequential numbers affect garbage collection.
- Learn how to keep only the most recent value of a column.