我使用的是mac版PostgreSql应用(http://postgresapp.com/)。我以前在其他机器上用过,但在我的macbook上安装时遇到了一些麻烦。我已经安装了应用程序,并运行:

psql -h localhost

它返回:

psql: FATAL:  database "<user>" does not exist

似乎我甚至不能运行控制台来创建它试图找到的数据库。当我跑步时,同样的事情也会发生:

psql 

或者如果我从应用程序下拉菜单启动psql:

机统计数据:

OSX 10.8.4 发生冲突

任何帮助都是感激的。

我也尝试过通过自制程序安装PostgreSql,我也遇到了同样的问题。我还读了申请文档页面,上面写着:

当Postgres。app首先启动,它创建$USER数据库, 当没有指定时,它是PSQL的默认数据库。的 默认用户为$ user,没有密码。

因此,似乎应用程序没有创建$USER,但我已经安装->卸载-重新安装了几次,所以它必须与我的机器。

我找到了答案,但我不确定它是如何工作的,因为在这个线程上回答的用户->让Postgresql在Mac中运行:数据库“postgres”不存在,没有跟进。我使用下面的命令来打开psql:

psql -d template1

我不回答这个问题,直到有人能解释为什么这样做。


当前回答

使用默认template1数据库登录:

#psql -d template1
#template1=# \l

  List of databases
   Name    |  Owner  | Encoding |   Collate   |    Ctype    |  Access privileges  
-----------+---------+----------+-------------+-------------+---------------------
 postgres  | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
 template1 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
(3 rows)

用你的userId创建一个数据库:

template1=# CREATE DATABASE gogasca WITH OWNER gogasca ENCODING 'UTF8';
CREATE DATABASE

退出,然后再次登录

template1=# \q
gonzo:~ gogasca$ psql -h localhost
psql (9.4.0)
Type "help" for help.

gogasca=# \l
                                List of databases
   Name    |  Owner  | Encoding |   Collate   |    Ctype    |  Access privileges  
-----------+---------+----------+-------------+-------------+---------------------
 gogasca   | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
 template1 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
(4 rows)

其他回答

在使用JDBC驱动程序时遇到了问题,因此只需要在URL中的主机名之后添加数据库(可能是冗余的,这取决于您可能使用的工具),例如。 jdbc: postgres: / / <主机(港口)> / < db名称>

详情请见:http://www.postgresql.org/docs/7.4/static/jdbc-use.html#JDBC-CONNECT

使用默认template1数据库登录:

#psql -d template1
#template1=# \l

  List of databases
   Name    |  Owner  | Encoding |   Collate   |    Ctype    |  Access privileges  
-----------+---------+----------+-------------+-------------+---------------------
 postgres  | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
 template1 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
(3 rows)

用你的userId创建一个数据库:

template1=# CREATE DATABASE gogasca WITH OWNER gogasca ENCODING 'UTF8';
CREATE DATABASE

退出,然后再次登录

template1=# \q
gonzo:~ gogasca$ psql -h localhost
psql (9.4.0)
Type "help" for help.

gogasca=# \l
                                List of databases
   Name    |  Owner  | Encoding |   Collate   |    Ctype    |  Access privileges  
-----------+---------+----------+-------------+-------------+---------------------
 gogasca   | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
 template1 | gogasca | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/gogasca         +
           |         |          |             |             | gogasca=CTc/gogasca
(4 rows)

当我试图在mac上打开postgresql时,我遇到了同样的错误

psql: FATAL:  database "user" does not exist

我找到了这个简单的命令来解决它:

method1

$ createdb --owner=postgres --encoding=utf8 user

和类型

 psql

方法2:

psql -d postgres

步骤1:

PSQL -d template1

现在你应该在PSQL终端上

步骤2:

创建数据库用户名

确保在数据库名称后使用分号(;);

可选:在PSQL终端上输入\ls或\l列出所有数据库;

步骤3:

PSQL -h localhost

现在你应该连接上了;

这是一个基本的误解。只是打字:

《植物遗传资源》

会得到这样的回应:

pgres <db_name> 

如果用户拥有访问数据库的权限,那么它将成功而不会出错。

我们可以详细了解导出的环境变量,但这是不必要的。这太基本了,不会因为任何其他原因而失败。