diff --git a/cmd/internal/tools_file_test.go b/cmd/internal/tools_file_test.go index 3856e3204555..c14e83aa3452 100644 --- a/cmd/internal/tools_file_test.go +++ b/cmd/internal/tools_file_test.go @@ -1710,9 +1710,33 @@ func TestPrebuiltTools(t *testing.T) { name: "cloudsqlpg prebuilt tools", in: cloudsqlpg_config, wantToolset: server.ToolsetConfigs{ - "cloud_sql_postgres_database_tools": tools.ToolsetConfig{ - Name: "cloud_sql_postgres_database_tools", - ToolNames: []string{"execute_sql", "list_tables", "list_active_queries", "list_available_extensions", "list_installed_extensions", "list_autovacuum_configurations", "list_memory_configurations", "list_top_bloated_tables", "list_replication_slots", "list_invalid_indexes", "get_query_plan", "list_views", "list_schemas", "database_overview", "list_triggers", "list_indexes", "list_sequences", "long_running_transactions", "list_locks", "replication_stats", "list_query_stats", "get_column_cardinality", "list_publication_tables", "list_tablespaces", "list_pg_settings", "list_database_stats", "list_roles", "list_table_stats", "list_stored_procedure"}, + "admin": tools.ToolsetConfig{ + Name: "admin", + ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance"}, + }, + "lifecycle": tools.ToolsetConfig{ + Name: "lifecycle", + ToolNames: []string{"create_backup", "restore_backup", "postgres_upgrade_precheck", "wait_for_operation", "database_overview", "get_instance", "list_instances"}, + }, + "data": tools.ToolsetConfig{ + Name: "data", + ToolNames: []string{"execute_sql", "list_tables", "list_views", "list_schemas", "list_triggers", "list_indexes", "list_sequences", "list_stored_procedure"}, + }, + "monitor": tools.ToolsetConfig{ + Name: "monitor", + ToolNames: []string{"get_system_metrics", "get_query_metrics", "list_query_stats", "get_query_plan", "list_database_stats", "list_active_queries", "long_running_transactions", "list_locks"}, + }, + "health": tools.ToolsetConfig{ + Name: "health", + ToolNames: []string{"list_top_bloated_tables", "list_invalid_indexes", "list_table_stats", "get_column_cardinality", "list_autovacuum_configurations", "list_tablespaces", "database_overview", "list_pg_settings"}, + }, + "view-config": tools.ToolsetConfig{ + Name: "view-config", + ToolNames: []string{"list_available_extensions", "list_installed_extensions", "list_memory_configurations", "list_pg_settings", "database_overview", "get_instance"}, + }, + "replication": tools.ToolsetConfig{ + Name: "replication", + ToolNames: []string{"replication_stats", "list_replication_slots", "list_publication_tables", "list_roles", "list_pg_settings", "database_overview"}, }, }, }, @@ -1720,9 +1744,21 @@ func TestPrebuiltTools(t *testing.T) { name: "cloudsqlmysql prebuilt tools", in: cloudsqlmysql_config, wantToolset: server.ToolsetConfigs{ - "cloud_sql_mysql_database_tools": tools.ToolsetConfig{ - Name: "cloud_sql_mysql_database_tools", - ToolNames: []string{"execute_sql", "list_tables", "get_query_plan", "list_active_queries", "list_tables_missing_unique_indexes", "list_table_fragmentation"}, + "admin": tools.ToolsetConfig{ + Name: "admin", + ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation"}, + }, + "data": tools.ToolsetConfig{ + Name: "data", + ToolNames: []string{"execute_sql", "list_tables", "get_query_plan", "list_active_queries"}, + }, + "monitor": tools.ToolsetConfig{ + Name: "monitor", + ToolNames: []string{"get_query_plan", "list_active_queries", "get_query_metrics", "get_system_metrics", "list_table_fragmentation", "list_tables_missing_unique_indexes"}, + }, + "lifecycle": tools.ToolsetConfig{ + Name: "lifecycle", + ToolNames: []string{"create_backup", "restore_backup", "clone_instance", "list_instances", "get_instance", "wait_for_operation"}, }, }, }, @@ -1730,10 +1766,22 @@ func TestPrebuiltTools(t *testing.T) { name: "cloudsqlmssql prebuilt tools", in: cloudsqlmssql_config, wantToolset: server.ToolsetConfigs{ - "cloud_sql_mssql_database_tools": tools.ToolsetConfig{ - Name: "cloud_sql_mssql_database_tools", + "admin": tools.ToolsetConfig{ + Name: "admin", + ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation"}, + }, + "data": tools.ToolsetConfig{ + Name: "data", ToolNames: []string{"execute_sql", "list_tables"}, }, + "monitor": tools.ToolsetConfig{ + Name: "monitor", + ToolNames: []string{"get_system_metrics"}, + }, + "lifecycle": tools.ToolsetConfig{ + Name: "lifecycle", + ToolNames: []string{"create_backup", "restore_backup", "clone_instance", "list_instances", "get_instance", "wait_for_operation"}, + }, }, }, { diff --git a/internal/prebuiltconfigs/tools/cloud-sql-mssql.yaml b/internal/prebuiltconfigs/tools/cloud-sql-mssql.yaml index 2b2671dcf301..78fda88c51a8 100644 --- a/internal/prebuiltconfigs/tools/cloud-sql-mssql.yaml +++ b/internal/prebuiltconfigs/tools/cloud-sql-mssql.yaml @@ -13,27 +13,82 @@ # limitations under the License. sources: - cloudsql-mssql-source: - kind: cloud-sql-mssql - project: ${CLOUD_SQL_MSSQL_PROJECT} - region: ${CLOUD_SQL_MSSQL_REGION} - instance: ${CLOUD_SQL_MSSQL_INSTANCE} - database: ${CLOUD_SQL_MSSQL_DATABASE} - user: ${CLOUD_SQL_MSSQL_USER} - password: ${CLOUD_SQL_MSSQL_PASSWORD} - ipType: ${CLOUD_SQL_MSSQL_IP_TYPE:public} + cloudsql-mssql-source: + kind: cloud-sql-mssql + project: ${CLOUD_SQL_MSSQL_PROJECT} + region: ${CLOUD_SQL_MSSQL_REGION} + instance: ${CLOUD_SQL_MSSQL_INSTANCE} + database: ${CLOUD_SQL_MSSQL_DATABASE} + user: ${CLOUD_SQL_MSSQL_USER} + password: ${CLOUD_SQL_MSSQL_PASSWORD} + ipType: ${CLOUD_SQL_MSSQL_IP_TYPE:public} + cloud-sql-admin-source: + kind: cloud-sql-admin + defaultProject: ${CLOUD_SQL_MSSQL_PROJECT:} + cloud-monitoring-source: + kind: cloud-monitoring tools: - execute_sql: - kind: mssql-execute-sql - source: cloudsql-mssql-source - description: Use this tool to execute SQL. - - list_tables: - kind: mssql-list-tables - source: cloudsql-mssql-source - description: "Lists detailed schema information (object type, columns, constraints, indexes, triggers, comment) as JSON for user-created tables (ordinary or partitioned). Filters by a comma-separated list of names. If names are omitted, lists all tables in user schemas." - + execute_sql: + kind: mssql-execute-sql + source: cloudsql-mssql-source + description: Use this tool to execute SQL. + list_tables: + kind: mssql-list-tables + source: cloudsql-mssql-source + description: "Lists detailed schema information (object type, columns, constraints, indexes, triggers, comment) as JSON for user-created tables (ordinary or partitioned). Filters by a comma-separated list of names. If names are omitted, lists all tables in user schemas." + get_system_metrics: + kind: cloud-monitoring-query-prometheus + source: cloud-monitoring-source + description: "Fetches system level cloudmonitoring data (timeseries metrics) for a SqlServer instance using a PromQL query. Take projectId and instanceId from the user for which the metrics timeseries data needs to be fetched.\nTo use this tool, you must provide the Google Cloud `projectId` and a PromQL `query`.\n\nGenerate PromQL `query` for SqlServer system metrics. Use the provided metrics and rules to construct queries, Get the labels like `instance_id` from user intent.\n\nDefaults:\n1. Interval: Use a default interval of `5m` for `_over_time` aggregation functions unless a different window is specified by the user.\n\nPromQL Query Examples:\n1. Basic Time Series: `avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m])`\n2. Top K: `topk(30, avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n3. Mean: `avg(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n4. Minimum: `min(min_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n5. Maximum: `max(max_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n6. Sum: `sum(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n7. Count streams: `count(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n8. Percentile with groupby on database_id: `quantile by (\"database_id\")(0.99,avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n\nAvailable Metrics List: metricname. description. monitored resource. labels. database_id is actually the instance id and the format is `project_id:instance_id`. \n1. `cloudsql.googleapis.com/database/cpu/utilization`: Current CPU utilization as a percentage of the reserved CPU. `cloudsql_database`. `database`, `project_id`, `database_id`.\n2. `cloudsql.googleapis.com/database/memory/usage`: RAM usage in bytes, excluding buffer/cache. `cloudsql_database`. `database`, `project_id`, `database_id`.\n3. `cloudsql.googleapis.com/database/memory/total_usage`: Total RAM usage in bytes, including buffer/cache. `cloudsql_database`. `database`, `project_id`, `database_id`.\n4. `cloudsql.googleapis.com/database/disk/bytes_used`: Data utilization in bytes. `cloudsql_database`. `database`, `project_id`, `database_id`.\n5. `cloudsql.googleapis.com/database/disk/quota`: Maximum data disk size in bytes. `cloudsql_database`. `database`, `project_id`, `database_id`.\n6. `cloudsql.googleapis.com/database/disk/read_ops_count`: Delta count of data disk read IO operations. `cloudsql_database`. `database`, `project_id`, `database_id`.\n7. `cloudsql.googleapis.com/database/disk/write_ops_count`: Delta count of data disk write IO operations. `cloudsql_database`. `database`, `project_id`, `database_id`.\n8. `cloudsql.googleapis.com/database/network/received_bytes_count`: Delta count of bytes received through the network. `cloudsql_database`. `database`, `project_id`, `database_id`.\n9. `cloudsql.googleapis.com/database/network/sent_bytes_count`: Delta count of bytes sent through the network. `cloudsql_database`. `destination`, `database`, `project_id`, `database_id`.\n10. `cloudsql.googleapis.com/database/sqlserver/memory/buffer_cache_hit_ratio`: Current percentage of pages found in the buffer cache without reading from disk. `cloudsql_database`. `database`, `project_id`, `database_id`.\n11. `cloudsql.googleapis.com/database/sqlserver/memory/memory_grants_pending`: Current number of processes waiting for a workspace memory grant. `cloudsql_database`. `database`, `project_id`, `database_id`.\n12. `cloudsql.googleapis.com/database/sqlserver/memory/free_list_stall_count`: Total number of requests that waited for a free page. `cloudsql_database`. `database`, `project_id`, `database_id`.\n13. `cloudsql.googleapis.com/database/swap/pages_swapped_in_count`: Total count of pages swapped in from disk since the system was booted. `cloudsql_database`. `database`, `project_id`, `database_id`.\n14. `cloudsql.googleapis.com/database/swap/pages_swapped_out_count`: Total count of pages swapped out to disk since the system was booted. `cloudsql_database`. `database`, `project_id`, `database_id`.\n15. `cloudsql.googleapis.com/database/sqlserver/memory/checkpoint_page_count`: Total number of pages flushed to disk by a checkpoint. `cloudsql_database`. `database`, `project_id`, `database_id`.\n16. `cloudsql.googleapis.com/database/sqlserver/memory/lazy_write_count`: Total number of buffers written by the buffer manager's lazy writer. `cloudsql_database`. `database`, `project_id`, `database_id`.\n17. `cloudsql.googleapis.com/database/sqlserver/memory/page_life_expectancy`: Current number of seconds a page will stay in the buffer pool. `cloudsql_database`. `database`, `project_id`, `database_id`.\n18. `cloudsql.googleapis.com/database/sqlserver/memory/page_operation_count`: Total number of physical database page reads or writes. `cloudsql_database`. `operation`, `database`, `project_id`, `database_id`.\n19. `cloudsql.googleapis.com/database/sqlserver/transactions/page_split_count`: Total number of page splits from overflowing index pages. `cloudsql_database`. `database`, `project_id`, `database_id`.\n20. `cloudsql.googleapis.com/database/sqlserver/transactions/deadlock_count`: Total number of lock requests that resulted in a deadlock. `cloudsql_database`. `locked_resource`, `database`, `project_id`, `database_id`.\n21. `cloudsql.googleapis.com/database/sqlserver/transactions/transaction_count`: Total number of transactions started. `cloudsql_database`. `database`, `project_id`, `database_id`.\n22. `cloudsql.googleapis.com/database/sqlserver/transactions/batch_request_count`: Total number of Transact-SQL command batches received. `cloudsql_database`. `database`, `project_id`, `database_id`.\n23. `cloudsql.googleapis.com/database/sqlserver/transactions/sql_compilation_count`: Total number of SQL compilations. `cloudsql_database`. `database`, `project_id`, `database_id`.\n24. `cloudsql.googleapis.com/database/sqlserver/transactions/sql_recompilation_count`: Total number of SQL recompilations. `cloudsql_database`. `database`, `project_id`, `database_id`.\n25. `cloudsql.googleapis.com/database/sqlserver/connections/processes_blocked`: Current number of blocked processes. `cloudsql_database`. `database`, `project_id`, `database_id`.\n26. `cloudsql.googleapis.com/database/sqlserver/transactions/lock_wait_time`: Total time lock requests were waiting for locks. `cloudsql_database`. `locked_resource`, `database`, `project_id`, `database_id`.\n27. `cloudsql.googleapis.com/database/sqlserver/transactions/lock_wait_count`: Total number of lock requests that required the caller to wait. `cloudsql_database`. `locked_resource`, `database`, `project_id`, `database_id`.\n28. `cloudsql.googleapis.com/database/network/connections`: Number of connections to databases on the instance. `cloudsql_database`. `database`, `project_id`, `database_id`.\n29. `cloudsql.googleapis.com/database/sqlserver/connections/login_attempt_count`: Total number of login attempts since the last server restart. `cloudsql_database`. `database`, `project_id`, `database_id`.\n30. `cloudsql.googleapis.com/database/sqlserver/connections/logout_count`: Total number of logout operations since the last server restart. `cloudsql_database`. `database`, `project_id`, `database_id`.\n31. `cloudsql.googleapis.com/database/sqlserver/connections/connection_reset_count`: Total number of logins started from the connection pool since the last server restart. `cloudsql_database`. `database`, `project_id`, `database_id`.\n32. `cloudsql.googleapis.com/database/sqlserver/transactions/full_scan_count`: Total number of unrestricted full scans (base-table or full-index). `cloudsql_database`. `database`, `project_id`, `database_id`.\n" + restore_backup: + kind: cloud-sql-restore-backup + source: cloud-sql-admin-source + clone_instance: + kind: cloud-sql-clone-instance + source: cloud-sql-admin-source + get_instance: + kind: cloud-sql-get-instance + source: cloud-sql-admin-source + list_instances: + kind: cloud-sql-list-instances + source: cloud-sql-admin-source + create_database: + kind: cloud-sql-create-database + source: cloud-sql-admin-source + list_databases: + kind: cloud-sql-list-databases + source: cloud-sql-admin-source + create_user: + kind: cloud-sql-create-users + source: cloud-sql-admin-source + create_backup: + kind: cloud-sql-create-backup + source: cloud-sql-admin-source + create_instance: + kind: cloud-sql-mssql-create-instance + source: cloud-sql-admin-source + wait_for_operation: + kind: cloud-sql-wait-for-operation + source: cloud-sql-admin-source + multiplier: 4 toolsets: - cloud_sql_mssql_database_tools: - - execute_sql - - list_tables + admin: + - create_instance + - get_instance + - list_instances + - create_database + - list_databases + - create_user + - wait_for_operation + data: + - execute_sql + - list_tables + monitor: + - get_system_metrics + lifecycle: + - create_backup + - restore_backup + - clone_instance + - list_instances + - get_instance + - wait_for_operation diff --git a/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml b/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml index 08e89e427894..ebf3680b08f3 100644 --- a/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml +++ b/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml @@ -22,6 +22,11 @@ sources: user: ${CLOUD_SQL_MYSQL_USER:} password: ${CLOUD_SQL_MYSQL_PASSWORD:} ipType: ${CLOUD_SQL_MYSQL_IP_TYPE:PUBLIC} + cloud-sql-admin-source: + kind: cloud-sql-admin + defaultProject: ${CLOUD_SQL_MYSQL_PROJECT:} + cloud-monitoring-source: + kind: cloud-monitoring tools: execute_sql: kind: mysql-execute-sql @@ -47,12 +52,107 @@ tools: kind: mysql-list-table-fragmentation source: cloud-sql-mysql-source description: List table fragmentation in MySQL, by calculating the size of the data and index files and free space allocated to each table. The query calculates fragmentation percentage which represents the proportion of free space relative to the total data and index size. Storage can be reclaimed for tables with high fragmentation using OPTIMIZE TABLE. + create_backup: + kind: cloud-sql-create-backup + source: cloud-sql-admin-source + restore_backup: + kind: cloud-sql-restore-backup + source: cloud-sql-admin-source + clone_instance: + kind: cloud-sql-clone-instance + source: cloud-sql-admin-source + list_instances: + kind: cloud-sql-list-instances + source: cloud-sql-admin-source + create_instance: + kind: cloud-sql-mysql-create-instance + source: cloud-sql-admin-source + create_database: + kind: cloud-sql-create-database + source: cloud-sql-admin-source + get_system_metrics: + kind: cloud-monitoring-query-prometheus + source: cloud-monitoring-source + description: "Fetches system level cloudmonitoring data (timeseries metrics) for a MySQL instance using a PromQL query. Take projectId and instanceId from the user for which the metrics timeseries data needs to be fetched.\nTo use this tool, you must provide the Google Cloud `projectId` and a PromQL `query`.\n\nGenerate PromQL `query` for MySQL system metrics. Use the provided metrics and rules to construct queries, Get the labels like `instance_id` from user intent.\n\nDefaults:\n1. Interval: Use a default interval of `5m` for `_over_time` aggregation functions unless a different window is specified by the user.\n\nPromQL Query Examples:\n1. Basic Time Series: `avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m])`\n2. Top K: `topk(30, avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n3. Mean: `avg(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n4. Minimum: `min(min_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n5. Maximum: `max(max_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n6. Sum: `sum(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n7. Count streams: `count(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n8. Percentile with groupby on database_id: `quantile by (\"database_id\")(0.99,avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n\nAvailable Metrics List: metricname. description. monitored resource. labels. database_id is actually the instance id and the format is `project_id:instance_id`. \n1. `cloudsql.googleapis.com/database/cpu/utilization`: Current CPU utilization as a percentage of reserved CPU. `cloudsql_database`. `database`, `project_id`, `database_id`.\n2. `cloudsql.googleapis.com/database/network/connections`: Number of connections to the database instance. `cloudsql_database`. `database`, `project_id`, `database_id`.\n3. `cloudsql.googleapis.com/database/network/received_bytes_count`: Delta count of bytes received through the network. `cloudsql_database`. `database`, `project_id`, `database_id`.\n4. `cloudsql.googleapis.com/database/network/sent_bytes_count`: Delta count of bytes sent through the network. `cloudsql_database`. `destination`, `database`, `project_id`, `database_id`.\n5. `cloudsql.googleapis.com/database/memory/components`: Memory usage for components like usage, cache, and free memory. `cloudsql_database`. `component`, `database`, `project_id`, `database_id`.\n6. `cloudsql.googleapis.com/database/disk/bytes_used_by_data_type`: Data utilization in bytes. `cloudsql_database`. `data_type`, `database`, `project_id`, `database_id`.\n7. `cloudsql.googleapis.com/database/disk/read_ops_count`: Delta count of data disk read IO operations. `cloudsql_database`. `database`, `project_id`, `database_id`.\n8. `cloudsql.googleapis.com/database/disk/write_ops_count`: Delta count of data disk write IO operations. `cloudsql_database`. `database`, `project_id`, `database_id`.\n9. `cloudsql.googleapis.com/database/mysql/queries`: Delta count of statements executed by the server. `cloudsql_database`. `database`, `project_id`, `database_id`.\n10. `cloudsql.googleapis.com/database/mysql/questions`: Delta count of statements sent by the client. `cloudsql_database`. `database`, `project_id`, `database_id`.\n11. `cloudsql.googleapis.com/database/mysql/received_bytes_count`: Delta count of bytes received by MySQL process. `cloudsql_database`. `database`, `project_id`, `database_id`.\n12. `cloudsql.googleapis.com/database/mysql/sent_bytes_count`: Delta count of bytes sent by MySQL process. `cloudsql_database`. `database`, `project_id`, `database_id`.\n13. `cloudsql.googleapis.com/database/mysql/innodb_buffer_pool_pages_dirty`: Number of unflushed pages in the InnoDB buffer pool. `cloudsql_database`. `database`, `project_id`, `database_id`.\n14. `cloudsql.googleapis.com/database/mysql/innodb_buffer_pool_pages_free`: Number of unused pages in the InnoDB buffer pool. `cloudsql_database`. `database`, `project_id`, `database_id`.\n15. `cloudsql.googleapis.com/database/mysql/innodb_buffer_pool_pages_total`: Total number of pages in the InnoDB buffer pool. `cloudsql_database`. `database`, `project_id`, `database_id`.\n16. `cloudsql.googleapis.com/database/mysql/innodb_data_fsyncs`: Delta count of InnoDB fsync() calls. `cloudsql_database`. `database`, `project_id`, `database_id`.\n17. `cloudsql.googleapis.com/database/mysql/innodb_os_log_fsyncs`: Delta count of InnoDB fsync() calls to the log file. `cloudsql_database`. `database`, `project_id`, `database_id`.\n18. `cloudsql.googleapis.com/database/mysql/innodb_pages_read`: Delta count of InnoDB pages read. `cloudsql_database`. `database`, `project_id`, `database_id`.\n19. `cloudsql.googleapis.com/database/mysql/innodb_pages_written`: Delta count of InnoDB pages written. `cloudsql_database`. `database`, `project_id`, `database_id`.\n20. `cloudsql.googleapis.com/database/mysql/open_tables`: The number of tables that are currently open. `cloudsql_database`. `database`, `project_id`, `database_id`.\n21. `cloudsql.googleapis.com/database/mysql/opened_table_count`: The number of tables opened since the last sample. `cloudsql_database`. `database`, `project_id`, `database_id`.\n22. `cloudsql.googleapis.com/database/mysql/open_table_definitions`: The number of table definitions currently cached. `cloudsql_database`. `database`, `project_id`, `database_id`.\n23. `cloudsql.googleapis.com/database/mysql/opened_table_definitions_count`: The number of table definitions cached since the last sample. `cloudsql_database`. `database`, `project_id`, `database_id`.\n24. `cloudsql.googleapis.com/database/mysql/innodb/dictionary_memory`: Memory allocated for the InnoDB dictionary cache. `cloudsql_database`. `database`, `project_id`, `database_id`.\n" + create_user: + kind: cloud-sql-create-users + source: cloud-sql-admin-source + get_query_metrics: + kind: cloud-monitoring-query-prometheus + source: cloud-monitoring-source + description: | + Fetches query level cloudmonitoring data (timeseries metrics) for queries running in Mysql instance using a PromQL query. Take projectID and instanceID from the user for which the metrics timeseries data needs to be fetched. + To use this tool, you must provide the Google Cloud `projectId` and a PromQL `query`. + Generate PromQL `query` for Mysql query metrics. Use the provided metrics and rules to construct queries, Get the labels like `instance_id`, `query_hash` from user intent. If query_hash is provided then use the per_query metrics. Query hash and query id are same. + + Defaults: + 1. Interval: Use a default interval of `5m` for `_over_time` aggregation functions unless a different window is specified by the user. + + PromQL Query Examples: + 1. Basic Time Series: `avg_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m])` + 2. Top K: `topk(30, avg_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 3. Mean: `avg(avg_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 4. Minimum: `min(min_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 5. Maximum: `max(max_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 6. Sum: `sum(avg_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 7. Count streams: `count(avg_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 8. Percentile with groupby on resource_id, database: `quantile by ("resource_id","database")(0.99,avg_over_time({"__name__"="dbinsights.googleapis.com/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + + Available Metrics List: metricname. description. monitored resource. labels. resource_id label format is `project_id:instance_id` which is actually instance id only. aggregate is the aggregated values for all query stats, Use aggregate metrics if query id is not provided. For perquery metrics do not fetch querystring unless specified by user specifically. Have the aggregation on query hash to avoid fetching the querystring. Do not use latency metrics for anything. + 1. `dbinsights.googleapis.com/aggregate/latencies`: Cumulative query latency distribution per user and database. `cloudsql_instance_database`. `user`, `client_addr`, `database`, `project_id`, `resource_id`. + 2. `dbinsights.googleapis.com/aggregate/execution_time`: Cumulative query execution time per user and database. `cloudsql_instance_database`. `user`, `client_addr`, `database`, `project_id`, `resource_id`. + 3. `dbinsights.googleapis.com/aggregate/execution_count`: Total number of query executions per user and database. `cloudsql_instance_database`. `user`, `client_addr`, `database`, `project_id`, `resource_id`. + 4. `dbinsights.googleapis.com/aggregate/lock_time`: Cumulative lock wait time per user and database. `cloudsql_instance_database`. `user`, `client_addr`, `lock_type`, `database`, `project_id`, `resource_id`. + 5. `dbinsights.googleapis.com/aggregate/io_time`: Cumulative IO wait time per user and database. `cloudsql_instance_database`. `user`, `client_addr`, `database`, `project_id`, `resource_id`. + 6. `dbinsights.googleapis.com/aggregate/row_count`: Total number of rows affected during query execution. `cloudsql_instance_database`. `user`, `client_addr`, `row_status`, `database`, `project_id`, `resource_id`. + 7. `dbinsights.googleapis.com/perquery/latencies`: Cumulative query latency distribution per user, database, and query. `cloudsql_instance_database`. `querystring`, `user`, `client_addr`, `query_hash`, `database`, `project_id`, `resource_id`. + 8. `dbinsights.googleapis.com/perquery/execution_time`: Cumulative query execution time per user, database, and query. `cloudsql_instance_database`. `querystring`, `user`, `client_addr`, `query_hash`, `database`, `project_id`, `resource_id`. + 9. `dbinsights.googleapis.com/perquery/execution_count`: Total number of query executions per user, database, and query. `cloudsql_instance_database`. `querystring`, `user`, `client_addr`, `query_hash`, `database`, `project_id`, `resource_id`. + 10. `dbinsights.googleapis.com/perquery/lock_time`: Cumulative lock wait time per user, database, and query. `cloudsql_instance_database`. `querystring`, `user`, `client_addr`, `lock_type`, `query_hash`, `database`, `project_id`, `resource_id`. + 11. `dbinsights.googleapis.com/perquery/io_time`: Cumulative io wait time per user, database, and query. `cloudsql_instance_database`. `querystring`, `user`, `client_addr`, `query_hash`, `database`, `project_id`, `resource_id`. + 12. `dbinsights.googleapis.com/perquery/row_count`: Total number of rows affected during query execution. `cloudsql_instance_database`. `querystring`, `user`, `client_addr`, `query_hash`, `row_status`, `database`, `project_id`, `resource_id`. + 13. `dbinsights.googleapis.com/pertag/latencies`: Cumulative query latency distribution per user, database, and tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `database`, `project_id`, `resource_id`. + 14. `dbinsights.googleapis.com/pertag/execution_time`: Cumulative query execution time per user, database, and tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `database`, `project_id`, `resource_id`. + 15. `dbinsights.googleapis.com/pertag/execution_count`: Total number of query executions per user, database, and tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `database`, `project_id`, `resource_id`. + 16. `dbinsights.googleapis.com/pertag/lock_time`: Cumulative lock wait time per user, database and tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `lock_type`, `tag_hash`, `database`, `project_id`, `resource_id`. + 17. `dbinsights.googleapis.com/pertag/io_time`: Cumulative IO wait time per user, database and tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `database`, `project_id`, `resource_id`. + 18. `dbinsights.googleapis.com/pertag/row_count`: Total number of rows affected during query execution. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `row_status`, `database`, `project_id`, `resource_id`. + wait_for_operation: + kind: cloud-sql-wait-for-operation + source: cloud-sql-admin-source + multiplier: 4 + get_instance: + kind: cloud-sql-get-instance + source: cloud-sql-admin-source + list_databases: + kind: cloud-sql-list-databases + source: cloud-sql-admin-source toolsets: - cloud_sql_mysql_database_tools: + admin: + - create_instance + - get_instance + - list_instances + - create_database + - list_databases + - create_user + - wait_for_operation + data: - execute_sql - list_tables - get_query_plan - list_active_queries - - list_tables_missing_unique_indexes + monitor: + - get_query_plan + - list_active_queries + - get_query_metrics + - get_system_metrics - list_table_fragmentation + - list_tables_missing_unique_indexes + lifecycle: + - create_backup + - restore_backup + - clone_instance + - list_instances + - get_instance + - wait_for_operation diff --git a/internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml b/internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml index 956823f8d373..ebf0bd0fdb96 100644 --- a/internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml +++ b/internal/prebuiltconfigs/tools/cloud-sql-postgres.yaml @@ -13,251 +13,333 @@ # limitations under the License. sources: - cloudsql-pg-source: - kind: cloud-sql-postgres - project: ${CLOUD_SQL_POSTGRES_PROJECT} - region: ${CLOUD_SQL_POSTGRES_REGION} - instance: ${CLOUD_SQL_POSTGRES_INSTANCE} - database: ${CLOUD_SQL_POSTGRES_DATABASE} - user: ${CLOUD_SQL_POSTGRES_USER:} - password: ${CLOUD_SQL_POSTGRES_PASSWORD:} - ipType: ${CLOUD_SQL_POSTGRES_IP_TYPE:public} - + cloudsql-pg-source: + kind: cloud-sql-postgres + project: ${CLOUD_SQL_POSTGRES_PROJECT} + region: ${CLOUD_SQL_POSTGRES_REGION} + instance: ${CLOUD_SQL_POSTGRES_INSTANCE} + database: ${CLOUD_SQL_POSTGRES_DATABASE} + user: ${CLOUD_SQL_POSTGRES_USER:} + password: ${CLOUD_SQL_POSTGRES_PASSWORD:} + ipType: ${CLOUD_SQL_POSTGRES_IP_TYPE:public} + cloud-sql-admin-source: + kind: cloud-sql-admin + defaultProject: ${CLOUD_SQL_POSTGRES_PROJECT:} + cloud-monitoring-source: + kind: cloud-monitoring tools: - execute_sql: - kind: postgres-execute-sql - source: cloudsql-pg-source - description: Use this tool to execute sql. - - list_tables: - kind: postgres-list-tables - source: cloudsql-pg-source - description: "Lists detailed schema information (object type, columns, constraints, indexes, triggers, owner, comment) as JSON for user-created tables (ordinary or partitioned). Filters by a comma-separated list of names. If names are omitted, lists all tables in user schemas." - - list_active_queries: - kind: postgres-list-active-queries - source: cloudsql-pg-source - description: "List the top N (default 50) currently running queries (state='active') from pg_stat_activity, ordered by longest-running first. Returns pid, user, database, application_name, client_addr, state, wait_event_type/wait_event, backend/xact/query start times, computed query_duration, and the SQL text." - - list_available_extensions: - kind: postgres-list-available-extensions - source: cloudsql-pg-source - description: "Discover all PostgreSQL extensions available for installation on this server, returning name, default_version, and description." - - list_installed_extensions: - kind: postgres-list-installed-extensions - source: cloudsql-pg-source - description: "List all installed PostgreSQL extensions with their name, version, schema, owner, and description." - - long_running_transactions: - kind: postgres-long-running-transactions - source: cloudsql-pg-source - description: "Identifies and lists database transactions that exceed a specified time limit. For each of the long running transactions, the output contains the process id, database name, user name, application name, client address, state, connection age, transaction age, query age, last activity age, wait event type, wait event, and query string." - - list_locks: - kind: postgres-list-locks - source: cloudsql-pg-source - description: "Identifies all locks held by active processes showing the process ID, user, query text, and an aggregated list of all transactions and specific locks (relation, mode, grant status) associated with each process." - - replication_stats: - kind: postgres-replication-stats - source: cloudsql-pg-source - description: "Lists each replica's process ID, user name, application name, backend_xmin (standby's xmin horizon reported by hot_standby_feedback), client IP address, connection state, and sync_state, along with lag sizes in bytes for sent_lag (primary to sent), write_lag (sent to written), flush_lag (written to flushed), replay_lag (flushed to replayed), and the overall total_lag (primary to replayed)." - - list_autovacuum_configurations: - kind: postgres-sql - source: cloudsql-pg-source - description: "List PostgreSQL autovacuum-related configurations (name and current setting) from pg_settings." - statement: | - SELECT name, - setting - FROM pg_settings - WHERE category = 'Autovacuum'; - - list_memory_configurations: - kind: postgres-sql - source: cloudsql-pg-source - description: "List PostgreSQL memory-related configurations (name and current setting) from pg_settings." - statement: | - ( - SELECT - name, - pg_size_pretty((setting::bigint * 1024)::bigint) setting - FROM pg_settings - WHERE name IN ('work_mem', 'maintenance_work_mem') - ) - UNION ALL - ( - SELECT - name, - pg_size_pretty((((setting::bigint) * 8) * 1024)::bigint) - FROM pg_settings - WHERE name IN ('shared_buffers', 'wal_buffers', 'effective_cache_size', 'temp_buffers') - ) - ORDER BY 1 DESC; - - list_top_bloated_tables: - kind: postgres-sql - source: cloudsql-pg-source - description: | - List the top tables by dead-tuple (approximate bloat signal), returning schema, table, live/dead tuples, percentage, and last vacuum/analyze times. - statement: | - SELECT - schemaname AS schema_name, - relname AS relation_name, - n_live_tup AS live_tuples, - n_dead_tup AS dead_tuples, - TRUNC((n_dead_tup::NUMERIC / NULLIF(n_live_tup + n_dead_tup, 0)) * 100, 2) AS dead_tuple_percentage, - last_vacuum, - last_autovacuum, - last_analyze, - last_autoanalyze - FROM pg_stat_user_tables - ORDER BY n_dead_tup DESC - LIMIT COALESCE($1::int, 50); - parameters: - - name: limit - description: "The maximum number of results to return." - type: integer - default: 50 - - list_replication_slots: - kind: postgres-sql - source: cloudsql-pg-source - description: "List key details for all PostgreSQL replication slots (e.g., type, database, active status) and calculates the size of the outstanding WAL that is being prevented from removal by the slot." - statement: | - SELECT - slot_name, - slot_type, - plugin, - database, - temporary, - active, - restart_lsn, - confirmed_flush_lsn, - xmin, - catalog_xmin, - pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal - FROM pg_replication_slots; - - list_invalid_indexes: - kind: postgres-sql - source: cloudsql-pg-source - description: "Lists all invalid PostgreSQL indexes which are taking up disk space but are unusable by the query planner. Typically created by failed CREATE INDEX CONCURRENTLY operations." - statement: | - SELECT - nspname AS schema_name, - indexrelid::regclass AS index_name, - indrelid::regclass AS table_name, - pg_size_pretty(pg_total_relation_size(indexrelid)) AS index_size, - indisready, - indisvalid, - pg_get_indexdef(pg_class.oid) AS index_def - FROM pg_index - JOIN pg_class ON pg_class.oid = pg_index.indexrelid - JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace - WHERE indisvalid = FALSE; - - get_query_plan: - kind: postgres-sql - source: cloudsql-pg-source - description: "Generate a PostgreSQL EXPLAIN plan in JSON format for a single SQL statement—without executing it. This returns the optimizer's estimated plan, costs, and rows (no ANALYZE, no extra options). Use in production safely for plan inspection, regression checks, and query tuning workflows." - statement: | - EXPLAIN (FORMAT JSON) {{.query}}; - templateParameters: - - name: query - type: string - description: "The SQL statement for which you want to generate plan (omit the EXPLAIN keyword)." - required: true - - list_views: - kind: postgres-list-views - source: cloudsql-pg-source - - list_schemas: - kind: postgres-list-schemas - source: cloudsql-pg-source - - database_overview: - kind: postgres-database-overview - source: cloudsql-pg-source - - list_triggers: - kind: postgres-list-triggers - source: cloudsql-pg-source - - list_indexes: - kind: postgres-list-indexes - source: cloudsql-pg-source - - list_sequences: - kind: postgres-list-sequences - source: cloudsql-pg-source - - list_query_stats: - kind: postgres-list-query-stats - source: cloudsql-pg-source - - get_column_cardinality: - kind: postgres-get-column-cardinality - source: cloudsql-pg-source - - list_table_stats: - kind: postgres-list-table-stats - source: cloudsql-pg-source - - list_publication_tables: - kind: postgres-list-publication-tables - source: cloudsql-pg-source - - list_tablespaces: - kind: postgres-list-tablespaces - source: cloudsql-pg-source - - list_pg_settings: - kind: postgres-list-pg-settings - source: cloudsql-pg-source + execute_sql: + kind: postgres-execute-sql + source: cloudsql-pg-source + description: Use this tool to execute sql. + list_tables: + kind: postgres-list-tables + source: cloudsql-pg-source + description: "Lists detailed schema information (object type, columns, constraints, indexes, triggers, owner, comment) as JSON for user-created tables (ordinary or partitioned). Filters by a comma-separated list of names. If names are omitted, lists all tables in user schemas." + list_active_queries: + kind: postgres-list-active-queries + source: cloudsql-pg-source + description: "List the top N (default 50) currently running queries (state='active') from pg_stat_activity, ordered by longest-running first. Returns pid, user, database, application_name, client_addr, state, wait_event_type/wait_event, backend/xact/query start times, computed query_duration, and the SQL text." + list_available_extensions: + kind: postgres-list-available-extensions + source: cloudsql-pg-source + description: "Discover all PostgreSQL extensions available for installation on this server, returning name, default_version, and description." + list_installed_extensions: + kind: postgres-list-installed-extensions + source: cloudsql-pg-source + description: "List all installed PostgreSQL extensions with their name, version, schema, owner, and description." + long_running_transactions: + kind: postgres-long-running-transactions + source: cloudsql-pg-source + description: "Identifies and lists database transactions that exceed a specified time limit. For each of the long running transactions, the output contains the process id, database name, user name, application name, client address, state, connection age, transaction age, query age, last activity age, wait event type, wait event, and query string." + list_locks: + kind: postgres-list-locks + source: cloudsql-pg-source + description: "Identifies all locks held by active processes showing the process ID, user, query text, and an aggregated list of all transactions and specific locks (relation, mode, grant status) associated with each process." + replication_stats: + kind: postgres-replication-stats + source: cloudsql-pg-source + description: "Lists each replica's process ID, user name, application name, backend_xmin (standby's xmin horizon reported by hot_standby_feedback), client IP address, connection state, and sync_state, along with lag sizes in bytes for sent_lag (primary to sent), write_lag (sent to written), flush_lag (written to flushed), replay_lag (flushed to replayed), and the overall total_lag (primary to replayed)." + list_autovacuum_configurations: + kind: postgres-sql + source: cloudsql-pg-source + description: "List PostgreSQL autovacuum-related configurations (name and current setting) from pg_settings." + statement: | + SELECT name, + setting + FROM pg_settings + WHERE category = 'Autovacuum'; + list_memory_configurations: + kind: postgres-sql + source: cloudsql-pg-source + description: "List PostgreSQL memory-related configurations (name and current setting) from pg_settings." + statement: | + ( + SELECT + name, + pg_size_pretty((setting::bigint * 1024)::bigint) setting + FROM pg_settings + WHERE name IN ('work_mem', 'maintenance_work_mem') + ) + UNION ALL + ( + SELECT + name, + pg_size_pretty((((setting::bigint) * 8) * 1024)::bigint) + FROM pg_settings + WHERE name IN ('shared_buffers', 'wal_buffers', 'effective_cache_size', 'temp_buffers') + ) + ORDER BY 1 DESC; + list_top_bloated_tables: + kind: postgres-sql + source: cloudsql-pg-source + description: | + List the top tables by dead-tuple (approximate bloat signal), returning schema, table, live/dead tuples, percentage, and last vacuum/analyze times. + statement: | + SELECT + schemaname AS schema_name, + relname AS relation_name, + n_live_tup AS live_tuples, + n_dead_tup AS dead_tuples, + TRUNC((n_dead_tup::NUMERIC / NULLIF(n_live_tup + n_dead_tup, 0)) * 100, 2) AS dead_tuple_percentage, + last_vacuum, + last_autovacuum, + last_analyze, + last_autoanalyze + FROM pg_stat_user_tables + ORDER BY n_dead_tup DESC + LIMIT COALESCE($1::int, 50); + parameters: + - name: limit + description: "The maximum number of results to return." + type: integer + default: 50 + list_replication_slots: + kind: postgres-sql + source: cloudsql-pg-source + description: "List key details for all PostgreSQL replication slots (e.g., type, database, active status) and calculates the size of the outstanding WAL that is being prevented from removal by the slot." + statement: | + SELECT + slot_name, + slot_type, + plugin, + database, + temporary, + active, + restart_lsn, + confirmed_flush_lsn, + xmin, + catalog_xmin, + pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal + FROM pg_replication_slots; + list_invalid_indexes: + kind: postgres-sql + source: cloudsql-pg-source + description: "Lists all invalid PostgreSQL indexes which are taking up disk space but are unusable by the query planner. Typically created by failed CREATE INDEX CONCURRENTLY operations." + statement: | + SELECT + nspname AS schema_name, + indexrelid::regclass AS index_name, + indrelid::regclass AS table_name, + pg_size_pretty(pg_total_relation_size(indexrelid)) AS index_size, + indisready, + indisvalid, + pg_get_indexdef(pg_class.oid) AS index_def + FROM pg_index + JOIN pg_class ON pg_class.oid = pg_index.indexrelid + JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace + WHERE indisvalid = FALSE; + get_query_plan: + kind: postgres-sql + source: cloudsql-pg-source + description: "Generate a PostgreSQL EXPLAIN plan in JSON format for a single SQL statement—without executing it. This returns the optimizer's estimated plan, costs, and rows (no ANALYZE, no extra options). Use in production safely for plan inspection, regression checks, and query tuning workflows." + statement: | + EXPLAIN (FORMAT JSON) {{.query}}; + templateParameters: + - name: query + type: string + description: "The SQL statement for which you want to generate plan (omit the EXPLAIN keyword)." + required: true + list_views: + kind: postgres-list-views + source: cloudsql-pg-source + list_schemas: + kind: postgres-list-schemas + source: cloudsql-pg-source + database_overview: + kind: postgres-database-overview + source: cloudsql-pg-source + list_triggers: + kind: postgres-list-triggers + source: cloudsql-pg-source + list_indexes: + kind: postgres-list-indexes + source: cloudsql-pg-source + list_sequences: + kind: postgres-list-sequences + source: cloudsql-pg-source + list_query_stats: + kind: postgres-list-query-stats + source: cloudsql-pg-source + get_column_cardinality: + kind: postgres-get-column-cardinality + source: cloudsql-pg-source + list_table_stats: + kind: postgres-list-table-stats + source: cloudsql-pg-source + list_publication_tables: + kind: postgres-list-publication-tables + source: cloudsql-pg-source + list_tablespaces: + kind: postgres-list-tablespaces + source: cloudsql-pg-source + list_pg_settings: + kind: postgres-list-pg-settings + source: cloudsql-pg-source + list_database_stats: + kind: postgres-list-database-stats + source: cloudsql-pg-source + list_roles: + kind: postgres-list-roles + source: cloudsql-pg-source + list_stored_procedure: + kind: postgres-list-stored-procedure + source: cloudsql-pg-source + list_databases: + kind: cloud-sql-list-databases + source: cloud-sql-admin-source + create_backup: + kind: cloud-sql-create-backup + source: cloud-sql-admin-source + postgres_upgrade_precheck: + kind: postgres-upgrade-precheck + source: cloud-sql-admin-source + create_instance: + kind: cloud-sql-postgres-create-instance + source: cloud-sql-admin-source + wait_for_operation: + kind: cloud-sql-wait-for-operation + source: cloud-sql-admin-source + multiplier: 4 + get_system_metrics: + kind: cloud-monitoring-query-prometheus + source: cloud-monitoring-source + description: "Fetches system level cloudmonitoring data (timeseries metrics) for a Postgres instance using a PromQL query. Take projectId and instanceId from the user for which the metrics timeseries data needs to be fetched.\nTo use this tool, you must provide the Google Cloud `projectId` and a PromQL `query`.\n\nGenerate PromQL `query` for Postgres system metrics. Use the provided metrics and rules to construct queries, Get the labels like `instance_id` from user intent.\n\nDefaults:\n1. Interval: Use a default interval of `5m` for `_over_time` aggregation functions unless a different window is specified by the user.\n\nPromQL Query Examples:\n1. Basic Time Series: `avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m])`\n2. Top K: `topk(30, avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n3. Mean: `avg(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n4. Minimum: `min(min_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n5. Maximum: `max(max_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n6. Sum: `sum(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n7. Count streams: `count(avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n8. Percentile with groupby on database_id: `quantile by (\"database_id\")(0.99,avg_over_time({\"__name__\"=\"cloudsql.googleapis.com/database/cpu/utilization\",\"monitored_resource\"=\"cloudsql_database\",\"project_id\"=\"my-projectId\",\"database_id\"=\"my-projectId:my-instanceId\"}[5m]))`\n\nAvailable Metrics List: metricname. description. monitored resource. labels. database_id is actually the instance id and the format is `project_id:instance_id`. \n1. `cloudsql.googleapis.com/database/postgresql/new_connection_count`: Count of new connections added to the postgres instance. `cloudsql_database`. `database`, `project_id`, `database_id`.\n2. `cloudsql.googleapis.com/database/postgresql/backends_in_wait`: Number of backends in wait in postgres instance. `cloudsql_database`. `backend_type`, `wait_event`, `wait_event_type`, `project_id`, `database_id`.\n3. `cloudsql.googleapis.com/database/postgresql/transaction_count`: Delta count of number of transactions. `cloudsql_database`. `database`, `transaction_type`, `project_id`, `database_id`.\n4. `cloudsql.googleapis.com/database/memory/components`: Memory stats components in percentage as usage, cache and free memory for the database. `cloudsql_database`. `component`, `project_id`, `database_id`.\n5. `cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag`: Replication lag in bytes for Postgres External Server (ES) replicas. Aggregated across all DBs on the replica. `cloudsql_database`. `project_id`, `database_id`.\n6. `cloudsql.googleapis.com/database/cpu/utilization`: Current CPU utilization represented as a percentage of the reserved CPU that is currently in use. Values are typically numbers between 0.0 and 1.0 (but might exceed 1.0). Charts display the values as a percentage between 0% and 100% (or more). `cloudsql_database`. `project_id`, `database_id`.\n7. `cloudsql.googleapis.com/database/disk/bytes_used_by_data_type`: Data utilization in bytes. `cloudsql_database`. `data_type`, `project_id`, `database_id`.\n8. `cloudsql.googleapis.com/database/disk/read_ops_count`: Delta count of data disk read IO operations. `cloudsql_database`. `project_id`, `database_id`.\n9. `cloudsql.googleapis.com/database/disk/write_ops_count`: Delta count of data disk write IO operations. `cloudsql_database`. `project_id`, `database_id`.\n10. `cloudsql.googleapis.com/database/postgresql/num_backends_by_state`: Number of connections to the Cloud SQL PostgreSQL instance, grouped by its state. `cloudsql_database`. `database`, `state`, `project_id`, `database_id`.\n11. `cloudsql.googleapis.com/database/postgresql/num_backends`: Number of connections to the Cloud SQL PostgreSQL instance. `cloudsql_database`. `database`, `project_id`, `database_id`.\n12. `cloudsql.googleapis.com/database/network/received_bytes_count`: Delta count of bytes received through the network. `cloudsql_database`. `project_id`, `database_id`.\n13. `cloudsql.googleapis.com/database/network/sent_bytes_count`: Delta count of bytes sent through the network. `cloudsql_database`. `destination`, `project_id`, `database_id`.\n14. `cloudsql.googleapis.com/database/postgresql/deadlock_count`: Number of deadlocks detected for this database. `cloudsql_database`. `database`, `project_id`, `database_id`.\n15. `cloudsql.googleapis.com/database/postgresql/blocks_read_count`: Number of disk blocks read by this database. The source field distingushes actual reads from disk versus reads from buffer cache. `cloudsql_database`. `database`, `source`, `project_id`, `database_id`.\n16. `cloudsql.googleapis.com/database/postgresql/tuples_processed_count`: Number of tuples(rows) processed for a given database for operations like insert, update or delete. `cloudsql_database`. `operation_type`, `database`, `project_id`, `database_id`.\n17. `cloudsql.googleapis.com/database/postgresql/tuple_size`: Number of tuples (rows) in the database. `cloudsql_database`. `database`, `tuple_state`, `project_id`, `database_id`.\n18. `cloudsql.googleapis.com/database/postgresql/vacuum/oldest_transaction_age`: Age of the oldest transaction yet to be vacuumed in the Cloud SQL PostgreSQL instance, measured in number of transactions that have happened since the oldest transaction. `cloudsql_database`. `oldest_transaction_type`, `project_id`, `database_id`.\n19. `cloudsql.googleapis.com/database/replication/log_archive_success_count`: Number of successful attempts for archiving replication log files. `cloudsql_database`. `project_id`, `database_id`.\n20. `cloudsql.googleapis.com/database/replication/log_archive_failure_count`: Number of failed attempts for archiving replication log files. `cloudsql_database`. `project_id`, `database_id`.\n21. `cloudsql.googleapis.com/database/postgresql/transaction_id_utilization`: Current utilization represented as a percentage of transaction IDs consumed by the Cloud SQL PostgreSQL instance. Values are typically numbers between 0.0 and 1.0. Charts display the values as a percentage between 0% and 100% . `cloudsql_database`. `project_id`, `database_id`.\n22. `cloudsql.googleapis.com/database/postgresql/num_backends_by_application`: Number of connections to the Cloud SQL PostgreSQL instance, grouped by applications. `cloudsql_database`. `application`, `project_id`, `database_id`.\n23. `cloudsql.googleapis.com/database/postgresql/tuples_fetched_count`: Total number of rows fetched as a result of queries per database in the PostgreSQL instance. `cloudsql_database`. `database`, `project_id`, `database_id`.\n24. `cloudsql.googleapis.com/database/postgresql/tuples_returned_count`: Total number of rows scanned while processing the queries per database in the PostgreSQL instance. `cloudsql_database`. `database`, `project_id`, `database_id`.\n25. `cloudsql.googleapis.com/database/postgresql/temp_bytes_written_count`: Total amount of data (in bytes) written to temporary files by the queries per database. `cloudsql_database`. `database`, `project_id`, `database_id`.\n26. `cloudsql.googleapis.com/database/postgresql/temp_files_written_count`: Total number of temporary files used for writing data while performing algorithms such as join and sort. `cloudsql_database`. `database`, `project_id`, `database_id`.\n" + restore_backup: + kind: cloud-sql-restore-backup + source: cloud-sql-admin-source + list_instances: + kind: cloud-sql-list-instances + source: cloud-sql-admin-source + create_database: + kind: cloud-sql-create-database + source: cloud-sql-admin-source + create_user: + kind: cloud-sql-create-users + source: cloud-sql-admin-source + get_query_metrics: + kind: cloud-monitoring-query-prometheus + source: cloud-monitoring-source + description: | + Fetches query level cloudmonitoring data (timeseries metrics) for queries running in Postgres instance using a PromQL query. Take projectID and instanceID from the user for which the metrics timeseries data needs to be fetched. + To use this tool, you must provide the Google Cloud `projectId` and a PromQL `query`. - list_database_stats: - kind: postgres-list-database-stats - source: cloudsql-pg-source + Generate PromQL `query` for Postgres query metrics. Use the provided metrics and rules to construct queries, Get the labels like `instance_id`, `query_hash` from user intent. If query_hash is provided then use the per_query metrics. Query hash and query id are same. - list_roles: - kind: postgres-list-roles - source: cloudsql-pg-source + Defaults: + 1. Interval: Use a default interval of `5m` for `_over_time` aggregation functions unless a different window is specified by the user. - list_stored_procedure: - kind: postgres-list-stored-procedure - source: cloudsql-pg-source + PromQL Query Examples: + 1. Basic Time Series: `avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m])` + 2. Top K: `topk(30, avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 3. Mean: `avg(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 4. Minimum: `min(min_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 5. Maximum: `max(max_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 6. Sum: `sum(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 7. Count streams: `count(avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + 8. Percentile with groupby on resource_id, database: `quantile by ("resource_id","database")(0.99,avg_over_time({"__name__"="cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time","monitored_resource"="cloudsql_instance_database","project_id"="my-projectId","resource_id"="my-projectId:my-instanceId"}[5m]))` + Available Metrics List: metricname. description. monitored resource. labels. resource_id label format is `project_id:instance_id` which is actually instance id only. aggregate is the aggregated values for all query stats, Use aggregate metrics if query id is not provided. For perquery metrics do not fetch querystring unless specified by user specifically. Have the aggregation on query hash to avoid fetching the querystring. Do not use latency metrics for anything. + 1. `cloudsql.googleapis.com/database/postgresql/insights/aggregate/latencies`: Aggregated query latency distribution. `cloudsql_instance_database`. `user`, `client_addr`, `project_id`, `resource_id`. + 2. `cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time`: Accumulated aggregated query execution time since the last sample. `cloudsql_instance_database`. `user`, `client_addr`, `project_id`, `resource_id`. + 3. `cloudsql.googleapis.com/database/postgresql/insights/aggregate/io_time`: Accumulated aggregated IO time since the last sample. `cloudsql_instance_database`. `user`, `client_addr`, `io_type`, `project_id`, `resource_id`. + 4. `cloudsql.googleapis.com/database/postgresql/insights/aggregate/lock_time`: Accumulated aggregated lock wait time since the last sample. `cloudsql_instance_database`. `user`, `client_addr`, `lock_type`, `project_id`, `resource_id`. + 5. `cloudsql.googleapis.com/database/postgresql/insights/aggregate/row_count`: Aggregated number of retrieved or affected rows since the last sample. `cloudsql_instance_database`. `user`, `client_addr`, `project_id`, `resource_id`. + 6. `cloudsql.googleapis.com/database/postgresql/insights/aggregate/shared_blk_access_count`: Aggregated shared blocks accessed by statement execution. `cloudsql_instance_database`. `user`, `client_addr`, `access_type`, `project_id`, `resource_id`. + 7. `cloudsql.googleapis.com/database/postgresql/insights/perquery/latencies`: Per query latency distribution. `cloudsql_instance_database`. `user`, `client_addr`, `querystring`, `query_hash`, `project_id`, `resource_id`. + 8. `cloudsql.googleapis.com/database/postgresql/insights/perquery/execution_time`: Accumulated execution times per user per database per query. `cloudsql_instance_database`. `user`, `client_addr`, `querystring`, `query_hash`, `project_id`, `resource_id`. + 9. `cloudsql.googleapis.com/database/postgresql/insights/perquery/io_time`: Accumulated IO time since the last sample per query. `cloudsql_instance_database`. `user`, `client_addr`, `io_type`, `querystring`, `query_hash`, `project_id`, `resource_id`. + 10. `cloudsql.googleapis.com/database/postgresql/insights/perquery/lock_time`: Accumulated lock wait time since the last sample per query. `cloudsql_instance_database`. `user`, `client_addr`, `lock_type`, `querystring`, `query_hash`, `project_id`, `resource_id`. + 11. `cloudsql.googleapis.com/database/postgresql/insights/perquery/row_count`: The number of retrieved or affected rows since the last sample per query. `cloudsql_instance_database`. `user`, `client_addr`, `querystring`, `query_hash`, `project_id`, `resource_id`. + 12. `cloudsql.googleapis.com/database/postgresql/insights/perquery/shared_blk_access_count`: Shared blocks accessed by statement execution per query. `cloudsql_instance_database`. `user`, `client_addr`, `access_type`, `querystring`, `query_hash`, `project_id`, `resource_id`. + 13. `cloudsql.googleapis.com/database/postgresql/insights/pertag/latencies`: Query latency distribution. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `project_id`, `resource_id`. + 14. `cloudsql.googleapis.com/database/postgresql/insights/pertag/execution_time`: Accumulated execution times since the last sample. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `project_id`, `resource_id`. + 15. `cloudsql.googleapis.com/database/postgresql/insights/pertag/io_time`: Accumulated IO time since the last sample per tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `io_type`, `tag_hash`, `project_id`, `resource_id`. + 16. `cloudsql.googleapis.com/database/postgresql/insights/pertag/lock_time`: Accumulated lock wait time since the last sample per tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `lock_type`, `tag_hash`, `project_id`, `resource_id`. + 17. `cloudsql.googleapis.com/database/postgresql/insights/pertag/shared_blk_access_count`: Shared blocks accessed by statement execution per tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `access_type`, `tag_hash`, `project_id`, `resource_id`. + 18. `cloudsql.googleapis.com/database/postgresql/insights/pertag/row_count`: The number of retrieved or affected rows since the last sample per tag. `cloudsql_instance_database`. `user`, `client_addr`, `action`, `application`, `controller`, `db_driver`, `framework`, `route`, `tag_hash`, `project_id`, `resource_id`. + clone_instance: + kind: cloud-sql-clone-instance + source: cloud-sql-admin-source + get_instance: + kind: cloud-sql-get-instance + source: cloud-sql-admin-source toolsets: - cloud_sql_postgres_database_tools: - - execute_sql - - list_tables - - list_active_queries - - list_available_extensions - - list_installed_extensions - - list_autovacuum_configurations - - list_memory_configurations - - list_top_bloated_tables - - list_replication_slots - - list_invalid_indexes - - get_query_plan - - list_views - - list_schemas - - database_overview - - list_triggers - - list_indexes - - list_sequences - - long_running_transactions - - list_locks - - replication_stats - - list_query_stats - - get_column_cardinality - - list_publication_tables - - list_tablespaces - - list_pg_settings - - list_database_stats - - list_roles - - list_table_stats - - list_stored_procedure + admin: + - create_instance + - get_instance + - list_instances + - create_database + - list_databases + - create_user + - wait_for_operation + - clone_instance + lifecycle: + - create_backup + - restore_backup + - postgres_upgrade_precheck + - wait_for_operation + - database_overview + - get_instance + - list_instances + data: + - execute_sql + - list_tables + - list_views + - list_schemas + - list_triggers + - list_indexes + - list_sequences + - list_stored_procedure + monitor: + - get_system_metrics + - get_query_metrics + - list_query_stats + - get_query_plan + - list_database_stats + - list_active_queries + - long_running_transactions + - list_locks + health: + - list_top_bloated_tables + - list_invalid_indexes + - list_table_stats + - get_column_cardinality + - list_autovacuum_configurations + - list_tablespaces + - database_overview + - list_pg_settings + view-config: + - list_available_extensions + - list_installed_extensions + - list_memory_configurations + - list_pg_settings + - database_overview + - get_instance + replication: + - replication_stats + - list_replication_slots + - list_publication_tables + - list_roles + - list_pg_settings + - database_overview