2017-02-02 38 views
1

我想連接到我本地的postgres數據庫與knex,但我不斷收到此錯誤。連接到本地主機上的postgresql與knex時出現錯誤

{ Error: connect ECONNREFUSED 127.0.0.1:5432 
    at Object.exports._errnoException (util.js:1022:11) 
    at exports._exceptionWithHostPort (util.js:1045:20) 
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14) 
    code: 'ECONNREFUSED', 
    errno: 'ECONNREFUSED', 
    syscall: 'connect', 
    address: '127.0.0.1', 
    port: 5432 } 

// Here is how everything is set up: 
const connection = require('./db/knexfile.js').development; 
const knex = require('knex')(connection); 
const app = express(); 
const server = app.listen(PORT, '127.0.0.1', 'localhost',() => console.log(`Listening on ${ PORT }`)); 

// Inside knexfile.js 
module.exports = { 
    development: { 
    client: 'pg', 
    connection: { 
     "user": "development", 
     "password": "development", 
     "database": "testdb", 
     "host": "127.0.0.1", 
     "port": 5432 
    }, 
    pool: { 
     min: 2, 
     max: 10 
    }, 
    migrations: { 
     tableName: 'knex_migrations' 
    } 
    } 
}; 

其他信息: 我也運行過的WebPack在localhost陣營前端:3000穿過的WebPack服務器上的代理服務器設置發送HTTP請求到8080,但這似乎是工作。

我也有在localhost上運行的elasticsearch:9200,而且這似乎也是一樣。

回答

0

問題是我的postgres安裝版本不正確。我重新安裝postgres,不再有問題。

-1

另一種更快的方法是連接到本地數據庫就是使用AF_UNIX套接字。你將不得不放棄訪問權限的Linux用戶將託管應用程序:

development: 
    connection: { 
    host: '/var/run/postgresql', // On Debian it is this one, check your distro 
    database: 'database_name' 
    }, 

這種訪問的被測量是不是通過AF_INET(TCP/IP)套接字會快30%。

這裏有一篇舊文章:Performance of UNIX sockets vs TCP sockets

相關問題