import { useState } from 'react'; import { AdminLayout } from '@/components/layout/AdminLayout'; import { AdminPageLayout } from '@/components/admin'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { useMaintenanceTables, useVacuumTable, useAnalyzeTable, useReindexTable, } from '@/hooks/admin/useDatabaseMaintenance'; import { Database, RefreshCw, Zap, Settings, AlertTriangle } from 'lucide-react'; import { Skeleton } from '@/components/ui/skeleton'; export default function DatabaseMaintenance() { const { data: tables, isLoading, refetch } = useMaintenanceTables(); const vacuumMutation = useVacuumTable(); const analyzeMutation = useAnalyzeTable(); const reindexMutation = useReindexTable(); const [selectedTable, setSelectedTable] = useState(null); const handleVacuum = (tableName: string) => { setSelectedTable(tableName); vacuumMutation.mutate(tableName); }; const handleAnalyze = (tableName: string) => { setSelectedTable(tableName); analyzeMutation.mutate(tableName); }; const handleReindex = (tableName: string) => { setSelectedTable(tableName); reindexMutation.mutate(tableName); }; const isOperationPending = (tableName: string) => { return ( selectedTable === tableName && (vacuumMutation.isPending || analyzeMutation.isPending || reindexMutation.isPending) ); }; return ( Superuser Access Required These operations require superuser privileges. They can help improve database performance by reclaiming storage, updating statistics, and rebuilding indexes.
VACUUM Reclaims storage occupied by dead tuples and makes space available for reuse ANALYZE Updates statistics used by the query planner for optimal query execution plans REINDEX Rebuilds indexes to eliminate bloat and restore optimal index performance
Database Tables Select maintenance operations to perform on each table
{isLoading ? (
{Array.from({ length: 5 }).map((_, i) => ( ))}
) : tables && tables.length > 0 ? (
Table Name Rows Table Size Indexes Size Total Size Actions {tables.map((table) => ( {table.table_name} {table.row_count?.toLocaleString() || 'N/A'} {table.table_size} {table.indexes_size} {table.total_size}
))}
) : (
No tables available
)}
); }