connect oracle Database using perl [duplicate] - oracle

I am getting the following error connecting to an Oracle 11g database using a simple Perl script:
failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var or PATH (Windows) and or NLS settings, permissions, etc. at
The script is as follows:
#!/usr/local/bin/perl
use strict;
use DBI;
if ($#ARGV < 3) {
print "Usage: perl testDbAccess.pl dataBaseUser dataBasePassword SID dataBasePort\n";
exit 0;
}
my ($user, $pwd, $sid, $port) = #ARGV;
my $host = `hostname`;
my $dbh;
my $sth;
my $dbname = "dbi:Oracle:HOST=$host;SID=$sid;PORT=$port";
openDbConnection();
closeDbConnection();
sub openDbConnection() {
$dbh = DBI->connect ($dbname, $user ,$pwd , { RaiseError => 1}) || die "Database connection not made: $DBI::errstr";
}
sub closeDbConnection() {
#$sth->finish();
$dbh->disconnect();
}
Anyone seen this problem before?

Check your Oracle client configuration (including, as the message says, ORACLE_HOME), check file permissions, etc. It's unlikely that DBI per se has anything to do with the problem, and I know for a fact that DBD::Oracle is compatible with the 11g libraries (at least the 11g InstantClient).

Install the perl module DBD::Oracle
Add use DBD::Oracle; into your perl script.
This made the problem go away for me.

Afther upgrade Oracle form 10.2.0.4 to 10.2.0.5 my Perl-CGI not working, the error.log file of Apache was the error:
DBI connect('DB','user',...) failed: ERROR OCIEnvNlsCreate. Check
ORACLE_HOME (Linux) env var or PATH (Windows) and or NLS settings,
permissions, etc. at ...
OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var or PATH (Windows)
and or NLS settings, permissions, etc.! at ...
adding the following directive solve the problem:
my $ORACLE_HOME = "/usw/app/oracle/product/10.2";
$ENV{ORACLE_HOME}=$ORACLE_HOME;

Sorry for bringing this thread alive again, but I've been trying to solve this issue for weeks. Nowhere did I find that what finally solved it for me.
Environment: RedHat 6.5, Oracle Instant Client 12.1, Apache 2.2
What solved it for me:
Change the permissions of the directory where Oracle Instant Client is installed., which must also be the value of LD_LIBRARY_PATH. The directory wasn't accessible to "other", just owner and group. This command made the whole difference:
# chmod o+rx INSTANTCLIENT-DIRECTORY
I had been trying to create every possible combination of ORACLE_HOME and LD_LIBRARY_PATH. (Even "unsetting" ORACLE_HOME; I found suggestions that would solve the issue, since Instant Client needed only LD_LIBRARY_PATH and !NOT! ORACLE_HOME.) Nothing helped, until ...
it hit me to look further in the error message:
failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var
or PATH (Windows) and or NLS settings, permissions, etc.
permissions being the key word!
Hope this helps someone else!

2021 Update for CentOS 8 etc:-
If you use systemctl, nothing in your environment or Apache setup can pass environment vars to DBI!
you need to edit the /usr/lib/systemd/system/httpd.service file and add appropriate lines like this after the [Service] section:
[Service]
Environment=ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
Then re-start apache as usual:-
/bin/systemctl restart httpd.service
(Vote this up if it helped you: this web page is the #1 google result for this old problem which systemctl "security" has rebirthed)

Check the #!/usr/bin/perl (first line of your script) is the right perl version you wish to use too !

Previous answers don't solve this problem, but they did point me in the right direction: The launched environment was missing the DYLD_LIBRARY_PATH for Oracle instantclient. You can check by calling: launchctl export
or
launchctl getenv variable_name in OS X 10.10
I compared the output from my .bash_profile and found that the path to instanclient wasn't in launchctl PATH and DYLD_LIBRARY_PATH - Once I added them with the following it worked:
launchctl setenv PATH /path/to/instantclient
launchctl setenv DYLD_LIBRARY_PATH /path/to/instantclient

The environment variable used to specify the Oracle libraries may be different from one system to another. On most systems, use LD_LIBRARY_PATH but it may also be LIBPATH (notably on AIX), DYLD_LIBRARY_PATH, or maybe others.

I too went through the same issue. In my case ORACLE_HOME environment variable was incorrect.

Related

Cassandra - "The system cannot find the file specified"

I have installed Cassandra on Windows 10, and now when I try to run it using "cassandra", I get the following error:
Any ideas?
After looking at the file it seems, powershell script cassandra-env.ps1 executes following function:
if (Test-Path Env:\JAVA_HOME)
{
$env:JAVA_BIN = "$env:JAVA_HOME\bin\java.exe"
}
elseif (Get-Command "java.exe")
{
$env:JAVA_BIN = "java.exe"
}
else
{
echo "ERROR! No JAVA_HOME set and could not find java.exe in the path."
exit
}
I'm not an expert on Cassandra stuff, but if I were you I would run this script and make sure $env:JAVA_BIN is set correctly, and from there I would follow its trail and check
ParseJVMInfo function in the conf\cassandra-env.ps1 file which is throwing error in your setup.
Update:
Check JAVA_HOME environment variable and see if it is setup such that [JAVA_HOME]\bin\java.exe exists.
Don't install Cassandra into directory where the name has space in it. Startup script for Windows has problems with such names.
Update after an additional investigation:
Looking more precisely into the code, it looks like it can't start Java with the given command-line switches: -d64 -version - either Java executable isn't in the PATH, or the -d64 switch isn't supported for your version of Java - for example, if you installed 32-bit version of Java. Please try to run the java -d64 -version from the command line to check that it works
In my case I updated my java version and added latest version in system environment and run this command as administrator in cassandra specieid path(C:\Program Files\apache-cassandra-3.11.6\bin).
cassandra.bat -f
its running perfactly!!
and also make sure You must allow the execution of PowerShell Scripts. for this check out this one
https://www.howtogeek.com/106273/how-to-allow-the-execution-of-powershell-scripts-on-windows-7/
actually , its not about the path ...
its about giving the proper access / privilege to the path you are trying to access , that's something have to do with UAC setting on windows , try minimize it and make sure you have the right access through clicking on folder properties and giving permission to your user or everyone to access this path read / change or full control .
so u don't have to uninstall anything :)

Default Search_Path Variable Stuck After Installing Postgis with Homebrew on Mac

After installing postgresql and postgis on my mac ...
brew install postgres
brew install postgis
...I have a search_path which is stuck on being just set to "postgis". The value in the postgresql.conf file is ignored or overwritten, it doesn't even mention postgis by default. Also if I run commands such as ...
ALTER USER ken SET search_path TO postgis,schema1,schema2;
ALTER DATABASE coneddb SET search_path TO postgis,shema1,schema2;
...then the path is still set to just "postgis" upon starting a new connection. What am I missing that is overriding my search_path and won't let me override it with user or database specific settings?
Uggggh. When everything else failed I tried a reboot of the machine. Bingo. No idea why a reboot would have been required here but that seems to have done the trick. My search_path is now what it is in the postgresql.conf file. And yes, I had stopped and started the service to reload the conf file. In fact, I had even made sure that changes to the conf file were being recognized by changing the port number and proving that when I brought postgresql back up it was listening on the specified port and not on the original port. So, really no idea what was going on here.

Setting Windows PATH for Postgres tools

I cannot access PostgreSQL through the command line in Windows. Although I am able to create and update the databases, access them through PGAdminIII, and push to Heroku, I am unable to access them directly through my command line using the psql command.
When I try to create a database by using the command
$ createdb mydb
as explained in the PG documentation, I get the message
createdb: command not found
The documentation suggests that in this case, "PostgreSQL was not installed properly. Try calling the command with an absolute path instead." Sure enough, I am able to create a database by entering the direct path to the file:
$ c:/postgreSQL/9.1/bin/createdb mydb
Does this mean that the path can be reconfigured to connect correctly? Or do I need to reinstall? I've reinstalled several times, and have not been able to set the correct path. I currently have both the /bin and /lib paths addedto my system and user(:Umezo) paths, but still no access from the command line.
User variables for umezo
variable name: Path
variable value: C:\PostgreSQL\9.1\bin; C:\PostgreSQL\9.1\lib
System variables
variable name: Path
variable value: C:\PostgreSQL\9.1\bin; C:\PostgreSQL\9.1\lib
Any information or feedback regarding how I can fix my installment would be appreciated.
My info is as below:
I mostly followed these sources here and here. I installed a 32 bit version of 9.1 because some sources suggested issues with 64 bit.
PG download version: Installer Version 9.1 Win x86-32
Operating System: Windows 7 (64 bit)
pg_hba.conf
#TYPE DATABASE USER CIER-ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
postgresql.conf
# - Connection Settings -
listen_addresses = '*'
port = 5432
max_connections = 100
pg_ident.conf
# *Everything is commented out*
Login Role Umezo #from properties window in PGAdminIII
Properties/Role name: Umezo
Properties/Can login: "check"
Role privileges: all categories "check"
configuring postreSQL PATH variable on Windows 7
I encountered this issue too. I'm using Git Bash, hence the Unix-style $ prompt on Windows.
$ rails db
Couldn't find database client: psql, psql.exe. Check your $PATH and try again.
Here's what I did:
In Windows 7, navigate to:
Control Panel
All Control Panel Items
System
Advanced System Settings
Environment Variables
from the System Variables box select "PATH"
Edit...
Then append this string to the existing PATH Variable Value:
;C:\Program Files\PostgreSQL\9.2\bin
and click "OK" three times to exit the menus.
Now, close the console and restart it.
Navigate back to the directory of your Rails app. In my case, this is accomplished with:
$ cd rails_projects/sample_app
Then, try again:
$ rails db
sources:
How do I put PostgreSQL /bin directory on my path in Windows?
http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast
Settings Windows Path For Postgresql
open my Computer ==>
right click inside my computer and select properties ==>
Click on Advanced System Settings ==>
Environment Variables ==>
from the System Variables box select "PATH" ==>
Edit... ==>
then add this at the end of whatever you find their
;C:\PostgreSQL\9.2\bin; C:\PostgreSQL\9.2\lib
after that continue to click OK
open cmd/command prompt.... open psql in command prompt with this
psql -U username database
eg. i have a database name FRIENDS and a user MEE.. it will be
psql -U MEE FRIENDS
you will be then prompted to give the password of the user in question.
Thanks
Set path For PostgreSQL in Windows:
Searching for env will show Edit environment variables for your account
Select Environment Variables
From the System Variables box select PATH
Click New (to add new path)
Change the PATH variable to include the bin directory of your PostgreSQL installation.
then add new path their....[for example]
C:\Program Files\PostgreSQL\12\bin
After that click OK
Open CMD/Command Prompt. Type this to open psql
psql -U username database_name
For Example psql -U postgres test
Now, you will be prompted to give Password for the User. (It will be hidden as a security measure).
Then you are good to go.
All you need to do is to change the PATH variable to include the bin directory of your PostgreSQL installation.
An explanation on how to change environment variables is here:
http://support.microsoft.com/kb/310519
http://www.computerhope.com/issues/ch000549.htm
To verify that the path is set correctly, you can use:
echo %PATH%
on the commandline.
On Postgres 9.6(PgAdmin 4) , this can be set up in Preferences->Paths->Binary paths:
- set PostgreSQL Binary Path variable to "C:\Program Files\PostgreSQL\9.6\bin" or where you have installed
In order to connect my git bash to the postgreSQL, I had to add at least 4 environment variables to the windows. Git, Node.js, System 32 and postgreSQL. This is what I set as the value for the Path variable: C:\Windows\System32;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\PostgreSQL\12\bin; and It works perfectly.
Set Environment in Windows
Our createdbfile exists in this marked folder .so copy this folder path and paste inside environment variables setting under system variables.
start -> Environment Variables
select Environment variable
Create a new environment variable like this
Add environment variable postgres as %postgres% in the path variable
Now check by taking a new command prompt and typing conda (close already opened terminal or cmd)
Now live
Incase any one still wondering how to add environment variables then please use this link to add variables.
Link: https://sqlbackupandftp.com/blog/setting-windows-path-for-postgres-tools
I am using Windows 8 and the above solutions did not work out for me. I downgraded Postgres from 9.4 to 9.3. Man,it worked :)

Hadoop on OSX "Unable to load realm info from SCDynamicStore"

I am getting this error on startup of Hadoop on OSX 10.7:
Unable to load realm info from SCDynamicStore
put: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/travis/input/conf. Name node is in safe mode.
It doesn't appear to be causing any issues with the functionality of Hadoop.
Matthew Buckett's suggestion in HADOOP-7489 worked for me. Add the following to your hadoop-env.sh file:
export HADOOP_OPTS="-Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk"
As an update to this (and to address David Williams' point about Java 1.7), I experienced that only setting the .realm and .kdc properties was insufficient to stop the offending message.
However, by examining the source file that is omitting the message I was able to determine that setting the .krb5.conf property to /dev/null was enough to suppress the message. Obviously if you actually have a krb5 configuration, better to specify the actual path to it.
In total, my hadoop-env.sh snippet is as follows:
HADOOP_OPTS="${HADOOP_OPTS} -Djava.security.krb5.realm= -Djava.security.krb5.kdc="
HADOOP_OPTS="${HADOOP_OPTS} -Djava.security.krb5.conf=/dev/null"
I'm having the same issue on OS X 10.8.2, Java version 1.7.0_21. Unfortunately, the above solution does not fix the problem with this version :(
Edit: I found the solution to this, based on a hint I saw here. In the hadoop-env.sh file, change the JAVA_HOME setting to:
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
(Note the grave quotes here.)
FYI, you can simplify this further by only specifying the following:
export HADOOP_OPTS="-Djava.security.krb5.realm= -Djava.security.krb5.kdc="
This is mentioned in HADOOP-7489 as well.
I had similar problem on MacOS and after trying different combinations this is what worked for me universally (both Hadoop 1.2 and 2.2):
in $HADOOP_HOME/conf/hadoop-env.sh set the following lines:
# Set Hadoop-specific environment variables here.
export HADOOP_OPTS="-Djava.security.krb5.realm= -Djava.security.krb5.kdc="
# The java implementation to use.
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
Hope this will help
and also add
YARN_OPTS="$YARN_OPTS -Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk"
before executing start-yarn.sh (or start-all.sh) on cdh4.1.3
I had this error when debugging MapReduce from Eclipse, but it was a red herring. The real problem was that I should have been remote debugging by adding debugging parameters to the JAVA_OPTS
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044
And then creating a new "Remote Java Application" profile in the debug configuration that pointed to port 1044.
This article has some more in-depth information about the debugging side of things. It's talking about Solr, but works much the same with Hadoop. If you have trouble, stick a message below and I'll try to help.

Migrating ANT sqlplus execution from MacOSX to Windows, getting TNS error

I have a working ANT build.xml that executes sqlplus to compile PL/SQL. I develop on MacOSX. My coworker is going to start contributing to the same application. He develops on WinXP. The sqlplus exec from ANT returns a TNS ORA-12560 error on WinXP. The identical build.xml works on MacOSX. The run string that ANT should be constructing on WinXP works in the DOS shell. We have set up the TNS_ADMIN environment variable in WinXP. What could I be missing?
I'm not sure from your description whether you're using the ANT SQL Task (http://ant.apache.org/manual/Tasks/sql.html) or if your using the exec task to call Sqlplus. Can you please clarify?
If you're calling sqlplus as an external command, you will be at the mercy of two main things:
a) environment variables
b) tnsnames.ora file
Windows and unix are different in how they handle specifying where you want to connect. In OSX you'll have the ORACLE_HOME and ORACLE_SID environment variables set. In Windows this would be in the registry. You may also have TNS_ADMIN set which determines where your tnsnames.ora file will be found.
First thing to check would be if you are both using the same tnsnames.ora file.
If you are, have both of you try to run tnsping to verify that the alias is configured properly.
Get back to us with the results of those tests.

Resources