如何在 Windows 7 上的 PostgreSQL 中创建数据库?

Jon*_*nas 7 windows-7 database postgresql

我在自己的家用电脑上使用 Windows 7。我已经安装了 PostgreSQL,现在我想创建一个数据库。

我尝试过,createdb mydatabase但收到此错误消息:

createdb: could not connect to database postgres: FATAL: role "Jonas" does
not exist
Run Code Online (Sandbox Code Playgroud)

我还尝试创建一个角色“Jonas”,createuser Jonas但我遇到了同样的错误,即使我在 PowerShell 中以管理员身份登录。

如何在我的 Windows 7 机器上创建 PostgreSQL 数据库?

ta.*_*.is 6

http://www.postgresql.org/docs/8.1/static/tutorial-createdb.html

另一种回应可能是这样的:

createdb: could not connect to database postgres: FATAL:  user "joe" does not
exist
Run Code Online (Sandbox Code Playgroud)

其中提到了您自己的登录名。如果管理员尚未为您创建 PostgreSQL 用户帐户,则会发生这种情况。(PostgreSQL 用户帐户不同于操作系统用户帐户。)如果您是管理员,请参阅第 18 章以获取创建帐户的帮助。您需要成为安装 PostgreSQL 的操作系统用户(通常是 postgres)才能创建第一个用户帐户


小智 5

来自http://www.postgresql.org/docs/8.1/static/tutorial-createdb.html

也可能是您被分配了一个与您的操作系统用户名不同的 PostgreSQL 用户名;在这种情况下,您需要使用 -U 开关或设置 PGUSER 环境变量来指定您的 PostgreSQL 用户名。

我遇到了同样的问题,现在我用

createdb -U postgres dbname
Run Code Online (Sandbox Code Playgroud)