If we take the example on the main page:
var pg = require('pg');
var conString = "postgres://username:password@localhost/database";
//this initializes a connection pool
//it will keep idle connections open for a (configurable) 30 seconds
//and set a limit of 10 (also configurable)
pg.connect(conString, function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query('SELECT $1::int AS number', ['1'], function(err, result) {
//call `done()` to release the client back to the pool
done();
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].number);
//output: 1
});
});
And simply switch to Node.js 6.0.0, we are immediately getting an error:
error fetching client from pool { error: password authentication failed for user "postgres"
at Connection.parseE (D:\NodeJS\tests\node_modules\pg\lib\connection.js:539:11)
at Connection.parseMessage (D:\NodeJS\tests\node_modules\pg\lib\connection.js:366:17)
at Socket.<anonymous> (D:\NodeJS\tests\node_modules\pg\lib\connection.js:105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:535:20)
name: 'error',
length: 115,
severity: 'FATAL',
code: '28P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'src\\backend\\libpq\\auth.c',
line: '304',
routine: 'auth_failed' }
i.e. authentication doesn't work under the newly released Node.js 6.0.0
My Test environment:
I get the same error
error fetching client from pool { error: password authentication failed for user "username"
at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:539:11)
at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:366:17)
at Socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:535:20)
name: 'error',
length: 93,
severity: 'FATAL',
code: '28P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'auth.c',
line: '285',
routine: 'auth_failed' }
My Test environment:
Yep, same here as @migolo and @vitaly-t
(also, I think I need to wear sunglasses to fit into this community)
I wonder how this happened? There shouldn't be an API breaking change in v6 other than the worker process API.
Btw, what's this file: 'auth.c' file being mentioned?
Btw, what's this file: 'auth.c' file being mentioned?
That's where all the authentication mambo-jumbo happens inside PostgreSQL server code. It is always mentioned on any authentication-related error.
I've done some initial debugging, and I am almost certain the issue is caused by one of the changes to the Buffer.
From the change-log:
The following significant changes have been made since the previous Node.js v5.0.0 release:
Buffer() and SlowBuffer() constructors have been deprecatedBuffer.prototype.lastIndexOf() method has been addedFor example, if I do something like this:
Connection.prototype.parseCString = function(buffer) {
console.log('BUFFER:', buffer.length);
var start = this.offset;
while(buffer[this.offset++] !== 0) { }
return buffer.toString(this.encoding, start, this.offset - 1);
};
in file connection.js, i see immediate change in the received buffer length as I change to Node.js 6.0.0
Same issue here
Hello everyone,
Here's what fixes the Node v6.0.0 problem:
https://github.com/ignitenet-martynas/node-postgres/commit/77560fe1bbc80ba0a629720161d81dbb6286166d
I confirm it works for me
Works for me too.
I confirm this to be the fix indeed! Thank you @ignitenet-martynas !
So it was the Buffer as I thought :)
@brianc Now we just need the PR to make into a new release ;) And I think it should be 4.6.0 ;)
The issue has been resolved with 4.5.5 release.
Thank you @ignitenet-martynas and @brianc :+1:
Thanks for your help with reporting it & digging in and finding it was an issue with the buffer @vitaly-t!!
Btw, judging by the fix, this is probably due to by https://github.com/nodejs/node/pull/5522, not the Buffer changes. crypto now treats strings as utf8, not as binary if no encoding is specified.
Precisely, @ChALkeR.
Sorry for zombying this issue but I seem to be having the same problem despite upgrading to pg 4.5.5 on node 6.2.1. Same error: password authentication failed for user. I'm using RDS if that helps - is there anyone else still experiencing this issue?
Apologies - this was my fault. Another issue masquerading as this one that I've managed to fix.
I am getting the same error right now am on node 6.0.0 and my lib/client also has var outer = Client.md5(Buffer.concat([new Buffer(inner), msg.salt]));
DOESnt work for me.
have same problem,,and i try your solution but still error, cannot 'gulp serve'
hope your help.
PS C:\webproj\dreamhouse-web-app> gulp serve
[10:45:36] Using gulpfile C:\webproj\dreamhouse-web-app\gulpfile.js
[10:45:36] Starting 'clean'...
[10:45:36] Finished 'clean' after 69 ms
[10:45:36] Starting 'watch'...
[10:45:36] Starting 'sass'...
[10:45:36] Starting 'html'...
[10:45:36] Starting 'fonts'...
[10:45:36] Starting 'scripts'...
[10:45:36] Finished 'scripts' after 118 ms
[10:45:36] Finished 'html' after 160 ms
[10:45:36] Finished 'fonts' after 177 ms
[10:45:38] Finished 'sass' after 2.14 s
7.6 MB bytes written (9.89 seconds)
[10:45:49] Finished 'watch' after 13 s
[10:45:49] Starting 'serve'...
Listening at: http://localhost:8200
[10:45:49] Finished 'serve' after 302 ms
events.js:160
throw er; // Unhandled 'error' event
^
error: password authentication failed for user "taufikmas"
at Connection.parseE (C:\webproj\dreamhouse-web-app\node_modulespg\libconnection.js:539:11)
at Connection.parseMessage (C:\webproj\dreamhouse-web-app\node_modulespg\libconnection.js:366:17)
at Socket. (C:\webproj\dreamhouse-web-app\node_modulespg\libconnection.js:105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
@fixduino did you test it under Node 4.x? Which version of node-postgres are you using?
i use latest node 6.0 . win10.
is node jss 6.0 not support pg 4.5.5?
i try for this tutorial https://github.com/dreamhouseapp/dreamhouse-web-app
@fixduino try Node.js 4.x, your problem could be unrelated, i.e. if you still get the same error, then it is not related, and you simply got your password wrong.
@fixduino I'd need to see your code but it looks like you're using the wrong password.
i never put my password. where is location for set password? thx
client.js -- https://pastebin.com/XQYs5xWv
conection-parameters.js -- https://pastebin.com/44mHmsgh
thx for help
SOLVED.. just a little mistake to set parameter..
in server.js
var connectionString = process.env.DATABASE_URL || 'postgres://postgres:admin@localhost:5432/dreamhouse'; //postgres://YourUserName:YourPassword@localhost:5432/YourDatabase";
thanks all.
win10. nodejs 6.0
Excuse me I cannot open this link https://github.com/ignitenet-martynas/node-postgres/commit/77560fe1bbc80ba0a629720161d81dbb6286166d it show 404 not found
@ignitenet-martynas
@endermaxximum Well the fix has been integrated into node-postgres quite a while ago therefore I deleted the fork...
okay.thank you
This is the error that I got.

could you help me what wrong with my code? @ignitenet-martynas
here is my code: `var express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
cons = require('consolidate'),
dust = require('dustjs-helpers'),
pg = require('pg'),
app = express();
var pool = new pg.Pool()
// DB Connect String
// from owner Loaserver pass 00000000
var connect ="postgres://Loraserver:00000000@localhost/Lopicaserver";
// Assign Dust Engine to .dust Files
app.engine('dust', cons.dust);
// Set Default Ext .dust
app.set('view engine', 'dust');
app.set('views', __dirname + '/views');
// Set Public Folder
app.use(express.static(path.join(__dirname, 'public')));
// Body Parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function(req, res){
//connect using created pool
pool.connect(function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query('SELECT * FROM public.loradata', function(err, result){
if(err){
return console.error('error running query', err);
}
res.render('index', {loradata: result.rows});
done();
});
});
});
// Server
app.listen(3000, function(){
console.log('Server Started On Port 3000');
});`
@endermaxximum Your connection string isn鈥檛 used anywhere. Pass it to the pool constructor (documentation):
var pool = new pg.Pool({
connectionString: "postgres://Loraserver:00000000@localhost/Lopicaserver",
});
Thank you so much.
@charmander
Most helpful comment
Hello everyone,
Here's what fixes the Node v6.0.0 problem:
https://github.com/ignitenet-martynas/node-postgres/commit/77560fe1bbc80ba0a629720161d81dbb6286166d