Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Tuesday, March 27, 2012

Database Mirroring: Cannot set the Mirror Server instance as the partner on Principle server

Hi,

I’m trying to get database mirroring working but having problem when principal and mirror are not on the Domain. (I got it working once if both principle and mirror servers are on the domain.) Both servers have fully qualified domain names. Both have Windows server 2003 SP1 and SQL Server 2005 June CTP.

I used Local System Acct/Mixed mode and follow the Setting up Database Mirroring using Certificates article in the BOL: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/df489ecd-deee-465c-a26a-6d1bef6d7b66.htm

I kept getting error when trying to set the Mirror Server instance as the partner on Principle server with this command:

ALTER DATABASE Testdb

SET PARTNER = 'TCP://<mirror server.fqdomainname.com>:5022';

GO

Here is the error I kept getting:

Msg 1460, Level 16, State 2, Line 1

The partner for database "Testdb" is not defined or is different from the one attempting to establish database

How can I troubleshoot this further? Could anyone please point me in the right direction?

Thanks,
Pamb

so, i went to the devloper and asked "What is the 1460 error?"

he looked around and he finally said "We don't throw that error any more. Go tell the customer that, in fact, they are not seeing this error. Use the Force. :)"

OK, then i offered to buy him a beer.

two minutes later, it turns out that the error occurs when comparing the server names AND there are different collations for the two different servers. the code was changed recently to compare the server names differently.

so, make sure that the collations on the two servers are the same.

hope that helps!!

thanks,
mark|||Hi Mark,

Thanks for your response. Unfortunately, I have a few more questions...

I could check the Collation setting on the Principal database and it is set to "SQL_Latin1_General_CP1_CI_AS" but since the Mirror Database is in the restoring mode, I can't seem to check it's setting. Well, is this the right collation setting first of all?

Thanks in advance again for your help.

Pam|||Hi Mark,

I managed to check the collation setting at the Server-level and Database-level on both Principle and Mirror databases and the Collation is set to "SQL_Latin1_General_CP1_CI_AS".

What's next? Tequila? :)

Thanks again,
Pam

|||Pam,

I have the same error ... how did you finally manage?
Thanks
Jerome|||We shouldn't be breakin' out the Tequila yet.

From the developer:

--
you can get the 1460 error if:

1) your _servers_ (not the dbs themselves) have different collations

2) you are not specifying the name of the partner correctly (use netstat on the boxes to see what the box thinks it's called)

3) you are trying to establish on a secondary network
1. i know that you said you checked the server collations, but make sure.
2. make sure that you are specifying the correct FQDN.
3. this isn't a security problem. it is failing at the direct string compares. so, what you provided at the setup for the string compare is not what the server thinks that it is called.

are there multiple NICs on your machines?

thanks,
mark

|||Hi Mark,

What do you mean by a Secondary Network?

Yes, there are two nics on both machines. So, we just tried setting them up using just one IP address and issued the set partner query again but got same error.

I then started from scratch by uninstalling server/data and followed the same mirroring process but still got the same error.

[We also noticed that the TCP/IP protocols (Server IP and Localhost IP) are disabled under the Server Configuration Manager so I enabled them.]
Which table does this query issue against?
ALTER DATABASE Scout
SET PARTNER = 'TCP://<FQDN:5022';
Thanks,
Pam

|||

Hi Mark,

We have finally figured this out and would actually like to report what seems to be the software problem.

Here are the steps that we took...

1. We modified the Hosts file (under Windows32\System\Drivers\etc) on both machines so they could resolve each others fully qualified domain names:

principal.foo.com 10.0.0.132
mirror.foo.com 10.0.0.133

2. In the Advanced TCP/IP settings for DNS, we set the "DNS suffix for this connection" to foo.com.

3. We then issued the set partner queries using FQD name:

Alter database set PARTNER = 'TCP://principal.foo.com:5022'; [on the Mirror server]

Alter database set PARTNER = 'TCP://mirror.foo.com:5022'; [on the Principal server]

This failed the same 1460 error

4. We then tried it without the domain names:

Alter database set PARTNER = 'TCP://principal:5022'; [on the Mirror server]
Alter database set PARTNER = 'TCP://mirror:5022'; [on the Principal server]

*Success!*
What gave us a clue was running the Database Mirroring Properties Wizard on the Principal server. We noticed that the Wizard shows a non-FQDN as the Principal server, i.e. ‘TCP://principal:5022’.

It’s not clear to us how SQL is generating the principal name that has to be later string matched against name issued from the mirror server. This is a pretty fragile mechanism. We’d like to suggest that the TCP://[hostname] be resolved in the typical way, i.e. convert hostnames to IP’s as necessary and compare the IP addresses.

Thanks for all your help! [you owe us a beer ;-)]

Pam

Sunday, March 25, 2012

Database Mirroring is not working at all in RTM

I tried all the scenarios .

1- three CLEAN machines in the same domain each has a default instance
2- 1 machine having principal and witness and another one having mirror
3- 1 machine has all

the service for all of them is running under 1 account which is the domain admin.

but still i always getting the same error 1418 "the nework address '...' can not be reached or does not exist ..." when i try to add the mirror server as a partner for the principal server from the principal server .

i tried using TSQL and management studio

this error is driving me crazy , i search on google even for it and in forums and BOL and everwhere .
i followed the exact steps .

You know that the mirroring is available only under trace flag in RTM version? You need to use TF-1400

Thanks

|||

This is Books Online info on this flag (1400):

Enables database mirroring. This trace flag is allowed only when using the -T trace# startup option during start up of the server instance. Therefore, enabling mirroring requires a restart of the server instance. For more information about using Setup options, see Using the SQL Server Service Startup Options.

Important:
Microsoft support policies do not apply to the database mirroring feature in SQL Server 2005. Database mirroring is currently disabled by default, but may be enabled for evaluation purposes only by using trace flag 1400 as a startup parameter. Database mirroring should not be used in production environments, and Microsoft support services will not support databases or applications that use database mirroring. Database mirroring documentation is included in SQL Server 2005 for evaluation purposes only, and the Documentation Policy for SQL Server 2005 Support and Upgrade does not apply to the database mirroring documentation.

After starting up a server instance using this trace flag, you can set up and evaluate database mirroring. For more information, see Setting Up Database Mirroring.

Trace flag 1400 is a temporary flag. This flag will be removed when database mirroring is made available for general production use.

|||Hi getting exactly the same problem, how and where exactly do you put the -T1400 ..? Ive put it what i think is the correct place, but still get the same error as you and the three operating modes under the mirroe tab are still grayed out..?

chris|||Basically, you need to modify the service that startups and add the flag to the end of the file path.|||

Open configuration tools, then choose SQL Server Configuration Manager. Double click on SQL Server; choose the advanced tab then startup parameters.
This is what mine looks like:

-dC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf; -T1400

|||

i tried of course the Trace -T1400

but still the same

|||I was experiencing the same problem until I realised from the example above that there is a ; after the file path and before the trace switch. It's all working nicely now.|||

Hey all,

I am having the same problem. But the funny thing is that I had set up Mirroring on the three servers (Principal, Mirror and Witness) and tested it and everything was working fine unitil I needed to change the Server's computer name. I Stopped Mirroring, renamed my servers, dropped all the objects created during the setup of the mirror session(Master Key, Certificates, Endpoints, users, logins and even the database itself) on all the machines. then I followed the same steps to setup the mirroring session as before. I can proceed the setup until I get to the point of setup the partners. I connect to the Mirror server issue the Set Partner = 'TCP://PrincipalServer.Domain.ie:5024' and it works. Then I connect to the Principal and issue the the Set Partner ='TCP://MirrorServer.Domain.ie:5025' and what I get is this F*** Error 1418 saying that the server network address cannot be reached bla bla bla...

I have done follow the steps twice, so to make sure that I had made any mistakes. I check the ports on both servers to see if they are listen to 5024 and they are. I even reinstalled the damm server again with no success. I check to see if trace flag is enabled , I checked permissions, Endpoints, etc......... No success!

If there is anyone at the end of this line, who have an idea of what is going on, please give me a light. I don't know what else to look at.

regards,

adasilva

Database Mirroring is not working at all in RTM

I tried all the scenarios .

1- three CLEAN machines in the same domain each has a default instance
2- 1 machine having principal and witness and another one having mirror
3- 1 machine has all

the service for all of them is running under 1 account which is the domain admin.

but still i always getting the same error 1418 "the nework address '...' can not be reached or does not exist ..." when i try to add the mirror server as a partner for the principal server from the principal server .

i tried using TSQL and management studio

this error is driving me crazy , i search on google even for it and in forums and BOL and everwhere .
i followed the exact steps .

You know that the mirroring is available only under trace flag in RTM version? You need to use TF-1400

Thanks

|||

This is Books Online info on this flag (1400):

Enables database mirroring. This trace flag is allowed only when using the -T trace# startup option during start up of the server instance. Therefore, enabling mirroring requires a restart of the server instance. For more information about using Setup options, see Using the SQL Server Service Startup Options.

Important:
Microsoft support policies do not apply to the database mirroring feature in SQL Server 2005. Database mirroring is currently disabled by default, but may be enabled for evaluation purposes only by using trace flag 1400 as a startup parameter. Database mirroring should not be used in production environments, and Microsoft support services will not support databases or applications that use database mirroring. Database mirroring documentation is included in SQL Server 2005 for evaluation purposes only, and the Documentation Policy for SQL Server 2005 Support and Upgrade does not apply to the database mirroring documentation.

After starting up a server instance using this trace flag, you can set up and evaluate database mirroring. For more information, see Setting Up Database Mirroring.

Trace flag 1400 is a temporary flag. This flag will be removed when database mirroring is made available for general production use.

|||Hi getting exactly the same problem, how and where exactly do you put the -T1400 ..? Ive put it what i think is the correct place, but still get the same error as you and the three operating modes under the mirroe tab are still grayed out..?

chris|||Basically, you need to modify the service that startups and add the flag to the end of the file path.|||

Open configuration tools, then choose SQL Server Configuration Manager. Double click on SQL Server; choose the advanced tab then startup parameters.
This is what mine looks like:

-dC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf; -T1400

|||

i tried of course the Trace -T1400

but still the same

|||I was experiencing the same problem until I realised from the example above that there is a ; after the file path and before the trace switch. It's all working nicely now.|||

Hey all,

