diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.refactorlog b/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.refactorlog index 8b550bd7..b61d5f9c 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.refactorlog +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.refactorlog @@ -2926,4 +2926,11 @@ + + + + + + + \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.sqlproj b/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.sqlproj index 3126dd38..adfa4095 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.sqlproj +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.sqlproj @@ -93,53 +93,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - @@ -163,7 +177,6 @@ - @@ -190,7 +203,6 @@ - @@ -198,12 +210,10 @@ - - @@ -215,9 +225,7 @@ - - @@ -270,7 +278,6 @@ - @@ -286,11 +293,9 @@ - - @@ -301,15 +306,12 @@ - - - @@ -318,7 +320,6 @@ - @@ -328,7 +329,6 @@ - @@ -336,14 +336,12 @@ - - @@ -370,6 +368,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/SetDacVersion.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/SetDacVersion.sql index a10e0d3f..62a157e7 100644 Binary files a/SqlWatch.Monitor/Project.SqlWatch.Database/SetDacVersion.sql and b/SqlWatch.Monitor/Project.SqlWatch.Database/SetDacVersion.sql differ diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_enable_compression_sqlwatch_indexes.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_enable_compression_sqlwatch_indexes.sql deleted file mode 100644 index 77b1785c..00000000 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_enable_compression_sqlwatch_indexes.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE PROCEDURE [dbo].[usp_sqlwatch_config_enable_compression_sqlwatch_indexes] -as - -declare @sql varchar(max) -set @sql = '' - -select @sql = @sql + 'alter index [' + idx.name +'] on ' + sh.name + '.' + tbl.name + ' rebuild partition = all with (data_compression = page); -' -from sys.indexes idx -inner join sys.tables tbl - on tbl.object_id = idx.object_id -inner join sys.schemas sh - on tbl.schema_id = sh.schema_id -where tbl.name like 'sqlwatch%' -and idx.name is not null - -print @sql -exec (@sql) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_enable_compression_sqlwatch_tables.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_enable_compression_sqlwatch_tables.sql deleted file mode 100644 index 7186e811..00000000 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Procedures/usp_sqlwatch_config_enable_compression_sqlwatch_tables.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE PROCEDURE [dbo].[usp_sqlwatch_config_enable_compression_sqlwatch_tables] -as - -declare @sql varchar(max) -set @sql = '' -select @sql = @sql + 'alter table ' + TABLE_SCHEMA + '.' + TABLE_NAME + ' rebuild partition = all with (data_compression = page); -' -from INFORMATION_SCHEMA.TABLES -WHERE TABLE_NAME LIKE '%sqlwatch_%' -and TABLE_TYPE = 'BASE TABLE' - -print @sql -exec (@sql) - diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/idx_sqlwatch_logger_agent_job_history_run_date.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/idx_sqlwatch_logger_agent_job_history_run_date.sql new file mode 100644 index 00000000..9c77e29b --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/idx_sqlwatch_logger_agent_job_history_run_date.sql @@ -0,0 +1,3 @@ +create nonclustered index idx_sqlwatch_logger_agent_job_history_run_date + on dbo.sqlwatch_logger_agent_job_history (run_date) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/idx_sqlwatch_logger_agent_job_history_run_date_utc.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/idx_sqlwatch_logger_agent_job_history_run_date_utc.sql new file mode 100644 index 00000000..44a400c9 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/idx_sqlwatch_logger_agent_job_history_run_date_utc.sql @@ -0,0 +1,3 @@ +create nonclustered index idx_sqlwatch_logger_agent_job_history_run_date_utc + on dbo.sqlwatch_logger_agent_job_history (run_date_utc) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/pk_sqlwatch_logger_agent_job_history.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/pk_sqlwatch_logger_agent_job_history.sql new file mode 100644 index 00000000..c4b5bce8 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/pk_sqlwatch_logger_agent_job_history.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_agent_job_history] + ADD CONSTRAINT [pk_sqlwatch_logger_agent_job_history] + PRIMARY KEY CLUSTERED ([sql_instance], [snapshot_time], [sqlwatch_job_id], [sqlwatch_job_step_id], [sysjobhistory_instance_id], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/sqlwatch_logger_agent_job_history.sql similarity index 65% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/sqlwatch_logger_agent_job_history.sql index c02d8a83..79e1b9cd 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_agent_job_history/sqlwatch_logger_agent_job_history.sql @@ -1,8 +1,8 @@ CREATE TABLE [dbo].[sqlwatch_logger_agent_job_history] ( [sql_instance] varchar(32) not null, - [sqlwatch_job_id] smallint, - [sqlwatch_job_step_id] int, + [sqlwatch_job_id] smallint not null, + [sqlwatch_job_step_id] int not null, [sysjobhistory_instance_id] int not null, [sysjobhistory_step_id] int not null, [run_duration_s] real not null, @@ -11,20 +11,9 @@ [snapshot_time] datetime2(0) not null, [snapshot_type_id] tinyint not null, [run_date_utc] datetime not null constraint df_sqlwatch_logger_agent_job_history_run_date_utc default ('1970-01-01'), - constraint pk_sqlwatch_logger_agent_job_history primary key ( - [sql_instance], [snapshot_time], [sqlwatch_job_id], [sqlwatch_job_step_id], [sysjobhistory_instance_id], [snapshot_type_id] - ), constraint fk_sqlwatch_logger_agent_job_history_job foreign key ([sql_instance],[sqlwatch_job_id],[sqlwatch_job_step_id]) references [dbo].[sqlwatch_meta_agent_job_step] (sql_instance, [sqlwatch_job_id], sqlwatch_job_step_id) on delete cascade, constraint fk_sqlwatch_logger_agent_job_history_snapshot_header foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time], [sql_instance], [snapshot_type_id]) on delete cascade on update cascade ) -go - -create nonclustered index idx_sqlwatch_logger_agent_job_history_run_date - on dbo.sqlwatch_logger_agent_job_history (run_date) -go - -create nonclustered index idx_sqlwatch_logger_agent_job_history_run_date_utc - on dbo.sqlwatch_logger_agent_job_history (run_date_utc) go \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_1.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_1.sql new file mode 100644 index 00000000..14ab8df7 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_1.sql @@ -0,0 +1,4 @@ +create nonclustered index idx_sqlwatch_logger_check_1 + on [dbo].[sqlwatch_logger_check] ([status_change]) + include ([check_status]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_2.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_2.sql new file mode 100644 index 00000000..345cd95f --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_2.sql @@ -0,0 +1,4 @@ +create nonclustered index idx_sqlwatch_logger_check_2 + on [dbo].[sqlwatch_logger_check] ([sql_instance],[check_id]) + include ([snapshot_time],[snapshot_type_id]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_3.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_3.sql new file mode 100644 index 00000000..652e36b8 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/idx_sqlwatch_logger_check_3.sql @@ -0,0 +1,4 @@ +create nonclustered index idx_sqlwatch_logger_check_3 + on [dbo].[sqlwatch_logger_check] ([check_id]) + include ([sql_instance],[snapshot_time],[snapshot_type_id],[check_value]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/pk_sqlwatch_logger_check.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/pk_sqlwatch_logger_check.sql new file mode 100644 index 00000000..2cee9562 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/pk_sqlwatch_logger_check.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_check] + ADD CONSTRAINT [pk_sqlwatch_logger_check] + PRIMARY KEY CLUSTERED (snapshot_time, sql_instance, check_id, snapshot_type_id) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/sqlwatch_logger_check.sql similarity index 62% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/sqlwatch_logger_check.sql index 53607cb6..60afbd21 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check/sqlwatch_logger_check.sql @@ -12,9 +12,6 @@ [is_flapping] bit, [baseline_threshold] real, - /* primary key */ - constraint pk_sqlwatch_logger_check primary key clustered (snapshot_time, sql_instance, check_id, snapshot_type_id), - /* foreign key to header to process cascade retention */ constraint fk_sqlwatch_logger_check_header foreign key ( [snapshot_time], [sql_instance], [snapshot_type_id] ) references [dbo].[sqlwatch_logger_snapshot_header] ( [snapshot_time], [sql_instance], [snapshot_type_id] ) on delete cascade, @@ -22,19 +19,4 @@ /* foreign key to config check to delete any logger records when the check is deleted */ constraint fk_sqlwatch_meta_check foreign key ( [sql_instance], [check_id] ) references dbo.[sqlwatch_meta_check] ( [sql_instance], [check_id] ) on delete cascade -) -go - -create nonclustered index idx_sqlwatch_logger_check_1 - on [dbo].[sqlwatch_logger_check] ([status_change]) - include ([check_status]) -go - -create nonclustered index idx_sqlwatch_logger_check_2 - on [dbo].[sqlwatch_logger_check] ([sql_instance],[check_id]) - include ([snapshot_time],[snapshot_type_id]) -go - -create nonclustered index idx_sqlwatch_logger_check_3 - on [dbo].[sqlwatch_logger_check] ([check_id]) - include ([sql_instance],[snapshot_time],[snapshot_type_id],[check_value]) \ No newline at end of file +) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action/pk_sqlwatch_logger_check_action.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action/pk_sqlwatch_logger_check_action.sql new file mode 100644 index 00000000..b8025a55 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action/pk_sqlwatch_logger_check_action.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_check_action] + ADD CONSTRAINT [pk_sqlwatch_logger_check_action] + PRIMARY KEY clustered ([snapshot_time], [sql_instance], [check_id], [snapshot_type_id], [action_id]) + with (data_compression=page) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action/sqlwatch_logger_check_action.sql similarity index 90% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action/sqlwatch_logger_check_action.sql index 932a2a4b..66387a6e 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_check_action/sqlwatch_logger_check_action.sql @@ -8,9 +8,6 @@ [action_id] smallint not null, [action_attributes] xml, - /* primary key */ - constraint pk_sqlwatch_logger_check_action primary key clustered ([snapshot_time], [sql_instance], [check_id], [snapshot_type_id], [action_id]), - /* foreign key to logger to ensure deletion is applied when the parent record is removed */ --constraint fk_sqlwatch_logger_check_action_logger_check foreign key ( -- snapshot_time, sql_instance, check_id, snapshot_type_id diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database/PK_logger_disk_util_database.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database/PK_logger_disk_util_database.sql new file mode 100644 index 00000000..dba9b80a --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database/PK_logger_disk_util_database.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_disk_utilisation_database] + ADD CONSTRAINT [PK_logger_disk_util_database] + PRIMARY KEY CLUSTERED ([snapshot_time],[snapshot_type_id],[sql_instance], [sqlwatch_database_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database/sqlwatch_logger_disk_utilisation_database.sql similarity index 87% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database/sqlwatch_logger_disk_utilisation_database.sql index 667dc157..9b57b3f3 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_database/sqlwatch_logger_disk_utilisation_database.sql @@ -9,8 +9,8 @@ [unused_bytes] bigint, [log_size_total_bytes] bigint, [log_size_used_bytes] bigint, - [snapshot_time] datetime2(0), - [snapshot_type_id] tinyint, + [snapshot_time] datetime2(0) not null, + [snapshot_type_id] tinyint not null, [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_disk_utilisation_database_sql_instance default (@@SERVERNAME), --https://github.com/marcingminski/sqlwatch/issues/165 @@ -21,8 +21,6 @@ [internal_object_reserved_page_count] bigint null, [mixed_extent_page_count] bigint null, - constraint PK_logger_disk_util_database - primary key clustered ([snapshot_time],[snapshot_type_id],[sql_instance], [sqlwatch_database_id]), constraint FK_logger_disk_util_database_database foreign key ([sql_instance],[sqlwatch_database_id]) references [dbo].[sqlwatch_meta_database] ([sql_instance],[sqlwatch_database_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table/pk_sqlwatch_logger_disk_utilisation_table.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table/pk_sqlwatch_logger_disk_utilisation_table.sql new file mode 100644 index 00000000..816b6c6d --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table/pk_sqlwatch_logger_disk_utilisation_table.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_disk_utilisation_table] + ADD CONSTRAINT [pk_sqlwatch_logger_disk_utilisation_table] + PRIMARY KEY CLUSTERED ([snapshot_time], [sql_instance], [snapshot_type_id], sqlwatch_database_id, sqlwatch_table_id) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table/sqlwatch_logger_disk_utilisation_table.sql similarity index 86% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table/sqlwatch_logger_disk_utilisation_table.sql index 4aa61b31..d2688aba 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_table/sqlwatch_logger_disk_utilisation_table.sql @@ -15,10 +15,6 @@ total_pages_delta real, used_pages_delta real, - constraint pk_sqlwatch_logger_disk_utilisation_table primary key clustered ( - [snapshot_time], [sql_instance], [snapshot_type_id], sqlwatch_database_id, sqlwatch_table_id - ), - constraint fk_sqlwatch_logger_disk_utilisation_table_header foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references dbo.sqlwatch_logger_snapshot_header ([snapshot_time], [sql_instance], [snapshot_type_id]) on delete cascade, diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume/PK_disk_util_vol.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume/PK_disk_util_vol.sql new file mode 100644 index 00000000..501513cd --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume/PK_disk_util_vol.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_disk_utilisation_volume] + ADD CONSTRAINT [PK_disk_util_vol] + PRIMARY KEY CLUSTERED (snapshot_time, [snapshot_type_id], [sql_instance], [sqlwatch_volume_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume/sqlwatch_logger_disk_utilisation_volume.sql similarity index 83% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume/sqlwatch_logger_disk_utilisation_volume.sql index 4f481adb..5d878767 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_disk_utilisation_volume/sqlwatch_logger_disk_utilisation_volume.sql @@ -4,11 +4,8 @@ [volume_free_space_bytes] bigint, [volume_total_space_bytes] bigint, [snapshot_time] datetime2(0) not null, - [snapshot_type_id] tinyint, + [snapshot_type_id] tinyint not null, [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_disk_utilisation_volume_sql_instance default (@@SERVERNAME), - constraint PK_disk_util_vol primary key clustered ( - snapshot_time, [snapshot_type_id], [sql_instance], [sqlwatch_volume_id] - ), constraint fk_sqlwatch_logger_disk_utilisation_volume_id foreign key ([sql_instance], [sqlwatch_volume_id]) references [dbo].[sqlwatch_meta_os_volume] ([sql_instance], [sqlwatch_volume_id]) on delete cascade, constraint FK_disk_util_vol_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade ) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats/pk_sqlwatch_logger_dm_exec_requests.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats/pk_sqlwatch_logger_dm_exec_requests.sql new file mode 100644 index 00000000..b97940c6 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats/pk_sqlwatch_logger_dm_exec_requests.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_dm_exec_requests_stats] + ADD CONSTRAINT [pk_sqlwatch_logger_dm_exec_requests] + primary key clustered ([type], snapshot_time, sql_instance, snapshot_type_id) + with (data_compression=page) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats/sqlwatch_logger_dm_exec_requests_stats.sql similarity index 84% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats/sqlwatch_logger_dm_exec_requests_stats.sql index efc65794..6fee3b3d 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_requests_stats/sqlwatch_logger_dm_exec_requests_stats.sql @@ -14,9 +14,6 @@ waiting_tasks real null, waiting_tasks_wait_duration_ms real null, - constraint pk_sqlwatch_logger_dm_exec_requests - primary key clustered ([type], snapshot_time, sql_instance, snapshot_type_id), - constraint fk_sqlwatch_logger_dm_exec_requests_snapshot_header foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time], [sql_instance], [snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats/pk_sqlwatch_logger_dm_exec_sessions.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats/pk_sqlwatch_logger_dm_exec_sessions.sql new file mode 100644 index 00000000..20f5e9d3 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats/pk_sqlwatch_logger_dm_exec_sessions.sql @@ -0,0 +1,10 @@ +ALTER TABLE [dbo].[sqlwatch_logger_dm_exec_sessions_stats] + ADD CONSTRAINT [pk_sqlwatch_logger_dm_exec_sessions] + PRIMARY KEY clustered + ( + [type] ASC, + [snapshot_time] ASC, + [snapshot_type_id] ASC, + [sql_instance] ASC + ) + with (data_compression=page) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats/sqlwatch_logger_dm_exec_sessions_stats.sql similarity index 79% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats/sqlwatch_logger_dm_exec_sessions_stats.sql index db209669..ed734075 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_dm_exec_sessions_stats/sqlwatch_logger_dm_exec_sessions_stats.sql @@ -12,14 +12,6 @@ reads real not null, writes real not null, - constraint pk_sqlwatch_logger_dm_exec_sessions primary key clustered - ( - [type] ASC, - [snapshot_time] ASC, - [snapshot_type_id] ASC, - [sql_instance] ASC - ), - constraint [fk_sqlwatch_logger_dm_exec_sessions_snapshot_header] foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header] ([snapshot_time], [sql_instance], [snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/idx_sqlwatch_logger_errorlog_1.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/idx_sqlwatch_logger_errorlog_1.sql new file mode 100644 index 00000000..95963e8f --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/idx_sqlwatch_logger_errorlog_1.sql @@ -0,0 +1,4 @@ +create nonclustered index idx_sqlwatch_logger_errorlog_1 on [dbo].[sqlwatch_logger_errorlog] ( + keyword_id, log_type_id, sql_instance + ) include (log_date) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/pk_sqlwatch_logger_errorlog.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/pk_sqlwatch_logger_errorlog.sql new file mode 100644 index 00000000..111389d4 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/pk_sqlwatch_logger_errorlog.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_errorlog] + ADD CONSTRAINT [pk_sqlwatch_logger_errorlog] + PRIMARY KEY CLUSTERED (snapshot_time, log_date, attribute_id, errorlog_text_id, keyword_id, log_type_id, snapshot_type_id) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/sqlwatch_logger_errorlog.sql similarity index 58% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/sqlwatch_logger_errorlog.sql index 11dabdca..cc2ca1fc 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_errorlog/sqlwatch_logger_errorlog.sql @@ -1,25 +1,19 @@ CREATE TABLE [dbo].[sqlwatch_logger_errorlog] ( sql_instance varchar(32) not null default @@SERVERNAME, - log_date datetime, - attribute_id smallint, - errorlog_text_id int, - keyword_id smallint, - log_type_id int, - snapshot_time datetime2(0), - snapshot_type_id tinyint, + log_date datetime not null, + attribute_id smallint not null, + errorlog_text_id int not null, + keyword_id smallint not null, + log_type_id int not null, + snapshot_time datetime2(0) not null, + snapshot_type_id tinyint not null, record_count real --there could be many entries of the same type at the same time in the error log (especially failed logins) - constraint pk_sqlwatch_logger_errorlog primary key clustered ( - snapshot_time, log_date, attribute_id, errorlog_text_id, keyword_id, log_type_id, snapshot_type_id - ), + constraint fk_sqlwatch_logger_errorlog_keyword foreign key (sql_instance, keyword_id, log_type_id) references dbo.sqlwatch_meta_errorlog_keyword (sql_instance, keyword_id, log_type_id) on delete cascade, constraint fk_sqlwatch_logger_errorlog_snapshot foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references dbo.sqlwatch_logger_snapshot_header ([snapshot_time], [sql_instance], [snapshot_type_id]) on delete cascade ); -go - -create nonclustered index idx_sqlwatch_logger_errorlog_1 on [dbo].[sqlwatch_logger_errorlog] ( - keyword_id, log_type_id, sql_instance - ) include (log_date); \ No newline at end of file +go \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states/pk_sqlwatch_logger_hadr_database_replica_states.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states/pk_sqlwatch_logger_hadr_database_replica_states.sql new file mode 100644 index 00000000..1b922808 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states/pk_sqlwatch_logger_hadr_database_replica_states.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_hadr_database_replica_states] + ADD CONSTRAINT [pk_sqlwatch_logger_hadr_database_replica_states] + PRIMARY KEY ([hadr_group_name],[replica_server_name],[database_name],[snapshot_time],[sql_instance],[snapshot_type_id]) + with (data_compression=page) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states/sqlwatch_logger_hadr_database_replica_states.sql similarity index 80% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states/sqlwatch_logger_hadr_database_replica_states.sql index 9363465b..aba12f1c 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_hadr_database_replica_states/sqlwatch_logger_hadr_database_replica_states.sql @@ -1,11 +1,11 @@ CREATE TABLE [dbo].[sqlwatch_logger_hadr_database_replica_states] ( - [hadr_group_name] nvarchar(128), - [replica_server_name] nvarchar(128), + [hadr_group_name] nvarchar(128) not null, + [replica_server_name] nvarchar(128) not null, [availability_mode] tinyint, [failover_mode] tinyint, --[sqlwatch_database_id] smallint null, - [database_name] nvarchar(128), + [database_name] nvarchar(128) not null, [is_local] bit, [is_primary_replica] bit, [synchronization_state] tinyint, @@ -25,9 +25,6 @@ [snapshot_time] datetime2(0) not null, [sql_instance] varchar(32) not null , - constraint pk_sqlwatch_logger_hadr_database_replica_states - primary key ([hadr_group_name],[replica_server_name],[database_name],[snapshot_time],[sql_instance],[snapshot_type_id]), - constraint fk_sqlwatch_logger_hadr_database_replica_states_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_histogram/pk_logger_index_histogram.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_histogram/pk_logger_index_histogram.sql new file mode 100644 index 00000000..1a323ac6 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_histogram/pk_logger_index_histogram.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_index_histogram] + ADD CONSTRAINT [pk_logger_index_histogram] + PRIMARY KEY CLUSTERED ([snapshot_time],[sql_instance], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_index_id], [sqlwatch_stat_range_id], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats_histogram.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_histogram/sqlwatch_logger_index_usage_stats_histogram.sql similarity index 88% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats_histogram.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_histogram/sqlwatch_logger_index_usage_stats_histogram.sql index 91213d58..d43832f8 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats_histogram.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_histogram/sqlwatch_logger_index_usage_stats_histogram.sql @@ -12,7 +12,6 @@ [snapshot_type_id] [tinyint] NOT NULL, [collection_time] datetime, [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_index_usage_stats_histogram_sql_instance default (@@SERVERNAME), - constraint [pk_logger_index_histogram] primary key nonclustered ([snapshot_time],[sql_instance], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_index_id], [sqlwatch_stat_range_id], [snapshot_type_id]), constraint [fk_sqlwatch_logger_index_histogram_index] foreign key ([sql_instance], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_index_id]) references [dbo].[sqlwatch_meta_index] ([sql_instance], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_index_id]) on delete cascade, --constraint [fk_logger_index_stats_histogram_database] foreign key ([sql_instance], [sqlwatch_database_id]) references [dbo].[sqlwatch_meta_database] ([sql_instance], [sqlwatch_database_id]) on delete cascade on update cascade, diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats/pk_logger_missing_indexes.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats/pk_logger_missing_indexes.sql new file mode 100644 index 00000000..9bb130ce --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats/pk_logger_missing_indexes.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_index_missing_stats] + ADD CONSTRAINT [pk_logger_missing_indexes] + PRIMARY KEY CLUSTERED ([sql_instance], [snapshot_time], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_missing_index_id], [sqlwatch_missing_index_stats_id], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats/sqlwatch_logger_index_missing_stats.sql similarity index 83% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats/sqlwatch_logger_index_missing_stats.sql index 802e2c43..82d4ae47 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_missing_stats/sqlwatch_logger_index_missing_stats.sql @@ -4,18 +4,16 @@ [sqlwatch_table_id] int not null, [sqlwatch_missing_index_id] int not null, [sqlwatch_missing_index_stats_id] int identity(1,1), - [snapshot_time] datetime2(0), + [snapshot_time] datetime2(0) not null, [last_user_seek] datetime, [unique_compiles] bigint, [user_seeks] bigint, [user_scans] bigint, [avg_total_user_cost] float, [avg_user_impact] float, - [snapshot_type_id] tinyint, + [snapshot_type_id] tinyint not null, [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_index_missing_stats_sql_instance default (@@SERVERNAME), - constraint pk_logger_missing_indexes primary key clustered ( - [sql_instance], [snapshot_time], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_missing_index_id], [sqlwatch_missing_index_stats_id], [snapshot_type_id] - ), + --constraint fk_logger_missing_indexes_database -- foreign key ([sql_instance], [sqlwatch_database_id]) -- references [dbo].[sqlwatch_meta_database] ([sql_instance], [sqlwatch_database_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats/pk_index_usage_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats/pk_index_usage_stats.sql new file mode 100644 index 00000000..e7cf1272 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats/pk_index_usage_stats.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_index_usage_stats] + ADD CONSTRAINT [pk_index_usage_stats] + PRIMARY KEY clustered ([snapshot_time], [sql_instance], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_index_id], [partition_id], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats/sqlwatch_logger_index_usage_stats.sql similarity index 92% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats/sqlwatch_logger_index_usage_stats.sql index b644c9d8..6f53bb62 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_index_usage_stats/sqlwatch_logger_index_usage_stats.sql @@ -27,7 +27,6 @@ [user_lookups_delta] real null, [partition_count] real null, [partition_count_delta] real null, - constraint [pk_index_usage_stats] primary key clustered ([snapshot_time], [sql_instance], [sqlwatch_database_id], [sqlwatch_table_id], [sqlwatch_index_id], [partition_id], [snapshot_type_id]), --constraint [fk_index_usage_stats_database] foreign key ([sql_instance], [sqlwatch_database_id]) references [dbo].[sqlwatch_meta_database] ([sql_instance], [sqlwatch_database_id]) on delete cascade on update cascade, --constraint fk_sqlwatch_logger_index_usage_stats_table foreign key ([sql_instance],[sqlwatch_database_id],[sqlwatch_table_id]) -- references [dbo].[sqlwatch_meta_table] ([sql_instance],[sqlwatch_database_id],[sqlwatch_table_id]) on delete cascade, diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats/pk_sql_perf_mon_file_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats/pk_sql_perf_mon_file_stats.sql new file mode 100644 index 00000000..fcac7f89 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats/pk_sql_perf_mon_file_stats.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_file_stats] + ADD CONSTRAINT [pk_sql_perf_mon_file_stats] + PRIMARY KEY CLUSTERED ([sql_instance], [snapshot_time], [sqlwatch_database_id], [sqlwatch_master_file_id], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats/sqlwatch_logger_perf_file_stats.sql similarity index 92% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats/sqlwatch_logger_perf_file_stats.sql index 40ae4bb6..01d1b2da 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_file_stats/sqlwatch_logger_perf_file_stats.sql @@ -24,10 +24,7 @@ [delta_seconds] int null, constraint fk_sqlwatch_logger_perf_file_stats_master_file foreign key ([sql_instance], [sqlwatch_database_id], [sqlwatch_master_file_id]) references [dbo].[sqlwatch_meta_master_file] ([sql_instance], [sqlwatch_database_id], [sqlwatch_master_file_id]) on delete cascade, - constraint fk_sql_perf_mon_file_stats_snapshot_header foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time], [sql_instance], [snapshot_type_id]) on delete cascade on update cascade, - constraint pk_sql_perf_mon_file_stats primary key clustered ( - [sql_instance], [snapshot_time], [sqlwatch_database_id], [sqlwatch_master_file_id], [snapshot_type_id] - ) + constraint fk_sql_perf_mon_file_stats_snapshot_header foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time], [sql_instance], [snapshot_type_id]) on delete cascade on update cascade ) go diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks/pk_sql_perf_mon_os_memory_clerks.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks/pk_sql_perf_mon_os_memory_clerks.sql new file mode 100644 index 00000000..194052ec --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks/pk_sql_perf_mon_os_memory_clerks.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_os_memory_clerks] + ADD CONSTRAINT [pk_sql_perf_mon_os_memory_clerks] + PRIMARY KEY CLUSTERED ([snapshot_time], [snapshot_type_id], [sql_instance], [sqlwatch_mem_clerk_id]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks/sqlwatch_logger_perf_os_memory_clerks.sql similarity index 85% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks/sqlwatch_logger_perf_os_memory_clerks.sql index ff48a49f..909dc3e1 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_memory_clerks/sqlwatch_logger_perf_os_memory_clerks.sql @@ -3,15 +3,12 @@ [snapshot_time] datetime2(0) not null, [total_kb] bigint, [allocated_kb] bigint, - [sqlwatch_mem_clerk_id] smallint, + [sqlwatch_mem_clerk_id] smallint not null, [snapshot_type_id] tinyint not null constraint df_sqlwatch_logger_perf_os_memory_clerks_type default (1) , [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_perf_os_memory_clerks_sql_instance default (@@SERVERNAME), constraint fk_sql_perf_mon_os_memory_clerks_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, /* identifying relation */ - constraint [pk_sql_perf_mon_os_memory_clerks] primary key ( - [snapshot_time], [snapshot_type_id], [sql_instance], [sqlwatch_mem_clerk_id] - ), constraint fk_sqlwatch_logger_perf_os_memory_clerks_meta foreign key ([sql_instance], [sqlwatch_mem_clerk_id]) references [dbo].[sqlwatch_meta_memory_clerk] ([sql_instance], [sqlwatch_mem_clerk_id]) on delete cascade ) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/idx_sqlwatch_perf_counters_id_cntrl_values.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/idx_sqlwatch_perf_counters_id_cntrl_values.sql new file mode 100644 index 00000000..dc6df696 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/idx_sqlwatch_perf_counters_id_cntrl_values.sql @@ -0,0 +1,4 @@ +CREATE INDEX [idx_sqlwatch_perf_counters_id_cntrl_values] + ON [dbo].[sqlwatch_logger_perf_os_performance_counters] ([performance_counter_id],[sql_instance]) + INCLUDE ([cntr_value],[cntr_value_calculated]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/pk_sql_perf_mon_perf_counters.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/pk_sql_perf_mon_perf_counters.sql new file mode 100644 index 00000000..aff52c38 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/pk_sql_perf_mon_perf_counters.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_os_performance_counters] + ADD CONSTRAINT [pk_sql_perf_mon_perf_counters] + PRIMARY KEY CLUSTERED ([snapshot_time] asc, [snapshot_type_id],[sql_instance], [performance_counter_id] asc, [instance_name] asc) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/sqlwatch_logger_perf_os_performance_counters.sql similarity index 80% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/sqlwatch_logger_perf_os_performance_counters.sql index 04d7e043..a359ea7a 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_performance_counters/sqlwatch_logger_perf_os_performance_counters.sql @@ -11,7 +11,6 @@ [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_perf_os_performance_counters_sql_instance default (@@SERVERNAME), [cntr_value_calculated] real null, constraint fk_sql_perf_mon_perf_counters_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint [pk_sql_perf_mon_perf_counters] primary key ([snapshot_time] asc, [snapshot_type_id],[sql_instance], [performance_counter_id] asc, [instance_name] asc), constraint fk_sqlwatch_logger_perf_os_performance_counters_meta foreign key ([sql_instance], [performance_counter_id]) references [dbo].[sqlwatch_meta_performance_counter] ([sql_instance], [performance_counter_id]) on delete cascade ) @@ -25,8 +24,4 @@ go --GO --CREATE NONCLUSTERED INDEX idx_sqlwatch_perf_counters_002 --ON [dbo].[sqlwatch_logger_perf_os_performance_counters] ([snapshot_type_id],[sql_instance],[snapshot_time]) ---INCLUDE ([performance_counter_id],[instance_name],[cntr_value],[base_cntr_value]) - -CREATE NONCLUSTERED INDEX idx_sqlwatch_perf_counters_id_cntrl_values -ON [dbo].[sqlwatch_logger_perf_os_performance_counters] ([performance_counter_id],[sql_instance]) -INCLUDE ([cntr_value],[cntr_value_calculated]) +--INCLUDE ([performance_counter_id],[instance_name],[cntr_value],[base_cntr_value]) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory/pk_sql_perf_mon_os_process_memory.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory/pk_sql_perf_mon_os_process_memory.sql new file mode 100644 index 00000000..8c36098e --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory/pk_sql_perf_mon_os_process_memory.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_os_process_memory] + ADD CONSTRAINT [pk_sql_perf_mon_os_process_memory] + PRIMARY KEY CLUSTERED ([snapshot_time], [snapshot_type_id], [sql_instance]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory/sqlwatch_logger_perf_os_process_memory.sql similarity index 92% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory/sqlwatch_logger_perf_os_process_memory.sql index bedf07fc..b5a3d759 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_process_memory/sqlwatch_logger_perf_os_process_memory.sql @@ -16,9 +16,6 @@ [snapshot_type_id] tinyint not null constraint df_sqlwatch_logger_perf_os_process_memory_type default (1) , [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_perf_os_process_memory_sql_instance default (@@SERVERNAME), constraint fk_sql_perf_mon_os_process_memory_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint pk_sql_perf_mon_os_process_memory primary key clustered ( - [snapshot_time], [snapshot_type_id], [sql_instance] - ), constraint fk_sqlwatch_logger_perf_os_process_memory_server foreign key ([sql_instance]) references [dbo].[sqlwatch_meta_server] ([servername]) on delete cascade ) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers/pk_logger_perf_os_schedulers.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers/pk_logger_perf_os_schedulers.sql new file mode 100644 index 00000000..fcc5f183 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers/pk_logger_perf_os_schedulers.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_os_schedulers] + ADD CONSTRAINT [pk_logger_perf_os_schedulers] + PRIMARY KEY ([snapshot_time] ASC, [snapshot_type_id], [sql_instance]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers/sqlwatch_logger_perf_os_schedulers.sql similarity index 91% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers/sqlwatch_logger_perf_os_schedulers.sql index f3cdf93a..88ad92e2 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_schedulers/sqlwatch_logger_perf_os_schedulers.sql @@ -19,12 +19,9 @@ [total_scheduler_delay_ms] [bigint] NULL, [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_perf_os_schedulers_sql_instance default (@@SERVERNAME), constraint fk_logger_perf_os_schedulers foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint pk_logger_perf_os_schedulers primary key clustered ( - [snapshot_time] ASC, [snapshot_type_id], [sql_instance] - ), constraint fk_sqlwatch_logger_perf_os_schedulers_server foreign key ([sql_instance]) references [dbo].[sqlwatch_meta_server] ([servername]) on delete cascade -) +) GO --CREATE NONCLUSTERED INDEX idx_sqlwatch_os_schedulers_001 diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/idx_sqlwatch_logger_perf_os_wait_stats_wait_type_id.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/idx_sqlwatch_logger_perf_os_wait_stats_wait_type_id.sql new file mode 100644 index 00000000..711380e2 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/idx_sqlwatch_logger_perf_os_wait_stats_wait_type_id.sql @@ -0,0 +1,3 @@ +create nonclustered index idx_sqlwatch_logger_perf_os_wait_stats_wait_type_id + on [dbo].[sqlwatch_logger_perf_os_wait_stats] ([sql_instance], [wait_type_id]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/idx_sqlwatch_logger_perf_os_wait_stats_waiting_count_delta.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/idx_sqlwatch_logger_perf_os_wait_stats_waiting_count_delta.sql new file mode 100644 index 00000000..25184891 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/idx_sqlwatch_logger_perf_os_wait_stats_waiting_count_delta.sql @@ -0,0 +1,3 @@ +create nonclustered index idx_sqlwatch_logger_perf_os_wait_stats_waiting_count_delta + on [dbo].[sqlwatch_logger_perf_os_wait_stats] ([waiting_tasks_count_delta]) include ([wait_time_ms_delta]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/pk_sql_perf_mon_wait_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/pk_sql_perf_mon_wait_stats.sql new file mode 100644 index 00000000..8bb9de74 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/pk_sql_perf_mon_wait_stats.sql @@ -0,0 +1,4 @@ +ALTER TABLE[dbo].[sqlwatch_logger_perf_os_wait_stats] + ADD CONSTRAINT [pk_sql_perf_mon_wait_stats] + PRIMARY KEY CLUSTERED ([snapshot_time] asc, [snapshot_type_id] asc, [sql_instance] asc, [wait_type_id] asc) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/sqlwatch_logger_perf_os_wait_stats.sql similarity index 77% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/sqlwatch_logger_perf_os_wait_stats.sql index 360f3426..ede1269e 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_os_wait_stats/sqlwatch_logger_perf_os_wait_stats.sql @@ -15,21 +15,9 @@ [signal_wait_time_ms_delta] real not null, [delta_seconds] int not null, constraint fk_sql_perf_mon_wait_stats_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint [pk_sql_perf_mon_wait_stats] primary key ( - [snapshot_time] asc, [snapshot_type_id] asc, [sql_instance] asc, [wait_type_id] asc - ), constraint fk_sqlwatch_logger_perf_os_wait_stats_wait_type_id foreign key ([sql_instance], [wait_type_id]) references [dbo].[sqlwatch_meta_wait_stats] ( [sql_instance], [wait_type_id] ) on delete cascade -) - -go - -create nonclustered index idx_sqlwatch_logger_perf_os_wait_stats_waiting_count_delta - on [dbo].[sqlwatch_logger_perf_os_wait_stats] ([waiting_tasks_count_delta]) include ([wait_time_ms_delta]) -go - -create nonclustered index idx_sqlwatch_logger_perf_os_wait_stats_wait_type_id - on [dbo].[sqlwatch_logger_perf_os_wait_stats] ([sql_instance], [wait_type_id]) +) go /* aid filtering by server in the central repository */ diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats/pk_sqlwatch_logger_perf_procedure_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats/pk_sqlwatch_logger_perf_procedure_stats.sql new file mode 100644 index 00000000..3b1275de --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats/pk_sqlwatch_logger_perf_procedure_stats.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_procedure_stats] + ADD CONSTRAINT [pk_sqlwatch_logger_perf_procedure_stats] + PRIMARY KEY CLUSTERED ([sql_instance], [sqlwatch_database_id], [sqlwatch_procedure_id], [snapshot_time], [snapshot_type_id], [cached_time]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats/sqlwatch_logger_perf_procedure_stats.sql similarity index 88% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats/sqlwatch_logger_perf_procedure_stats.sql index 03ebbb8a..77591ea3 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_procedure_stats/sqlwatch_logger_perf_procedure_stats.sql @@ -36,15 +36,6 @@ delta_elapsed_time real null, delta_execution_count real null, - constraint pk_sqlwatch_logger_perf_procedure_stats primary key clustered ( - [sql_instance] - , [sqlwatch_database_id] - , [sqlwatch_procedure_id] - , [snapshot_time] - , [snapshot_type_id] - , [cached_time] - ), - constraint fk_sqlwatch_logger_perf_procedure_stats_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header] ([snapshot_time],[sql_instance],[snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats/pk_sqlwatch_logger_perf_query_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats/pk_sqlwatch_logger_perf_query_stats.sql new file mode 100644 index 00000000..94204f8c --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats/pk_sqlwatch_logger_perf_query_stats.sql @@ -0,0 +1,12 @@ +ALTER TABLE [dbo].[sqlwatch_logger_perf_query_stats] + ADD CONSTRAINT [pk_sqlwatch_logger_perf_query_stats] + PRIMARY KEY clustered ( + [sql_instance] + , plan_handle + , statement_start_offset + , statement_end_offset + , [snapshot_time] + , [snapshot_type_id] + , [creation_time] + ) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats/sqlwatch_logger_perf_query_stats.sql similarity index 90% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats/sqlwatch_logger_perf_query_stats.sql index ba918603..cb3d1bb8 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_perf_query_stats/sqlwatch_logger_perf_query_stats.sql @@ -74,15 +74,6 @@ delta_time_s int, - constraint pk_sqlwatch_logger_perf_query_stats primary key clustered ( - [sql_instance] - , plan_handle - , statement_start_offset - , statement_end_offset - , [snapshot_time] - , [snapshot_type_id] - , [creation_time] - ), constraint fk_sqlwatch_logger_perf_query_stats_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action/pk_sqlwatch_logger_report_action_action.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action/pk_sqlwatch_logger_report_action_action.sql new file mode 100644 index 00000000..3edc5813 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action/pk_sqlwatch_logger_report_action_action.sql @@ -0,0 +1,6 @@ +ALTER TABLE [dbo].[sqlwatch_logger_report_action] + ADD CONSTRAINT [pk_sqlwatch_logger_report_action_action] + primary key clustered ( + [snapshot_time], [sql_instance], [snapshot_type_id], [report_id], [action_id] + ) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action/sqlwatch_logger_report_action.sql similarity index 85% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action/sqlwatch_logger_report_action.sql index 3c5e13d9..b23147a7 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_report_action/sqlwatch_logger_report_action.sql @@ -5,9 +5,7 @@ [snapshot_type_id] tinyint not null constraint df_sqlwatch_logger_report_action_type default (18), [report_id] smallint not null, [action_id] smallint not null, - constraint pk_sqlwatch_logger_report_action_action primary key clustered ( - [snapshot_time], [sql_instance], [snapshot_type_id], [report_id], [action_id] - ), + /* replaced by trigger on config we can "detach it" and send to central repo */ --constraint fk_sqlwatch_logger_report_action_action foreign key ([action_id]) -- references [dbo].[sqlwatch_config_action] ([action_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/idx_sqlwatch_logger_snapshot_header_report_time.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/idx_sqlwatch_logger_snapshot_header_report_time.sql new file mode 100644 index 00000000..1b62dbe0 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/idx_sqlwatch_logger_snapshot_header_report_time.sql @@ -0,0 +1,3 @@ +create nonclustered index idx_sqlwatch_logger_snapshot_header_report_time + on [dbo].[sqlwatch_logger_snapshot_header] ([report_time]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/idx_sqlwatch_logger_snapshot_header_type_id.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/idx_sqlwatch_logger_snapshot_header_type_id.sql new file mode 100644 index 00000000..f8876680 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/idx_sqlwatch_logger_snapshot_header_type_id.sql @@ -0,0 +1,3 @@ +create nonclustered index idx_sqlwatch_logger_snapshot_header_type_id + on [dbo].[sqlwatch_logger_snapshot_header] ([snapshot_type_id]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/pk_snapshot.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/pk_snapshot.sql new file mode 100644 index 00000000..3588f77c --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/pk_snapshot.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_snapshot_header] + ADD CONSTRAINT [pk_snapshot] + PRIMARY KEY CLUSTERED ([snapshot_time], [sql_instance], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/sqlwatch_logger_snapshot_header.sql similarity index 86% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/sqlwatch_logger_snapshot_header.sql index a095146e..0ea62ec6 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_snapshot_header/sqlwatch_logger_snapshot_header.sql @@ -1,16 +1,11 @@ CREATE TABLE [dbo].[sqlwatch_logger_snapshot_header] ( - [snapshot_time] datetime2(0), + [snapshot_time] datetime2(0) not null, [snapshot_type_id] tinyint not null, [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_snapshot_header_sql_instance default (@@SERVERNAME), [report_time] smalldatetime, --AS dateadd(mi, datepart(TZOFFSET,SYSDATETIMEOFFSET()), (CONVERT([smalldatetime],dateadd(minute,ceiling(datediff(second,(0),CONVERT([time],CONVERT([datetime],[snapshot_time])))/(60.0)),datediff(day,(0),[snapshot_time]))))) PERSISTED NOT NULL, [snapshot_time_utc_offset] smallint not null constraint df_sqlwatch_logger_snapshot_header_time_offset default (datepart(TZOFFSET,SYSDATETIMEOFFSET())) , - /* primary key */ - constraint pk_snapshot primary key clustered ( - [snapshot_time], [sql_instance], [snapshot_type_id] - ), - /* foreign key to snapshot type, to make sure we only have valid snapshots otherwise retention routines may not work */ constraint fk_sqlwatch_logger_snapshot_header_type_id foreign key ([snapshot_type_id]) references dbo.[sqlwatch_config_snapshot_type]([snapshot_type_id]), @@ -47,11 +42,3 @@ go -- and i.snapshot_type_id = h.snapshot_type_id -- end - -create nonclustered index idx_sqlwatch_logger_snapshot_header_report_time - on [dbo].[sqlwatch_logger_snapshot_header] ([report_time]) - -go - -create nonclustered index idx_sqlwatch_logger_snapshot_header_type_id - on [dbo].[sqlwatch_logger_snapshot_header] ([snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration/pk_sqlwatch_logger_system_configuration.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration/pk_sqlwatch_logger_system_configuration.sql new file mode 100644 index 00000000..0dd5c6b6 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration/pk_sqlwatch_logger_system_configuration.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_system_configuration] + ADD CONSTRAINT [pk_sqlwatch_logger_system_configuration] + PRIMARY KEY CLUSTERED (sql_instance, sqlwatch_configuration_id, snapshot_time, snapshot_type_id) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration/sqlwatch_logger_system_configuration.sql similarity index 75% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration/sqlwatch_logger_system_configuration.sql index ce01a130..e516772b 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_system_configuration/sqlwatch_logger_system_configuration.sql @@ -4,11 +4,8 @@ sqlwatch_configuration_id smallint not null, value int not null, value_in_use int not null, - snapshot_time datetime2(0), - snapshot_type_id tinyint default(26), - constraint pk_sqlwatch_logger_system_configuration primary key clustered ( - sql_instance, sqlwatch_configuration_id, snapshot_time, snapshot_type_id - ), + snapshot_time datetime2(0) not null, + snapshot_type_id tinyint default(26) not null, constraint fk_sqlwatch_logger_system_configuration_keyword foreign key (sql_instance, sqlwatch_configuration_id) references dbo.sqlwatch_meta_system_configuration (sql_instance, sqlwatch_configuration_id)on delete cascade, constraint fk_sqlwatch_logger_system_configuration_snapshot foreign key ([snapshot_time], [sql_instance], [snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/idx_sqlwatch_logger_xes_blockers_1.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/idx_sqlwatch_logger_xes_blockers_1.sql new file mode 100644 index 00000000..10cc189c --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/idx_sqlwatch_logger_xes_blockers_1.sql @@ -0,0 +1,3 @@ +CREATE NONCLUSTERED INDEX idx_sqlwatch_logger_xes_blockers_1 + ON [dbo].[sqlwatch_logger_xes_blockers] ([monitor_loop],[blocking_ecid],[blocking_spid]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/pk_logger_perf_xes_blockers.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/pk_logger_perf_xes_blockers.sql new file mode 100644 index 00000000..912a3df0 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/pk_logger_perf_xes_blockers.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_xes_blockers] + ADD CONSTRAINT [pk_logger_perf_xes_blockers] + primary key clustered ([event_time], [monitor_loop], [blocked_spid], blocked_ecid, [blocking_spid], blocking_ecid, [sql_instance], [snapshot_time], [snapshot_type_id]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/sqlwatch_logger_xes_blockers.sql similarity index 77% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/sqlwatch_logger_xes_blockers.sql index 23cae420..a81282ec 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_blockers/sqlwatch_logger_xes_blockers.sql @@ -29,9 +29,6 @@ [snapshot_type_id] tinyint not null, [sql_instance] varchar(32) not null, - constraint pk_logger_perf_xes_blockers - primary key clustered ([event_time], [monitor_loop], [blocked_spid], blocked_ecid, [blocking_spid], blocking_ecid, [sql_instance], [snapshot_time], [snapshot_type_id]), - constraint fk_logger_perf_xes_blockers foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) @@ -44,5 +41,3 @@ ) go -CREATE NONCLUSTERED INDEX idx_sqlwatch_logger_xes_blockers_1 - ON [dbo].[sqlwatch_logger_xes_blockers] ([monitor_loop],[blocking_ecid],[blocking_spid]) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/idx_sqlwatch_xes_iosubsystem_event_time.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/idx_sqlwatch_xes_iosubsystem_event_time.sql new file mode 100644 index 00000000..5f7ce79d --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/idx_sqlwatch_xes_iosubsystem_event_time.sql @@ -0,0 +1,3 @@ +create unique nonclustered index idx_sqlwatch_xes_iosubsystem_event_time + on [dbo].[sqlwatch_logger_xes_iosubsystem] ([event_time], [sql_instance]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/pk_logger_performance_xes_iosubsystem.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/pk_logger_performance_xes_iosubsystem.sql new file mode 100644 index 00000000..fe256b43 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/pk_logger_performance_xes_iosubsystem.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_xes_iosubsystem] + ADD CONSTRAINT [pk_logger_performance_xes_iosubsystem] + PRIMARY KEY CLUSTERED ([snapshot_time], [snapshot_type_id], [sql_instance], [event_time]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/sqlwatch_logger_xes_iosubsystem.sql similarity index 73% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/sqlwatch_logger_xes_iosubsystem.sql index 9adca385..9dfe8d69 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_iosubsystem/sqlwatch_logger_xes_iosubsystem.sql @@ -1,6 +1,6 @@ CREATE TABLE [dbo].[sqlwatch_logger_xes_iosubsystem] ( - [event_time] datetime, + [event_time] datetime not null, [io_latch_timeouts] bigint, [total_long_ios] bigint, [longest_pending_request_file] varchar(255), @@ -9,14 +9,7 @@ [snapshot_type_id] tinyint not null constraint df_sqlwatch_logger_xes_iosubsystem_type default (1) , [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_xes_iosubsystem_sql_instance default (@@SERVERNAME), constraint fk_logger_performance_xes_iosubsystem_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint [pk_logger_performance_xes_iosubsystem] primary key ( - [snapshot_time], [snapshot_type_id], [sql_instance], [event_time] - ), constraint fk_sqlwatch_logger_xes_iosubsystem_server foreign key ([sql_instance]) references [dbo].[sqlwatch_meta_server] ([servername]) on delete cascade ); -go - -create unique nonclustered index idx_sqlwatch_xes_iosubsystem_event_time - on [dbo].[sqlwatch_logger_xes_iosubsystem] ([event_time], [sql_instance]); -go +go \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries/pk_logger_perf_xes_long_queries.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries/pk_logger_perf_xes_long_queries.sql new file mode 100644 index 00000000..682d657f --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries/pk_logger_perf_xes_long_queries.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_xes_long_queries] + ADD CONSTRAINT [pk_logger_perf_xes_long_queries] + PRIMARY KEY ([snapshot_time], [snapshot_type_id], [event_time], [event_name],[session_id], plan_handle) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries/sqlwatch_logger_xes_long_queries.sql similarity index 89% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries/sqlwatch_logger_xes_long_queries.sql index ed71caa3..f9a672bf 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_long_queries/sqlwatch_logger_xes_long_queries.sql @@ -22,10 +22,6 @@ attach_activity_id varchar(40), event_data xml, - constraint pk_logger_perf_xes_long_queries primary key nonclustered ( - [snapshot_time], [snapshot_type_id], [event_time], [event_name],[session_id], plan_handle - ), - constraint fk_logger_perf_xes_long_queries foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/idx_sqlwatch_logger_xes_query_problems_1.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/idx_sqlwatch_logger_xes_query_problems_1.sql new file mode 100644 index 00000000..d5dfed16 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/idx_sqlwatch_logger_xes_query_problems_1.sql @@ -0,0 +1,3 @@ +create unique nonclustered index idx_sqlwatch_logger_xes_query_problems_1 + on [dbo].[sqlwatch_logger_xes_query_problems] ([event_time], [event_name], [event_hash], [occurence]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/pk_sqlwatch_logger_xes_query_problems.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/pk_sqlwatch_logger_xes_query_problems.sql new file mode 100644 index 00000000..6bf09929 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/pk_sqlwatch_logger_xes_query_problems.sql @@ -0,0 +1,8 @@ +ALTER TABLE [dbo].[sqlwatch_logger_xes_query_problems] + --although the hash is done on the entire event so will take time and name into account. + --I am going to make these fields part PK for improvement performance when reading data. I may change it later depending on performance + + --actually, this will fragment the index as hell. it needs a better design + ADD CONSTRAINT [pk_sqlwatch_logger_xes_query_problems] + PRIMARY KEY nonclustered ([snapshot_time], [sql_instance], [snapshot_type_id], [event_id]) + with (data_compression=page) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/sqlwatch_logger_xes_query_problems.sql similarity index 60% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/sqlwatch_logger_xes_query_problems.sql index f19e7c30..28e42799 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_problems/sqlwatch_logger_xes_query_problems.sql @@ -14,13 +14,6 @@ [problem_details] xml, [event_hash] varbinary(20), [occurence] real, - - constraint pk_sqlwatch_logger_xes_query_problems - --although the hash is done on the entire event so will take time and name into account. - --I am going to make these fields part PK for improvement performance when reading data. I may change it later depending on performance - - --actually, this will fragment the index as hell. it needs a better design - primary key nonclustered ([snapshot_time], [sql_instance], [snapshot_type_id], [event_id]), constraint fk_sqlwatch_logger_xes_query_problems_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) @@ -33,7 +26,3 @@ on delete cascade ) go - -create unique nonclustered index idx_sqlwatch_logger_xes_query_problems_1 - on [dbo].[sqlwatch_logger_xes_query_problems] ([event_time], [event_name], [event_hash], [occurence]) -go diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/idx_sqlwatch_xes_query_processing_event_time.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/idx_sqlwatch_xes_query_processing_event_time.sql new file mode 100644 index 00000000..ff4057e0 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/idx_sqlwatch_xes_query_processing_event_time.sql @@ -0,0 +1,3 @@ +create unique nonclustered index idx_sqlwatch_xes_query_processing_event_time + on [dbo].[sqlwatch_logger_xes_query_processing] ([event_time], [sql_instance]) + with (data_compression=page) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/pk_logger_xe_query_processing.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/pk_logger_xe_query_processing.sql new file mode 100644 index 00000000..6aeab266 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/pk_logger_xe_query_processing.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_xes_query_processing] + ADD CONSTRAINT [pk_logger_xe_query_processing] + PRIMARY KEY CLUSTERED ([snapshot_time], [snapshot_type_id], [sql_instance], [event_time]) + WITH (DATA_COMPRESSION=PAGE) diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/sqlwatch_logger_xes_query_processing.sql similarity index 74% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/sqlwatch_logger_xes_query_processing.sql index 60f8ce82..4f21cfc8 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_query_processing/sqlwatch_logger_xes_query_processing.sql @@ -1,6 +1,6 @@ CREATE TABLE [dbo].[sqlwatch_logger_xes_query_processing] ( - [event_time] datetime, + [event_time] datetime not null, [max_workers] bigint, [workers_created] bigint, [idle_workers] bigint, @@ -11,14 +11,7 @@ [snapshot_type_id] tinyint not null constraint df_sqlwatch_logger_xes_query_processing_type default (1) , [sql_instance] varchar(32) not null constraint df_sqlwatch_logger_xes_query_processing_sql_instance default (@@SERVERNAME), constraint fk_logger_xe_query_processing_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint [pk_logger_xe_query_processing] primary key ( - [snapshot_time], [snapshot_type_id], [sql_instance], [event_time] - ), constraint fk_sqlwatch_logger_xes_query_processing_server foreign key ([sql_instance]) references [dbo].[sqlwatch_meta_server] ([servername]) on delete cascade ); -go - -create unique nonclustered index idx_sqlwatch_xes_query_processing_event_time - on [dbo].[sqlwatch_logger_xes_query_processing] ([event_time], [sql_instance]); -go +go \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event/pk_sqlwatch_logger_xes_wait_stat_event.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event/pk_sqlwatch_logger_xes_wait_stat_event.sql new file mode 100644 index 00000000..2e280397 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event/pk_sqlwatch_logger_xes_wait_stat_event.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_logger_xes_wait_event] + ADD CONSTRAINT [pk_sqlwatch_logger_xes_wait_stat_event] + PRIMARY KEY CLUSTERED (event_time, wait_type_id, session_id, [sql_instance], [snapshot_time], [snapshot_type_id] , activity_id) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event/sqlwatch_logger_xes_wait_event.sql similarity index 84% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event/sqlwatch_logger_xes_wait_event.sql index 0f498f5b..8dffba7e 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_logger_xes_wait_event/sqlwatch_logger_xes_wait_event.sql @@ -4,7 +4,7 @@ wait_type_id smallint not null, duration bigint not null, signal_duration bigint null, - session_id int, + session_id int not null, username nvarchar(255), client_hostname nvarchar(255), client_app_name nvarchar(255), @@ -14,13 +14,9 @@ sql_instance varchar(32) not null, snapshot_time datetime2(0) not null, snapshot_type_id tinyint not null, - activity_id varchar(40), + activity_id varchar(40) not null, event_data xml, - constraint pk_sqlwatch_logger_xes_wait_stat_event primary key clustered ( - event_time, wait_type_id, session_id, [sql_instance], [snapshot_time], [snapshot_type_id] , activity_id - ), - constraint fk_sqlwatch_logger_xes_wait_stat_event_snapshot_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_interval_minutes.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_interval_minutes.sql new file mode 100644 index 00000000..f0015f97 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_interval_minutes.sql @@ -0,0 +1,4 @@ +CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_interval_minutes + ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([interval_minutes]) + INCLUDE ([performance_counter_id],[instance_name],[sql_instance],[snapshot_time]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_perf_counter.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_perf_counter.sql new file mode 100644 index 00000000..efca2545 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_perf_counter.sql @@ -0,0 +1,4 @@ +CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_perf_counter + ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([performance_counter_id],[sql_instance]) + INCLUDE ([cntr_value_calculated_avg],[snapshot_time_offset]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_sql_instance.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_sql_instance.sql new file mode 100644 index 00000000..f32bee70 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_sql_instance.sql @@ -0,0 +1,4 @@ +CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_sql_instance + ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([sql_instance]) + INCLUDE ([performance_counter_id],[cntr_value_calculated_avg],[snapshot_time_offset]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_valid_until.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_valid_until.sql new file mode 100644 index 00000000..37557a56 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_valid_until.sql @@ -0,0 +1,3 @@ +CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_valid_until + ON dbo.sqlwatch_trend_perf_os_performance_counters ([valid_until]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_value.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_value.sql new file mode 100644 index 00000000..f54a339c --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/idx_sqlwatch_trend_perf_os_performance_counters_value.sql @@ -0,0 +1,4 @@ +CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_value + ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([performance_counter_id],[sql_instance],[interval_minutes]) + INCLUDE ([cntr_value_calculated_avg]) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/pk_sqlwatch_trend_perf_os_performance_counters.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/pk_sqlwatch_trend_perf_os_performance_counters.sql new file mode 100644 index 00000000..ecbd3b88 --- /dev/null +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/pk_sqlwatch_trend_perf_os_performance_counters.sql @@ -0,0 +1,4 @@ +ALTER TABLE [dbo].[sqlwatch_trend_perf_os_performance_counters] + ADD CONSTRAINT [pk_sqlwatch_trend_perf_os_performance_counters] + PRIMARY KEY CLUSTERED ([snapshot_time] , [instance_name] , [sql_instance], [interval_minutes], [performance_counter_id] ) + WITH (DATA_COMPRESSION=PAGE) \ No newline at end of file diff --git a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters.sql b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/sqlwatch_trend_perf_os_performance_counters.sql similarity index 50% rename from SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters.sql rename to SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/sqlwatch_trend_perf_os_performance_counters.sql index 086ac71f..b399e618 100644 --- a/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters.sql +++ b/SqlWatch.Monitor/Project.SqlWatch.Database/dbo/Tables/sqlwatch_trend_perf_os_performance_counters/sqlwatch_trend_perf_os_performance_counters.sql @@ -19,33 +19,8 @@ /* aggregates will be detached from header as no new snapshots will be created in the header table when aggregates are created they will have to be self-maintained when it comes to retention */ --constraint fk_sqlwatch_aggregate_perf_os_performance_counters_header foreign key ([snapshot_time],[sql_instance],[snapshot_type_id]) references [dbo].[sqlwatch_logger_snapshot_header]([snapshot_time],[sql_instance],[snapshot_type_id]) on delete cascade on update cascade, - constraint [pk_sqlwatch_trend_perf_os_performance_counters] - primary key ([snapshot_time] , [instance_name] , [sql_instance], [interval_minutes], [performance_counter_id] ), constraint fk_sqlwatch_trend_perf_os_performance_counters_meta foreign key ([sql_instance], [performance_counter_id]) references [dbo].[sqlwatch_meta_performance_counter] ([sql_instance], [performance_counter_id]) on delete cascade ) -go - -CREATE NONCLUSTERED INDEX sqlwatch_trend_perf_os_performance_counters_value -ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([performance_counter_id],[sql_instance],[interval_minutes]) -INCLUDE ([cntr_value_calculated_avg]) -go - -CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_valid_until -ON dbo.sqlwatch_trend_perf_os_performance_counters ([valid_until]) -go - -CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_interval_minutes -ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([interval_minutes]) -INCLUDE ([performance_counter_id],[instance_name],[sql_instance],[snapshot_time]) -go - -CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_sql_instance -ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([sql_instance]) -INCLUDE ([performance_counter_id],[cntr_value_calculated_avg],[snapshot_time_offset]) -go - -CREATE NONCLUSTERED INDEX idx_sqlwatch_trend_perf_os_performance_counters_perf_counter -ON [dbo].[sqlwatch_trend_perf_os_performance_counters] ([performance_counter_id],[sql_instance]) -INCLUDE ([cntr_value_calculated_avg],[snapshot_time_offset]) \ No newline at end of file +go \ No newline at end of file