1.创建表空间enmtbs和数据库musicdb
omm=# create tablespace enmtbs relative location 'tablespace/enmtbs';
CREATE TABLESPACE
omm=# create database musicdb tablespace enmtbs ;
CREATE DATABASE
复制
2.查看数据库集簇中有哪些数据库
omm=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+---------+-------+-------------------
musicdb | omm | UTF8 | C | C |
omm | omm | UTF8 | C | C |
postgres | omm | UTF8 | C | C |
template0 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
(5 rows)
omm=# select datname from pg_database ;
datname
-----------
template1
omm
template0
musicdb
postgres
(5 rows)
复制
3.查看数据库默认的表空间信息
omm=# select spcname from pg_tablespace where oid = ( select dattablespace from pg_database where datname = 'musicdb' );
spcname
---------
enmtbs
(1 row)
复制
4.查看数据库下有哪些模式
omm=# \dn+
List of schemas
Name | Owner | Access privileges | Description | WithBlockChain
-----------------+-------+-------------------+----------------------------------+----------------
blockchain | omm | | blockchain schema | f
cstore | omm | | reserved schema for DELTA tables | f
db4ai | omm | omm=UC/omm +| db4ai schema | f
| | =U/omm | |
dbe_perf | omm | | dbe_perf schema | f
dbe_pldebugger | omm | omm=UC/omm +| dbe_pldebugger schema | f
| | =U/omm | |
dbe_pldeveloper | omm | omm=UC/omm +| dbe_pldeveloper schema | f
| | =U/omm | |
pkg_service | omm | | pkg_service schema | f
public | omm | omm=UC/omm +| standard public schema | f
| | =U/omm | |
snapshot | omm | | snapshot schema | f
sqladvisor | omm | omm=UC/omm +| sqladvisor schema | f
| | =U/omm | |
(10 rows)
omm=# \dn
List of schemas
Name | Owner
-----------------+-------
blockchain | omm
cstore | omm
db4ai | omm
dbe_perf | omm
dbe_pldebugger | omm
dbe_pldeveloper | omm
pkg_service | omm
public | omm
snapshot | omm
sqladvisor | omm
(10 rows)
复制
5.查询当前连接的数据库下有哪些表:
omm=# with my_tables(table_catalog, table_schema, table_name, table_type) as
omm-# ( select table_catalog, table_schema, table_name, table_type
omm(# from information_schema.tables
omm(# where table_schema not in ('pg_catalog', 'information_schema','dbe_perf')
omm(# )
omm-#
omm-# select * from my_tables;
omm | db4ai | snapshot | BASE TABLE
omm | dbe_pldeveloper | gs_errors | BASE TABLE
omm | dbe_pldeveloper | gs_source | BASE TABLE
复制
6.更改数据库默认的表空间
omm=# create tablespace new_tbs relative location 'tablespace/new_tbs';
CREATE TABLESPACE
omm=# alter database musicdb set tablespace new_tbs ;
ALTER DATABASE
## 检查数据库默认空间是否发生更改
omm=# select spcname from pg_tablespace where oid = ( select dattablespace from pg_database where datname = 'musicdb' );
new_tbs
复制
7.重新命名数据库
omm=# alter database musicdb rename to musicdb_new;
ALTER DATABASE
omm=# \l
musicdb_new | omm | UTF8 | C | C |
omm | omm | UTF8 | C | C |
postgres | omm | UTF8 | C | C |
template0 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
复制
8.修改数据库的默认用户
omm=# create user user1 sysadmin identified by 'abcd@123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# alter database musicdb_new owner to user1 ;
ALTER DATABASE
omm=# \l
musicdb_new | user1 | UTF8 | C | C |
omm | omm | UTF8 | C | C |
postgres | omm | UTF8 | C | C |
template0 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
复制
9.删除数据库
omm=# drop database musicdb_new ;
DROP DATABASE
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论

2年前

评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
484次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
304次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
198次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
161次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
155次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
137次阅读
2025-04-30 16:39:58
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
91次阅读
2025-04-18 10:49:53
Postgresql数据库单个Page最多存储多少行数据
maozicb
83次阅读
2025-04-23 16:02:19
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
57次阅读
2025-04-17 10:41:47
RISC-V 首迎 openGauss 7.0.0-RC1 全量版适配!数据库核心功能完整落地开源架构
openGauss
47次阅读
2025-04-16 10:33:59