如何使用默认windows用户名连接到PostgreSQL

如何使用默认windows用户名连接到PostgreSQL,postgresql,authentication,psql,Postgresql,Authentication,Psql,我已经读过多篇文章,他们在连接到postgres默认用户时遇到了问题 但是,在我的情况下,我可以毫无问题地连接到用户postgres,但我不能使用默认的windows用户登录。当我使用sqlshell时,它只是将我登录到postgres用户 Server [localhost]: Database [postgres]: Port [5432]: Username [postgres]: maximilian Password for user maximilian: psql (12.1) W

我已经读过多篇文章,他们在连接到postgres默认用户时遇到了问题

但是,在我的情况下,我可以毫无问题地连接到用户
postgres
,但我不能使用默认的windows用户登录。当我使用sqlshell时,它只是将我登录到postgres用户

Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]: maximilian
Password for user maximilian:
psql (12.1)
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=#         ----> As you can see still logged in as postgres user
我在postgres中设置为用户,如下所示:

postgres=# \du
                                    List of roles
 Role name  |                         Attributes                         | Member of
------------+------------------------------------------------------------+-----------
 maximilian | Superuser                                                  | {}
 postgres   | Superuser, Create role, Create DB, Replication, Bypass RLS | {} 
如果我想使用CMD命令提示符
psql
-默认用户是
Maximilian
,输入密码时返回错误

C:\Users\Maximilian>psql --help

Connection options:
  -h, --host=HOSTNAME      database server host or socket directory (default: "local socket")
  -p, --port=PORT          database server port (default: "5432")
  -U, --username=USERNAME  database user name (default: "Maximilian")
  -w, --no-password        never prompt for password
  -W, --password           force password prompt (should happen automatically)

psql: error: could not connect to server: FATAL:  password authentication failed for user "Maximilian"
psql
在我在postgres中创建该角色/用户之前,已经将
Maximilian
识别为默认用户


非常感谢任何帮助

在PostgreSQL中,大小写很重要,即使SQL是大小写折叠的,除非引用

数据库用户是
maximilian
,但操作系统用户是
maximilian

您可以重命名用户:

ALTER ROLE maximilian RENAME TO "Maximilian";
但“引用”的混合大小写标识符确实是个坏主意

因此,我建议您将环境变量
PGUSER
设置为
maximilian
,然后这将是默认用户名

顺便说一下:
psql
提示符中的
postgres
不是用户名,而是连接到的数据库