代码之家  ›  专栏  ›  技术社区  ›  Davtho1983

使用Postgres Shell创建用户

  •  0
  • Davtho1983  · 技术社区  · 7 年前

    我正在学习这本书的一个教程

    Mele, Antonio. Django 2 by Example: Build powerful and reliable Python web applications from scratch (Kindle Locations 1917-1918). Packt Publishing. Kindle Edition.
    

    我在这里:

    > Adding full-text search to your blog
     > Installing PostgreSQL
    

    我在Windows10上,我安装了PostgresFine。在Postgres shell中键入以下说明:

    su postgres
    createuser -dP blog
    

    我想我正在尝试创建一个名为“blog”的用户,该用户将具有密码并允许创建数据库?

    当我这样做的时候,我得到:

    Server [localhost]: su postgres
    Database [postgres]: createuser -dP blog
    Port [5432]:
    Username [postgres]:
    psql: warning: extra command-line argument "postgres" ignored
    psql: warning: extra command-line argument "-d" ignored
    psql: warning: extra command-line argument "createuser" ignored
    psql: warning: extra command-line argument "-dP" ignored
    psql: warning: extra command-line argument "blog" ignored
    psql: warning: extra command-line argument "-p" ignored
    psql: warning: extra command-line argument "5432" ignored
    psql: could not translate host name "su" to address: Unknown host
    Press any key to continue . . .
    

    我不知道该怎么办,到底发生了什么?说明很不清楚

    2 回复  |  直到 7 年前
        1
  •  1
  •   Gregory Arenius    7 年前

    看起来你在使用psql中的命令, su postgres createuser -dP blog 这是为了一个巴什式的外壳。 苏格拉底 说要切换Postgres OS用户, createuser 命令是用于创建数据库用户的shell命令。但是,如果您在psql中,则无法访问该命令。

    当psql请求数据库连接信息时,似乎您正在输入这些命令,因此即使您发送它sql/psql命令,它也不会在此时起作用。

    这里是 PostgreSQL Documentation 创建用户 命令。使用系统shell中的此命令创建数据库用户。

    这里是 PostgreSQL Documentation CREATE ROLE . 这就是从PSQL中创建用户的方法。

        2
  •  1
  •   Neil Anderson    7 年前

    createuser 是从命令行发出的命令。因为您在Windows上,这意味着它是一个.exe文件,可能位于Postgres安装位置的bin目录中。在命令提示或PowerShell提示下使用 createuser -dP blog .

    此外,您可能需要提供 -h localhost -p 5432 -U postgres -W password createuser.exe 使其能够与服务器通信。