psql说数据库不存在,但是在pgadmin中确实存在

时间:2018-06-27 00:54:48

标签: postgresql

我刚刚在Windows上安装了Postgres v10.4,并使用pgadmin创建了一个名为analysis的新数据库。它在那里,我可以在pgadmin中看到它,并且其中有一张表。但是,我无法使用psql连接到该数据库。

enter image description here

C:\WINDOWS\system32>psql -d postgres -U postgres
psql (10.4)
WARNING: Console code page (850) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

postgres=# l
postgres-# \l
                                                  List of databases
   Name    |  Owner   | Encoding |           Collate           |            Ctype            |   Access privileges
-----------+----------+----------+-----------------------------+-----------------------------+-----------------------
 postgres  | postgres | UTF8     | English_United Kingdom.1252 | English_United Kingdom.1252 |
 template0 | postgres | UTF8     | English_United Kingdom.1252 | English_United Kingdom.1252 | =c/postgres          +
           |          |          |                             |                             | postgres=CTc/postgres
 template1 | postgres | UTF8     | English_United Kingdom.1252 | English_United Kingdom.1252 | =c/postgres          +
           |          |          |                             |                             | postgres=CTc/postgres
(3 rows)


postgres-# \q

C:\WINDOWS\system32>psql -d analysis -U postgres
psql: FATAL:  database "analysis" does not exist

C:\WINDOWS\system32>

我不知道我在使用psql做什么,但是我发现我只能以用户postgres身份连接到db postgres。有一个\l命令,它显示了3个数据库(其中2个是template0和template1),我什至在pgadmin中都看不到。

如何连接到刚刚在pgadmin中创建的数据库(分析)?谁能解释我在pgadmin中登录的用户,如果它与“ postgres”不同,或者不是,我在psql中看不到我在pgadmin中看到的东西?

1 个答案:

答案 0 :(得分:1)

template0和template1被称为框架数据库。当您使用CREATE DATABASE命令postgres复制现有的数据库。 默认情况下,template1数据库用于创建新数据库。

我认为您的pgadmin和psql连接到了不同的集群。 Postgresql中的集群是服务器的单个实例中的一个或多个数据库的集合

您发布的图像未显示pgadmin浏览器的完整视图。但 如果有2个集群,则可以在pgadmin中看到“ Servers(2)”。要查找每个群集的运行端口,请右键单击相应的群集并选择属性,然后单击“连接”选项卡。在这里可以看到端口号。 然后使用该端口连接到psql中的集群。

相关问题