I am trying to restore a DB2 database to a backup from another database (also DB2). The restore seems to run fine. However, I am receiving the error: Tablespace access is not allowed. I checked the state of the tablespaces and they are stuck in Restore Pending. How do I get them in the correct state? If that's not possible, are there any other suggestions? BTW, I am working in a Windows environment and am using Data Studio for the restore.
So you tried to do a so called redirected restore as it seems (used the option redirect in the restore command) - right? This means you get the chance to redefine paths during the restore.
The restore ist split up in basically three parts:
restore is reading the data and stops
lets you redefine the paths
restore will finish the restore writing data to the new locations
During Step2 you would see the tablespaces being in restore pending as the restore has started but has not finished yet.
To support you in Step 2 I recommend using
restore... redirect generate script <scriptname>
which will give you a script with all the possible/necessary commands.
Check out
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.ha.doc/doc/c0006249.html?lang=en
Remember to check the database state afterwards as you might want / need to do a rollfowrds operation as well.
For tablespace states check out following website
http://www.ibm.com/developerworks/data/library/techarticle/dm-0407melnyk/#rp
Since you are using automatic storage, you'll need to redefine the paths of storage groups that are different in the target. I'm afraid I cannot say how it's done in Data Studio, but there should be a way to accomplish this via the GUI.
In the command line you'll need to do something along these lines. Firstly, determine the storage groups that need redefinition, e.g. by running db2pd -d yourdb -storagegroups. The result would look similar to this:
Storage Group Configuration:
Address SGID Default DataTag Name
0x00007F239319BB20 0 Yes 0 IBMSTOGROUP
Storage Group Statistics:
Address SGID State Numpaths NumDropPen
0x00007F239319BB20 0 0x00000000 1 0
Storage Group Paths:
Address SGID PathID PathState PathName
0x00007F23931C1000 0 0 InUse /export/db2data
Note the names of the storage groups that would have invalid paths on the target system.
Now you can start the restore:
db2 restore db yourdb from <path> redirect
The command will quickly complete. At this point you will be able to redefine the storage groups:
db2 set stogroup paths for <your_stogroup> on '<new_path>'
Once you've done that, continue the restore:
db2 restore db yourdb continue
Finish this off with rollforward if needed.
Follow the below steps:
Find the last backup image. and its path
Perform redirect Restore:
db2 "RESTORE DATABASE dbname FROM /path TAKEN AT timestamp into NEWDBNAME REDIRECT GENERATE SCRIPT redirectRestore.sql"
Using the VI editor make changes to the redirectRestore.sql file, Change the pathname of the stogroup paths.
Run the .sql file
db2 -tvf redirectRestore.sql
Perform Rollforward if required.
db2 rollforward db dbname to end of logs
Related
After the scheduled maintenance when the DBA tried to start the SQL Server;
it failed due to some corruption issue with storage subsystem.
Later on, we identified that the drive on which we had our TempDB's data and log files was corrupt and it was preventing SQL Server from starting successfully.
(Drive was corrupt, so I am unable to read anything from that drive)
So basically we did not have Tempdb database on the server.
And we had to start SQL Server without TempDB
So how do we start the SQL Server without TempDB and how do we fix this?
Before you try anything make sure you backup your data. If one drive failed, another one might fail and leave you without your data. Drives that are purchases at around the same time tend to fail around the same time too.
You need to do that even if some of the data is stored in a RAID array - RAID isn't the same as a backup. If something happens to the array, your best case scenario is that you'll wait for a few hours to recover the data. Worst case, you could lose it all.
The process is described in The SQL Server Instance That Will not Start in the TempDB location does not exist section, and other sites like Start SQL Server without tempdb.
You'll have to start SQL Server with Minimal Configuration. In that state, tempdb isn't used. You can do this with the -f command-line parameter. You can specify this parameter in the service's property page, or by calling sqlservr.exe -f from the command line, eg:
sqlservr -f
Another option is to use the -t3608 trace flag which starts only the master database.
sqlservr -t3608
After that, you need to connect to the server with the sqlcmd utility, eg :
sqlcmd -S myservername -E
to connect using Windows authentication.
Once you do this, you can go to the master database and change the file location of the tempdb files:
USE master;
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf');
GO
After that, remove the parameters from the service (if you set them there) and restart the service.
Finally, you may have to reconsider the placement of TempDB. TempDB is used heavily for sorting, calculating window functions or in situations where the available RAM isn't enough. Some operations require creating intermediate results, which get stored in TempDB. In general, you should have
multiple tempdb files, although the exact number depends on the server's workload.
How to Start SQL Server without TempDB database?
Step 1: Start the SQL Server in minimal configuration mode.
Click here
to see, "How to start the SQL Server in minimal mode using command prompt".
Step 2: Once SQL Server has started with minimum configuration mode;
connect to SQL Server instance and move TempDB data and log file to a new location.
See, move TempDB data and log files to new location
Step 3: Once you have performed the troubleshooting steps; exit SQLCMD window by typing Quit and Press Enter.
Step 4: . In the initial window click CTRL C and enter Y to Stop SQL Server Service.
Step 5 : Eventually, start the SQL Server Database Engine by Using SQL Server Configuration Manager.
What version of SQL Server it is? One simple solution is to move the tempdb.* files from that location and restart the SQL Server it will create new tempdb files. If you keep those files in that same location it will fail to start.
In SQL Server 2016 If you remove the tempdb physical files, on startup it will see they are missing and rebuild them on the fly in the location they are supposed to be in sysdatabases.
Currently Database is running on No-Archive Log mode. Can i Take only all datafiles (*.dbf) backup i.e. Excluding REDO and Control Files.
Also please let me know steps to restore the *.dbf file back in location.
If you want this database to be opened with simple startup command then you need redo and control files, since they are parts of the database.
However, if you don't have redo and control files in your cold backup then you will have to create control file with the script, usually generated with alter database backup controlfile to trace; and open the database with alter database open resetlogs - this command will create new redo logs.
Actually, you can open the database without the redo logs with alter database open resetlogs if this is a cold copy. The cold copy does not require recovery:
SQL> recover database until cancel using backup controlfile;
ORA-00279: change 6846169 generated at 01/20/2016 16:00:29 needed for thread 1
ORA-00289: suggestion : +DATA
ORA-00280: change 6846169 for thread 1 is in sequence #521
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database open resetlogs;
Database altered.
So no, you don't need redo logs with cold backups. The only requirement fot that is that the database have to be shutdown with immediate, not abort. So it would be consistent.
You also need the control files and red log files.
To restore, shutdown the database and copy the files back to their original locations. Then start the database.
Not recommended practice for a production environment. But I do this a lot with a test environment where I keep different version of the same database as cold backup sets.
I want to use the command line to restore MSSQL databases from customer computers to my computer.
The syntax is:
RESTORE DATABASE [MyDB] FROM DISK='D:BackupsMyDB.bak' WITH
MOVE 'AdventureWorks2008R2_Data' TO 'D:\MyData\MyAdvWorks_Data.mdf'
It works but each time I need to specify the logical name after MOVE because it is in another folder in the origin.
Is there a way to restore backup files in a new location without having to use the logical name?
For example, I would like something like:
RESTORE DATABASE [MyDB] FROM DISK='D:BackupsMyDB.bak' WITH
MOVE * TO 'D:\MyData'
If you are trying to move the location of the files, then you definitely need to specify the logical name.
http://msdn.microsoft.com/en-us/library/ms190255.aspx
You can use the RESTORE FILELISTONLY command to find the physical and logical names if the target is another server.
http://technet.microsoft.com/en-us/library/ms173778.aspx
Below is a script from Greg Robidoux. It generates restore TSQL code for a given database via the BACKUP chain.
You might be able to use it as a starting point to solve your own problem.
http://www.mssqltips.com/sqlservertip/1243/auto-generate-sql-server-database-restore-scripts/
Good luck
Crafty DBA
I have a PostgreSQL DB at my computer and I have an application that runs queries on it.
How can I see which queries has run on my DB?
I use a Linux computer and pgadmin.
Turn on the server log:
log_statement = all
This will log every call to the database server.
I would not use log_statement = all on a production server. Produces huge log files.
The manual about logging-parameters:
log_statement (enum)
Controls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements). [...]
Resetting the log_statement parameter requires a server reload (SIGHUP). A restart is not necessary. Read the manual on how to set parameters.
Don't confuse the server log with pgAdmin's log. Two different things!
You can also look at the server log files in pgAdmin, if you have access to the files (may not be the case with a remote server) and set it up correctly. In pgadmin III, have a look at: Tools -> Server status. That option was removed in pgadmin4.
I prefer to read the server log files with vim (or any editor / reader of your choice).
PostgreSql is very advanced when related to logging techniques
Logs are stored in Installationfolder/data/pg_log folder. While log settings are placed in postgresql.conf file.
Log format is usually set as stderr. But CSV log format is recommended. In order to enable CSV format change in
log_destination = 'stderr,csvlog'
logging_collector = on
In order to log all queries, very usefull for new installations, set min. execution time for a query
log_min_duration_statement = 0
In order to view active Queries on your database, use
SELECT * FROM pg_stat_activity
To log specific queries set query type
log_statement = 'all' # none, ddl, mod, all
For more information on Logging queries see PostgreSql Log.
I found the log file at /usr/local/var/log/postgres.log on a mac installation from brew.
While using Django with postgres 10.6, logging was enabled by default, and I was able to simply do:
tail -f /var/log/postgresql/*
Ubuntu 18.04, django 2+, python3+
You can see in pg_log folder if the log configuration is enabled in postgresql.conf with this log directory name.
My sql server marked one database as suspected , on checking i found my mdf,ldf files are missing, but no errors on chkdsk, what it means some virus ?
Either the files were deleted, or they have been moved and a master database backup restored from before the change in location. In both cases the physical files can only be deleted or moved if the database is offline - either because sql server was shut down or the database was closed.
Either of these things is highly unlikely to have happened accidentally. It's unlikely to be a generic virus or trojan as such would either have to specifically delete the files on startup before SQL Server started (assuming your database starts automatically) or shut down the database then specifically delete the files. Given that chkdsk doesn't report errors either it's unlikely to be a disk issue, so it's a virtual certainty that the cause of the error is deliberate database (mis)management.
I think the most likely option is that a dba has decided that the files should be moved elsewhere - typically this is done for space or performance reasons - for instance if a new drive is added to a machine that is running out of space then the database could be moved to that. For some reason a backup of the master database has subsequently been restored from a point before the move.
My first action would be to do a full scan of the system for all mdf/ldf files and (hopefully) locate them. I'd also do a scan of backups and look for the latest master database backup. You could either then try restoring the last master backup and see if that fixed the issue (i'd back up the current master first of course), and failing that, or directly, reattach the missing files.
If you cannot find the mdf/ldf files then your only option is restore from backup. If you don't have a backup then your database is lost.
http://support.microsoft.com/kb/180500
At startup, SQL Server attempts to obtain an exclusive lock on the device file. If the device is being used by another process (for example, backup software) or if the file is missing, the scenario described above will be encountered. In these cases, there is usually nothing wrong with the devices and database. For the database to recover correctly, the device must be made available, and the database status must be reset.
It means someone deleted the files.
They can not be deleted when in use so it happened:
when SQL Server was shut down
the database was closed (Express version usually)
the database was taken offline
All user dbs will share the same folder (edit) by default (end edit) so this is deliberate
The more exotic options include restoring the master db where the databases/MDF files listed in the restored master db do not exist etc. But I doubt it.
In this situation, you can check the SQL Server logs. Go to Management, Click on SQL Server Logs and click on current and check the message.
In my case, I got this:
Error 17207, severity 16, state 1 (it is related to log file deletion or corruption)
Solution:
Set the database into single user mode:
Alter database dbname set single_user
Now set the database into emergency mode:
Alter database dbname set emergency
Repair missing log file or corrupted log file with data loss.
DBCC CHECKDB ('dbname', REAPIR_ALLOW_DATA_LOSS)
Note: You may loss the data by using this command. It also depends on client's approval.
Now set the db in multi user mode;
alter database dbname set multi_user
In SQL Server suspect database is a mode when user unable to connect with database.
At this time user unable to perform any action and can not do anything like no open no backup and no restore etc.
Possible cause for this problem can be one of the following:
1. Database is corrupted
2. Insufficient memory state.
3. unexpected shutdown etc.
4. OS is unable to find the database file