构建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 role, 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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值