构建PostgreSQL工作环境

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

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

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

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


orcl=# insert into t1 values(1);
INSERT 0 1
orcl=# select * from t1;
@H_301_40@id @H_301_40@
----
@H_301_40@1
(1 row)

猜你在找的Postgre SQL相关文章