加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

构建PostgreSQL工作环境

发布时间:2020-12-13 17:30:35 所属栏目:百科 来源:网络整理
导读:构建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
构建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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读