I am having the same problem. But the funny thing is that I had set up Mirroring on the three servers (Principal, Mirror and Witness) and tested it and everything was working fine unitil I needed to change the Server's computer name. I Stopped Mirroring, renamed my servers, dropped all the objects created during the setup of the mirror session(Master Key, Certificates, Endpoints, users, logins and even the database itself) on all the machines. then I followed the same steps to setup the mirroring session as before. I can proceed the setup until I get to the point of setup the partners. I connect to the Mirror server issue the Set Partner = 'TCP://PrincipalServer.Domain.ie:5024' and it works. Then I connect to the Principal and issue the the Set Partner ='TCP://MirrorServer.Domain.ie:5025' and what I get is this F*** Error 1418 saying that the server network address cannot be reached bla bla bla...

I have done follow the steps twice, so to make sure that I had made any mistakes. I check the ports on both servers to see if they are listen to 5024 and they are. I even reinstalled the damm server again with no success. I check to see if trace flag is enabled , I checked permissions, Endpoints, etc......... No success!

If there is anyone at the end of this line, who have an idea of what is going on, please give me a light. I don't know what else to look at.

regards,

adasilva

Database Mirroring is not working at all in RTM

I tried all the scenarios .

1- three CLEAN machines in the same domain each has a default instance
2- 1 machine having principal and witness and another one having mirror
3- 1 machine has all

the service for all of them is running under 1 account which is the domain admin.

but still i always getting the same error 1418 "the nework address '...' can not be reached or does not exist ..." when i try to add the mirror server as a partner for the principal server from the principal server .

i tried using TSQL and management studio

this error is driving me crazy , i search on google even for it and in forums and BOL and everwhere .
i followed the exact steps .

You know that the mirroring is available only under trace flag in RTM version? You need to use TF-1400

Thanks

|||

This is Books Online info on this flag (1400):

Enables database mirroring. This trace flag is allowed only when using the -T trace# startup option during start up of the server instance. Therefore, enabling mirroring requires a restart of the server instance. For more information about using Setup options, see Using the SQL Server Service Startup Options.

Important:
Microsoft support policies do not apply to the database mirroring feature in SQL Server 2005. Database mirroring is currently disabled by default, but may be enabled for evaluation purposes only by using trace flag 1400 as a startup parameter. Database mirroring should not be used in production environments, and Microsoft support services will not support databases or applications that use database mirroring. Database mirroring documentation is included in SQL Server 2005 for evaluation purposes only, and the Documentation Policy for SQL Server 2005 Support and Upgrade does not apply to the database mirroring documentation.

After starting up a server instance using this trace flag, you can set up and evaluate database mirroring. For more information, see Setting Up Database Mirroring.

Trace flag 1400 is a temporary flag. This flag will be removed when database mirroring is made available for general production use.

|||Hi getting exactly the same problem, how and where exactly do you put the -T1400 ..? Ive put it what i think is the correct place, but still get the same error as you and the three operating modes under the mirroe tab are still grayed out..?

chris|||Basically, you need to modify the service that startups and add the flag to the end of the file path.|||

Open configuration tools, then choose SQL Server Configuration Manager. Double click on SQL Server; choose the advanced tab then startup parameters.
This is what mine looks like:

-dC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf; -T1400

|||

i tried of course the Trace -T1400

but still the same

|||I was experiencing the same problem until I realised from the example above that there is a ; after the file path and before the trace switch. It's all working nicely now.|||

Hey all,

I am having the same problem. But the funny thing is that I had set up Mirroring on the three servers (Principal, Mirror and Witness) and tested it and everything was working fine unitil I needed to change the Server's computer name. I Stopped Mirroring, renamed my servers, dropped all the objects created during the setup of the mirror session(Master Key, Certificates, Endpoints, users, logins and even the database itself) on all the machines. then I followed the same steps to setup the mirroring session as before. I can proceed the setup until I get to the point of setup the partners. I connect to the Mirror server issue the Set Partner = 'TCP://PrincipalServer.Domain.ie:5024' and it works. Then I connect to the Principal and issue the the Set Partner ='TCP://MirrorServer.Domain.ie:5025' and what I get is this F*** Error 1418 saying that the server network address cannot be reached bla bla bla...

I have done follow the steps twice, so to make sure that I had made any mistakes. I check the ports on both servers to see if they are listen to 5024 and they are. I even reinstalled the damm server again with no success. I check to see if trace flag is enabled , I checked permissions, Endpoints, etc......... No success!

If there is anyone at the end of this line, who have an idea of what is going on, please give me a light. I don't know what else to look at.

regards,

adasilva

sql

Database Mirroring is not working at all in RTM

I tried all the scenarios .

1- three CLEAN machines in the same domain each has a default instance
2- 1 machine having principal and witness and another one having mirror
3- 1 machine has all

the service for all of them is running under 1 account which is the domain admin.

but still i always getting the same error 1418 "the nework address '...' can not be reached or does not exist ..." when i try to add the mirror server as a partner for the principal server from the principal server .

i tried using TSQL and management studio

this error is driving me crazy , i search on google even for it and in forums and BOL and everwhere .
i followed the exact steps .

You know that the mirroring is available only under trace flag in RTM version? You need to use TF-1400

Thanks

|||

This is Books Online info on this flag (1400):

Enables database mirroring. This trace flag is allowed only when using the -T trace# startup option during start up of the server instance. Therefore, enabling mirroring requires a restart of the server instance. For more information about using Setup options, see Using the SQL Server Service Startup Options.

Important:
Microsoft support policies do not apply to the database mirroring feature in SQL Server 2005. Database mirroring is currently disabled by default, but may be enabled for evaluation purposes only by using trace flag 1400 as a startup parameter. Database mirroring should not be used in production environments, and Microsoft support services will not support databases or applications that use database mirroring. Database mirroring documentation is included in SQL Server 2005 for evaluation purposes only, and the Documentation Policy for SQL Server 2005 Support and Upgrade does not apply to the database mirroring documentation.

After starting up a server instance using this trace flag, you can set up and evaluate database mirroring. For more information, see Setting Up Database Mirroring.

Trace flag 1400 is a temporary flag. This flag will be removed when database mirroring is made available for general production use.

|||Hi getting exactly the same problem, how and where exactly do you put the -T1400 ..? Ive put it what i think is the correct place, but still get the same error as you and the three operating modes under the mirroe tab are still grayed out..?

chris|||Basically, you need to modify the service that startups and add the flag to the end of the file path.|||

Open configuration tools, then choose SQL Server Configuration Manager. Double click on SQL Server; choose the advanced tab then startup parameters.
This is what mine looks like:

-dC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf; -T1400

|||

i tried of course the Trace -T1400

but still the same

|||I was experiencing the same problem until I realised from the example above that there is a ; after the file path and before the trace switch. It's all working nicely now.|||

Hey all,

I am having the same problem. But the funny thing is that I had set up Mirroring on the three servers (Principal, Mirror and Witness) and tested it and everything was working fine unitil I needed to change the Server's computer name. I Stopped Mirroring, renamed my servers, dropped all the objects created during the setup of the mirror session(Master Key, Certificates, Endpoints, users, logins and even the database itself) on all the machines. then I followed the same steps to setup the mirroring session as before. I can proceed the setup until I get to the point of setup the partners. I connect to the Mirror server issue the Set Partner = 'TCP://PrincipalServer.Domain.ie:5024' and it works. Then I connect to the Principal and issue the the Set Partner ='TCP://MirrorServer.Domain.ie:5025' and what I get is this F*** Error 1418 saying that the server network address cannot be reached bla bla bla...

I have done follow the steps twice, so to make sure that I had made any mistakes. I check the ports on both servers to see if they are listen to 5024 and they are. I even reinstalled the damm server again with no success. I check to see if trace flag is enabled , I checked permissions, Endpoints, etc......... No success!

If there is anyone at the end of this line, who have an idea of what is going on, please give me a light. I don't know what else to look at.

regards,

adasilva

Database mirroring and log growth

Hi all:
I have implemented database mirroring and it is working great. However, the
database log files are growing and growing and growing... is there a way to
manage the size of the log files?
ThanksHi Jim
Have you seen http://msdn2.microsoft.com/en-us/library/ms345414.aspx. If the
mirror is significantly behind the log file will grow.
John
"Jim Norton" wrote:

> Hi all:
> I have implemented database mirroring and it is working great. However, t
he
> database log files are growing and growing and growing... is there a way t
o
> manage the size of the log files?
> Thanks
>
>sql

Thursday, March 22, 2012

Database mirroring and log growth

Hi all:
I have implemented database mirroring and it is working great. However, the
database log files are growing and growing and growing... is there a way to
manage the size of the log files?
Thanks
Hi Jim
Have you seen http://msdn2.microsoft.com/en-us/library/ms345414.aspx. If the
mirror is significantly behind the log file will grow.
John
"Jim Norton" wrote:

> Hi all:
> I have implemented database mirroring and it is working great. However, the
> database log files are growing and growing and growing... is there a way to
> manage the size of the log files?
> Thanks
>
>

Database Mirroring

Im trying to get mirroring working go my endpoints set using the wizard,
the servers are called server1 and server2 when I trying to start
mirroring I get "specify the FQDN for each server, and click start
mirroring again" the computers see each other as server1 and server2 is
there away round this error ?You should follow the recommandation of the following topic on the Books on
Line:
SQL Server Database Engine -> Administering the Database Engine ->
Configuring High Availability -> Database Mirroring -> Setting Up Database
Mirroring -> Specifying a Server Network Address(Database Mirroring)
Gilberto
"sambino" wrote:

> Im trying to get mirroring working go my endpoints set using the wizard,
> the servers are called server1 and server2 when I trying to start
> mirroring I get "specify the FQDN for each server, and click start
> mirroring again" the computers see each other as server1 and server2 is
> there away round this error ?
>

Database Mirroring

Im trying to get mirroring working go my endpoints set using the wizard,
the servers are called server1 and server2 when I trying to start
mirroring I get "specify the FQDN for each server, and click start
mirroring again" the computers see each other as server1 and server2 is
there away round this error ?You should follow the recommandation of the following topic on the Books on
Line:
SQL Server Database Engine -> Administering the Database Engine ->
Configuring High Availability -> Database Mirroring -> Setting Up Database
Mirroring -> Specifying a Server Network Address(Database Mirroring)
Gilberto
"sambino" wrote:
> Im trying to get mirroring working go my endpoints set using the wizard,
> the servers are called server1 and server2 when I trying to start
> mirroring I get "specify the FQDN for each server, and click start
> mirroring again" the computers see each other as server1 and server2 is
> there away round this error ?
>

Wednesday, March 21, 2012

Database Mirror and Failover

