node-postgres: connection strings not working in 6.x
Moving from v5.1 to v6.x, the same connection strings no longer work.
This used to work up until v5.1 at least:
var cn = "postgres://postgres@localhost:5433/newone";
pg.connect(cn,...)
Now with v6.1, calling:
var cn = "postgres://postgres@localhost:5433/newone";
var pool = new pg.Pool(cn);
pool.connect(function (err, client, done) {
throws the following error:
{ error: database "Vitaly" does not exist
at Connection.parseE (D:\NodeJS\tests\node_modules\pg\lib\connection.js:543:11) at Connection.parseMessage (D:\NodeJS\tests\node_modules\pg\lib\connection.js:370:17)
at Socket.<anonymous> (D:\NodeJS\tests\node_modules\pg\lib\connection.js:109: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:543:20)
name: 'error', length: 107,
severity: 'FATAL',
code: '3D000',
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\\utils\\init\\postinit.c',
line: '775',
routine: 'InitPostgres' }
I had to explicitly switch to the config object to make it work:
var cn = {
database: 'newone',
port: 5433,
host: 'localhost',
user: 'postgres'
};
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 29 (10 by maintainers)
But why database Vitaly does not exist?
Since
pg-pool
expects a config object and pool-factory.js was simply passing the argument directly topg-pool
it seems like checking if the passed in options are a string and parsing them into an object is all that was needed. I’ve created a PR but it seems the Travis build is having issues (I have the same issues running locally off master).@Globik thank you, but that is not where the problem is. We will try to figure the exact cause and attempt to fix it.
I will look at this when I get home. Problem should be occurring somewhere in this
val()
call: https://github.com/brianc/node-postgres/blob/master/lib/connection-parameters.js#L53You can parse a connection string using pg-connection-string.
Thank you, but no thank you. The issue is with the updated parser that needs to be fixed. I don’t want ugly work-arounds like this.
You must go check yr code and refactor it. Remove all Vitaly words, replace with “newone”. Make sure that database under that name exists. For every postgresql instances should be its own …/data directory.