English | 简体中文
Node-OpenGauss is implemented based on Node-PostGre.Achieve SHA256 encryption connection
A simple openGauss client for Node.js based on node-postgres.
npm install
const { Pool, Client } = require('./lib')
const pgConfig = {
user: '*********',
database: 'postgres',
password: '********',
host: '************',
port: 5432,
}
const pool = new Pool(pgConfig)
pool.on('error', (err, result) => {
return console.error('catch error: ', err)
})
pool.connect((err, client, release) => {
if (err) {
return console.log('can not connect to postgresql server.')
}
client.query('DROP TABLE test;')
client.query(`CREATE TABLE test
(
c_customer_sk integer
);`)
client.query('insert into test values(1111)', (err, res) => {
console.log(res)
})
client.query('update test set c_customer_sk = 2222', (err, res) => {
console.log(res)
})
client.query('SELECT * FROM test;', (err, res) => {
console.log(res)
})
client.query('delete from test where c_customer_sk = 2222', (err, res) => {
console.log(res)
})
client.query('SELECT * FROM test;', (err, res) => {
console.log(res)
})
release()
return console.log('connect to postgresql successfully!')
})
function rollback(client) {
//terminating a client connection will
//automatically rollback any uncommitted transactions
//so while it's not technically mandatory to call
//ROLLBACK it is cleaner and more correct
return client
.query('ROLLBACK')
.then(() => client.end())
.catch(() => client.end())
}
Development on MacOS/Linux is preferred :)
- Please deploy OpenGauss on
CentOS 7
oropenEuler 20.3 LTS
- Ensure you have a openGauss instance running, follow this https://opengauss.org/zh/docs/2.0.1/docs/Quickstart/Quickstart.html to set up it
Navigate to examples
and run following to test driver:
/*
example
*/
cd packages/pg/
node test-1.js
- Configure the client access authentication method
- [Please refer to here for specific implementation] (https://github.com/brianc/node-postgres)
- [Refer to the JDBC driver for encryption] (https://gitee.com/opengauss/openGauss-connector-jdbc)
-
[SEMMNI ERROR]
When doing simpleinstall, we may get this error
"On systemwide basis, the maximum number of SEMMNI is not correct. the current SEMMNI value is: .... Please check it."
According to the installation script, SEMMNI should be greater than 321.875
On CentOS 7 we can do this to modify it
$ sudo vim /etc/sysctl.conf
Add this line to the end of file
kernel.sem = 250 32000 100 400
Then use
shift + double z
or:wq
to save and exit thevim
Finally execute it to apply our settings
$ /sbin/sysctl -p
-
[The account was locked]
Enter the gsql on your server
Then run this
alter user
[username]
account unlock; -
[Adding IPv4 rules allows all external links to the password to be verified by SHA256]
Open this file:
/opt/software/openGauss/data/single_node/pg_hba.conf
add this:
host all all 0.0.0.0/0 sha256
-
[GUC]
Click here