C3 AI Documentation Home

Perform Database Maintenance to Reclaim Disk Space

You can run APIs to perform database maintenance for PostgreSQL and Cassandra. The C3 Agentic AI Platform provides APIs for PostgreSQL and Cassandra databases to run disk space reclaimation operations.

Prerequisites

Complete the following requirements:

Reclaim disk space in PostgreSQL

PostgreSQL automatically and regularly performs VACUUM and ANALYZE operations to effectively reclaim storage occupied by dead tuples. To learn more about VACUUM in PostgreSQL, see the PostgreSQL documentation VACUUM SQL Commands.

You might want to manually reclaim disk space after running high-volume data operations, when you notice performance degradation, or when automatic vacuuming has not kept up with storage needs. To check if you need to manually run a vacuum operation, run the following code in C3 AI Console:

JavaScript
DbAdmin.inst().getVacuumStats()

This code returns statistics for tables, ordered descending by number of dead tuples. See the Type documentation DbAdmin#getVacuumStats to learn how to specify a table or column.

You can manually reclaim disk space for your PostgreSQL database with the following APIs:

  • DbAdmin#vacuum: Runs native PostgreSQL vacuum and analyze operations for the current datastore. You can specify a specific table and column, or run it on all tables. The method also supports full vacuum mode and analyzes operations to update query planner statistics.
  • DbAdmin#vacuumAll: Runs native PostgreSQL vacuum and analyze operations for all datastores. You can specify tables and columns, and whether to perform full vacuum and analyze operations.

See the Type documentation for DbAdmin to learn about the parameters these APIs take.

Example PostgreSQL vacuum commands

The following are examples of how to run the DbAdmin.vacuum command in C3 AI Console:

DescriptionCommand
Analyze on all tables in current datastoreDbAdmin.inst().vacuum(null, null, false, true);
Vacuum a specific table with analyze set to trueDbAdmin.inst().vacuum("MyTable", null, false, true);
Vacuum a specific column in a tableDbAdmin.inst().vacuum("MyTable", "my_column", false, true);
Perform a "full" vacuum on a specific tableDbAdmin.inst().vacuum("MyTable", null, true, true);
Vacuum without analyze on all tablesDbAdmin.inst().vacuum(null, null, false, false);

The parameters that these APIs take match the native operations in PostgreSQL. See the Type documentation for DbAdmin.vacuum and DbAdmin.vacuumAll, and the PostgreSQL documentation VACUUM SQL Commands to learn more about these parameters.

You can also apply these example parameters to the DbAdmin.vacuumAll() API.

Reclaim disk space in Cassandra

Cassandra performs repair and compaction operations to maintain a healthy system. The repair operation ensures data consistency across replicas, and the compaction operation cleans up and optimizes local on-disk data.

To learn more about repair in Cassandra, see the Cassandra documentation Repair.

To learn more about compaction in Cassandra, see the Cassandra documentation Compaction.

You might want to run repair and compaction operations if your Cassandra database has a high tombstone count. You can check tombstone count in your server's Grafana instance at https://<yourserverdomain>/grafana. Navigate to Cassandra cluster overview to check tombstone count. Contact your C3 AI representative for credentials to access Grafana.

Because incremental repair and minor compactions are not sufficient to maintain a healthy system, you can run full repair and full compaction for Cassandra with the following APIs:

See the Type documentation for CassandraDB to learn more about these APIs.

Example Cassandra repair command

Here is an example of how to run the CassandraDB.repair() API in the C3 AI Console:

  1. Define the CassandraDB.RepairSpec:

    JavaScript
    spec = {confirm: true, keyspace: "platform_myenv_db"} 

    This code creates a repair specification with two required parameters:

    • withConfirm(true): Required confirmation to run the repair operation
    • withKeyspace("platform_myenv_db"): Specifies the Cassandra keyspace to repair (in this example, the platform_myenv_db keyspace)

    To search for keyspaces, run the following command:

    JavaScript
    Cassandra.Cluster.inst().keyspace

    Keyspaces take the following format:

    See the Type documentation for CassandraDB.RepairSpec to learn about additional optional parameters such as specific tables, repair parallelism, intensity settings, and datacenter targeting.

  2. Run the CassandraDB.repair API:

    JavaScript
    CassandraDB.listForApp(C3.app()).repair(spec)

    This code references a Cassandra service ID for your application and runs the repair operation using the previously defined specification.

    To reference the Cassandra service ID for your environment or cluster, use the C3.env() or Cluster.c3App() as values for the CloudService#listForEnv and CloudService#listForApp methods. For example, use listForEnv(C3.env() to refer to your environment Cassandra service ID, or use listForApp(Cluster.c3App()) to refer to the cluster Cassandra service ID.

  3. Check the repair status:

    JavaScript
    CassandraDB.listForApp(C3.app()).repairStatus()

    This code fetches the current status of the repair operation for the instance of Cassandra specified by the service ID.

Example Cassandra compaction command

Here is an example of how to run the CassandraDB.compact() API in the C3 AI Console:

  1. Define the CassandraDB.CompactionSpec:

    JavaScript
    spec = {confirm: true} 

    This code creates a compaction specification with the required confirmation parameter.

    See the Type documentation for CassandraDB.CompactionSpec to learn about additional optional parameters for configuring compaction operations.

  2. Run the CassandraDB.compact() API:

    JavaScript
    CassandraDB.listForApp(C3.app()).compact(spec)

    This code references the Cassandra service ID of your application and runs compaction using the previously defined specification.

  3. Check the compaction status:

    JavaScript
    CassandraDB.listForApp(C3.app()).compactionStatus()

    This code fetches the current status of the compaction operation.

See also

Was this page helpful?