PostgreSQL Operation-psql Basic commands

Source: Internet
Author: User
Tags mysql show databases postgresql psql

I. Description of the order
Psql is the interactive terminal of PostgreSQL, which is equivalent to Sqlplus in Oracle. When the command is executed to connect to the database, the default user and database are Postgres

second, the command parameters
-C command: Specifies that psql executes an SQL command (enclosed in double quotation marks) and exits after execution.
-D database name: the names of the databases to be connected.
-F file Name: Use the data in the file as the input source of the command, after processing the file, Psql end and exit.
-H hostname: Declares the host name of the server that is running
-L: Lists all available databases, and then exits.
-l file name: Outputs all query records to a file in addition to the normal output source.
-o FileName: Redirects all queries to the file.
-P Port: Specifies the listening port of the PostgreSQL server.
-Q: Let Psql silently perform the task that is being handled. By default, Psql prints a welcome and a lot of other information.
-u username: establishes a connection to the database in place of the default user for the specified user.
-V: Output version information, and then exit

three, built-in commands
#\c database name: Switch database, equivalent to the use of MySQL dbname
#\q: Exit Psql
#\l: List the database, equivalent to the MySQL show databases
#\dt: List of tables, equivalent to show tables
#\d table name: View table structure, equivalent to DESC tblname
#\conninfo: Displays information about the current connection
#\timing: Toggle Command Timer switch (currently off)
#\! [command]: Execute commands in the shell or open a shell
#\a: Toggle between non-aligned and Aligned modes
#\c [title]: Set table header or cancel
#\f [delimiter]: Displays or sets the field separator symbol for non-aligned mode
#\h: Toggle HTML Output Mode (currently off)
#\o [file name]: Write all query results to the file or | pipe "pipe"
#\db [Database name]: list tablespace
#\du [Database name]: List roles
#\p: Displays the contents of the query buffer, that is, print the previous SQL command
#\cd [catalogue]: Changing the current working directory
#\i file name: Execute command from File
#\echo [string]: Writes a string to standard output
#\w [filename]: Output the previous SQL command to the specified file or pipe "pipe"
#\g [filename]: Output The result of the previous SQL command to the specified file or pipe "pipe"

#\o [filename]: Outputs all subsequent query results to the specified file or pipe "pipe" until the next individual #\o is encountered

#\unset variable name: empty (delete) internal variable

#\encoding [encoded name]: Displays or sets the client code

#\password [user name]: Securely change passwords for users
#\prompt [variable name]: Prompt user to set internal variables
#\set [variable name [variable value]]: Set internal, if no parameters list all variables

PostgreSQL Operation-psql Basic commands

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.