postgresql - psql 说数据库不存在但它确实存在于 pgadmin
问题描述
我刚刚在 Windows 上安装了 Postgres v10.4,并使用 pgadmin 创建了一个名为 analysis 的新数据库。它就在那里,我可以在 pgadmin 中看到它,并且它有一个表。但是,我无法使用 psql 连接到该数据库。
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 中看到的内容?
解决方案
template0 和 template1 被称为骨架数据库。当您使用 CREATE DATABASE 命令 postgres 复制现有数据库。默认情况下,template1 数据库用于创建新数据库。
我认为您的 pgadmin 和 psql 连接到不同的集群。postgresql 中的集群是单个服务器实例中一个或多个数据库的集合
您发布的图像未显示 pgadmin 浏览器的完整视图。但是如果有 2 个集群,那么您可以在 pgadmin 中看到类似“Servers(2)”的信息。要查找每个集群的运行端口,请右键单击相应的集群并选择属性,然后单击连接选项卡。这里可以看到端口号。然后使用该端口连接到 psql 中的集群。
推荐阅读
- webpack - 使用 webpack/ts 别名从另一个文件导入 JSDoc
- reactjs - 如何在我的 UI 表单中增强钩子视图的空状态
- reactjs - 用主页路径反应路由器问题
- reactjs - Stripe,如何检索付款历史记录?
- angular - Angular 在路由后不会破坏源组件
- performance - 当正在搜索的属性具有索引时,通过 baseDN 限制 LDAP 搜索是否会带来任何好处?
- javascript - 开发中如何强制 ReactJS 忽略主页值?
- r - R:标记 n-gram 但不去除标点符号
- python - 带有网格的 Tkinter 滚动条:滚动过去的帧和滚动条灰色
- swift - nw_socket_get_input_frames [C4:1] recvmsg(fd 35, 9216 bytes) [61: Connection denied]