Hello,
I'm just configuring a Database Mirror with SQL 2005 SP2. I have two SQL-Servers SQL1 and SQL2 and one Whitness. Everything is working fine, when I plug out the ethernet cable from SQL1 the whitness is detecting the failure an is switching over to SQL2 and so on. The running application is connecting to SQL2 after the failure. In case of a restart of the application the client tries to connect to SQL1, which is not reachable. As I'm expecting there should be a connect to SQL2 after the sqlclient can't reach SQL1 but with netstat -na I only see connection attempts to SQL1. From a former posting I got the Information about some existing connections to SQL1, but I made a restart of the client so be sure that there is no existing connection to SQL1. When both SQL-Servers are reachable and I do a manual failover everything is working fine, so I think database mirroring only works, when both servers are online. Is this true?
My connection string looks like this:
Data Source=DBSRV1;Failover Partner=DBSRV2;Initial Catalog=TEST;User ID=test;Password=test;Network Library=DBMSSOCN;Load Balance Timeout=5"
Thanks for your help
Greetings from Germany
Christian
Christian Grbner
MVP ISA Server
Hilfe & Infos rund um den ISA Server: http://www.msisafaq.de !!!!
NEU !!! Das Handbuch zum ISA 2006 - http://www.msisafaq.de/buch/
Database mirroring works either way depending on which mode you're in. It's
the automatic failover in high safety mode that may or may not meet your
needs. Specifically, not the failover part but rather the new client
connections part post failover (as per your scenario).
Automatic failover only works if your client's data access layer (SNAC or
ADO/ODBC.NET) has cached both server names. This happens in the first
connection attempt on the server. This is usually the primary server unless
you have specific code in your app (just a few simple lines) to test for
both. Many DB Mirroring implementations are "as-is" using exising apps
without code tweaks so they connect to their "original" primary as per
normal ops but benefit from automatic reconnect in a failover.
However, if the primary server was down before the client connects for the
first time, it would not know there is a mirror server to connect to which
is what you're seeing. Whether it's a new client connection or a re-started
app/web server, it's the same effect; you don't have the mirror server name
cached so the app/web server or client doesn't know it exists.
joe.
"Christian Grbner [MVP]" <newsgroups@.groeby.net> wrote in message
news:uunWT7wuHHA.2360@.TK2MSFTNGP06.phx.gbl...
Hello,
I'm just configuring a Database Mirror with SQL 2005 SP2. I have two
SQL-Servers SQL1 and SQL2 and one Whitness. Everything is working fine, when
I plug out the ethernet cable from SQL1 the whitness is detecting the
failure an is switching over to SQL2 and so on. The running application is
connecting to SQL2 after the failure. In case of a restart of the
application the client tries to connect to SQL1, which is not reachable. As
I'm expecting there should be a connect to SQL2 after the sqlclient can't
reach SQL1 but with netstat -na I only see connection attempts to SQL1. From
a former posting I got the Information about some existing connections to
SQL1, but I made a restart of the client so be sure that there is no
existing connection to SQL1. When both SQL-Servers are reachable and I do a
manual failover everything is working fine, so I think database mirroring
only works, when both servers are online. Is this true?
My connection string looks like this:
Data Source=DBSRV1;Failover Partner=DBSRV2;Initial Catalog=TEST;User
ID=test;Password=test;Network Library=DBMSSOCN;Load Balance Timeout=5"
Thanks for your help
Greetings from Germany
Christian
Christian Grbner
MVP ISA Server
Hilfe & Infos rund um den ISA Server: http://www.msisafaq.de !!!!
NEU !!! Das Handbuch zum ISA 2006 - http://www.msisafaq.de/buch/

Monday, March 19, 2012

database management?

Hi to All,
I am working in vb and C# .net as front hand and use mySql or Squel server as back-hand.
task is, i did here it that, we have more than one table, each and every is related by using the concept of Primary and Foreign key management.
in that database if i remove a record from master table, than the related record of all child talbes shall auto-matically reoved that is my question how it does happen.
first thing that you have understood my problem if yes than please if you have any idea, mail me.
i will very much thnks in advance to you.
bye
regards Rajat.Moving to more appropriate forum.|||

In SQL Server you can either implement tzhis using your own logic by triggers or you use the built in automatically working functonality whic is called cascading delete. See more information about this in the Online help of SQL Server:

http://msdn2.microsoft.com/en-us/library/ms186973.aspx


Jens K. Suessmeyer.

-
http://www.sqlserver2005.de
-

Sunday, March 11, 2012

Database Maintenance Plans

Hello everyone,
I'm new to DB Maint Plans, so let me apologize upfront. I've taken over a system from a DBA who is no longer working here, and he set up Maint Plans for all of the existing DBs. The plans show up in the Enterprise Manager under "Management->Database Maintenance Plans" like they should, but there are also entries in the "Management->SQL Server Agent->Jobs" area. When I set up a new DB Maint Plan for a new DB, it seems to be working fine, but I don't have any corresponding entries in Jobs. Did the other DBA set these up manually? Does anyone know why he might have done this? Is it needed? The jobs and job steps look like the following:

[DBName]Full:
EXECUTE master.dbo.xp_sqlmaint N'-PlanID 33C423D0-CC31-40BD-A357-7DCCAB1DC262 -WriteHistory -VrfyBackup -BkUpMedia DISK -BkUpDB "W:\sqldata\MSSQL$P001\Backup" -DelBkUps 1WEEKS -CrBkSubDir -BkExt "BAK"'

[DBName]Maint Integrity Checks:
EXECUTE master.dbo.xp_sqlmaint N'-PlanID 33C423D0-CC31-40BD-A357-7DCCAB1DC262 -WriteHistory -CkDB '

[DBName]Maint Optimizations:
EXECUTE master.dbo.xp_sqlmaint N'-PlanID 33C423D0-CC31-40BD-A357-7DCCAB1DC262 -WriteHistory -RebldIdx 10 -RmUnusedSpace 50 10 '

Any help or insight would be greatly appreciated!
Thanks in advance,
CatWhen you set up a plan, it should set up a job. In Enterprise Manager folders window, right-click on Jobs and select "Refresh". I'm betting the GUI just isn't aware of the change you made...|||I would suggest that you start with BOL (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/entrmgr/em_6x7w.asp) for Database Maintenance Plans, and go from there.

-PatP|||When you set up a plan, it should set up a job. In Enterprise Manager folders window, right-click on Jobs and select "Refresh". I'm betting the GUI just isn't aware of the change you made...

Hi Blindman,
Thanks for your reply. I refreshed the GUI for Jobs, but I still don't see my maint plan tasks. Strange! I figured that it must have set up the jobs automatically, but since it didn't set up anything for mine, I didn't know what to think. Do you know if I might have done something incorrectly in setting up my plan? They appear to be working fine.

Well, any further insight would be appreciated.
Thanks for your time.
Cat|||Sorry. I'm not sure why they aren't showing up in your job list. I don't use the Maintenance Plans anyway.|||I would suggest that you start with BOL (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/entrmgr/em_6x7w.asp) for Database Maintenance Plans, and go from there.

-PatP

