Get the App
SLTechnology News&Howtos  ›  Database  › 

Basic operation of PostgreSQL

Shulou Source: shulou.com Published: 2022-06-01 12:17:26 09月10日 Update

1. Create a user

Postgres=# create user test password 'test'

CREATE ROLE

Note: there is no distinction between user and role in PostgreSQL. "CREATE USER" is an alias for "CREATE ROLE". The two commands are almost identical, except that the user created by the "CREATE USER" command has the LOGIN attribute by default, while the user created by the "CREATE ROLE" command does not have the LOGIN attribute by default.

two。 Create a tablespace

Postgres=# create tablespace tbs owner test location'd:\ postgresql\ data\ tbs'

CREATE TABLESPACE

3. Create a database

Postgres=# create database mydb with owner = test encoding = 'UTF8' tablespace =' tbs'

CREATE DATABASE

4. Authorize the user

Postgres=# grant all on database mydb to test with grant option

GRANT

Postgres=# grant all on tablespace tbs to test

GRANT

5. Connect to the database with the newly created user

D:\ PostgreSQL\ bin > psql-U test mydb

Psql (12.0)

Enter "help" for help.

Mydb= >

Tags: User command attribute data database same two information alias concept space role help input basic operation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux MySQL Docker Huawei