PostgreSQL SQL statements

Source: Internet
Author: User
Tags psql

First, use superuser to connect to the database

By default, the Super User is set to ipvs.

The connection script command is Psql. This is in the bin directory of the installation directory.

/Bin $ Psql

Postgres -#

Create a user. Create a database under user management

Postgres-# create role John login createrole createdb password 'john'; // grant permissions to John: logon permission, create user permission, and create database permission. And grant the user the permission to use the password to log on.

 

 

Create USER commands

The create USER command is equivalent to the create role command,

Note that the login attribute is already set by default when you use create user. However, role is not the default one.

 

Create a user. Yes, this user has the right to create a database.

UseCreate roleNameCreatedb

Generally, other permissions are assigned to role. For example, one role can be used to create another role.

UseCreate role
NameCreaterole

 

Query USER commands

Check if the created user is successfully created. Run the S-# \ du command.

 

After creating a user, create a database managed by the user

Postgres-# create database mss owner John;

Show all databases

Postgres-# \ L

 

To log out of the current user, run the \ q command.

 

How can I create and use a user and log on to a database under the user management.

 

 

 

 

 

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.