I have looked there (if I hadn't I would not have been able to set up a plan in the first place). If I had found the answers to my specific questions, I would not have posted them here. I realize that there are a lot of people who post questions on these boards without taking any time to research the answers themselves, but... 1) I am not one of them, and 2) Sometimes it is easier and less frustrating to ask a human for a quick answer to a question than to try and weed through the enormous amount of information contained in the BOL. If you are going to take the time to respond to a post, it would be more helpful if you would offer more specific areas or keywords to search on to reduce the amount of time spent pouring over information that does not apply.

Thank you for your time.
Cat|||Sorry. I'm not sure why they aren't showing up in your job list. I don't use the Maintenance Plans anyway.

Well, thank you! At least I know that the previous DBA did not manually set up the jobs. That's one mystery solved.

Thanks again, you're a sweetheart!
Cat|||Not necessarily. I set up jobs manually. The Maintenance Plan wizard sucks.|||I have If you are going to take the time to respond to a post, it would be more helpful if you would offer more specific areas or keywords to search on to reduce the amount of time spent pouring over information that does not apply.

Thank you for your time.
Cat
Hi Cat,
I think you have meet with some of the best and wonderful people of this forum.They are gurus in this field and they spend their valuable and busy time to answer questions from the most difficult one to the most silliest one.I bet that their suggestions are most helpful and have a deep insight.They have a huge patience and delicate word style to deal with everybody with extreme politeness.I suggest you to follow them without any hesitation,bcoz they have the best intention that you could think of. I am saying this not only they are my favourite but they are really a nice human being.|||Well, I'm not always delicate... ;)|||As Blindman noted, the Maintenance Plan Wizard is better than nothing, but to a DBA that's been around for a while it isn't a lot better than nothing. I'm one of the "crusty old pharts" that still prefers the level of control that comes from writing the maintenance scripts myself at the Transact-SQL level.

Usually when I see what you've decribed (Maintenance plans set up, then jobs set up to further customize the plan), it usually means that whoever set them up originally figured out they needed more, so they manually scheduled the job to allow them to customize the existing setup using parameters.

Sorry if I was a bit short up front. I've been running into a lot of posters/users complaining something to the effect of: "My toy is broke, you need to fix it for me, NOW" and that apparently carried forward into my response to your original question. I should have read it more closely before I responded.

-PatP|||Delicately handled, Pat.|||Sorry if I was a bit short up front. I've been running into a lot of posters/users complaining something to the effect of: "My toy is broke, you need to fix it for me, NOW" and that apparently carried forward into my response to your original question. I should have read it more closely before I responded.

-PatP

Thank you for that! And I'm sorry too if my tone was a bit harsh, I had been having a frustrating day. I have seen many of the posts on this board which you describe and I know that it can be frustrating.

I suspect that the previous DBA either did not set up the jobs himself and they were set up by SQL Server (like blindman suggested), OR he did set them up but only because he thought he had to rather than because he wanted to tweek them. I have come to find many of his DBA practises quite suspect to say the least.

Thanks again to everyone for their responses!
Cat

Thursday, March 8, 2012

Database Maintenance Plan no longer deleting old files

My maintenance plan is set up to delete the old database dump files and transaction logs. After months of this working, the dump files are no longer being deleted. This has happened before. I recreated the plan and it worked for a while, then stopped again. The old transaction logs are being deleted as scheduled. Please help.Below KB might help:
http://support.microsoft.com/default.aspx?scid=kb;en-us;303292&Product=sql2k
Also, check out below great troubleshooting suggestions from Bill H at MS:
-- Log files don't delete --
This is likely to be either a permissions problem or a sharing violation
problem. The maintenance plan is run as a job, and jobs are run by the
SQLServerAgent service.
Permissions:
1. Determine the startup account for the SQLServerAgent service
(Start|Programs|Administrative tools|Services|SQLServerAgent|Startup). This
account is the security context for jobs, and thus the maintenance plan.
2. If SQLServerAgent is started using LocalSystem (as opposed to a domain
account) then skip step 3.
3. On that box, log onto NT as that account. Using Explorer, attempt to
delete an expired backup. If that succeeds then go to Sharing Violation
section.
4. Log onto NT with an account that is an administrator and use Explorer to
look at the Properties|Security of the folder (where the backups reside)
and ensure the SQLServerAgent startup account has Full Control. If the
SQLServerAgent startup account is LocalSystem, then the account to consider
is SYSTEM.
5. In NT, if an account is a member of an NT group, and if that group has
Access is Denied, then that account will have Access is Denied, even if
that account is also a member of the Administrators group. Thus you may
need to check group permissions (if the Startup Account is a member of a
group).
6. Keep in mind that permissions (by default) are inherited from a parent
folder. Thus, if the backups are stored in C:\bak, and if someone had
denied permission to the SQLServerAgent startup account for C:\, then
C:\bak will inherit access is denied.
Sharing violation:
This is likely to be rooted in a timing issue, with the most likely cause
being another scheduled process (such as NT Backup or Anti-Virus software)
having the backup file open at the time when the SQLServerAgent (i.e., the
maintenance plan job) tried to delete it.
1. Download filemon and handle from www.sysinternals.com.
2. I am not sure whether filemon can be scheduled, or you might be able to
use NT scheduling services to start filemon just before the maintenance
plan job is started, but the filemon log can become very large, so it would
be best to start it some short time before the maintenance plan starts.
3. Inspect the filemon log for another process that has that backup file
open (if your lucky enough to have started filemon before this other
process grabs the backup folder), and inspect the log for the results when
the SQLServerAgent agent attempts to open that same file.
4. Schedule the job or that other process to do their work at different
times.
5. You can use the handle utility if you are around at the time when the
job is scheduled to run.
If the backup files are going to a \\share or a mapped drive (as opposed to
local drive), then you will need to modify the above (with respect to where
the tests and utilities are run).
Finally, inspection of the maintenance plan's history report might be
useful.
Thanks,
Bill Hollinshead
Microsoft, SQL Server
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Smith" <anonymous@.discussions.microsoft.com> wrote in message
news:B0355203-D93B-44F1-AD39-9EEE5194DEE3@.microsoft.com...
> My maintenance plan is set up to delete the old database dump files and transaction logs. After
months of this working, the dump files are no longer being deleted. This has happened before. I
recreated the plan and it worked for a while, then stopped again. The old transaction logs are
being deleted as scheduled. Please help.|||"Tibor Karaszi" <tibor.please_reply_to_public_forum.karaszi@.cornerstone.se> wrote in message news:<O7uyC2XxDHA.3224@.tk2msftngp13.phx.gbl>...
> Below KB might help:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;303292&Product=sql2k
>
> Also, check out below great troubleshooting suggestions from Bill H at MS:
>
> -- Log files don't delete --
> This is likely to be either a permissions problem or a sharing violation
> problem. The maintenance plan is run as a job, and jobs are run by the
> SQLServerAgent service.
> Permissions:
> 1. Determine the startup account for the SQLServerAgent service
> (Start|Programs|Administrative tools|Services|SQLServerAgent|Startup). This
> account is the security context for jobs, and thus the maintenance plan.
> 2. If SQLServerAgent is started using LocalSystem (as opposed to a domain
> account) then skip step 3.
> 3. On that box, log onto NT as that account. Using Explorer, attempt to
> delete an expired backup. If that succeeds then go to Sharing Violation
> section.
> 4. Log onto NT with an account that is an administrator and use Explorer to
> look at the Properties|Security of the folder (where the backups reside)
> and ensure the SQLServerAgent startup account has Full Control. If the
> SQLServerAgent startup account is LocalSystem, then the account to consider
> is SYSTEM.
> 5. In NT, if an account is a member of an NT group, and if that group has
> Access is Denied, then that account will have Access is Denied, even if
> that account is also a member of the Administrators group. Thus you may
> need to check group permissions (if the Startup Account is a member of a
> group).
> 6. Keep in mind that permissions (by default) are inherited from a parent
> folder. Thus, if the backups are stored in C:\bak, and if someone had
> denied permission to the SQLServerAgent startup account for C:\, then
> C:\bak will inherit access is denied.
> Sharing violation:
> This is likely to be rooted in a timing issue, with the most likely cause
> being another scheduled process (such as NT Backup or Anti-Virus software)
> having the backup file open at the time when the SQLServerAgent (i.e., the
> maintenance plan job) tried to delete it.
> 1. Download filemon and handle from www.sysinternals.com.
> 2. I am not sure whether filemon can be scheduled, or you might be able to
> use NT scheduling services to start filemon just before the maintenance
> plan job is started, but the filemon log can become very large, so it would
> be best to start it some short time before the maintenance plan starts.
> 3. Inspect the filemon log for another process that has that backup file
> open (if your lucky enough to have started filemon before this other
> process grabs the backup folder), and inspect the log for the results when
> the SQLServerAgent agent attempts to open that same file.
> 4. Schedule the job or that other process to do their work at different
> times.
> 5. You can use the handle utility if you are around at the time when the
> job is scheduled to run.
> If the backup files are going to a \\share or a mapped drive (as opposed to
> local drive), then you will need to modify the above (with respect to where
> the tests and utilities are run).
> Finally, inspection of the maintenance plan's history report might be
> useful.
> Thanks,
> Bill Hollinshead
> Microsoft, SQL Server
>
>
> --
> Tibor Karaszi, SQL Server MVP
> Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
>
> "Smith" <anonymous@.discussions.microsoft.com> wrote in message
> news:B0355203-D93B-44F1-AD39-9EEE5194DEE3@.microsoft.com...
> > My maintenance plan is set up to delete the old database dump files and transaction logs. After
> months of this working, the dump files are no longer being deleted. This has happened before. I
> recreated the plan and it worked for a while, then stopped again. The old transaction logs are
> being deleted as scheduled. Please help.
You may also want to check what the 'effective' date is on your job -
see if your date range is out of whack, or else, if the process that
is supposed to be deleting the files is running into a 'file lock'. I
have had problems before like this, where a process that copies my old
backup files to a new directory was not actually terminating all the
time, and so then whenever the other process tried to delete them, it
couldn't. If you can look at that - it may help - or else, try
rebooting the server (if you can) and waiting to see if it behaves
normally again.
When in doubt, reboot *grin*
Sonya

Wednesday, March 7, 2012

Database Maintenance Plan

I created a Database Maintence Plan to backup one of my database @. 7pm but doesn't seem to do anything at all. It was working for the past months untill just this morning i noticed that no latest *.BAK files were created since 18-Aug-2006. I have other databases which do backup OK except for this particular database. I can manually back it up but cannot automatically backup from the Database Maintenance Plan.

I can't seem to locate any error messages in the Log...Any ideas how i can get this working again?Check the SQL Server Agent Jobs to see if it is enabled. If it is not there, go to the DB Maintenance Job and reschedule it and the save it again. You should then see it in the SQL Server Agent Jobs.

Database Maintenance - DBCC REINDEX

Running SQL Server 2000.
I'm working on developing a maintenance plan that will keep our
databases healthy, and running at their best possible potential.
There are a few issues that come to mind after reading the various
ways of cleaning up things...and after trying a few of them I've got a
few more questions.
For instance, I just created a job to do the following:
1) shrink the log file by backing up with truncate only and then doing
a shrinkfile.
2) i then did a DBREINDEX on each table in the db
3) I then did an updateusage
What i found is that I could have done better by doing the shrinkfile
after the DBREINDEX since it grew the log file so much, but I'm wary
of what this could hurt. I know I could switch from Full Recover to
Bulk-Logged but I'm hesitant to do that because of the possible data
loss.
I would love to come up with a plan that could run nightly/weekly that
would fix my indexes and maintain my log files.
What would be the best way to implement what I've done above?
Thanks
Step 1: read and ponder http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
Step 2, use the code found in BOL under DBCC SHOWCONTIG which only rebuild the indexes which are
fragmented in the first place.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jcrider@.gmail.com> wrote in message
news:1184688227.637963.246580@.m37g2000prh.googlegr oups.com...
> Running SQL Server 2000.
> I'm working on developing a maintenance plan that will keep our
> databases healthy, and running at their best possible potential.
> There are a few issues that come to mind after reading the various
> ways of cleaning up things...and after trying a few of them I've got a
> few more questions.
> For instance, I just created a job to do the following:
> 1) shrink the log file by backing up with truncate only and then doing
> a shrinkfile.
> 2) i then did a DBREINDEX on each table in the db
> 3) I then did an updateusage
> What i found is that I could have done better by doing the shrinkfile
> after the DBREINDEX since it grew the log file so much, but I'm wary
> of what this could hurt. I know I could switch from Full Recover to
> Bulk-Logged but I'm hesitant to do that because of the possible data
> loss.
> I would love to come up with a plan that could run nightly/weekly that
> would fix my indexes and maintain my log files.
> What would be the best way to implement what I've done above?
> Thanks
>
|||I've read through that article several times and I'm aware of the Rebuild on
the tables that need it most.
The main part of my question is about the timing of the shrinkfile, and how
that can help with the log file size during the initial run. Is there a
benefit to running the shrinkfile before the DBCC REINDEX, Before and after,
or just after? That's the biggest question I have.
Our log files get pretty big even under normal operations and I believe that
an index (even if just on the tables that need it) and shrinkfile nightly may
help.
"Tibor Karaszi" wrote:

