PostgreSQL Getting Started command

Source: Internet
Author: User
Tags psql

1 Command line logon database

There are two ways to execute the psql command directly under the system shell, instead of entering the PSQL environment before connecting to the database. Examples are given below:

(1) Direct login

Execute command:psql-h 192.168.1.120-u username-d dbname , where username is the database user name, dbname is the name of the database to be connected, prompt to enter the password after execution is as follows: Password for User username: (Enter password here)

Enter the PSQL environment after entering the password.

(2) Switch database

Sometimes it is necessary to switch the database in Psql environment, at this time execute the following PSQL command:

\c dbname username ServerIP Port

In addition to the database name, other parameters are optional, if you use the default value can be used-as a placeholder

After executing this command, you are also prompted for a password.

2 View Help

Psql provides a good online help document, the total Entry command is the helper, enter this command to see

vsb9=# help is using Psql, the command-line interface to PostgreSQL. Type: \copyright For distribution Terms \h to help with SQL commands \? For help with Psql commands \g or terminate with semicolon to execute query \q to quit

As you can see, the Help for standard SQL commands is separate from the Help for Psql-specific commands. Enter \ To view the Psql command, you will find that all Psql commands start with \, which is easy to distinguish from standard SQL commands.

3 Common commands

For ease of memory, the corresponding MySQL command is also listed here.

(1) List all the databases

Mysql:show databases

Psql: \l or \list

(2) Switch database

Mysql:use dbname

Psql: \c dbname

(3) List the data tables under the current database

Mysql:show tables

Psql: \d

(4) List all fields of the specified table

Mysql:show columns from table name

Psql: \d TableName

(5) View the basic situation of the specified table

Mysql:describe TableName

Psql: \d+ tablename

(6) Sign out

Mysql:quit or \q

Psql:\q

Reference: PostgreSQL 8.1 Chinese documents

PostgreSQL Getting Started command

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.