调整日志等级
This commit is contained in:
		| @@ -177,13 +177,13 @@ func (ps *PostgresStorage) creatingHyperTable() error { | ||||
| 	for _, table := range tablesToConvert { | ||||
| 		tableName := table.model.TableName() | ||||
| 		chunkInterval := "1 days" // 统一设置为1天 | ||||
| 		ps.logger.Infow("准备将表转换为超表", "table", tableName, "chunk_interval", chunkInterval) | ||||
| 		ps.logger.Debugw("准备将表转换为超表", "table", tableName, "chunk_interval", chunkInterval) | ||||
| 		sql := fmt.Sprintf("SELECT create_hypertable('%s', '%s', chunk_time_interval => INTERVAL '%s', if_not_exists => TRUE);", tableName, table.timeColumn, chunkInterval) | ||||
| 		if err := ps.db.Exec(sql).Error; err != nil { | ||||
| 			ps.logger.Errorw("转换为超表失败", "table", tableName, "error", err) | ||||
| 			return fmt.Errorf("将 %s 转换为超表失败: %w", tableName, err) | ||||
| 		} | ||||
| 		ps.logger.Infow("成功将表转换为超表 (或已转换)", "table", tableName) | ||||
| 		ps.logger.Debugw("成功将表转换为超表 (或已转换)", "table", tableName) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @@ -220,22 +220,23 @@ func (ps *PostgresStorage) applyCompressionPolicies() error { | ||||
| 		compressAfter := "3 days" // 统一设置为2天后(即进入第3天)开始压缩 | ||||
|  | ||||
| 		// 1. 开启表的压缩设置,并指定分段列 | ||||
| 		ps.logger.Infow("为表启用压缩设置", "table", tableName, "segment_by", policy.segmentColumn) | ||||
| 		ps.logger.Debugw("为表启用压缩设置", "table", tableName, "segment_by", policy.segmentColumn) | ||||
| 		// 使用 + 而非Sprintf以规避goland静态检查报错 | ||||
| 		alterSQL := "ALTER TABLE" + " " + tableName + " SET (timescaledb.compress, timescaledb.compress_segmentby = '" + policy.segmentColumn + "');" | ||||
| 		if err := ps.db.Exec(alterSQL).Error; err != nil { | ||||
| 			// 忽略错误,因为这个设置可能是不可变的,重复执行会报错 | ||||
| 			ps.logger.Warnw("启用压缩设置时遇到问题 (可能已设置,可忽略)", "table", tableName, "error", err) | ||||
| 		} | ||||
| 		ps.logger.Debugw("成功为表启用压缩设置 (或已启用)", "table", tableName) | ||||
|  | ||||
| 		// 2. 添加压缩策略 | ||||
| 		ps.logger.Infow("为表添加压缩策略", "table", tableName, "compress_after", compressAfter) | ||||
| 		ps.logger.Debugw("为表添加压缩策略", "table", tableName, "compress_after", compressAfter) | ||||
| 		policySQL := fmt.Sprintf("SELECT add_compression_policy('%s', INTERVAL '%s', if_not_exists => TRUE);", tableName, compressAfter) | ||||
| 		if err := ps.db.Exec(policySQL).Error; err != nil { | ||||
| 			ps.logger.Errorw("添加压缩策略失败", "table", tableName, "error", err) | ||||
| 			return fmt.Errorf("为 %s 添加压缩策略失败: %w", tableName, err) | ||||
| 		} | ||||
| 		ps.logger.Infow("成功为表添加压缩策略 (或已存在)", "table", tableName) | ||||
| 		ps.logger.Debugw("成功为表添加压缩策略 (或已存在)", "table", tableName) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @@ -247,22 +248,22 @@ func (ps *PostgresStorage) creatingIndex() error { | ||||
| 	// 如果索引已存在,此命令不会报错 | ||||
|  | ||||
| 	// 为 sensor_data 表的 data 字段创建 GIN 索引 | ||||
| 	ps.logger.Info("正在为 sensor_data 表的 data 字段创建 GIN 索引") | ||||
| 	ps.logger.Debug("正在为 sensor_data 表的 data 字段创建 GIN 索引") | ||||
| 	ginSensorDataIndexSQL := "CREATE INDEX IF NOT EXISTS idx_sensor_data_data_gin ON sensor_data USING GIN (data);" | ||||
| 	if err := ps.db.Exec(ginSensorDataIndexSQL).Error; err != nil { | ||||
| 		ps.logger.Errorw("为 sensor_data 的 data 字段创建 GIN 索引失败", "error", err) | ||||
| 		return fmt.Errorf("为 sensor_data 的 data 字段创建 GIN 索引失败: %w", err) | ||||
| 	} | ||||
| 	ps.logger.Info("成功为 sensor_data 的 data 字段创建 GIN 索引 (或已存在)") | ||||
| 	ps.logger.Debug("成功为 sensor_data 的 data 字段创建 GIN 索引 (或已存在)") | ||||
|  | ||||
| 	// 为 tasks.parameters 创建 GIN 索引 | ||||
| 	ps.logger.Info("正在为 tasks 表的 parameters 字段创建 GIN 索引") | ||||
| 	ps.logger.Debug("正在为 tasks 表的 parameters 字段创建 GIN 索引") | ||||
| 	taskGinIndexSQL := "CREATE INDEX IF NOT EXISTS idx_tasks_parameters_gin ON tasks USING GIN (parameters);" | ||||
| 	if err := ps.db.Exec(taskGinIndexSQL).Error; err != nil { | ||||
| 		ps.logger.Errorw("为 tasks 的 parameters 字段创建 GIN 索引失败", "error", err) | ||||
| 		return fmt.Errorf("为 tasks 的 parameters 字段创建 GIN 索引失败: %w", err) | ||||
| 	} | ||||
| 	ps.logger.Info("成功为 tasks 的 parameters 字段创建 GIN 索引 (或已存在)") | ||||
| 	ps.logger.Debug("成功为 tasks 的 parameters 字段创建 GIN 索引 (或已存在)") | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user