A summary of the initial use of PostgreSQL

Source: Internet
Author: User
Tags psql

First, installation

When the PostgreSQL installation is complete, a user named Postgres and a database named Postgres are generated by default. You can use your own Psql.exe tool to log in. The Help information is as follows

The commands to connect to the local PostgreSQL instance are as follows:

Where:-u Specifies the user name to connect to,-d specifies the name of the database to connect to,-h specifies the IP address of the machine where PostgreSQL is located, and-p specifies the port number of the machine where PostgreSQL is located

From the PostgreSQL documentation, you know that a instance can manage multiple databases, which can form a cluster (cluster).

Ii. adding new users and new databases

Create the database user Dbuser and set the password: Create user dbuser with PASSWORD ' dbuser ';

Create the user database (here named DB1) and specify the owner for Dbuser:CREATE database db1 owner Dbuser;

All permissions to the DB1 database are assigned to Dbuser, otherwise dbuser can only log in to the console without any database operation permissions:GRANT all privileges on database db1 to Dbuser;

Use the \q command to exit the console (you can also press Ctrl+d directly):\q

Third, create the table

Under a database, if you create a table without schema, a schema named public is created by default, and the table is placed under that schema. PostgreSQL manages databases in the form of library->schema (schemas), database objects (such as tables, views, functions).

Creating a table: Create TABLE T1 (id bigint);

The default is placed under the schema named Public, as shown below

Four, console commands

1 \c This command can be used to switch the logged-on user and the logged-on database without exiting the PSQL environment. However, not too easy to use, switch users and switch the database can only do one operation at a time, cannot do at the same time. The Help information for the command is as follows

Simple to use:

To view the current connection information:

Switch to User Dbuser

Switch to Database DB1

2 In addition to the above usage, the \c command can also be used to view the current connection information

3 \conninfo: Lists the current database and connection information.

4 \DN View all schemas under a database

5 \dt View information for a table below a database

The default view is the information for the following table of the schema named public, such as

If you want to view other schemas, such as view information for the table below the schema named DPI, the command is as follows

V. Modify the PostgreSQL configuration to allow remote connections

Modify C:\Program files\postgresql\9.1\data\pg_hba.conf File

Also make sure that the configuration for the listener in the C:\Program files\postgresql\9.1\data\postgresql.conf

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.