46

Heroku PostgreSQL DB に接続しようとしていますが、SSL エラーが発生し続けます。接続文字列で SSL を有効にする方法を知っている人はいますか?

postgres://user:pass@host:port/database;

どこでも探していますが、あまり人気のあるトピックではないようです。ちなみに、私は Nodejs と node-pg モジュールを接続プール方式で実行しています。

pg.connect(connString, function(err, client, done) {
  // Should work.
});

コメントは大歓迎です。

4

9 に答える 9

20

node-postgresから新しいクライアントを作成するときに、以下のコードを使用することもできます。

var pg = require("pg");

var client = new pg.Client({
  user: "yourUser",
  password: "yourPass",
  database: "yourDatabase",
  port: 5432,
  host: "host.com",
  ssl: true
});

client.connect();

var query = client.query('CREATE TABLE people(id SERIAL PRIMARY KEY, name VARCHAR(100) not null)');

query.on('row', function(row) {
  console.log(row.name);
});

query.on('end', client.end.bind(client));

お役に立てれば!

于 2015-05-07T19:16:14.550 に答える
16

Google Cloud PG とpg-promiseでも同様のニーズがありました。?ssl=true( を使用して)得たエラーは でしたconnection requires a valid client certificate

SSL 接続は文書化されていませんが、 node-postgrespg-promiseで構築されています。リンクで説明されているように、構成パラメーターは次のもの以上のものにすることができます。ssltrue

const pgp = require('pg-promise')();
const fs = require('fs');

const connectionConf = {
    host: 'myhost.com',
    port: 5432,
    database: 'specific_db_name',
    user: 'my_App_user',
    password: 'aSecretePass',
    ssl: {
        rejectUnauthorized : false,
        ca   : fs.readFileSync("server-ca.pem").toString(),
        key  : fs.readFileSync("client-key.pem").toString(),
        cert : fs.readFileSync("client-cert.pem").toString(),
  }

};
const new_db = pgp(connectionConf);
new_db.any('SELECT * FROM interesting_table_a LIMIT 10')
    .then(res => {console.log(res);})
    .catch(err => {console.error(err);})
    .then(() => {new_db.$pool.end()});
于 2018-08-21T09:23:10.593 に答える