暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss 每日一练第8天

原创 酷酷咖啡 2022-12-02
125

openGauss 每日一练第8天

准备

  • 切换用户,连接数据库

    su - omm gsql -r

1.创建表空间newtbs1、 ds_location1,查看表空间

-- 创建表空间 newtbs1 ds_location1 CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/newtbs1'; CREATE TABLESPACE ds_location1 RELATIVE LOCATION 'tablespace/ds_location1'; -- 查看当前有哪些表空间 omm=# \db List of tablespaces Name | Owner | Location --------------+-------+------------------------- ds_location1 | omm | tablespace/ds_location1 newtbs1 | omm | tablespace/newtbs1 pg_default | omm | pg_global | omm | (4 rows)

2.创建一个数据库newdb1,默认表空间为newtbs1

omm=# CREATE DATABASE newdb1 WITH TABLESPACE =newtbs1 ; CREATE DATABASE omm=# \l+ List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description -----------+-------+----------+---------+-------+-------------------+-------+------------+-------------------------------------------- newdb1 | omm | UTF8 | C | C | | 12 MB | newtbs1 | omm | omm | UTF8 | C | C | | 12 MB | pg_default | postgres | omm | UTF8 | C | C | | 12 MB | pg_default | default administrative connection database template0 | omm | UTF8 | C | C | =c/omm +| 12 MB | pg_default | default template for new databases | | | | | omm=CTc/omm | | | template1 | omm | UTF8 | C | C | =c/omm +| 12 MB | pg_default | unmodifiable empty database | | | | | omm=CTc/omm | | | (5 rows)

3.创建用户user5,并授予SYSADMIN权限,访问数据库newdb1,在表空间ds_location1上,创建一个表newt1(表结构自定义)

omm=# drop user user5 ; DROP ROLE omm=# CREATE USER user5 IDENTIFIED BY 'abcd@1234'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# alter user user5 sysadmin ; ALTER ROLE omm=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------------------------------------------------------------+----------- gaussdb | Sysadmin | {} omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} user5 | Sysadmin | {} -- 使用user5 连接到newdb1 库 omm=# \c newdb1 user5; Password for user user5: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "newdb1" as user "user5". -- 在表空间ds_location1上创建 表newt1 newdb1=> create table newt1(textcol char(30)) tablespace ds_location1 ; CREATE TABLE newdb1=> \dt+ List of relations Schema | Name | Type | Owner | Size | Storage | Description --------+-------+-------+-------+---------+----------------------------------+------------- public | newt1 | table | user5 | 0 bytes | {orientation=row,compression=no} | (1 row)

4.查看表所在的表空间

newdb1=> select * from pg_tables where tablename = 'newt1'; musicdb schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_ddl_time ------------+-----------+------------+--------------+------------+----------+-------------+--------------+-------------------------------+------------------------------- public | newt1 | user5 | ds_location1 | f | f | f | user5 | 2022-12-02 09:35:33.950938+08 | 2022-12-02 09:35:33.950938+08 (1 row)

5.查看表空间newtbs1、 ds_location1上的对象

-- 查看ds_location1 上的对象 newdb1=> select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner from pg_class a, pg_tablespace tb where a.relkind in ('r', 'i') and a.reltablespace=tb.oid and tb.spcname='ds_location1' order by a.relpages desc; musicdb relname | relkind | relpages | pg_size_pretty | reltablespace | relowner ---------+---------+----------+----------------+---------------+---------- newt1 | r | 0 | 0 bytes | 16392 | 16398 (1 row) -- 查看 newtbs1 上的对象 newdb1=> select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner from pg_class a, pg_tablespace tb where a.relkind in ('r', 'i') and a.reltablespace=tb.oid and tb.spcname='newtbs1' order by a.relpages desc; musicdb relname | relkind | relpages | pg_size_pretty | reltablespace | relowner ---------+---------+----------+----------------+---------------+---------- (0 rows)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论