> Step 1: read and ponder http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
> Step 2, use the code found in BOL under DBCC SHOWCONTIG which only rebuild the indexes which are
> fragmented in the first place.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jcrider@.gmail.com> wrote in message
> news:1184688227.637963.246580@.m37g2000prh.googlegr oups.com...
>
|||Why bother with shrinkfile in the first place? The log is emptied when you do a backup of the log.
If you want to break your log backup chain, then I suggest you do BACKUP LOG dbname WITH
TRUNCATE_ONLY after the shrink operation. I wouldn't shrink the file since it will only bump up to
the same size next night, so all you do if getting worse performance (*).
Actually, BACKUP LOG dbname WITH TRUNCATE ONLY will be removed in a future version, where setting
the db to simple recovery and then back to full achieves the same thing.
Also, you can even do concurrent or interleaved BACKUP LOG dbname WITH TRUNCATE ONLY along with your
DBREINDEX operations. This way you empty the log after each index rebuild. Or, the recommended way
(see above paragraph) would be to have the db in simple recovery during the reindex job.
You need, of course, think about the consequences of breaking the log backup chain. This is not
something to be taken lightly...
(*)
http://www.karaszi.com/SQLServer/info_dont_shrink.asp
http://sqlblog.com/blogs/tibor_karaszi/archive/2007/02/25/leaking-roof-and-file-shrinking.aspx
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:8AB8248A-5813-4308-A019-F4C3F2AE994A@.microsoft.com...[vbcol=seagreen]
> I've read through that article several times and I'm aware of the Rebuild on
> the tables that need it most.
> The main part of my question is about the timing of the shrinkfile, and how
> that can help with the log file size during the initial run. Is there a
> benefit to running the shrinkfile before the DBCC REINDEX, Before and after,
> or just after? That's the biggest question I have.
> Our log files get pretty big even under normal operations and I believe that
> an index (even if just on the tables that need it) and shrinkfile nightly may
> help.
> "Tibor Karaszi" wrote:
|||Ok, I'm currently doing a nightly Transaction Log Backup so I'm fine in that
regard and don't need to do that. If I understand you correctly, that does
the same thing as DBCC Shrinkfile (log).
You mention switching the recovery model.
Doesn't switching it from Full -> Simple...doing your stuff...and then
switching Simple -> Full break your log backup chain as well?
When you go from Simple to full you have to do a backup anyway.
From this article (http://msdn2.microsoft.com/en-us/library/ms178052.aspx)
- Immediately after you complete the switch to the full recovery model or
bulk-logged recovery model, take a full or differential database backup to
start the log chain.
The switch to the full or bulk-logged recovery model takes effect only after
the first data backup.
-If you switch from the full or bulk-logged recovery model to the simple
recovery model, you break the backup log chain. Therefore, we strongly
recommend that you back up the log immediately before switching, which allows
you to recover the database up to that point. After switching, you need to
take periodic data backups to protect your data and to truncate the inactive
portion of the transaction log.
Currently we have our the following procedure:
1) Our production server has the transaction logs backed up.
2) The Backup kicks off.
From what I gather, it would be best to run a job before those two that
executes a stored procedure reindexing the tables that need it. Then run a
DBCC UPDATEUSAGE.
Does that sound about right? I'm not sure how switching the recovery models
would play into our plans.
"Tibor Karaszi" wrote:

> Why bother with shrinkfile in the first place? The log is emptied when you do a backup of the log.
> If you want to break your log backup chain, then I suggest you do BACKUP LOG dbname WITH
> TRUNCATE_ONLY after the shrink operation. I wouldn't shrink the file since it will only bump up to
> the same size next night, so all you do if getting worse performance (*).
> Actually, BACKUP LOG dbname WITH TRUNCATE ONLY will be removed in a future version, where setting
> the db to simple recovery and then back to full achieves the same thing.
> Also, you can even do concurrent or interleaved BACKUP LOG dbname WITH TRUNCATE ONLY along with your
> DBREINDEX operations. This way you empty the log after each index rebuild. Or, the recommended way
> (see above paragraph) would be to have the db in simple recovery during the reindex job.
> You need, of course, think about the consequences of breaking the log backup chain. This is not
> something to be taken lightly...
> (*)
> http://www.karaszi.com/SQLServer/info_dont_shrink.asp
> http://sqlblog.com/blogs/tibor_karaszi/archive/2007/02/25/leaking-roof-and-file-shrinking.aspx
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jason7655@.discussions.microsoft.com> wrote in message
> news:8AB8248A-5813-4308-A019-F4C3F2AE994A@.microsoft.com...
>
|||> Ok, I'm currently doing a nightly Transaction Log Backup so I'm fine in that
> regard and don't need to do that. If I understand you correctly, that does
> the same thing as DBCC Shrinkfile (log).
No, not at all. Backup log will empty the log file. that is *not* the same thing as making the file
smaller. Read my blog about leaking roof for analogy.

> Doesn't switching it from Full -> Simple...doing your stuff...and then
> switching Simple -> Full break your log backup chain as well?
Yes, it does. My point was that BACKUP LOG WITH TRUNCATE ONLY breaks the recovery model, and this
this command is deprecated, the "new" way of achieving this is to switch to simple and back to full.
Switching to simple and back to full does the same thing as BACKUP LOG WITH TRUNCATE ONLY. And yes,
both breaks the log backup chain.

> When you go from Simple to full you have to do a backup anyway.
Yes, if you want to keep doing log backups.

> From what I gather, it would be best to run a job before those two that
> executes a stored procedure reindexing the tables that need it. Then run a
> DBCC UPDATEUSAGE.
I don't understand what DBCC UPDATEUSAGE has to do with things.
Perhaps we can go back to the requirements, because, honestly, I'm a bit lost here.
What are your requirements?
Do you need to do log backups at all?
Do you need an unbroken chain of log backups over a longer time?
Also, what exactly is it that you now want to achieve?
Keep the log file small but also do DBREINDEX?
If you can provide information about above, we can probably suggest some reasonable scheme for you.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:6BFDD6D2-14D3-40D5-A4D1-4F3C0DDF7A84@.microsoft.com...[vbcol=seagreen]
> Ok, I'm currently doing a nightly Transaction Log Backup so I'm fine in that
> regard and don't need to do that. If I understand you correctly, that does
> the same thing as DBCC Shrinkfile (log).
> You mention switching the recovery model.
> Doesn't switching it from Full -> Simple...doing your stuff...and then
> switching Simple -> Full break your log backup chain as well?
> When you go from Simple to full you have to do a backup anyway.
> From this article (http://msdn2.microsoft.com/en-us/library/ms178052.aspx)
> - Immediately after you complete the switch to the full recovery model or
> bulk-logged recovery model, take a full or differential database backup to
> start the log chain.
> The switch to the full or bulk-logged recovery model takes effect only after
> the first data backup.
> -If you switch from the full or bulk-logged recovery model to the simple
> recovery model, you break the backup log chain. Therefore, we strongly
> recommend that you back up the log immediately before switching, which allows
> you to recover the database up to that point. After switching, you need to
> take periodic data backups to protect your data and to truncate the inactive
> portion of the transaction log.
> Currently we have our the following procedure:
> 1) Our production server has the transaction logs backed up.
> 2) The Backup kicks off.
> From what I gather, it would be best to run a job before those two that
> executes a stored procedure reindexing the tables that need it. Then run a
> DBCC UPDATEUSAGE.
> Does that sound about right? I'm not sure how switching the recovery models
> would play into our plans.
>
> "Tibor Karaszi" wrote:
|||The requirements:
The databases have not been properly maintained for some time. The only
maintenance on them have been the backup and transaction log
backup.Fragmentation has occured at the pc level as well as database level.
I would like to implement a plan that essentially returns a database to best
health on a consistent basis (whether that be nightly, weekly, or monthly).
The databases have become large, and that's understandable...but it's also
made me wonder what the benefits of doing a shrinkdatabase on them would do
but that is a different story.
We defragmented the physical disks, and it's suggested that after a physical
defrag you rebuild the indexes. That's what got us to this point and it's
got me wondering the benefits of scheduled reindexing.
I don't guess that the DBCC UPDATEUSAGE is absolutely necessary, but it was
in some old scripts that i found.
Yes, we need to do log backups so that the transaction logs will fit on the
backup tape.
Unbroken chain over a longer period of time? Not so sure, because we keep 2
weeks backup of the transaction logs.
What I want to acheive is the best possible performance of my system, and
sheduled jobs would be the way I'd like to do it.
"Tibor Karaszi" wrote:

