| |

VerySource

 Forgot password?
 Register
Search
View: 4565|Reply: 29

| M | My database log is full at once, what should I do?

[Copy link]

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-18 01:40:01
| Show all posts |Read mode
The log for database 'cnepa' is full. Please back up the database's transaction log to free up some log space.
Every two days
Do not need log files
Or let the SQL database be compressed every two hours

What should I do
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 13:18:01
| Show all posts
Limit log increase:

According to the book, once the database is operated, the log may record N entries.
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-1-23 16:27:01
| Show all posts
Can also be emptied or dumped!
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-23 17:00:02
| Show all posts
lz can back up log files once a day and then compress them. These can be made to run automatically.
If you don't really need a log file, you can change the database's failure recovery model to simple, and change the file growth mode to M instead of percentage.
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-23 17:54:01
| Show all posts
Limit hard drive growth; expand hard drive capacity
Reply

Use magic Report

0

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-23 19:18:02
| Show all posts
Don't log just like "jccg1124" to change the database's failure recovery model to simple
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-23 20:36:02
| Show all posts
Back it up, you can clear the log
Reply

Use magic Report

0

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-1-24 19:18:01
| Show all posts
if exists (select * from dbo.sysobjects where id = object_id (N '[dbo]. [p_backupdb]') and OBJECTPROPERTY (id, N'IsProcedure ') = 1)
drop procedure [dbo]. [p_backupdb]
GO
create proc p_backupdb
@dbname sysname = '', --The name of the database to be backed up, if not specified, the current database is backed up
@bkpath nvarchar (260) = '', --The directory where the backup files are stored.If not specified, the default SQL backup directory is used.
@bkfname nvarchar (260) = '', --Backup file name,\DBNAME\can be used for the database name,\DATE\for the date, and\TIME\for the time.
@bktype nvarchar (10) = 'DB',-backup type: 'DB' backup database, 'DF' differential backup, 'LOG' log backup
@appendfile bit = 1-Append / overwrite backup file
as
 declare @sql varchar (8000)
 if isnull (@dbname, '') = '' set @ dbname = db_name ()
 if isnull (@bkpath, '') = '' set @ bkpath = dbo.f_getdbpath (null)
 if isnull (@bkfname, '') = '' set @ bkfname = '\DBNAME\_\DATE\_\TIME\.BAK'
 set @ bkfname = replace (replace (replace (@ bkfname, '\DBNAME\', @ dbname)
  , '\DATE\', convert (varchar, getdate (), 112))
  , '\TIME\', replace (convert (varchar, getdate (), 108), ':', ''))
 set @ sql = 'backup' + case @bktype when 'LOG' then 'log' else 'database' end + @ dbname
  + 'to disk =' '' + @ bkpath + @ bkfname
  + '' 'with' + case @bktype when 'DF' then 'DIFFERENTIAL,' else '' end
  + case @appendfile when 1 then 'NOINIT' else 'INIT' end
 print @sql
 exec (@sql)
go


--Back up the current database
exec p_backupdb @ bkpath = 'c:\', @ bkfname = 'db_\DATE\_db.bak'
-Differential backup of the current database
exec p_backupdb @ bkpath = 'c:\', @ bkfname = 'db_\DATE\_df.bak', @ bktype = 'DF'
--Back up the current database log
exec p_backupdb @ bkpath = 'c:\', @ bkfname = 'db_\DATE\_log.bak', @ bktype = 'LOG'
Reply

Use magic Report

0

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-1-24 19:27:01
| Show all posts
if exists (select * from dbo.sysobjects where id = object_id (N '[dbo]. [p_backupdb]') and OBJECTPROPERTY (id, N'IsProcedure ') = 1)
drop procedure [dbo]. [p_backupdb]
GO
create proc p_backupdb
@dbname sysname = '', --The name of the database to be backed up, if not specified, the current database is backed up
@bkpath nvarchar (260) = '', --The directory where the backup files are stored.If not specified, the default SQL backup directory is used.
@bkfname nvarchar (260) = '', --Backup file name,\DBNAME\can be used for the database name,\DATE\for the date, and\TIME\for the time.
@bktype nvarchar (10) = 'DB',-backup type: 'DB' backup database, 'DF' differential backup, 'LOG' log backup
@appendfile bit = 1-Append / overwrite backup file
as
 declare @sql varchar (8000)
 if isnull (@dbname, '') = '' set @ dbname = db_name ()
 if isnull (@bkpath, '') = '' set @ bkpath = dbo.f_getdbpath (null)
 if isnull (@bkfname, '') = '' set @ bkfname = '\DBNAME\_\DATE\_\TIME\.BAK'
 set @ bkfname = replace (replace (replace (@ bkfname, '\DBNAME\', @ dbname)
  , '\DATE\', convert (varchar, getdate (), 112))
  , '\TIME\', replace (convert (varchar, getdate (), 108), ':', ''))
 set @ sql = 'backup' + case @bktype when 'LOG' then 'log' else 'database' end + @ dbname
  + 'to disk =' '' + @ bkpath + @ bkfname
  + '' 'with' + case @bktype when 'DF' then 'DIFFERENTIAL,' else '' end
  + case @appendfile when 1 then 'NOINIT' else 'INIT' end
 print @sql
 exec (@sql)
go
Reply

Use magic Report

0

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-25 10:45:01
| Show all posts
Clear, it will be cleared at intervals.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list