GridGain Developers Hub

Expiry Policies

Expiry Policy specifies the point of time at which an entry is considered expired. Time can be specified freely in the TIMESTAMP data format.

Configuration

GridGain 9 relies on a dedicated table column to configure data expiry. When creating a table, make sure to have the dedicated column to store TTL, and then specify it as a TTL column by using the EXPIRE AT keyword. For example:

CREATE TABLE Person (
    id int PRIMARY KEY,
    name varchar,
    ttl timestamp
) EXPIRE AT ttl;

The table above uses a ttl column to store the expiration data for each row.

You can also set a default value to the column by using the DEFAULT keyword:

CREATE TABLE Person (
    id int PRIMARY KEY,
    name varchar,
    ttl timestamp DEFAULT (CURRENT_TIMESTAMP + INTERVAL '2' HOURS)
) EXPIRE AT ttl;

When specifying the default timestamp, the time must be specified in the CURRENT_TIMESTAMP + {interval} format. The interval can be specified in:

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

  • MONTHS

In the table above, all newly created rows will be scheduled for removal after 2 hours.

Enabling Expiration Policy for Existing Table

To enable data expiration on an existing table, first add a column to it that you will use for TTL definition. Then, use the SET EXPIRE AT command to set the column as the TTL definition.

ALTER TABLE Person ADD COLUMN ttl timestamp;
ALTER TABLE Person SET EXPIRE AT ttl;

Disabling Expiration Policy

To disable data expiration for the table, use the DROP EXPIRE command:

ALTER TABLE Person DROP EXPIRE;

You can also drop the column you used to TTL if you no longer need it to save space.