构建PostgreSQL工作环境

前端之家收集整理的这篇文章主要介绍了构建PostgreSQL工作环境前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
构建Postgresql工作环境
jieshiyeskey@gmail.com

1.创建用户并附权限及设置密码
postgres=# create role markgeng password 'Jieshi11gR2' login superuser createdb createrole;
CREATE ROLE

postgres=# \dg+
List of roles
Role name | Attributes | Member of | Description
-----------+------------------------------------------------+-----------+-------------
markgeng | Superuser,Create role,Create DB | {} |
postgres | Superuser,Create DB,Replication | {} |

2.创建表空间
postgres=# create tablespace tsp_users owner markgeng location '/Library/Postgresql/9.2/data/tsp_users';
postgres=# \db+
List of tablespaces
Name | Owner| Location | Access privileges | Description
------------+----------+----------------------------------------+-------------------+-------------
pg_default | postgres | | |
pg_global | postgres | | |
tsp_users | markgeng | /Library/Postgresql/9.2/data/tsp_users | |
3.创建数据库
postgres=# create database orcl owner=markgeng tablespace=tsp_users;
CREATE DATABASE
postgres=# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
---------------+----------+----------+---------+-------+-----------------------+---------+------------+--------------------------------------------
home_markgeng | postgres | UTF8 | C | C | | 6233 kB | pg_default |
orcl | markgeng | UTF8 | C | C | | 6293 kB | tsp_users|
postgres | postgres | UTF8| C | C | | 6797 kB | pg_default | default administrative connection database
template0 | postgres | UTF8| C | C | =c/postgres +| 6177 kB | pg_default | unmodifiable empty database
| | | | | postgres=CTc/postgres | | |
template1 | postgres | UTF8| C | C | =c/postgres +| 6185 kB | pg_default | default template for new databases
| | | | | postgres=CTc/postgres |
4.创建schema
postgres=# \c orcl markgeng
Password for user markgeng:
You are now connected to database "orcl" as user "markgeng".
orcl=# create schema authorization markgeng;
CREATE SCHEMA
orcl=# \dn+
List of schemas
Name | Owner | Access privileges | Description
----------+----------+----------------------+------------------------
markgeng | markgeng | |
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(2 rows)
5.创建表
orcl=# create table t1(id int);
CREATE TABLE
orcl=# \dt+
List of relations
Schema | Name | Type |Owner| Size | Description
----------+------+-------+----------+---------+-------------
markgeng | t1 | table | markgeng | 0 bytes |
(1 row)
orcl=# \d t1
Table "markgeng.t1"
Column | Type | Modifiers
--------+---------+-----------
id | integer |


orcl=# insert into t1 values(1);
INSERT 0 1
orcl=# select * from t1;
id
----
1
(1 row)
原文链接:https://www.f2er.com/postgresql/195810.html

猜你在找的Postgre SQL相关文章