📜  PostgreSQL – Psql 命令

📅  最后修改于: 2022-05-13 01:57:15.834000             🧑  作者: Mango

PostgreSQL – Psql 命令

Psql是一个用于处理 PostgreSQL 数据库的交互式终端。它用于更快、更有效地从 PostgreSQL 数据库服务器查询数据。在本文中,我们将研究一些最常用的 Psql 命令。

下表提供了常用的 Psql 命令:

CommandDescriptionAdditional Information
psql -d database -U user -WConnects to a database under a specific user-d: used to state the database name
-U:used to state the database user
psql -h host -d database -U user -WConnect to a database that resides on another host-h: used to state the host
-d: used to state the database name
-U:used to state the database user
psql -U user -h host “dbname=db sslmode=require”Use SSL mode for the connection-h: used to state the host
-U:used to state the database user
\c dbnameSwitch connection to a new database
\lList available databases
\dtList available tables
\d table_nameDescribe a table such as a column, type, modifiers of columns, etc.
\dnList all schemas of the currently connected database
\dfList available functions in the current database
\dvList available views in the current database
\duList all users and their assign roles
SELECT version();Retrieve the current version of PostgreSQL server
\gExexute the last command again
\sDisplay command history
\s filenameSave the command history to a file
\i filenameExecute psql commands from a file
\?Know all available psql commands
\hGet helpEg:to get detailed information on ALTER TABLE statement use the \h ALTER TABLE
\eEdit command in your own editor
\aSwitch from aligned to non-aligned column output
\HSwitch the output to HTML format
\qExit psql shell