Python clears database error logs and python database logs

Source: Internet
Author: User

Python clears database error logs and python database logs

# Coding = gbk
From encodings import gbk
Import re
Import sys
Import OS
Import pyodbc
Import traceback
Import decimal

 

# Connecting to a database
Conn = pyodbc. connect ('driver = {SQL Server}; SERVER = 192.168.1.43; DATABASE = master; UID = sa; PWD = passwd123! ')

# Obtain the cursor object for operations
Cursor = conn. cursor ()

# Clearing error logs
# Query = "select username, userid from dbo. tbluser where username = '% S'" % (uname)
Query = "EXEC sys. sp_cycle_errorlog"
Cursor.exe cute (query)
Conn. commit

Data = cursor. nextset ()

While not data:
Print ('43 error logs cleared! ')
Break

# Clearing proxy logs
# Query = "select username, userid from dbo. tbluser where username = '% S'" % (uname)
Query1 = "EXEC msdb. dbo. sp_cycle_agent_errorlog"
Cursor.exe cute (query1)
Conn. commit

Data1 = cursor. nextset ()

While not data1:
Print ('43 proxy logs cleared! ')
Break

 


# Close the connection and release resources

Cursor. close ()
Conn. close ()

Com3 = 'pause'
OS. system (com3)


How does python view error logs?

There are 39 rows of test. py, and an object is None? It means that you must use any object without initialization.
The information in this log indicates the last line of NoneType. Check whether the method called by test. py is incorrect.
You can place an order in IDLE to see if the environment variables are not as expected.

How to clear SQL database logs? What is the impact on the database after being cleared?

How to clear SQL logs

1. Open the query analyzer and enter the command
Dump transaction database name WITH NO_LOG
2. open the Enterprise Manager and right-click the database you want to compress -- all tasks -- shrink database -- shrink file -- Select log file -- select to shrink to XXM In the shrink mode, here we will provide a minimum number of M that can be reduced. Enter this number directly and click OK.

There are two methods to clear logs:

1. Automatic cleanup

The database option Trunc Log on Chkpt is enabled to enable the database system to automatically clear logs at intervals. The advantage of this method is that it is automatically executed by SQL Server without manual intervention, and generally logs are not full. The disadvantage is that only logs are cleared without backup.

2. Manual cleanup

Run "dump transaction" to clear logs. The following two commands can clear logs:

Dump transaction with truncate_only
Dump transaction with no_log

You can use the "dump transaction with trancate_only" command to delete the inactive parts of the transaction log. When writing this command into the transaction log, you must perform necessary concurrency checks. SYBASE provides "dump transaction with no_log" to deal with some very pressing situations. Using this command is highly risky. the SQL Server displays a warning message. To ensure Database Consistency as much as possible, you should take it as the "last move ".

The preceding two methods only clear logs without backing up logs. to back up logs, run the "dump transaction database_name to dumpdevice" command.

No impact on the database after clearing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.