簡體   English   中英

在命令行中輸入psql時,我應該登錄什么?

[英]What am I logging in as when I type psql in the command line?

如果我只是鍵入psql我會在命令行中打開程序,對嗎? 我以誰身份登錄? 當我選擇隨后要進入的數據庫時,我會說那個用戶嗎?

我是誰? 在postgres中

類型

select user;

知道你是誰

Windows中的示例

c:\Program Files\PostgreSQL\9.5\pg_env.bat
C:\Program Files\PostgreSQL\9.5>psql
Password:
psql (9.5.1)

postgres=# select user;
 current_user
--------------
 postgres
(1 row)

在此示例中,用戶名是postgres,因為pg_env.bat設置PGUSER=postgres

我在Linux中的狀況

如果鍵入psql postgres,請嘗試使用與OS用戶相同的名稱進行連接。

Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.9.36-x86_64-linode85 x86_64)
Last login: Sat Sep 16 11:02:09 2017 
tute@codenautas-server:~$ whoami
tute
tute@codenautas-server:~$ psql
psql: FATAL:  role "tute" does not exist
tute@codenautas-server:~$

您可以使用enviroment變量對其進行更改或將其更改:

sudo -u postgres psql
# select user;
 current_user
--------------
 postgres

您可以使用psql的提示

例如:

\set PROMPT1 '%[%033[33;1m%]%x%[%033[0m%]%[%033[1m%]%n@%/%[%033[0m%]%R%# '

顯示類似user@database=#的提示

使用psqlrc文件永久設置提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM