DB2 LUW "set db2instance" in Windows Shell not working properly - cmd

I am an experienced database administrator with IBM DB2 LUW and I am constantly running into the following problem. Any hint would be highly appreciated. We are running DB2 V 11.1.4070 on this machine.
We have a Windows server running DB2 on four instances. We need to backup the databases on a regular basis. We are using the external software Dataprotector for backing up the databases on an external storage device. We are using CMD-Batchfiles to execute the backup.
The problem I have is the following. In the first line I need to set the value of the OS-Variable "db2instance" to the value of the actual instance I need to backup.
This reads something like this
set db2instance=INSTANCE1
db2 connect to database1
db2 quiesce database
db2 connect reset
db2 deactivate database database1
Call Dataprotector
db2 activate database database1
db2 connect to database1
db2 unquiesce database
db2 connect reset
The problem I am running into is: the set db2instance statement isn't executed every time.
Sometimes it is executed fine, some other time it is not excecuted and some times it is executed but afterwards the shell gets corrupted and any db2 statement yields #
SQL10007N Message "-1390" could not be retrieved. Reason code: "6"
Problem seems to be related somewhat to this one
Any help would be appreciated.

Related

Oracle Privilege - User can create table but cannot write rows

A user has been configured on Oracle. Via this user, I can create an ODBC connection and an OCI connection, and these both test fine in Win10. Using Alteryx with the ODBC and OCI connection, we try to write data to a new table.
The table is created and appears in PL/SQL with the expected column names. However, the rows are never written and the connection just hangs at this point.
What could be wrong? I am not an Oracle Admin
Based on comments you were expecting oracle to commit without executing "commit" command explicitly. It's not enabled by default in oracle so you have to turn it on.
It's not possible to turn this on for the database, but on client apps only.
E.g. "set autocommit on" command in SQL Plus.
So you need to check docs for the client application you're connected with (presumably Alteryx is the one). It might have such a feature.

Get pluggable databases in a stopped Oracle container database?

I'm trying to write a script that gets the Oracle container databases and their pluggable databases on a given server. I can get these handily enough when the CDB is open - but is there a way to get the PDB's of a closed/stopped container database? The databases are on Windows and I'm writing the script in PowerShell.
Any help would be much appreciated.

Oracle Database Backup in DBeaver

I am new to Oracle databases. I have installed DBeaver (never used this before too) to connect to the database.
I have created a connection (which I believe is called database) and now I am able to see the database tables and everything. How do I take the backup of the Oracle Database in DBeaver so I can use it locally for test purposes before making any change on live database?
I can't find any option to take the backup of connection/database.
To do a proper backup of your Oracle Database, you should use the oracle provided utility, Recovery Manager. It's a command line interface that's called from your DB server shell prompt via 'RMAN'
You can also use Data Pump to export all or part of a database that can be used to import to another database...not really used for recovery of an existing database.
I'm not aware of your tool having interfaces for either of these Oracle features.
You might not need a backup at all for your needs, take a look at Oracle Flashback Technology.
DBeaver does not support oracle database export import. See details here:
https://dbeaver.com/docs/wiki/Backup-Restore/
You need to run the sqlplus tool to create a folder where oracle is going to import/export database dumps. Login should happen as sys as sysdba and enter the password you previously entered during database server installation. Example:
sqlplus sys/[your password] as sysdba
After you successfully logged into sqlplus run the following command (don't forget to set to a different folder that you prefer to use):
create or replace directory DATA_PUMP_DIR as 'D:\Database Backups';
Once this is done exit from sqlplus and enter the following command into the command line (again no sqlplus should be used here)
expdp sys/[your password]#localhost:1521/[listener name] file=your-database-dump-file.dmp owner=[your schema]
Once this is done and finished you can zip your database dump if you would like to upload it somewhere else. (I had 9 GB dump and the zipped size was 1.6 GB)

How to connect to Oracle DB without OracleService*?

This answer states that we should start OracleService* in order to connect to an Oracle DB.
However, there isn't a OracleService* among the list shown by services.msc.
Is there any other way to connect to an Oracle DB from command line, without using OracleService*?

Run commandline command at remote Oracle server using SQL*Plus

I have a machine running Oracle 10g server in windows server 2008. I want to take backup of the database. I also want to take backup of some files saved on hard disk by oracle server that users have uploaded using my website.
I can connect to the Oracle server using sql developer and sqlplus. I can run sql queries on the server.
In order to take backup of database I have to run the command "exp" (this is the only way of taking backup of databases that I know). There might be some other way but there is another problem because of which I must run dos command. That problem is to take backup of files. These files are stored in c:\mydir. The folder mydir is not accessible anyway through web and is not a shared folder.
I have tried running "host " in sqlplus after connecting to oracle server, that is at "sql>" prompt. The command ran successfuly but at local machine, not at oracle server.
Edit: The "host" command is provided by sqlplus and is not an oracle command, means cannot be used in a query. Sqlplus even when connected to remote machine run the "host" command at local machine.
The target is to either make sqlplus run the "host" command at remote machine, Or run the dos command from inside a pl/sql query (independent of sqlplus).
In addition to what Justin has written:
If you want to take a logical snapshot of the database the new DataPump tool is preferred over the old (and deprecated) exp tool.
DataPump is a commandline tool (expdp) but also has a SQL API through Oracle packages and procedures.
The Data Pump API (including examples)
DBMS_DATAPUMP (reference)
But if you want a "real" backup you should look into RMAN
It is possible to create a Java stored procedure on the database server that executes an operating system command on the Oracle server. But it would be extremely unusual to use the export utility to backup a database-- that only creates a logical backup not a more appropriate physical backup. And it would be extremely unusual to run a backup by connecting to the database via SQL*Plus and spawning a job on the server operating system. It would make much more sense to create a job using the Windows scheduler on the database server that ran whatever export commands you want to run.

Resources