Skip to main content
Glama
blitzstermayank

Teradata MCP Server

dba_databaseSpace

Retrieve space allocation information for a specific Teradata database or view space usage across all databases to monitor storage capacity and manage database resources.

Instructions

Get database space if database name is provided, otherwise get all databases space allocations.

Arguments: database_name - database name

Returns: ResponseType: formatted response with query results + metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_nameYes

Implementation Reference

  • The handler function that implements the core logic of the 'dba_databaseSpace' tool. It queries the DBC.DiskSpaceV view to retrieve space allocation, current usage, free space, and percentage used for specified or all databases.
    def handle_dba_databaseSpace(conn: TeradataConnection, database_name: str | None | None, *args, **kwargs):
        """
        Get database space if database name is provided, otherwise get all databases space allocations.
    
        Arguments:
          database_name - database name
    
        Returns:
          ResponseType: formatted response with query results + metadata
        """
        logger.debug(f"Tool: handle_dba_databaseSpace: Args: database_name: {database_name}")
    
        database_name_filter = f"AND objectdatabasename = '{database_name}'" if database_name else ""
    
        with conn.cursor() as cur:
            if not database_name:
                logger.debug("No database name provided, returning all databases and space information.")
                rows = cur.execute("""
                    SELECT
                        DatabaseName,
                        CAST(SUM(MaxPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceAllocated_GB,
                        CAST(SUM(CurrentPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceUsed_GB,
                        CAST((SUM(MaxPerm) - SUM(CurrentPerm))/1024/1024/1024 AS DECIMAL(10,2)) AS FreeSpace_GB,
                        CAST((SUM(CurrentPerm) * 100.0 / NULLIF(SUM(MaxPerm),0)) AS DECIMAL(10,2)) AS PercentUsed
                    FROM DBC.DiskSpaceV
                    WHERE MaxPerm > 0
                    GROUP BY 1
                    ORDER BY 5 DESC;
                """)
            else:
                logger.debug(f"Database name: {database_name}, returning space information for this database.")
                rows = cur.execute(f"""
                    SELECT
                        DatabaseName,
                        CAST(SUM(MaxPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceAllocated_GB,
                        CAST(SUM(CurrentPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceUsed_GB,
                        CAST((SUM(MaxPerm) - SUM(CurrentPerm))/1024/1024/1024 AS DECIMAL(10,2)) AS FreeSpace_GB,
                        CAST((SUM(CurrentPerm) * 100.0 / NULLIF(SUM(MaxPerm),0)) AS DECIMAL(10,2)) AS PercentUsed
                    FROM DBC.DiskSpaceV
                    WHERE MaxPerm > 0
                    AND DatabaseName = '{database_name}'
                    GROUP BY 1;
                """)
    
            data = rows_to_json(cur.description, rows.fetchall())
            metadata = {
                "tool_name": "dba_databaseSpace",
                "database_name": database_name,
                "total_databases": len(data)
            }
            logger.debug(f"Tool: handle_dba_databaseSpace: metadata: {metadata}")
            return create_response(data, metadata)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blitzstermayank/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server