Psql command Line Quick reference

Source: Internet
Author: User
Tags psql

The command syntax for Psql is:

psql [Options] [dbname [username]]

The Psql command-line options and their meanings are listed in table 1-1. Use the following command to see a complete list of options for Psql:

$ psql--help

Table 1-1 psql command-line Options

Options

Significance

-A

Respond to all inputs from the script

-A

The alignment mode of the table data output is canceled; The function is the same as "-P format=unaligned"

-C < query >

Just run a simple query (or internal command) and exit

-D < database name >

Specify the name of the database to which you are connected (default is $pgdatabase or the currently logged in user name)

-E

echo the query sent to the server

-E

Display query statements generated by internal commands

-F < file name >

Executes a query in a file, and then exits

-F < string >

Specifies the column data display delimiter (default = "|" ) with the same function as "-P fieldsep=< string >"

-H < host >

Specify the database server host (default is $pghost or localhost)

-H

Set table output mode to HTML; function same as "-P format=html"

--help

Show Help, then exit

-L

List the databases that exist, and then exit

-N

Disable ReadLine; block line edits

-o < file name >

Sends the output of the query to the file name specified files (send the output to a filter using the "| pipe" form)

-P < ports >

Specifies the port of the database server (default is $pgport or the default for compile-time settings, typically 4321)

-P Var[=arg]

Set print options Var to arg (View \pset command)

-Q

Run silently (without any messages, only the output of the query)

-R < String >

Sets the delimiter for the record (the default is line wrapping); The function is the same as "-P recordsep=< string >"

-S

Set to Single step mode (confirmation required for each query)

-S

Set single-line mode (the end of each row considers the query input to end, not a semicolon)

-T

Print lines only; features same as "-P tuples_only"

-T < text >

Set HTML table markup Options (Width,border, etc.); functions same as "-P tableattr=<text>"

-u < user name >

Specify the database user (default is $pguser or the currently logged on user name)

-V Name=value

Set the value of the PSQL variable name to

--version

Display version information and then exit, or use "-V"

-W

Force prompt for password (automatically executed if password is required)

-X

Turn on the extension table output, the function is the same as "-P expanded"

-X

Do not read startup files (~/.PSQLRC)

Psql Internal Command Quick reference

Internal commands supported by Psql are listed in table 1-2. In many versions of PostgreSQL, these commands have some more readable long modes (for example, \list is the \l Long mode command).

Table 1-1 psql command-line Options

Command

Significance

\?

List all Psql internal commands

\a

Toggles between table alignment and non-aligned mode.

\c[onnect] [dbname|-[user]]

Connect to the new database, and use "-" as the database name to connect to the default database. Database can be connected by user identity

\c < title >

Sets the title of the output table; The function is the same as "\pset title"

\CD < catalogue >

Change the working directory

\copy ...

Perform SQL COPY with data stream to the client machine.

\copyright

Display the use and release terms of PostgreSQL

\d < table >

Description table (or view, index, sequence builder)

\D{T|I|S|V}

List table/index/Sequence builder/view

\d{p| S|L}

List access Permissions/system tables/Large Objects

\da

List aggregates (aggregates)

\db

List table Spaces

\dc

List conversions

\dc

List casts

\dd [Object]

List notes for a table, type, function, or action

\dd

List domains

\df

List functions (custom functions??? ) need to verify

\dg

List groups

\dl

List large objects; You can also write "\lo_list"

\dn

List patterns

\do

List operators

\dt

List data types

\du

List users

\e [File]

Edit the current query buffer or file specified by using the external editor

\echo < text >

Print text to standard output

\encoding < coding >

Set up client-side encoding

\f < separators >

To modify the delimiter for an output field

\g [file name]

Send the results of the query to the backend (result output to file or | pipeline)

\h [command]

Displays help for SQL commands; * Indicates a detailed description of all commands

\h

Turn on HTML mode

\i < file name >

Read and execute a query from a file

\l

List all the databases

\lo_export,\lo_import,

\lo_list,\lo_unlink

Performing large object operations

\o [file name]

Send all query results to a file or | pipeline

\p

Displays the contents of the current query buffer

\pset < options >

To set the table output options, you can set the options to one of the following: Format,border,expanded,fieldsep,footer,null,recordsep,tuples_only,title,tableattr, Pager

\q

Exit Psql

\qecho < text >

Writing text to the query output stream (refer to the \o command)

\ r

Reset (empty) the query buffer

\s [file name]

Print history or save history in a file

\set < variables > < values >

Set internal variables

\ t

Show rows only (toggle between modes)

\ t < tags >

Set the markup for the HTML table; the same function as "\pset tableattr"

\timing

Displays the time when the command was executed (toggle between the display and not showing the two modes)

\z

List access permissions for tables, views, and sequence generators

\! Command

Switch to the shell or execute a shell command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.