我正在尝试从node.js postgres sql中删除一个名为test
的数据库,但它无法正常工作。
var express = require('express');
var app = express();
var pg = require('pg');
var pgp = require('pg-promise')();
// Connect to PostgreSQL database
var connectionString = process.env.DATABASE_URL || 'postgres://postgres:pass123@localhost:5432/test';
var db = pgp(connectionString);
db.connect();
db.query("DROP DATABASE test").then(function()
{
//createDatabases(db);
}).catch(function(err)
{
console.log(err);
});
但我收到错误
{ [error: cannot drop the currently open database]
name: 'error',
length: 87,
severity: 'ERROR',
code: '55006',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'dbcommands.c',
line: '834',
routine: 'dropdb' }
有谁知道如何修复它?
由于
答案 0 :(得分:1)
如错误所示,您无法连接到相关数据库以删除它。您可以连接到其他数据库,或使用pgtools
之类的工具$var = `pgrep ts3server`;
var_dump($var);