db:mssql

Mssql

Docker mssql Mssql docker

 # пробросить mnt/volume для WSL и жестких дисков + нестандартный порт
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=passw0rd_123" \
 -p 1434:1433 --name sql1 -h sql1 -v /mnt:/mnt/volume \
 -v /opt/docker/mssql/isoj:/var/opt/mssql/data
 -d mcr.microsoft.com/mssql/server:2019-latest

Пример работы с подключением из командной строки и выполнения восстановления

sudo docker exec -it sql3 "bash"
/opt/mssql-tools/bin/sqlcmd -S 172.31.28.155,1434 -U SA -P "passw0rd_123"
 
-- включить mssql agent
sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE;  
GO  
sp_configure 'Agent XPs', 1;  
GO  
RECONFIGURE  
GO  

--- MSSQL. Sql to Get info data of base , space used, files

--- MSSQL. Backup Restore

--- MSSQL. turn on agent

--- SCRIPT - for archive all files except ZIP

--- SCRIPT - for archive ZIP all files except last one for sort in time

--- SCRIPT - clear age files in directory

bcp [ISOJ].[dbo].[lNLogData] OUT i:\lNLogData.txt  -T -c -b 10000

https://stackoverflow.com/questions/56628/how-do-you-clear-the-sql-server-transaction-log

USE ISOJ
GO
 
DECLARE @FileName sysname = N'ISOJ';
DECLARE @TargetSize INT = (SELECT 1 + SIZE*8./1024 FROM sys.database_files WHERE name = @FileName);
DECLARE @Factor FLOAT = .995;
DECLARE @Inc INT = 0
 
WHILE @Inc < 10
BEGIN
    SET @Inc += 1
    SET @TargetSize *= @Factor;
    DBCC SHRINKFILE(@FileName, @TargetSize);
    DECLARE @msg VARCHAR(200) = 'Shrink file completed. Target Size: '+ 
         CAST(@TargetSize AS VARCHAR )+ ' MB. Timestamp: ';
    RAISERROR(@msg, 1, 1) WITH NOWAIT;
    WAITFOR DELAY '00:00:01';
END;
 
 
-- reclail logs
USE yourdb;
GO
CHECKPOINT;
GO
CHECKPOINT; -- run twice to ensure file wrap-around
GO
DBCC SHRINKFILE(yourdb_log, 200); -- unit is set in MBs
GO
-- Short way 
EXEC sp_msforeachtable 'SET QUOTED_IDENTIFIER ON; ALTER INDEX ALL ON ? REBUILD'

Rebuild indexes

If trace skip rows , need to do trace on server side
https://www.sqlservercentral.com/blogs/setting-up-a-server-side-trace

Check syncrhonize

Syncronize tables

TSQL example

  • db/mssql.txt
  • Last modified: 2021/11/03 09:53
  • by admin