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