小编Vim*_*Raj的帖子

如何借助 ssh2 库建立 SSH 到 postgres 服务器并使用 pg libary 进行查询?

我正在尝试使用节点应用程序(库:ssh2)中的 SSH 隧道连接到 Postgres 远程主机并查询数据(lib:pg)。

在我使用mysql2(节点库)之前,使用ssh2(节点库)创建隧道并连接到Mysql远程主机并能够查询数据。但我想在 Postgres 远程主机上做同样的事情,但我无法连接到它。

pg 客户端 obj 配置不支持来自 ssh2 ForwardOut 的流..!

或者,是否有任何库可以代替 ssh2、pg 来实现这一点

PS:在mysql2中,当我尝试使用stream:stream键值与mysql配置建立连接时。

var Clientssh = require('ssh2').Client;
var conn = new Clientssh();
conn.on('ready', function() {
    console.log('Client :: ready');
    conn.forwardOut(
        '127.0.0.1',
        5434,
        'localhost',
        5432,
        function(err, stream) {
            if (err) throw err;
            let conf = {
                host: 'localhost',
                port: 5434,
                user: 'test',
                database: 'test',
                password: 'test'
            }
            let remoteConnection = new Client(conf);
            remoteConnection.connect(function(err) {
                if (err) {
                    console.log(err);
                    console.log("Unable to connect to postgre");
                    res.send(err);
                } else …
Run Code Online (Sandbox Code Playgroud)

postgresql ssh node.js

5
推荐指数
0
解决办法
2143
查看次数

标签 统计

node.js ×1

postgresql ×1

ssh ×1