Skip to content

Commit

Permalink
Enabled Page Compression by Default (#473)
Browse files Browse the repository at this point in the history
When data compression is enabled post-deployment, the next DACPAC deployment will remove compression unless manual overrides are specified. This complicates deployments in large environments or in cases where the SQLWATCH database is large. From now on, all logger tables are now compressed by default. (If you have no compression enabled and are upgrading to this version, the upgrade can take a while whilst logger data is compressed)
  • Loading branch information
marcingminski authored Apr 9, 2023
1 parent 4ded794 commit 6c09e63
Show file tree
Hide file tree
Showing 87 changed files with 370 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2926,4 +2926,11 @@
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="keyword1" />
</Operation>
<Operation Name="Rename Refactor" Key="a9a02302-fe3d-4c3b-84b6-4c5ce1a570fe" ChangeDateTime="04/09/2023 16:53:54">
<Property Name="ElementName" Value="[dbo].[sqlwatch_trend_perf_os_performance_counters].[sqlwatch_trend_perf_os_performance_counters_value]" />
<Property Name="ElementType" Value="SqlIndex" />
<Property Name="ParentElementName" Value="[dbo].[sqlwatch_trend_perf_os_performance_counters]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="idx_sqlwatch_trend_perf_os_performance_counters_value" />
</Operation>
</Operations>
146 changes: 113 additions & 33 deletions SqlWatch.Monitor/Project.SqlWatch.Database/SQLWATCH.sqlproj

Large diffs are not rendered by default.

Binary file modified SqlWatch.Monitor/Project.SqlWatch.Database/SetDacVersion.sql
Binary file not shown.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,11 @@
[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,

/* 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])
)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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);
go
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 6c09e63

Please sign in to comment.