Common commands for working with PostgreSQL under Linux

Source: Internet
Author: User
Tags function definition postgresql

General:

\copyright display the use and release license terms for PostgreSQL
\g [file] or; Execute the query (and write the results to a file or | pipeline)
\h [name] SQL command syntax description, with * Show all commands syntax description
\q Exit Psql

Query buffer
\e [file] [line] Edit query buffer (or file) using external editor
\EF [FUNCNAME [line]] Edit function definition using external editor
\p Display the contents of the query buffer
\ r Reset (clear) the query buffer
\s [file] to display history or to save history in a file
The \w file writes the contents of the query buffer to the file

Input/Output
\copy ... Execute SQL COPY to send the data stream to the client host
\echo [string] writes a string to standard output
\i files to execute commands from a file
\o [file] writes all query results to a file or | pipeline
\qecho [string] writes a string to the query output stream (reference \o)

Informational
(option: S = Display System object, + = rest details)
\d[s+] Lists tables, views, and sequences
\d[s+] Name Description table, view, sequence, or index
\da[s] [mode] lists aggregate functions
\db[+] [mode] List table space
\dc[s] [mode] lists character encoding conversions
\DC [mode] list type casts
\dd[s] [mode] Show comments for an object
\DDP [mode] List default permissions
\dd[s] [mode] lists common domains
\det[+] [PATTERN] Lists reference tables
\des[+] [mode] lists external servers
\deu[+] [mode] list user mappings
\dew[+] [mode] lists external data wrappers
\df[antw][s+] [mode] list [include aggregate/general/trigger/window] function
\df[+] [mode] List text search configuration
\dfd[+] [mode] Lists text search dictionaries
\dfp[+] [mode] List text Search parser
\dft[+] [mode] List text Search template
\dg[+] [PATTERN] Lists roles
\di[s+] [mode] List index
\DL lists large objects with the same functionality as \lo_list
\dl[s+] [PATTERN] Lists all process languages
\dn[s+] [pattern] Lists all modes
\do[s] [schema] list operators
\do[s+] [PATTERN] Lists all proofing rules
\DP [mode] lists access permissions for tables, views, and sequences
\drds [Mode 1 [Mode 2]] lists the role settings for each database
\ds[s+] [mode] list sequence
\dt[s+] [mode] List table
\dt[s+] [mode] list data types
\du[+] [PATTERN] Lists roles
\dv[s+] [mode] List view
\de[s+] [PATTERN] Lists reference tables
\dx[+] [PATTERN] lists extensions
\l[+] List all databases
\sf[+] FUNCNAME display function definition
\z [mode] and \DP function the same

Formatting
\a switching between non-aligned and Aligned modes
\c [string] Sets the title of the table, or if no caption is canceled
\f [string] Displays or sets the field delimiter for non-aligned mode query output
\h Toggle HTML Output mode (currently off)
\pset name [value] setting table Output Options
(Name: = {format|border|expanded|fieldsep|footer|null|
Recordsep|tuples_only|title|tableattr|pager})
\ t [on | off] displays only records (currently closed)
\ t [string] set HTML < table > tag properties, or Cancel if not set
\x [on | off] Toggle Extended output mode (currently off)

Connection
\c[onnect] {[dbname|-user|-host|-port|-] | conninfo}
Connect to New database (currently "Postgres")
\encoding [encoded name] Displays or sets the client code
\password [USERNAME] Safely change the password for the user
\conninfo displaying information about the current connection

Operating system
\CD [Catalogue] Change the current working directory
\timing [on | off] Toggle Command timing switch (currently off)
\! [command] Executes a command in the shell or launches an interactive shell

Variable
\prompt [text] name prompts the user to set internal variables
\set [name [value]] SET internal variable, if no argument lists all variables
\unset name Empty (delete) internal variable

Large Object
\lo_export loboid File
\lo_import file [Note]
\lo_list
\lo_unlink loboid Large Object operation

Common commands for working with PostgreSQL under Linux

Related Article

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.