psql command (PostgreSQL interactive terminal) ¶
Description ¶
psql is PostgreSQL’s standard command line client application and is a standard part of most PostgreSQL installations.
It can be used both for terminal-based text-only interaction with a PostgreSQL server, and also for facilitating automated script-based tasks.
psql has been a core part of the PostgreSQL project since its inception and is usually present in PostgreSQL installations.
It can also be installed as a standalone application, and many operating systems/distributions provide separate packages for the PostgreSQL server itself and for the core client applications. psql has of course been ported to Windows, but with certain limitations, particularly readline support.
psql can connect to a PostgreSQL instance on the same server via a Unix domain socket if available, or connect TCP/IP to PostgreSQL running either on the local or a remote server.
psql -U postgres -d postgres
psql postgresql://<user>:<password>@<host>:<port>/<database_name>
psql postgresql://intranet:<password>@database-host:5432/db_intranet
- psql help
-
man
psql
+ psql
meta-commands
+
shell-like
features
-
psql PostgreSQL 15.1 Documentation
- Specifies that psql is to execute the given command string,command
- Switches to CSV (Comma-Separated Values) output mode
- Read commands from the file filename
- Switches to HTML output mode
- Put all query output into file filename
- Specifies that psql should do its work quietly
- the user is prompted before each command is sent to the server
- Connect to the database as the user username instead of the default
- single transaction
- Outputs information about the current database connection
- Shows the copyright and distribution terms of PostgreSQL
- Lists server configuration parameters and their values
- Lists database roles
- Lists schemas (namespaces)
- Lists tables, views and sequences with their associated access privileges
- Lists partitioned relations
- Lists defined configuration settings
- Lists database roles
-
psql PostgreSQL 15.1 Documentation
- psql commands examples