在Windows上设置默认PostgreSQL角色

bybem2ql  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(151)

我想在运行psql命令时设置Windows上PostgreSQL安装的默认角色。
我相信我已经根据an answer in another StackOverflow question使用以下命令正确创建了角色:

# Log in the root role
psql -U postgres

# Create role
create user Mathe with password '123';

字符串
如果我再次运行create user,我会得到:
错误:角色“mathe”已存在
当我不带参数再次运行psql时,我得到:
psql:error:connection to server at“localhost”(::1),port 5432 failed:FATAL:role“Mathe”does not exist
我相信,这是因为第一个字母的缘故。我怎么才能改变这个默认角色呢?
根据评论,我已经尝试过在没有任何东西的情况下运行psql来解决上述问题:

postgres-# ALTER ROLE Mathe
postgres-# SET LOGIN = true
postgres-# SET NOLOGIN = false


你知道为什么我会得到和上面一样的输出吗?
我已经尝试了@Luuk的命令:

C:\Users\Mathe>psql -U postgres
psql (16.0)
WARNING: Console code page (437) 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=# ALTER ROLE "mathe" RENAME TO "Mathe"
postgres-# \du
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 hydroper  |
 mathe     |
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS


我试了psql如下:

C:\Users\Mathe>psql -U mathe
psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL:  database "mathe" does not exist

C:\Users\Mathe>psql -U Mathe
psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL:  role "Mathe" does not exist

js5cn81o

js5cn81o1#

2个选择:
1.第一个月

$ psql -U postgres

postgres=#> ALTER ROLE "mathe" RENAME TO "Mathe"
ALTER ROLE
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 Mathe     | Superuser                                                  | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres=# QUIT

$ psql

字符串
P.S.您的系统上的属性可能会有所不同。

相关问题