All Products
Search
Document Center

PolarDB:Enable and use tiered storage for cold data

Last Updated:Mar 28, 2026

Cold data tiered storage lets you move infrequently accessed tables, indexes, and materialized views from high-speed cloud disk to Object Storage Service (OSS), significantly reducing storage costs while keeping the data fully queryable through standard SQL.

Prerequisites

Before you begin, ensure that you have:

  • A PolarDB for PostgreSQL (Compatible with Oracle) 2.0 cluster at revision version 2.0.14.21.0 or later

  • Hot standby disabled on the cluster (see Limitations for details)

Limitations

  • The feature is not available for clusters with hot standby enabled. To request an exception, contact us.

  • The feature cannot be disabled after enabling. To stop incurring charges, delete all cold data — you are not charged when no cold data is stored.

  • After you enable the cold data tiered storage feature for a cluster that has hot standby enabled, you cannot change the primary zone of the cluster. To request an exception, contact us.

  • The following DDL statements are not supported:

    • CREATE DATABASE dbname TABLESPACE OSS — creates a database directly in an OSS bucket

    • ALTER DATABASE dbname SET TABLESPACE OSS — moves an entire database to an OSS bucket

Important

The cluster restarts when you enable cold data tiered storage. Plan accordingly to avoid disruption.

How it works

After enabling cold data tiered storage, data remains in the high-speed storage of the integrated cloud drive by default. To move data to OSS, run the SQL statements described in Cold storage modes. After the move:

  • The tables, indexes, or materialized views no longer occupy disk space (or occupy only a small amount).

  • All standard SQL operations — including SELECT, INSERT, UPDATE, and DELETE — continue to work without any code changes.

  • Data stored in OSS is compressed. Restoring it to cloud disk requires approximately 1.4–4 times the OSS storage size.

Enable cold data tiered storage

  1. Log on to the PolarDB console. In the left-side navigation pane, click Clusters. In the upper-left corner, select the region of the cluster. In the cluster list, find the cluster and click its ID to go to the Basic Information page.

  2. In the left-side navigation pane, choose Settings and Management > Cold Data Tiered Storage.

  3. Click Enable to go to the Archive List page.

    image

  4. On the Archive List page, review the Basic Information and Archive List sections. The Archive List section contains two tabs: Full Table Archive List and Partitioned Table Archive List.

Note

If no data has been moved to cold storage yet, the Archive List section is empty.

Cold storage modes

Move existing tables, indexes, or materialized views to OSS

Run the corresponding ALTER statement to move an existing object to OSS:

ALTER TABLE tblname SET TABLESPACE OSS;
ALTER INDEX idxname SET TABLESPACE OSS;
ALTER MATERIALIZED VIEW mvname SET TABLESPACE OSS;
Note

Running ALTER TABLE tblname SET TABLESPACE OSS moves only the table data, not its indexes. To move indexes, run ALTER INDEX separately on each index.

Create tables, indexes, or materialized views directly in OSS

Two methods are available.

Method 1: Specify `TABLESPACE OSS` in the CREATE statement

CREATE TABLE tblname (...) TABLESPACE OSS;
CREATE TABLE tblname(...) TABLESPACE OSS AS SELECT ...;
CREATE INDEX idxname ON tblname(columnname) TABLESPACE OSS;
CREATE INDEX idxname ON tblname USING GiST(columnname) TABLESPACE OSS;
CREATE MATERIALIZED VIEW table_name TABLESPACE OSS AS query [ WITH [ NO ] DATA ];

Method 2: Set the default tablespace to OSS

Set default_tablespace once, then run CREATE statements as normal — all new objects go to OSS automatically.

SET default_tablespace = 'oss';
CREATE TABLE tblname (...);
CREATE INDEX idxname ON tblname(columnname);
CREATE INDEX idxname ON tblname USING GiST(columnname);
CREATE MATERIALIZED VIEW table_name AS query [ WITH [ NO ] DATA ];
Note

After setting default_tablespace, all new tables, indexes, and materialized views are created in OSS. Reset the setting when you no longer want to create cold objects:

RESET default_tablespace;

Move individual large object (LOB) fields to OSS

LOB fields of type blob, text, json, jsonb, array, or spatio-temporal data can be stored independently in OSS while the rest of the table remains on cloud disk. This is useful when a small number of large columns are driving most of your storage costs.

-- Create a table with a LOB field.
CREATE TABLE test_large_object(id serial, val text);