> No, not at all. Backup log will empty the log file. that is *not* the same thing as making the file
> smaller. Read my blog about leaking roof for analogy.
>
> Yes, it does. My point was that BACKUP LOG WITH TRUNCATE ONLY breaks the recovery model, and this
> this command is deprecated, the "new" way of achieving this is to switch to simple and back to full.
> Switching to simple and back to full does the same thing as BACKUP LOG WITH TRUNCATE ONLY. And yes,
> both breaks the log backup chain.
>
> Yes, if you want to keep doing log backups.
>
> I don't understand what DBCC UPDATEUSAGE has to do with things.
> Perhaps we can go back to the requirements, because, honestly, I'm a bit lost here.
> What are your requirements?
> Do you need to do log backups at all?
> Do you need an unbroken chain of log backups over a longer time?
> Also, what exactly is it that you now want to achieve?
> Keep the log file small but also do DBREINDEX?
> If you can provide information about above, we can probably suggest some reasonable scheme for you.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jason7655@.discussions.microsoft.com> wrote in message
> news:6BFDD6D2-14D3-40D5-A4D1-4F3C0DDF7A84@.microsoft.com...
>
|||So basically what you want to do is to have regular database backups and more frequent log backups.
And also defragment inside the database regularly. OK, this is perfectly normal.
You keep two weeks of log backups, and I suggest you try to have those as an unbroken chain of log
backups. Say you do db backup every night. And say you find out that a corruption occurred (broken
page, for instance) three days ago. You can now restore the most recent *healthy* db backup (4 days
ago) and all subsequent log backups. This is what I mean by having an unbroken chain of log backups.
If you think that this is a good idea, then don't set the db to simple recovery model and don't do
BACKUP LOG WITH TRUNCATE ONLY.
Since we need to start with the requirements and work from there, it is important that you and your
organization agree on whether above is the requirement for your database. Lets assume it is:
What backups to have is a no-brainer. Of course, you need to consider how frequent to do database
and log backups.
You also say you want to defragment your indexes. OK. The MS article I posted earlier has good
background information about this. Based on that article, you can decide whether to use DBCC
INDEXDEFRAG or DBCC DBREINDEX or a combination of the two (like reorganize if fragmentation is
between 5 and 30%, rebuild if higher). I suggest that you only reorganize or rebuild indexes that
aren't fragmented.
Now, the defragmentation of your indexes will generate log records. No way around this if you want
an unbroken chain of log backups. So you need to have resources to handle this (disk space for the
log and subsequent log backups).
As you probably know, I do not recommend shrink, and I posted a couple of articles earlier
describing why.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:9CF903A1-7D43-4774-A644-9EACDC7478C8@.microsoft.com...[vbcol=seagreen]
> The requirements:
> The databases have not been properly maintained for some time. The only
> maintenance on them have been the backup and transaction log
> backup.Fragmentation has occured at the pc level as well as database level.
> I would like to implement a plan that essentially returns a database to best
> health on a consistent basis (whether that be nightly, weekly, or monthly).
> The databases have become large, and that's understandable...but it's also
> made me wonder what the benefits of doing a shrinkdatabase on them would do
> but that is a different story.
> We defragmented the physical disks, and it's suggested that after a physical
> defrag you rebuild the indexes. That's what got us to this point and it's
> got me wondering the benefits of scheduled reindexing.
> I don't guess that the DBCC UPDATEUSAGE is absolutely necessary, but it was
> in some old scripts that i found.
> Yes, we need to do log backups so that the transaction logs will fit on the
> backup tape.
> Unbroken chain over a longer period of time? Not so sure, because we keep 2
> weeks backup of the transaction logs.
> What I want to acheive is the best possible performance of my system, and
> sheduled jobs would be the way I'd like to do it.
> "Tibor Karaszi" wrote:
|||Ok, so any clue why the following will work with 30 or 20, but not 10 for the
maximum fragmentation?
USE Database
-- Declare variables
SET NOCOUNT ON
DECLARE @.tablename VARCHAR (128)
DECLARE @.execstr VARCHAR (255)
DECLARE @.objectid INT
DECLARE @.indexid INT
DECLARE @.frag DECIMAL
DECLARE @.maxfrag DECIMAL
-- Decide on the maximum fragmentation to allow
SELECT @.maxfrag = 10.0;
-- Declare cursor
DECLARE tables CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
-- Create the table
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
-- Open the cursor
OPEN tables
-- Loop through all the tables in the database
FETCH NEXT
FROM tables
INTO @.tablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @.tablename + ''')
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS')
FETCH NEXT
FROM tables
INTO @.tablename
END
-- Close and deallocate the cursor
CLOSE tables
DEALLOCATE tables
-- Declare cursor for list of indexes to be defragged
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
-- Open the cursor
OPEN indexes
-- loop through the indexes
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.execstr = 'DBCC DBREINDEX (' + RTRIM(@.objectid) + ',
' + RTRIM(@.indexid) + ') WITH NO_INFOMSGS'
EXEC (@.execstr)
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag
END
-- Close and deallocate the cursor
CLOSE indexes
DEALLOCATE indexes
-- Delete the temporary table
DROP TABLE #fraglist
GO
"Tibor Karaszi" wrote:

> So basically what you want to do is to have regular database backups and more frequent log backups.
> And also defragment inside the database regularly. OK, this is perfectly normal.
> You keep two weeks of log backups, and I suggest you try to have those as an unbroken chain of log
> backups. Say you do db backup every night. And say you find out that a corruption occurred (broken
> page, for instance) three days ago. You can now restore the most recent *healthy* db backup (4 days
> ago) and all subsequent log backups. This is what I mean by having an unbroken chain of log backups.
> If you think that this is a good idea, then don't set the db to simple recovery model and don't do
> BACKUP LOG WITH TRUNCATE ONLY.
> Since we need to start with the requirements and work from there, it is important that you and your
> organization agree on whether above is the requirement for your database. Lets assume it is:
> What backups to have is a no-brainer. Of course, you need to consider how frequent to do database
> and log backups.
> You also say you want to defragment your indexes. OK. The MS article I posted earlier has good
> background information about this. Based on that article, you can decide whether to use DBCC
> INDEXDEFRAG or DBCC DBREINDEX or a combination of the two (like reorganize if fragmentation is
> between 5 and 30%, rebuild if higher). I suggest that you only reorganize or rebuild indexes that
> aren't fragmented.
> Now, the defragmentation of your indexes will generate log records. No way around this if you want
> an unbroken chain of log backups. So you need to have resources to handle this (disk space for the
> log and subsequent log backups).
> As you probably know, I do not recommend shrink, and I posted a couple of articles earlier
> describing why.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jason7655@.discussions.microsoft.com> wrote in message
> news:9CF903A1-7D43-4774-A644-9EACDC7478C8@.microsoft.com...
>
|||I'm working my way through the script, and below comment things as I find them:
You declare @.objectid as an int and then in the EXEC you LTRIM it. An int doesn't have trailing
spaces, since it isn't a string. I recommend you use CAST, since this is what you need to achieve
and is mire readable.
You pass the id of the table and index into DBCC DBREINDEX. Looking in Books Online, it need the
name, not the id.
You declare @.tablename as varchar(128), where it should be nvarchar(128), or preferrabley sysname.
For safety, I always declare my "execstrings" to nvarchar(4000).
The #fraglist table has table and index name as fixed length datatypes, Define them as variable and
you don't need to trim them later on.
Here's a revised script which seems to work:
-- Declare variables
SET NOCOUNT ON
DECLARE @.tablename sysname
DECLARE @.execstr nvarchar(4000)
DECLARE @.objectid INT
DECLARE @.indexid INT
DECLARE @.indexname sysname
DECLARE @.frag DECIMAL
DECLARE @.maxfrag DECIMAL
DECLARE @.sql nvarchar(4000)
-- Decide on the maximum fragmentation to allow
SELECT @.maxfrag = 10.0;
-- Declare cursor
DECLARE tables CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
-- Create the table
CREATE TABLE #fraglist (
ObjectName varCHAR (255),
ObjectId INT,
IndexName varCHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
-- Open the cursor
OPEN tables
-- Loop through all the tables in the database
FETCH NEXT
FROM tables
INTO @.tablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
PRINT ('DBCC SHOWCONTIG (''' + @.tablename + ''') WITH FAST, TABLERESULTS, ALL_INDEXES,
NO_INFOMSGS')
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @.tablename + ''') WITH FAST, TABLERESULTS, ALL_INDEXES,
NO_INFOMSGS')
FETCH NEXT
FROM tables
INTO @.tablename
END
-- Close and deallocate the cursor
CLOSE tables
DEALLOCATE tables
-- Declare cursor for list of indexes to be defragged
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
-- Open the cursor
OPEN indexes
-- loop through the indexes
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag, @.indexname
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.execstr = 'DBCC DBREINDEX (' + @.tablename + ', ' + @.indexname + ') WITH NO_INFOMSGS'
PRINT @.execstr
EXEC (@.execstr)
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag, @.indexname
END
-- Close and deallocate the cursor
CLOSE indexes
DEALLOCATE indexes
-- Delete the temporary table
DROP TABLE #fraglist
GO
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:F71215C6-A458-416D-8E51-8457583814CE@.microsoft.com...[vbcol=seagreen]
> Ok, so any clue why the following will work with 30 or 20, but not 10 for the
> maximum fragmentation?
> USE Database
> -- Declare variables
> SET NOCOUNT ON
> DECLARE @.tablename VARCHAR (128)
> DECLARE @.execstr VARCHAR (255)
> DECLARE @.objectid INT
> DECLARE @.indexid INT
> DECLARE @.frag DECIMAL
> DECLARE @.maxfrag DECIMAL
> -- Decide on the maximum fragmentation to allow
> SELECT @.maxfrag = 10.0;
> -- Declare cursor
> DECLARE tables CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> -- Create the table
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> -- Open the cursor
> OPEN tables
> -- Loop through all the tables in the database
> FETCH NEXT
> FROM tables
> INTO @.tablename
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> -- Do the showcontig of all indexes of the table
> INSERT INTO #fraglist
> EXEC ('DBCC SHOWCONTIG (''' + @.tablename + ''')
> WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS')
> FETCH NEXT
> FROM tables
> INTO @.tablename
> END
> -- Close and deallocate the cursor
> CLOSE tables
> DEALLOCATE tables
> -- Declare cursor for list of indexes to be defragged
> DECLARE indexes CURSOR FOR
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> -- Open the cursor
> OPEN indexes
> -- loop through the indexes
> FETCH NEXT
> FROM indexes
> INTO @.tablename, @.objectid, @.indexid, @.frag
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SELECT @.execstr = 'DBCC DBREINDEX (' + RTRIM(@.objectid) + ',
> ' + RTRIM(@.indexid) + ') WITH NO_INFOMSGS'
> EXEC (@.execstr)
> FETCH NEXT
> FROM indexes
> INTO @.tablename, @.objectid, @.indexid, @.frag
> END
> -- Close and deallocate the cursor
> CLOSE indexes
> DEALLOCATE indexes
> -- Delete the temporary table
> DROP TABLE #fraglist
> GO
> "Tibor Karaszi" wrote:

Database Maintenance - DBCC REINDEX

Running SQL Server 2000.
I'm working on developing a maintenance plan that will keep our
databases healthy, and running at their best possible potential.
There are a few issues that come to mind after reading the various
ways of cleaning up things...and after trying a few of them I've got a
few more questions.
For instance, I just created a job to do the following:
1) shrink the log file by backing up with truncate only and then doing
a shrinkfile.
2) i then did a DBREINDEX on each table in the db
3) I then did an updateusage
What i found is that I could have done better by doing the shrinkfile
after the DBREINDEX since it grew the log file so much, but I'm wary
of what this could hurt. I know I could switch from Full Recover to
Bulk-Logged but I'm hesitant to do that because of the possible data
loss.
I would love to come up with a plan that could run nightly/weekly that
would fix my indexes and maintain my log files.
What would be the best way to implement what I've done above?
ThanksStep 1: read and ponder http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
Step 2, use the code found in BOL under DBCC SHOWCONTIG which only rebuild t
he indexes which are
fragmented in the first place.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jcrider@.gmail.com> wrote in message
news:1184688227.637963.246580@.m37g2000prh.googlegroups.com...
> Running SQL Server 2000.
> I'm working on developing a maintenance plan that will keep our
> databases healthy, and running at their best possible potential.
> There are a few issues that come to mind after reading the various
> ways of cleaning up things...and after trying a few of them I've got a
> few more questions.
> For instance, I just created a job to do the following:
> 1) shrink the log file by backing up with truncate only and then doing
> a shrinkfile.
> 2) i then did a DBREINDEX on each table in the db
> 3) I then did an updateusage
> What i found is that I could have done better by doing the shrinkfile
> after the DBREINDEX since it grew the log file so much, but I'm wary
> of what this could hurt. I know I could switch from Full Recover to
> Bulk-Logged but I'm hesitant to do that because of the possible data
> loss.
> I would love to come up with a plan that could run nightly/weekly that
> would fix my indexes and maintain my log files.
> What would be the best way to implement what I've done above?
> Thanks
>|||I've read through that article several times and I'm aware of the Rebuild on
the tables that need it most.
The main part of my question is about the timing of the shrinkfile, and how
that can help with the log file size during the initial run. Is there a
benefit to running the shrinkfile before the DBCC REINDEX, Before and after,
or just after? That's the biggest question I have.
Our log files get pretty big even under normal operations and I believe that
an index (even if just on the tables that need it) and shrinkfile nightly ma
y
help.
"Tibor Karaszi" wrote:

> Step 1: read and ponder http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
> Step 2, use the code found in BOL under DBCC SHOWCONTIG which only rebuild
the indexes which are
> fragmented in the first place.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jcrider@.gmail.com> wrote in message
> news:1184688227.637963.246580@.m37g2000prh.googlegroups.com...
>|||Why bother with shrinkfile in the first place? The log is emptied when you d
o a backup of the log.
If you want to break your log backup chain, then I suggest you do BACKUP LOG
dbname WITH
TRUNCATE_ONLY after the shrink operation. I wouldn't shrink the file since i
t will only bump up to
the same size next night, so all you do if getting worse performance (*).
Actually, BACKUP LOG dbname WITH TRUNCATE ONLY will be removed in a future v
ersion, where setting
the db to simple recovery and then back to full achieves the same thing.
Also, you can even do concurrent or interleaved BACKUP LOG dbname WITH TRUNC
ATE ONLY along with your
DBREINDEX operations. This way you empty the log after each index rebuild. O
r, the recommended way
(see above paragraph) would be to have the db in simple recovery during the
reindex job.
You need, of course, think about the consequences of breaking the log backup
chain. This is not
something to be taken lightly...
(*)
http://www.karaszi.com/SQLServer/info_dont_shrink.asp
http://sqlblog.com/blogs/tibor_kara...>
rinking.aspx
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:8AB8248A-5813-4308-A019-F4C3F2AE994A@.microsoft.com...[vbcol=seagreen]
> I've read through that article several times and I'm aware of the Rebuild
on
> the tables that need it most.
> The main part of my question is about the timing of the shrinkfile, and ho
w
> that can help with the log file size during the initial run. Is there a
> benefit to running the shrinkfile before the DBCC REINDEX, Before and afte
r,
> or just after? That's the biggest question I have.
> Our log files get pretty big even under normal operations and I believe th
at
> an index (even if just on the tables that need it) and shrinkfile nightly
may
> help.
> "Tibor Karaszi" wrote:
>|||Ok, I'm currently doing a nightly Transaction Log Backup so I'm fine in that
regard and don't need to do that. If I understand you correctly, that does
the same thing as DBCC Shrinkfile (log).
You mention switching the recovery model.
Doesn't switching it from Full -> Simple...doing your stuff...and then
switching Simple -> Full break your log backup chain as well?
When you go from Simple to full you have to do a backup anyway.
From this article (http://msdn2.microsoft.com/en-us/library/ms178052.aspx)
- Immediately after you complete the switch to the full recovery model or
bulk-logged recovery model, take a full or differential database backup to
start the log chain.
The switch to the full or bulk-logged recovery model takes effect only after
the first data backup.
-If you switch from the full or bulk-logged recovery model to the simple
recovery model, you break the backup log chain. Therefore, we strongly
recommend that you back up the log immediately before switching, which allow
s
you to recover the database up to that point. After switching, you need to
take periodic data backups to protect your data and to truncate the inactive
portion of the transaction log.
Currently we have our the following procedure:
1) Our production server has the transaction logs backed up.
2) The Backup kicks off.
From what I gather, it would be best to run a job before those two that
executes a stored procedure reindexing the tables that need it. Then run a
DBCC UPDATEUSAGE.
Does that sound about right? I'm not sure how switching the recovery models
would play into our plans.
"Tibor Karaszi" wrote:

> Why bother with shrinkfile in the first place? The log is emptied when you
do a backup of the log.
> If you want to break your log backup chain, then I suggest you do BACKUP L
OG dbname WITH
> TRUNCATE_ONLY after the shrink operation. I wouldn't shrink the file since
it will only bump up to
> the same size next night, so all you do if getting worse performance (*).
> Actually, BACKUP LOG dbname WITH TRUNCATE ONLY will be removed in a future
version, where setting
> the db to simple recovery and then back to full achieves the same thing.
> Also, you can even do concurrent or interleaved BACKUP LOG dbname WITH TRU
NCATE ONLY along with your
> DBREINDEX operations. This way you empty the log after each index rebuild.
Or, the recommended way
> (see above paragraph) would be to have the db in simple recovery during th
e reindex job.
> You need, of course, think about the consequences of breaking the log back
up chain. This is not
> something to be taken lightly...
> (*)
> http://www.karaszi.com/SQLServer/info_dont_shrink.asp
> http://sqlblog.com/blogs/tibor_kara...
shrinking.aspx
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jason7655@.discussions.microsoft.com> wrote in message
> news:8AB8248A-5813-4308-A019-F4C3F2AE994A@.microsoft.com...
>|||> Ok, I'm currently doing a nightly Transaction Log Backup so I'm fine in thatn">
> regard and don't need to do that. If I understand you correctly, that doe
s
> the same thing as DBCC Shrinkfile (log).
No, not at all. Backup log will empty the log file. that is *not* the same t
hing as making the file
smaller. Read my blog about leaking roof for analogy.

> Doesn't switching it from Full -> Simple...doing your stuff...and then
> switching Simple -> Full break your log backup chain as well?
Yes, it does. My point was that BACKUP LOG WITH TRUNCATE ONLY breaks the rec
overy model, and this
this command is deprecated, the "new" way of achieving this is to switch to
simple and back to full.
Switching to simple and back to full does the same thing as BACKUP LOG WITH
TRUNCATE ONLY. And yes,
both breaks the log backup chain.

> When you go from Simple to full you have to do a backup anyway.
Yes, if you want to keep doing log backups.

> From what I gather, it would be best to run a job before those two that
> executes a stored procedure reindexing the tables that need it. Then run a
> DBCC UPDATEUSAGE.
I don't understand what DBCC UPDATEUSAGE has to do with things.
Perhaps we can go back to the requirements, because, honestly, I'm a bit los
t here.
What are your requirements?
Do you need to do log backups at all?
Do you need an unbroken chain of log backups over a longer time?
Also, what exactly is it that you now want to achieve?
Keep the log file small but also do DBREINDEX?
If you can provide information about above, we can probably suggest some rea
sonable scheme for you.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:6BFDD6D2-14D3-40D5-A4D1-4F3C0DDF7A84@.microsoft.com...[vbcol=seagreen]
> Ok, I'm currently doing a nightly Transaction Log Backup so I'm fine in th
at
> regard and don't need to do that. If I understand you correctly, that doe
s
> the same thing as DBCC Shrinkfile (log).
> You mention switching the recovery model.
> Doesn't switching it from Full -> Simple...doing your stuff...and then
> switching Simple -> Full break your log backup chain as well?
> When you go from Simple to full you have to do a backup anyway.
> From this article (http://msdn2.microsoft.com/en-us/library/ms178052.aspx)
> - Immediately after you complete the switch to the full recovery model or
> bulk-logged recovery model, take a full or differential database backup to
> start the log chain.
> The switch to the full or bulk-logged recovery model takes effect only aft
er
> the first data backup.
> -If you switch from the full or bulk-logged recovery model to the simple
> recovery model, you break the backup log chain. Therefore, we strongly
> recommend that you back up the log immediately before switching, which all
ows
> you to recover the database up to that point. After switching, you need to
> take periodic data backups to protect your data and to truncate the inacti
ve
> portion of the transaction log.
> Currently we have our the following procedure:
> 1) Our production server has the transaction logs backed up.
> 2) The Backup kicks off.
> From what I gather, it would be best to run a job before those two that
> executes a stored procedure reindexing the tables that need it. Then run a
> DBCC UPDATEUSAGE.
> Does that sound about right? I'm not sure how switching the recovery model
s
> would play into our plans.
>
> "Tibor Karaszi" wrote:
>|||The requirements:
The databases have not been properly maintained for some time. The only
maintenance on them have been the backup and transaction log
backup.Fragmentation has occured at the pc level as well as database level.
I would like to implement a plan that essentially returns a database to best
health on a consistent basis (whether that be nightly, weekly, or monthly).
The databases have become large, and that's understandable...but it's also
made me wonder what the benefits of doing a shrinkdatabase on them would do
but that is a different story.
We defragmented the physical disks, and it's suggested that after a physical
defrag you rebuild the indexes. That's what got us to this point and it's
got me wondering the benefits of scheduled reindexing.
I don't guess that the DBCC UPDATEUSAGE is absolutely necessary, but it was
in some old scripts that i found.
Yes, we need to do log backups so that the transaction logs will fit on the
backup tape.
Unbroken chain over a longer period of time? Not so sure, because we keep 2
weeks backup of the transaction logs.
What I want to acheive is the best possible performance of my system, and
sheduled jobs would be the way I'd like to do it.
"Tibor Karaszi" wrote:

> No, not at all. Backup log will empty the log file. that is *not* the same
thing as making the file
> smaller. Read my blog about leaking roof for analogy.
>
> Yes, it does. My point was that BACKUP LOG WITH TRUNCATE ONLY breaks the r
ecovery model, and this
> this command is deprecated, the "new" way of achieving this is to switch t
o simple and back to full.
> Switching to simple and back to full does the same thing as BACKUP LOG WIT
H TRUNCATE ONLY. And yes,
> both breaks the log backup chain.
>
> Yes, if you want to keep doing log backups.
>
> I don't understand what DBCC UPDATEUSAGE has to do with things.
> Perhaps we can go back to the requirements, because, honestly, I'm a bit l
ost here.
> What are your requirements?
> Do you need to do log backups at all?
> Do you need an unbroken chain of log backups over a longer time?
> Also, what exactly is it that you now want to achieve?
> Keep the log file small but also do DBREINDEX?
> If you can provide information about above, we can probably suggest some r
easonable scheme for you.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jason7655@.discussions.microsoft.com> wrote in message
> news:6BFDD6D2-14D3-40D5-A4D1-4F3C0DDF7A84@.microsoft.com...
>|||So basically what you want to do is to have regular database backups and mor
e frequent log backups.
And also defragment inside the database regularly. OK, this is perfectly nor
mal.
You keep two weeks of log backups, and I suggest you try to have those as an
unbroken chain of log
backups. Say you do db backup every night. And say you find out that a corru
ption occurred (broken
page, for instance) three days ago. You can now restore the most recent *hea
lthy* db backup (4 days
ago) and all subsequent log backups. This is what I mean by having an unbrok
en chain of log backups.
If you think that this is a good idea, then don't set the db to simple recov
ery model and don't do
BACKUP LOG WITH TRUNCATE ONLY.
Since we need to start with the requirements and work from there, it is impo
rtant that you and your
organization agree on whether above is the requirement for your database. Le
ts assume it is:
What backups to have is a no-brainer. Of course, you need to consider how fr
equent to do database
and log backups.
You also say you want to defragment your indexes. OK. The MS article I poste
d earlier has good
background information about this. Based on that article, you can decide whe
ther to use DBCC
INDEXDEFRAG or DBCC DBREINDEX or a combination of the two (like reorganize i
f fragmentation is
between 5 and 30%, rebuild if higher). I suggest that you only reorganize or
rebuild indexes that
aren't fragmented.
Now, the defragmentation of your indexes will generate log records. No way a
round this if you want
an unbroken chain of log backups. So you need to have resources to handle th
is (disk space for the
log and subsequent log backups).
As you probably know, I do not recommend shrink, and I posted a couple of ar
ticles earlier
describing why.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:9CF903A1-7D43-4774-A644-9EACDC7478C8@.microsoft.com...[vbcol=seagreen]
> The requirements:
> The databases have not been properly maintained for some time. The only
> maintenance on them have been the backup and transaction log
> backup.Fragmentation has occured at the pc level as well as database level
.
> I would like to implement a plan that essentially returns a database to be
st
> health on a consistent basis (whether that be nightly, weekly, or monthly)
.
> The databases have become large, and that's understandable...but it's also
> made me wonder what the benefits of doing a shrinkdatabase on them would d
o
> but that is a different story.
> We defragmented the physical disks, and it's suggested that after a physic
al
> defrag you rebuild the indexes. That's what got us to this point and it's
> got me wondering the benefits of scheduled reindexing.
> I don't guess that the DBCC UPDATEUSAGE is absolutely necessary, but it wa
s
> in some old scripts that i found.
> Yes, we need to do log backups so that the transaction logs will fit on th
e
> backup tape.
> Unbroken chain over a longer period of time? Not so sure, because we keep
2
> weeks backup of the transaction logs.
> What I want to acheive is the best possible performance of my system, and
> sheduled jobs would be the way I'd like to do it.
> "Tibor Karaszi" wrote:
>|||Ok, so any clue why the following will work with 30 or 20, but not 10 for th
e
maximum fragmentation?
USE Database
-- Declare variables
SET NOCOUNT ON
DECLARE @.tablename VARCHAR (128)
DECLARE @.execstr VARCHAR (255)
DECLARE @.objectid INT
DECLARE @.indexid INT
DECLARE @.frag DECIMAL
DECLARE @.maxfrag DECIMAL
-- Decide on the maximum fragmentation to allow
SELECT @.maxfrag = 10.0;
-- Declare cursor
DECLARE tables CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
-- Create the table
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
-- Open the cursor
OPEN tables
-- Loop through all the tables in the database
FETCH NEXT
FROM tables
INTO @.tablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @.tablename + ''')
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS')
FETCH NEXT
FROM tables
INTO @.tablename
END
-- Close and deallocate the cursor
CLOSE tables
DEALLOCATE tables
-- Declare cursor for list of indexes to be defragged
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
-- Open the cursor
OPEN indexes
-- loop through the indexes
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.execstr = 'DBCC DBREINDEX (' + RTRIM(@.objectid) + ',
' + RTRIM(@.indexid) + ') WITH NO_INFOMSGS'
EXEC (@.execstr)
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag
END
-- Close and deallocate the cursor
CLOSE indexes
DEALLOCATE indexes
-- Delete the temporary table
DROP TABLE #fraglist
GO
"Tibor Karaszi" wrote:

> So basically what you want to do is to have regular database backups and m
ore frequent log backups.
> And also defragment inside the database regularly. OK, this is perfectly n
ormal.
> You keep two weeks of log backups, and I suggest you try to have those as
an unbroken chain of log
> backups. Say you do db backup every night. And say you find out that a cor
ruption occurred (broken
> page, for instance) three days ago. You can now restore the most recent *h
ealthy* db backup (4 days
> ago) and all subsequent log backups. This is what I mean by having an unbr
oken chain of log backups.
> If you think that this is a good idea, then don't set the db to simple rec
overy model and don't do
> BACKUP LOG WITH TRUNCATE ONLY.
> Since we need to start with the requirements and work from there, it is im
portant that you and your
> organization agree on whether above is the requirement for your database.
Lets assume it is:
> What backups to have is a no-brainer. Of course, you need to consider how
frequent to do database
> and log backups.
> You also say you want to defragment your indexes. OK. The MS article I pos
ted earlier has good
> background information about this. Based on that article, you can decide w
hether to use DBCC
> INDEXDEFRAG or DBCC DBREINDEX or a combination of the two (like reorganize
if fragmentation is
> between 5 and 30%, rebuild if higher). I suggest that you only reorganize
or rebuild indexes that
> aren't fragmented.
> Now, the defragmentation of your indexes will generate log records. No way
around this if you want
> an unbroken chain of log backups. So you need to have resources to handle
this (disk space for the
> log and subsequent log backups).
> As you probably know, I do not recommend shrink, and I posted a couple of
articles earlier
> describing why.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "jason7655" <jason7655@.discussions.microsoft.com> wrote in message
> news:9CF903A1-7D43-4774-A644-9EACDC7478C8@.microsoft.com...
>|||I'm working my way through the script, and below comment things as I find th
em:
You declare @.objectid as an int and then in the EXEC you LTRIM it. An int do
esn't have trailing
spaces, since it isn't a string. I recommend you use CAST, since this is wha
t you need to achieve
and is mire readable.
You pass the id of the table and index into DBCC DBREINDEX. Looking in Books
Online, it need the
name, not the id.
You declare @.tablename as varchar(128), where it should be nvarchar(128), or
preferrabley sysname.
For safety, I always declare my "execstrings" to nvarchar(4000).
The #fraglist table has table and index name as fixed length datatypes, Defi
ne them as variable and
you don't need to trim them later on.
Here's a revised script which seems to work:
-- Declare variables
SET NOCOUNT ON
DECLARE @.tablename sysname
DECLARE @.execstr nvarchar(4000)
DECLARE @.objectid INT
DECLARE @.indexid INT
DECLARE @.indexname sysname
DECLARE @.frag DECIMAL
DECLARE @.maxfrag DECIMAL
DECLARE @.sql nvarchar(4000)
-- Decide on the maximum fragmentation to allow
SELECT @.maxfrag = 10.0;
-- Declare cursor
DECLARE tables CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
-- Create the table
CREATE TABLE #fraglist (
ObjectName varCHAR (255),
ObjectId INT,
IndexName varCHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
-- Open the cursor
OPEN tables
-- Loop through all the tables in the database
FETCH NEXT
FROM tables
INTO @.tablename
WHILE @.@.FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
PRINT ('DBCC SHOWCONTIG (''' + @.tablename + ''') WITH FAST, TABLERESULTS, A
LL_INDEXES,
NO_INFOMSGS')
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @.tablename + ''') WITH FAST, TABLERESULTS, AL
L_INDEXES,
NO_INFOMSGS')
FETCH NEXT
FROM tables
INTO @.tablename
END
-- Close and deallocate the cursor
CLOSE tables
DEALLOCATE tables
-- Declare cursor for list of indexes to be defragged
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag, IndexName
FROM #fraglist
WHERE LogicalFrag >= @.maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
-- Open the cursor
OPEN indexes
-- loop through the indexes
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag, @.indexname
WHILE @.@.FETCH_STATUS = 0
BEGIN
SELECT @.execstr = 'DBCC DBREINDEX (' + @.tablename + ', ' + @.indexname + ') W
ITH NO_INFOMSGS'
PRINT @.execstr
EXEC (@.execstr)
FETCH NEXT
FROM indexes
INTO @.tablename, @.objectid, @.indexid, @.frag, @.indexname
END
-- Close and deallocate the cursor
CLOSE indexes
DEALLOCATE indexes
-- Delete the temporary table
DROP TABLE #fraglist
GO
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:F71215C6-A458-416D-8E51-8457583814CE@.microsoft.com...[vbcol=seagreen]
> Ok, so any clue why the following will work with 30 or 20, but not 10 for
the
> maximum fragmentation?
> USE Database
> -- Declare variables
> SET NOCOUNT ON
> DECLARE @.tablename VARCHAR (128)
> DECLARE @.execstr VARCHAR (255)
> DECLARE @.objectid INT
> DECLARE @.indexid INT
> DECLARE @.frag DECIMAL
> DECLARE @.maxfrag DECIMAL
> -- Decide on the maximum fragmentation to allow
> SELECT @.maxfrag = 10.0;
> -- Declare cursor
> DECLARE tables CURSOR FOR
> SELECT TABLE_NAME
> FROM INFORMATION_SCHEMA.TABLES
> WHERE TABLE_TYPE = 'BASE TABLE'
> -- Create the table
> CREATE TABLE #fraglist (
> ObjectName CHAR (255),
> ObjectId INT,
> IndexName CHAR (255),
> IndexId INT,
> Lvl INT,
> CountPages INT,
> CountRows INT,
> MinRecSize INT,
> MaxRecSize INT,
> AvgRecSize INT,
> ForRecCount INT,
> Extents INT,
> ExtentSwitches INT,
> AvgFreeBytes INT,
> AvgPageDensity INT,
> ScanDensity DECIMAL,
> BestCount INT,
> ActualCount INT,
> LogicalFrag DECIMAL,
> ExtentFrag DECIMAL)
> -- Open the cursor
> OPEN tables
> -- Loop through all the tables in the database
> FETCH NEXT
> FROM tables
> INTO @.tablename
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> -- Do the showcontig of all indexes of the table
> INSERT INTO #fraglist
> EXEC ('DBCC SHOWCONTIG (''' + @.tablename + ''')
> WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS')
> FETCH NEXT
> FROM tables
> INTO @.tablename
> END
> -- Close and deallocate the cursor
> CLOSE tables
> DEALLOCATE tables
> -- Declare cursor for list of indexes to be defragged
> DECLARE indexes CURSOR FOR
> SELECT ObjectName, ObjectId, IndexId, LogicalFrag
> FROM #fraglist
> WHERE LogicalFrag >= @.maxfrag
> AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0
> -- Open the cursor
> OPEN indexes
> -- loop through the indexes
> FETCH NEXT
> FROM indexes
> INTO @.tablename, @.objectid, @.indexid, @.frag
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SELECT @.execstr = 'DBCC DBREINDEX (' + RTRIM(@.objectid) + ',
> ' + RTRIM(@.indexid) + ') WITH NO_INFOMSGS'
> EXEC (@.execstr)
> FETCH NEXT
> FROM indexes
> INTO @.tablename, @.objectid, @.indexid, @.frag
> END
> -- Close and deallocate the cursor
> CLOSE indexes
> DEALLOCATE indexes
> -- Delete the temporary table
> DROP TABLE #fraglist
> GO
> "Tibor Karaszi" wrote:
>