Author Archives: tore
How to drop a database when drop database fails
How to Drop a Database When drop database Fails
Follow the steps in this section to drop a database when drop database fails. Do not use these steps unless directed to do so by this book, or unless there is no critical data in the database.
1.Log in as the “sa”.
2.Check to make sure the database has been marked “suspect.” The following query produces a list of all databases which are marked suspect:
1> select name from master..sysdatabases
2> where status &256 = 256
3> go
3.If the database is marked “suspect”, go to step 4. If it is not marked “suspect”, mark it in one of the following ways:
a.Execute the sp_marksuspect stored procedure discussed under “How to Mark a Database “suspect””, and restart Adaptive Server to initialize the change.
b.Use the procedure below:
1> sp_configure”allow updates”, 1
2> go
1> use master
2> go
1> begin transaction
2> update sysdatabasesset status = 256
3> where name = “database_name”
4> go
Verify that only one row was affected and commit the transaction:
1> commit transaction
2> go
Reset the allow updates option of sp_configure:
1> sp_configure “allow updates”, 0
2>go
Restart Adaptive Server to initialize the change.
4.Remove the database:
1> dbccdbrepair(database_name,dropdb)
2> go
dbcc dbrepair sometimes displays an error message even though it successfully drops the database. If an error message occurs, verify that the database is gone by executing the use database_name command. This command should fail with a 911 error, since you dropped the database. If you find any other error, contact Sybase Technical Support.
How to move the master database to a new device
- Dump the user databases with the dump database command.
- Rename the dumped databases on the master device with sp_renamedb.
- Re-create the databases with their original names on another device with create database. Be sure they are created exactly like the old databases, to avoid 2558 and other errors. Refer to Error 2558 for more information.
- Load the dumps with load database.
- Use the online database command for each database to make the databases available for use.
- Check the databases in their new location to make sure the load was successful (that is, perform a simple query with isql), and if everything loaded successfully, drop the old databases from the master device.
- Back up the master database with the dump database command.
- Save the contents of key system tables such as sysdatabases, sysdevices, sysusages, and syslogins. Make a note of these values. Also make a note of the path to the dump device in sysdevices.
- Use the buildmaster utility to build a new master device with enough extra space so that you will never need to increase the master device again. When buildmaster completes, a new master database will exist on the new master device. The buildmaster executable is found in bin, so use ./buildmaster and follow the prompts.
- You now need to create a new runserver file which points to this new master device (the -d option). And start up the server with this new runserver file.
- Expand the size of the new master database with the alter database command, if necessary, so that it matches the size of the dumped master database(get this info from the original sysusages table where the size is in 2k blocks, the alter database command uses sizes in MB).
- Execute the following command in isql:
- Add the –m option to the runserver file to start Adaptive Server in single-user mode.
- Allow updates to the system catalog:
- Change the value for srvnetname in sysservers from SYB_BACKUP to the name of your backup server.
- Load the dump of the master database, using load database master from <full path name>.
- Reset the “high” value in master..sysdevices:
- If the previous update affected only one row, commit the transaction.
- Restart Adaptive Server.
- Turn off allow updates:
- Edit the new runserver file to take it out of single user mode, i.e remove the –m option and restart the server, if this all works fine (leave it for a while) then you can remove the original master device and its related run server file.
How to perform a load froma remote backup server
How to drop a corrupt table
Database status values in sysdatabases
Using set showplan
- The structure of any indices defined on the table(s) involved
- The distribution of data within the indices
- The number of rows in the table(s) involved
- The number of data pages used by the table(s) involved
- The amount of data cache SQL Server is currently using
- The access path that would require the least amount of I/O and, therefore, would be the fastest
- insert Using the direct method, the table into which the rows are being inserted cannot be a table which is being read from in the same command. The second query example in the previous section demonstrates this, where the rows are being inserted into the same table in which they are being selected from. In addition, if rows are being inserted into the target table, and one or more of the target table’s columns appear in the where clause of the query, then the deferred method, rather than the direct method, will be used.
- select into When a table is being populated with data by means of a select into command, the direct method will always be used to insert the new rows.
- delete For the direct update method to be used for delete, the query optimizer must be able to determine that either zero or one row qualifies for the delete. The only way to verify this is to check that one unique index exists on the table, which is qualified in the where clause of the delete command, and the target table is not joined with any other table(s).
- update For the direct update method to be used for update commands, the same criteria apply as for delete: a unique index must exist so that the query optimizer can determine that no more than one row qualifies for the update, and the only table in the update command is the target table to update. Also, all updated columns must be fixed-length datatypes, not variable- length datatypes. Note that any column that allows null values is internally stored by SQL Server as a variable-length datatype column.
Structure of databases as regards loading
A guide to Replication server in plain English
Introduction
This guide will hopefully cut to the chase and show how you can set up a simple replication system consisting of 1 dataserver, 2 databases (one replicating one receiving) and 2 replication servers, one for each database.Installing Replication server
This is quite straight forward; 1) After unloading the files from the CD you set up the $SYBASE variable and also $PATH to be $SYBASE/bin:$PATH. 2) Next run dsedit and add the names and network addresses of the replication server you are building, the ID server (original Repserver) if this is your 2nd or more Repserver, and also any dataservers you will be connecting to. 3) The menus are relatively self-explanatory, make sure that if this is the first Replication server in the system that you define it as an ID server. Also note that the RSSD devices are on the same machine as the dataserver used for the RSSD’s, ideally each Repserver would have its own dataserver, but in this example they also go from the one dataserver. The disk-partition goes in the same place as the Repserver files. 4) After having set all the option and having a complete next to each menu item, you can build the Repserver, if there are any problems you will be notified.Setting up the first Replication server
This replication server is called phoebe_rep On this replication server we need to create a connection to the primary database which is called sundry and sits on dataserver phoebe. This is done using rs_init, and selecting the option add database, the menu’s are self-explanatory, the only thing to look out for is the option deciding whether the database is replicated or not, for this connection select yes, as it is the primary database. This should create OK and set up the dsi links etc and also the rep-agent. The connection to a database can be stopped by issuing the following command from the Repserver, which controls it; suspend connection to phoebe.sundry and restarted with resume connection to phoebe.sundry.Setting up the second Replication server
The second replication server is called phoebe_2nd_rep On the creation of this second Repserver be sure to make sure the first Replication server is up and running and then point to it as the ID server, also when installed add the replicate database to it using rs_init, for this select no for the question, is this database replicated. The replicate database in this example is called sundry 3.Setting up Route
We need to create a route from each primary replication server to each replication server that subscribes to data from it(In this case from phoebe_Rep to phoebe_2nd_rep). To do this you will need to do the following; You will need to alter the connection from the RSSD database for the primary Repserver as follows (from the Primary Repserver), suspend connection to phoebe_rep_RSSD Then alter connection to phoebe_rep_RSSD set log transfer to on followed by resume connection to phoebe_Rep_RSSD . The reason for this is so that the Replicate Repserver can read any changed to the primary Repserver in terms of new definitions created etc and also get all the ones which already exist. Next you have to enable a repagent for this database, so log in to the phoebe server and issue the following command; sp_config_rep_agent phoebe_rep_RSSD, enable, phoebe_rep, sa, NULL followed by sp_start_rep_agent phoebe_rep_RSSD The command to actually create the route can now be issued from the primary Repserver (phoebe_Rep), Create route to phoebe_2nd_rep Set username as sa Set password as NULL The progress of this route creation can be checked with rs_helproute run from the RSSD for the primary Repserver i.e. from phoebe_rep_RSSD. If everything is OK this will report the rote as active.Setting up Replication
The next step is to select the table you want to replicate in the primary database (sundry) which is managed by the primary Repserver (phoebe_rep). In this example the table is called alpha1 and contains only 2 columns, one is an int and the other a char(10). To enable this table for replication, issue the following command from database sundry; sp_setreptable alpha1, true Incidentally the commands to start and stop the repagent for sundry (which monitors the transactions on the alpha1 table through the syslogs) is sp_start_rep_agent sundry and sp_stop_rep_agent sundry. Also to replicate a stored procedure (which can be a much more efficient way of doing things) the command is sp_setrepproc proc1, true You also need to create a table with the same column structure in the replicate database (sundry3) which is managed by the replicate Repserver (phoebe_2nd_rep), i.e. create table alpha1 (a int, b char(10)) This is also true for replicating stored procs where an identical stored proc must already exists in the replicate database. Now we can check to see whether all the connections/routes and repagents etc are all up by issuing admin who_is_down at each of the replication servers. If this is all clear then we are ready to To create the replication definition the command issued from the primary Repserver is; create replication definition repdef1 with primary at phoebe.sundry with all tables named ‘alpha1’ (a int, b char(10)) primary key (a) You always have to specify a primary key!! To check that the routing is working fine you can check whether the replication definition has been copied over to the replicate Replication server (phoebe_2nd_rep) by issuing the following command in phoebe_2nd_rep_RSSD on dataserver phoebe; rs_helprep Incidentally the stored proc to check on subscriptions is rs_helpsub Now we need to set up a subscription to this replication definition in the replicate Repserver as follows (command issued from phoebe_2nd_rep); create subscription sub1 for repdef1 with replicate at phoebe.sundry3 The server will now start materializing this table from the primary database to the replicate database and you can see the progress of this by issuing the following command from the Replicate Repserver; check subscription sub1 for repdef1 with replicate at phoebe.sundry3 If this comes back as valid then everything is fine You also check on subscription by issuing rs_helpsub from the replicate RSSD database.Verifying
The replication process is now set up and to check it insert a few rows into the sundry database alpha1 table and see if they are replicated to the sundry3 alpha1 table.DR for a Replication Server
- · If your primary database is irretrievably damaged, drop it. If the database is
- · Drop any damaged database devices using sp_dropdevice.
- · Create new database devices using disk init (if necessary).
- · Create the new database using create database with the for load option.
- · Load the database from the database dump.
- · Restore any transaction log dumps.
- · Activate the database using the online database command.
- · Recover any data modification lost from the primary database.
- · Re-synchronize the replicate database:
- · Re-materialize the replicate database.
- · Run rs_subcmp.
- · Replay the transaction log from a log backup.
- · Examine the error log of your primary Adaptive Server, looking for a message
- · Run sp_help_rep_agent on the RepAgent for the temporary recovery database:
- · Examine the error log of your primary Adaptive Server, looking for a message
- · Run sp_help_rep_agent on the RepAgent for the temporary recovery database:
- · Re-materializing the replicate database.
- · Running rs_subcmp.
- · In UNIX, you can use the touch command to create a file.
- · In Windows NT, you can create a file using a utility program such as Notepad.
- · Compare the primary and replicate databases, and replace any lost data.
- · Use the ignore loss command to restart replication.
- · If your RSSD database is irretrievably damaged, drop it. If the database is marked
- · Drop any damaged database devices using sp_dropdevice.
- · Create new database devices using disk init (if necessary).
- · Create the new RSSD database using create database with the for load option.
- · Load the database from the database dump.
- · Load the database from any transaction log dumps. Be sure to apply the
- · Activate the database using the online database command.
- · Compare the primary and replicate databases, and replace any lost data.
- · Use the ignore loss command to restart replication.
- · Clear the RSSD’s LTM truncation point:
- · Move the transaction log forward. Execute the following batch multiple times (40
- · Reset the RSSD’s LTM truncation point:
- · Increment the generation id number in the RSSD:
- · To start your Replication Server in normal mode, you should have a run server file
- · To start a RepAgent in normal mode, run the following command: