Segmentation when using node-oracle on ubuntu - oracle

I'm using node-oracle module with the following code (from the node-oracle documentation):
var oracle = require("oracle");
oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
if(err){ console.log("Connect err:" + err); }
if(connection){ console.log("Connection:" + connection); }
// selecting rows
connection.execute("SELECT nickname FROM users WHERE nickname = :1", ['luc'], function(err, results) {
console.log("execution");
console.log("RESULTS:" + results);
console.log("Err:" + err);
});
connection.setAutoCommit(true);
connection.commit(function(err) {
console.log("commiting");
// transaction committed
});
connection.rollback(function(err) {
console.log("rollback");
// transaction rolledback
});
connection.close(); // call this when you are done with the connection
});
This gives me different error messages :
$ node test_node_oracle.js
Connection:[object Connection]
rollback
commiting
execution
RESULTS:undefined
Err:Error: ORA-24324: service handle not initialized
Sometimes it also gives:
$ node test_node_oracle.js
Connection:[object Connection]
Segmentation fault
or also:
$ node test_node_oracle.js
Connection:[object Connection]
commiting
rollback
execution
RESULTS:undefined
Err:Error: ORA-32102: invalid OCI handle
sqlplus access works fine though:
$ sqlplus USER/PASS#192.168.1.120/orcl
SQL*Plus: Release 11.2.0.3.0 Production on Mon Mar 12 15:18:18 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>

connection.close(); // call this when you are done with the connection
I believe this get's called too soon, because all statements are non-blocking in node.js(event-loop). You should probably wrap it in proper callback(s) inside commit and rollback. You should also wrap all your code inside of connection callback
oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
// wrap all your code inside of this.
}

Related

Suddenly, Heroku credentials to a PostgreSQL server gives FATAL password for user error

Without changing anything in my settings, I can't connect to my PostgreSQL database hosted on Heroku. I can't access it in my application, and is given error
OperationalError: (psycopg2.OperationalError) FATAL: password authentication failed for user "<heroku user>" FATAL: no pg_hba.conf entry for host "<address>", user "<user>", database "<database>", SSL off
It says SSL off, but this is enabled as I have confirmed in PgAdmin. When attempting to access the database through PgAdmin 4 I get the same problem, saying that there is a fatal password authentication for user '' error.
I have checked the credentials for the database on Heroku, but nothing has changed. Am I doing something wrong? Do I have to change something in pg_hba.conf?
Edit: I can see in the notifications on Heroku that the database was updated right around the time the database stopped working for me. I am not sure if I triggered the update, however.
Here's the notification center:
In general, it isn't a good idea to hard-code credentials when connecting to Heroku Postgres:
Do not copy and paste database credentials to a separate environment or into your application’s code. The database URL is managed by Heroku and will change under some circumstances such as:
User-initiated database credential rotations using heroku pg:credentials:rotate.
Catastrophic hardware failures that require Heroku Postgres staff to recover your database on new hardware.
Security issues or threats that require Heroku Postgres staff to rotate database credentials.
Automated failover events on HA-enabled plans.
It is best practice to always fetch the database URL config var from the corresponding Heroku app when your application starts. For example, you may follow 12Factor application configuration principles by using the Heroku CLI and invoke your process like so:
DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app) your_process
This way, you ensure your process or application always has correct database credentials.
Based on the messages in your screenshot, I suspect you were affected by the second bullet. Whatever the cause, one of those messages explicitly says
Once it has completed, your database URL will have changed
I had the same issue. Thx to #Chris I solved it this way.
This file is in config/database.js (Strapi 3.1.3)
var parseDbUrl = require("parse-database-url");
if (process.env.NODE_ENV === 'production') {
module.exports = ({ env }) => {
var dbConfig = parseDbUrl(env('DATABASE_URL', ''));
return {
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: dbConfig.driver,
host: dbConfig.host,
port: dbConfig.port,
database: dbConfig.database,
username: dbConfig.user,
password: dbConfig.password,
},
options: {
ssl: false,
},
},
},
}
};
} else {
// to use the default local provider you can return an empty configuration
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'sqlite',
filename: env('DATABASE_FILENAME', '.tmp/data.db'),
},
options: {
useNullAsDefault: true,
},
},
},
});
}

Heroku postgres node connection timeout

I'm trying to connect to a Postgres database from my Heroku node app, which works when running locally, both through node and by running the heroku local web command, but when running it on Heroku, it times out while waiting for pool.connect
I'm running the following code snippet through the Heroku console (I've also tried using this code in my app directly, but this is more efficient than redeploying each time):
node -e "
const { Pool } = require('pg');
const pool = new Pool({
connectionTimeoutMillis: 15000,
connectionString: process.env.DATABASE_URL + '?sslmode=require',
ssl: {
rejectUnauthorized: true
}
});
console.log('pool created');
(async() => {
try {
console.log('connecting');
const client = await pool.connect(); // this never resolves
console.log('querying');
const { rows } = await client.query('SELECT * FROM test_table LIMIT 1;');
console.log('query success', rows);
client.release()
} catch (error) {
console.log('query error', error);
}
})()
"
Things I've tried so far:
Using the pg Clientinstead of Pool
Using ssl: true instead of ssl: { rejectUnauthorized: true }
Using client.query without using pool.connect
Increased and omitted connectionTimeoutMillis (it resolves quickly when running locally since I'm querying a database that has just one row)
I've also tried using callbacks and promises instead of async / await
I've tried setting the connectionString both with the ?sslmode=require parameter and without it
I have tried using pg versions ^7.4.1 and ^7.18.2 so far
My assumption is that there is something I'm missing with either the Heroku setup or SSL, any help would be greatly appreciated, Thanks!

Integrating oracle 11g with Grails and Hibernate

I have created a simple grails 3 application. I am trying to connect it to an Oracle database in the datasource configuration.
When I run
SELECT * FROM V$VERSION
in sql developer, the following data is returned back about my database.
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
my application.yml file looks like this:
dataSources:
dataSource:
pooled: true
dialect: org.hibernate.dialect.Oracle10gDialect
driverClassName: 'oracle.jdbc.OracleDriver'
username: 'superCool'
password: 'password'
url: 'jdbc:oracle:thin:#127.0.0.1:1521:coolio'
dbCreate: ''
my build.gradle file contains these lines for hibernate and oracle dependencies.
dependencies {
(...)
compile "org.grails.plugins:hibernate:4.3.10.5"
(...)
compile "org.hibernate:hibernate-ehcache"
compile("com.oracle:ojdbc7:12.1.0.2")
}
My service file looks as follows:
class DatabaseService {
DataSource dataSource
public void testMyDb(User user) {
try {
registerUser(new Sql(dataSource), user)
} catch (SQLException e) {
LOGGER.error("unable to register the user", e)
throw e
}
}
public void registerUser(Sql sql, User user) {
sql.call("{call isertUser(?)}", [user.name])
}
If I remove the
compile "org.grails.plugins:hibernate:4.3.10.5"
from the build.gradle, I can run my integration tests and the database is successfully reached. If I keep it there, I get the following error:
ERROR DatabaseService - unable to register the user
java.sql.SQLRecoverableException: Closed Connection
at oracle.jdbc.driver.PhysicalConnection.getAutoCommit(PhysicalConnection.java:2254) ~[ojdbc7-12.1.0.2.jar:12.1.0.2.0]
UPDATE 1:
I updated my build.gradle file to reference
compile("com.oracle:ojdbc6:11.2.0.2")
as opposed to
compile("com.oracle:ojdbc7:12.1.0.2")
and the generated error now refers to the setter:
ERROR DatabaseService - unable to register the user
java.sql.SQLRecoverableException: Closed Connection
at oracle.jdbc.driver.PhysicalConnection.setAutoCommit(PhysicalConnection.java:2254) ~[ojdbc7-12.1.0.2.jar:12.1.0.2.0]
UPDATE 2:
I caught the SQLException and got the sql error code from it. The code returned back: 08003. According to https://docs.oracle.com/cd/E15817_01/appdev.111/b31228/appd.htm ,
08003 - connection does not exist
So at this point, I set the pooled flag to false in the datasource, and everything worked just fine. So the problem here is narrowed down to that. The plugin is not reacting well to the pooled properties.
I have issued the following sql commands to figure out the size of my pool:
SELECT name, value FROM v$parameter WHERE name = 'sessions';
that returns back 1524.
I have also issued the sql command to see the current allocated amount:
SELECT COUNT(*) FROM v$session;
which returns back 58.
I suppose the question now is, what is causing the pooled property to go crazy.
The solution to this was to disable my pooling. I cannot tell if its a bug, r why it fails, but it does. Thankfully for me, I used jndi lookup for my dataSources, so replacing that made the spark.
dataSources:
dataSource:
pooled: false
dialect: org.hibernate.dialect.Oracle10gDialect
driverClassName: 'oracle.jdbc.OracleDriver'
username: 'superCool'
password: 'password'
url: 'jdbc:oracle:thin:#127.0.0.1:1521:coolio'
dbCreate: ''

Simple Flyway example fails with ORA-00911 invalid character

I'm trying out Flyway with a simple example, and somehow fell into an error I don't understand. This is just a "hello world" type project.
This migration script fails as posted here, but succeeds if I either remove the ";" at the end, or change the column default to anything but 'N'. Lowercase 'n' also fails.
I've used a hex editor to confirm everything is ascii, and can successfully run the migration script in Toad and SQuirreL. It only fails when going through Flyway.
I've also used the debugger to capture the SQL string within Flyway before it gets executed, and it looks fine there as well. Copying it from the debugger to Toad or SQuirreL also succeeds.
It's got to be something simple that I'm missing, but I can't see what it is. Any ideas?
Here's my only migration script:
CREATE TABLE APP_USER
(
USER_ID INTEGER NOT NULL,
USER_CONFIRMED CHAR(1) DEFAULT 'N'
);
and the code:
import javax.sql.DataSource;
import oracle.jdbc.pool.OracleDataSource;
import org.flywaydb.core.Flyway;
public class FlywayTask {
public static void main(String[] args) {
FlywayTask flywayTask = new FlywayTask();
try {
flywayTask.run();
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
System.out.println("FlywayTask Running!");
// Create Flyway instance w/ a datasource
Flyway flyway = new Flyway();
flyway.setDataSource(buildDS());
// Delete the WHOLE SCHEMA!! DANGER!!
flyway.clean();
// Start the migration
flyway.migrate();
}
public DataSource buildDS() {
...
return ods;
}
}
Running this against Oracle 10g or 11g results in this error:
FlywayTask Running!
Jun 12, 2015 10:38:40 AM org.flywaydb.core.internal.util.VersionPrinter printVersion
INFO: Flyway 3.2 by Boxfuse
Jun 12, 2015 10:38:41 AM org.flywaydb.core.internal.dbsupport.DbSupportFactory createDbSupport
INFO: Database: jdbc:oracle:thin:#(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=scan-dev-db.dev.probuild.com )(PORT=1525)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME=NTRADEV.dev.probuild.com))) (Oracle 11.2)
Jun 12, 2015 10:38:42 AM org.flywaydb.core.internal.command.DbClean cleanSchema
INFO: Cleaned schema "TOM1" (execution time 00:00.686s)
Jun 12, 2015 10:38:42 AM org.flywaydb.core.internal.command.DbValidate validate
INFO: Validated 1 migration (execution time 00:00.016s)
Jun 12, 2015 10:38:42 AM org.flywaydb.core.internal.metadatatable.MetaDataTableImpl createIfNotExists
INFO: Creating Metadata table: "TOM1"."schema_version"
Jun 12, 2015 10:38:43 AM org.flywaydb.core.internal.command.DbMigrate migrate
INFO: Current version of schema "TOM1": << Empty Schema >>
Jun 12, 2015 10:38:43 AM org.flywaydb.core.internal.command.DbMigrate applyMigration
INFO: Migrating schema "TOM1" to version 1 - Tables
Jun 12, 2015 10:38:43 AM org.flywaydb.core.internal.command.DbMigrate applyMigration
SEVERE: Migration of schema "TOM1" to version 1 failed! Please restore backups and roll back database and code!
org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Migration V1__Tables.sql failed
-------------------------------
SQL State : 22019
Error Code : 911
Message : ORA-00911: invalid character
Location : db/migration/V1__Tables.sql (C:\Workspaces\luna_64\flyway-spike\target\classes\db\migration\V1__Tables.sql)
Line : 3
Statement : CREATE TABLE APP_USER
(
USER_ID INTEGER NOT NULL,
USER_CONFIRMED CHAR(1) DEFAULT 'N'
);
at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:117)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:71)
at org.flywaydb.core.internal.command.DbMigrate$5.doInTransaction(DbMigrate.java:284)
at org.flywaydb.core.internal.command.DbMigrate$5.doInTransaction(DbMigrate.java:282)
at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
at org.flywaydb.core.internal.command.DbMigrate.applyMigration(DbMigrate.java:282)
at org.flywaydb.core.internal.command.DbMigrate.access$800(DbMigrate.java:46)
at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:207)
at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:156)
at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:156)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1059)
at org.flywaydb.core.Flyway$1.execute(Flyway.java:1006)
at org.flywaydb.core.Flyway.execute(Flyway.java:1418)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
at com.probuild.spike.flyway.FlywayTask.run(FlywayTask.java:34)
at com.probuild.spike.flyway.FlywayTask.main(FlywayTask.java:16)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:999)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1890)
at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1855)
at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:304)
at org.flywaydb.core.internal.dbsupport.JdbcTemplate.executeStatement(JdbcTemplate.java:238)
at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:114)
... 16 more
It is know bug of Flyway. It is fixed already, but it will be released in Flyway 4.0. Take a look at issue 1080

h2 mixed mode connection problem

I start h2 database in a servlet context listener:
public void contextInitialized(ServletContextEvent sce) {
org.h2.Driver.load();
String apprealPath = sce.getServletContext().getRealPath("\\");
String h2Url = "jdbc:h2:file:" + apprealPath + "DB\\cdb;AUTO_SERVER=true";
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(lc);
logger.debug("h2 url : " + h2Url);
try {
conn = DriverManager.getConnection(h2Url, "sa", "sa");
} catch (SQLException e) {
e.printStackTrace();
}
logger.debug("h2 database started in embedded mode");
sce.getServletContext().setAttribute("connection", conn);
}
then I try to use dbvisualizer to connect to h2 using following url :
jdbc:h2:tcp://localhost/~/cdb
but get these error messages:
An error occurred while establishing the connection:
Type: org.h2.jdbc.JdbcSQLException Error Code: 90067 SQL State: 90067
Message:
Connection is broken: "Connection refused: connect" [90067-148]
I tried to replace localhost with "172.17.33.181:58524" (I found it in cdb.lock.db)
reconnect with user "sa" password "sa" ,then server response changed to :
wrong username or password !
In the Automatic Mixed Mode, you don't need to (and you can't) use jdbc:h2:tcp://localhost. Just use the same URL everywhere, that means jdbc:h2:file:...DB\\cdb;AUTO_SERVER=true.
You can use the same database URL independent of whether the database is already open or not. Explicit client/server connections (using jdbc:h2:tcp:// or ssl://) are not supported.

Resources