-- Configure the LOB field to store in OSS.
ALTER TABLE test_large_object ALTER COLUMN val SET (storage_type='oss');

-- Subsequent inserts store the LOB data in OSS automatically.
INSERT INTO test_large_object(val)
  VALUES((SELECT string_agg(random()::text, ':') FROM generate_series(1, 10000)));
Note

The storage_type='oss' setting applies to data written after the configuration. Existing rows are not moved retroactively.

For more information about spatio-temporal data types, see Overview.

Move partitioned tables to OSS

Partitioned tables are the most common use case for cold data tiered storage. A typical pattern is to keep recent partitions on fast disk and move expired partitions to OSS.

Move all child tables

Three methods are available to put all partitions in OSS.

  • Method 1: Run ALTER TABLE on each child table individually:

    ALTER TABLE prt1_p1 SET TABLESPACE OSS;
    ALTER TABLE prt1_p2 SET TABLESPACE OSS;
  • Method 2: Create the parent table in OSS — child tables inherit the tablespace:

    CREATE TABLE prt1 (a int, b int) PARTITION BY RANGE(a) TABLESPACE OSS;
    
    -- Child tables are created in OSS by inheritance.
    CREATE TABLE prt1_p1 PARTITION OF prt1 FOR VALUES FROM (0) TO (250);
    CREATE TABLE prt1_p2 PARTITION OF prt1 FOR VALUES FROM (250) TO (500);
  • Method 3: Set the default tablespace before creating the table:

    SET default_tablespace = 'oss';
    CREATE TABLE prt1 (a int, b int) PARTITION BY RANGE(a);
    CREATE TABLE prt1_p1 PARTITION OF prt1 FOR VALUES FROM (0) TO (250);
    CREATE TABLE prt1_p2 PARTITION OF prt1 FOR VALUES FROM (250) TO (500);

Move specific child tables

If you want to move only expired, infrequently accessed child tables to OSS while leaving hot partitions on disk, change the tablespace of those specific child tables. This does not affect the access performance of the partitioned table and reduces storage costs.

-- prt1 is the parent partitioned table.
-- prt1_p1 is an active child table (stays on disk).
-- prt1_p2 is an expired child table (move to OSS).
ALTER TABLE prt1_p2 SET TABLESPACE OSS;

Configure the materialized cache

After enabling cold data tiered storage, PolarDB creates a small materialized cache on disk to store metadata and merge I/O for cold data access. For higher read performance on cold data, increase the cache size using the polar_smgrcache_size parameter.

ValueCache size
00 GB (materialized cache disabled)
11 GB
22 GB
128128 GB (maximum)

To change the cache size:

  1. Log on to the PolarDB console and go to the Basic Information page of your cluster.

  2. In the left-side navigation pane, choose Settings and Management > Parameters. Find the polar_smgrcache_size parameter and click Modify Parameter.

  3. Set the value, then click Submit Changes in the upper-left corner. Click OK in the Save Changes dialog. The cluster restarts to apply the change.

Note

If you set polar_smgrcache_size to 0 after cold data has been stored in OSS, materialized caching is disabled. This may slow failure recovery and the parameter may be unavailable during restart. To re-enable materialized caching, contact technical support.

Query cache usage

After enabling materialized caching, install the polar_monitor extension and query cache usage as needed:

-- Install the polar_monitor extension.
CREATE EXTENSION polar_monitor;

-- Query the materialized cache usage.
SELECT * FROM polar_smgrcaches;

The polar_smgrcaches view returns the following fields:

FieldDescription
smgrcacheCache ID
relfilenodeTable file associated with the cache
relchunknumberLocation of the cache within the table file
nblocksSize of the cache
dirtyWhether the cache contains dirty blocks
usagecountNumber of times the cache has been accessed
pinning_backendsNumber of backend processes depending on this cache

To manage cache state manually:

-- Flush the materialized cache to OSS.
SELECT polar_flush_smgrcache();

-- Evict the materialized cache from disk.
SELECT polar_evict_smgrcache();

Access and manage cold data

Query and modify cold data

Run standard SQL statements to read and write cold data — no code changes required. Cold data behaves the same as data in regular storage.

Restore cold data to cloud disk

Data stored in OSS is compressed. Before restoring data to cloud disk, make sure sufficient disk space is available. The required space is approximately 1.4–4 times the size of the OSS storage.

Delete cold data

Delete cold tables, indexes, or materialized views the same way you delete regular objects:

DELETE FROM tblname WHERE ...;
TRUNCATE TABLE tblname;
DROP TABLE tblname;