I have some databases on DB2 on an AIX server.
I login as the DB2 instance user id "chandroo" (having the db2profile set automatically when i login) and issue a command as below and get no result.
chandroo#xxxxxxxx::/db2/chandroo> db2 list db directory
chandroo#xxxxxxxx::/db2/chandroo>
However if I invoke the db2 directly from the installation directory I am able to see the entries , and I have no clue as to why it happens.
chandroo#xxxxxxxxx::/opt/IBM/db2/V9.5/bin> ./db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = CHANDB
Database name = CHANDB
Local database directory = /db2/chandroo/db
Database release level = c.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = CHAN
Database name = CHAN
Local database directory = /db2/chandroo/db
Database release level = c.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
chandroo#xxxxxxxxx::/opt/IBM/db2/V9.5/bin>
It sounds like the db2profile script isn't being sourced properly. The environment variables defined in that script need to be set for your current AIX shell process, not a temporary subprocess started by sh, ksh, or bash. This is accomplished by specifying a single dot instead of a program name to run the db2profile script. The difference is subtle, but important.
If that is the problem, running this command will fix the problem by properly initializing your current shell process:
. ~chandroo/sqllib/db2profile
and commands like db2 list db directory will start working.
The next step is to determine what is keeping that from happening in your $HOME/.profile startup script. If you see the call to db2profile using the proper syntax as shown above, there might be a problem with the execution permissions on $HOME/.profile.
Related
Facing a weird issue in DB2. Unable to connect to remote DB.
Catalogued Successfully. But when tried to connect to DB alias getting a error as
"SQL30061N The database alias or database name "NDTEST " was not
found at the remote node."
OS :- Linux
DB2Level :-
DB21085I This instance or install (instance name, where applicable:
"db2inst1") uses "64" bits and DB2 code release "SQL10055" with level
identifier "0606010E".
Informational tokens are "DB2 v10.5.0.5", "s141128", "IP23633", and Fix Pack
"5".
Product is installed at "/path/to/db2".
But we did not mention anything as "NDTEST ".
Database alias = QAZWSXED
Database name = NEWDB(changedName)
Node name = BASENNEW
Database release level = 10.00
Comment =
Directory entry type = Remote
Authentication = SERVER_ENCRYPT
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
Node name = BASENNEW
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = hostname
Service name = portNumber
db2 connect to QAZWSXED
SQL30061N The database alias or database name "NDTEST " was not
found at the remote node. SQLSTATE=08004
Error means exactly what is say - there is no NEWDB databsae on BASENNEW node.
The fact that you were able to catalog the database doesn't mean it is actually there. There is no connection attempt during the CATALOG DATABASE command (one is not prompted for password).
E.g. if I would create local TCP/IP loopback for my instance:
$ db2 catalog tcpip node loop remote localhost server 61115
I can with no issues catalog both existing (SAMPLE) and non-existing database (BADDB):
$ db2 catalog database sample as loopsamp at node loop
DB20000I The CATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
$ db2 catalog database baddb as loopbad at node loop
DB20000I The CATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
I will be able to connect to the first one:
Enter current password for kkuduk:
Database Connection Info
Database server = DB2/LINUXX8664 11.5.0.0
SQL authorization ID = KKUDUK
Local database alias = LOOPSAMP
but connection attempt to non-existing one will fail with SQL30061N
db2 connect to loopbad user kkuduk
Enter current password for kkuduk:
SQL30061N The database alias or database name "BADDB " was not
found at the remote node. SQLSTATE=08004
Please verify the node directory on the remote server by runnnig
$ db2 list db directory
and see if you have an entry for your database which has type Indirect
Directory entry type = Indirect
Edit:
I didn't notice your edit that changed the database name. If error returns stalled database name then indeed db2 terminate is needed to create new CLP client application (db2bp).
E.g. if I would uncatalog incorrect entry and cataloged it again I will get similar error as client will use cached entry pointing to incorrect database name:
$ db2 uncatalog db LOOPBAD
DB20000I The UNCATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
$ db2 catalog database sample as loopbad at node loop
DB20000I The CATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
$ db2 connect to loopbad user kkuduk
Enter current password for kkuduk:
SQL30061N The database alias or database name "BADDB " was not
found at the remote node. SQLSTATE=08004
db2 terminate terminates the Db2 CLP client back end and reads correctly new entry from the catalog:
$ db2 terminate
DB20000I The TERMINATE command completed successfully.
$ db2 connect to loopbad user kkuduk
Enter current password for kkuduk:
Database Connection Information
Database server = DB2/LINUXX8664 11.5.0.0
SQL authorization ID = KKUDUK
Local database alias = LOOPBAD
Found the problem - There was one entry in DCS(Database Connection Services). To check DCS details
db2 list dcs directory
above command provided a DCS entry with Target Database Name as NDTest .
Working fine after removing/un cataloguing the DCS entry.
I have a database (list db directory):
Database 4 entry:
Database alias = ABC
Database name = ABC
Local database directory = /data
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
I need to have an alias for that database because my application tries to connect to database DEF.
I can create an alias using
catalog db ABC as DEF
then the (list db directory) shows:
Database 4 entry:
Database alias = ABC
Database name = ABC
Local database directory = /data
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =code here
Database 5 entry:
Database alias = DEF
Database name = ABC
Local database directory = /data
Database release level = f.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
But after I connect to aliased db using:
db2 connect DEF
I can't access any schemas and tables from original database. Of course when I connect using ABC database name everything is visible and on place.
Am I misunderstanding aliases in DB2? Or maybe there is some option like "create an alias with data" or something like that?
You seem to misunderstand the purpose of a database-alias produced by db2 catalog database ABC as DEF.
For Db2 for Linux/Unix/Windows, a database ALIAS is not a SCHEMA.
You cannot use the new alias in SELECT or other SQL statements.
You can only reference the database-alias in the CONNECT step. After successful connection, use SQL as if you had connected to database ABC only.
The database-alias is only a pointer to a database.
The database being pointed to (in your case ABC) does not change, and the schemas inside it do not change, and you cannot change how you refer to objects like tables and views in those schemas.
In your SELECT (or other SQL statements) you must refer to the schemas that are present inside the physical database. So there really is not schema called DEF, becase DEF is an alias known only to the command-line-processor and db2-database-directory. If you wish to make new synonyms inside the database you are free to do that , but that is NOT the purpose of database-aliases.
As you seem to be running Db2 for Linux/Unix/Windows with local databases (Directory entry type = Indirect), you should connect to each database ABC and DEF and run both of the queries below and then compare their outputs from each database, and update your question with the outputs.
select char(os_name,20) as os_name
, char(os_version,5) as os_version
, char(os_release,20) as os_release
, char(host_name,30) as host_name
from sysibmadm.env_sys_info;
select char(inst_name,15) as inst_name
,char(release_num,20) as release_num
,char(service_level,20) as service_level
,char(bld_level,20) as bld_level
,char(ptf,20) as ptf
from sysibmadm.env_inst_info;
#mao - You are right!
I've been connected using external software to one node, and using shell db2 to other node. That was the reason that i wasn't able to see databases.
When I am restoring the database, by default data is going in C drive, but when I installed the db2 that time I specify the path in D drive only.
Also, sample database files created by db2 is stored in D drive.
Can anyone please tell me what is the issue?
I have run this command:
SELECT * FROM SYSIBMADM.DBPATHS
below is the result i fetched:
LOGPATH- D:\DB2\NODE000\SQL00001\SQLOGDIR\
DB_STORAGE_PATH- C:\
LOCAL_DB_DIRECTORY - D:\DB2\NODE000\SQLOGDIR\
DBPATH - D:\DB2\NODE000\SQL00001\
I Want to change this DB_STORAGE_PATH C:\ to D:\ for all the database which i will be restoring.
You can run db2set from db2 command line that will confirm you wheather db2 installed on path with other information;
db2-command-line> db2set
DB2_ATS_ENABLE=YES
DB2_CREATE_DB_ON_PATH=YES
DB2INSTPROF=C:\where\db2\installed\IBM\DB2\DB2COPY1
DB2COMM=TCPIP
You can get more information of Directory structure for your installed DB2 database product (Windows) here
You can run the following command SELECT * FROM SYSIBMADM.DBPATHS. This will give details of following variables of your installed db2 database;
LOGPATH
DB_STORAGE_PATH
LOCAL_DB_DIRECTORY
DBPATH
These commands will provide you enough information to locate your installed database. Then you can restore your database providing the exact path.
To add a storage path to an existing database, issue the following ALTER DATABASE statement:
ALTER DATABASE database-name ADD STORAGE ON storage-path
After adding one or more storage paths to the database, you may use the ALTER TABLESPACE statement to rebalance table spaces in the database so that they start to use the new storage paths immediately.
DB2 has a configuration parameter for the default path for databases, dftdbpath. In addition, the command db2sampl to create a sample database has an option dbpath to specify where to place that database.
db2sample -dbpath D:
The above would place the new database on drive D:.
You will find that there are default paths for certain operations. The overview of DB2 database manager configuration parameters has lists most of them.
For your specific issue I would assume that a parameter was changed some time after DB2 was installed and used initially.
For RESTORE be aware that the options TO and DBPATH are ignored if restoring an existing database.
I am writing a powershell script that outputs a query to a file. After connecting to the database, I get a permission denied error that i am not able to get around. This is a production database, so I cannot modify the existing table schema, just trying to write content to a file. I have also tried running the script below with the postgres (root) account, but had no luck.
Any help would be greatly appreciated.
$DBConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=localhost;Port=5432;Database=PRPC;Uid=id;Pwd=pwd";
$DBCommandText = "copy (select * from table) to
'C:\Users\myUser\Desktop\output.txt' with csv;";
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = $DBCommandText;
$DBCmd.ExecuteReader();
$DBConn.Close();
This depends a bit on the PostgreSQL version and how it was installed.
9.1 and older installed as the postgres operating system user on Windows by default. 9.2 and newer run as NETWORK SERVICE. In both cases you can change that default, e.g. to run under a domain account.
PostgreSQL's COPY command does file I/O as the user account the PostgreSQL server runs under. So that user must have write permission to the destination. Typically one user can't write to another user's home directory, so you're getting an error.
To permit this to work you'll need to create a directory then change its permissions in the Security properties tab so that the user PostgreSQL runs as has the right to write to it. You may also need to change the permissions on its containing directories so that PostgreSQL can read it; I'm not 100% sure of the details in the Windows permissions model, as I work mainly with unix systems.
Where are log file stored in DB2?
I am searching for a file with name Updatedb20100604182008.log
from this page:
http://www.ibm.com/developerworks/data/library/techarticle/0301kline/0301kline.html
(The article goes into further detail about default locations as well.)
The database logs are initially
created in a directory called
SQLOGDIR, a sub-directory of the
database directory. You can change the
location where active logs and future
archive logs are placed by changing
the value for this configuration
parameter to point to either a
different directory, or to a device.
Archive logs that are currently stored
in the database log path directory are
not moved to the new location if the
database is configured for
roll-forward recovery.
Because you can change the log path
location, the logs needed for
roll-forward recovery may exist in
different directories or on different
devices. You can change this
configuration parameter during the
roll-forward process to allow you to
access logs in multiple locations.
The change to the value of newlogpath
will not be applied until the database
is in a consistent state. An
informational database configuration
parameter, database_consistent,
indicates the status of the database.
Note: The database manager writes to
transaction logs one at a time. The
total size of transactions that can be
active is limited by the database
configuration parameters:
The DB2 log file location can be found from the DB CFG parameter - 'Path to log files'.
The command would be the below, without an explicit connection to the DB.
db2 get db cfg for db_name | grep 'Path to log files'
Else, you can connect to the DB first and use the command as follows:-
db2 connect to db_name
db2 get db cfg | grep 'Path to log files'
db2 terminate
db2 connect to database
db2 get db cfg | grep -i log
cd /data/dblogs/NODE0000(path to the log files)
cd LOGSTREAM0000(these is log folder)
ls -altr(we can see all the log files with .log extension)
rm abc.log (give the log name which you want to delete)