一、学习目标
本次课是该次实训的第八节课,本节课的重点仍然是学习openGauss表空间和数据库之间的关系,对于openGauss表空间在日常运维方面的一些注意点可参照我写的另一篇博文(https://www.modb.pro/db/570009 openGauss体系结构之表空间知识点总结(含常用语句亲测验证)) 这篇文章,里面有些细节要特别注意。
要通过实操来理解如设置了默认表空间,会对新创建的表有什么影响,并要学会如何设置默认表空间,如何建表设置在不同表空间上,以及如何查看表空间上的对象等。
二、测试练习
2.1 创建并查看表空间
root@modb:~# su - omm omm@modb:~$ gsql -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+---------+-------+------------------- 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 (4 rows) -- 创建表空间 newtbs1 omm=# CREATE TABLESPACE newtbs1 RELATIVE LOCATION 'tablespace/tbs_newtbs1'; CREATE TABLESPACE -- 创建表空间 ds_location1 omm=# CREATE TABLESPACE ds_location1 RELATIVE LOCATION 'tablespace/tbs_ds_location1'; CREATE TABLESPACE omm=# \db pg_default | omm | pg_global | omm | (4 rows) omm=# List of tablespaces Name | Owner | Location --------------+-------+----------------------------- ds_location1 | omm | tablespace/tbs_ds_location1 newtbs1 | omm | tablespace/tbs_newtbs1
复制
以上两句创建表空间的语句其实是在$PGDATA/pg_location/tablespace目录下创建了两个名为tbs_newtbs1和tbs_ds_location1的目录,openGauss创建表空间其实就是创建一个目录,但要特别注意的是表空间名称和表空间对应的目录并不是一定要同名,在这个目录下是一些和表空间相关的数据文件。
omm@modb:~$ gsql -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm=# \! echo omm=# \! echo $PGDATA /var/lib/opengauss/data omm=# \! ls -ld $PGDATA/pg_location/tablespace drwx------ 4 omm omm 4096 Dec 1 14:15 /var/lib/opengauss/data/pg_location/tablespace omm=# \! ls -lrt $PGDATA/pg_location/tablespace total 8 drwx------ 3 omm omm 4096 Dec 1 14:15 tbs_newtbs1 drwx------ 3 omm omm 4096 Dec 1 14:15 tbs_ds_location1 omm=# \! ls -lrt $PGDATA/pg_location/tablespace/tbs_newtbs1 total 4 drwx------ 3 omm omm 4096 Dec 1 14:15 PG_9.2_201611171_gaussdb omm=# \! ls -lrt $PGDATA/pg_location/tablespace/tbs_ds_location1 total 4 drwx------ 3 omm omm 4096 Dec 1 14:15 PG_9.2_201611171_gaussdb
复制
2.2 创建数据库并指定默认表空间
-- 判断newdb1数据库是否存在,存在则删除 omm=# drop DATABASE IF EXISTS newdb1; NOTICE: database "newdb1" does not exist, skipping DROP DATABASE -- 创建数据库newdb1并指定newtbs1为默认表空间 omm=# CREATE DATABASE newdb1 WITH TABLESPACE = newtbs1; CREATE DATABASE -- 查看数据库集簇里各数据库所对应的默认表空间 omm=# select datname,dattablespace,spcname from pg_database d, pg_tablespace t where d.dattablespace=t.oid; datname | dattablespace | spcname -----------+---------------+------------ template1 | 1663 | pg_default omm | 1663 | pg_default newdb1 | 16389 | newtbs1 template0 | 1663 | pg_default postgres | 1663 | pg_default (5 rows)
复制
2.3 创建用户并授权
-- 创建用户user1并指定密码 omm=# CREATE USER user1 IDENTIFIED BY 'kunpeng@1234'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE -- 为用user1授予SYSADMIN权限 omm=# ALTER USER user1 SYSADMIN; ALTER ROLE 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 user1 | user1 (11 rows) -- 查看用户都哪些权限 omm=# \dg gaussdb | Sysadmin | {} omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} user1 | Sysadmin | {} omm=# List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------------------------------------------------------------+-----------
复制
2.4 在不同表空间上创建表
-- 使用user1 切换数据库到 newdb1 omm=# \c newdb1 user1 Password for user user1: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "newdb1" as user "user1". -- 创建表并指定表空间 newdb1=> create table newtb1 (name char(10),position char(10)) tablespace ds_location1; CREATE TABLE newdb1=> insert into newtb1 values ('shanglei','DBA'); INSERT 0 1 newdb1=> select * from newtb1; name | position ------------+------------ shanglei | DBA (1 row) -- 在默认表空间上创建表 newdb1=> create table newtb2 (name char(10),city char(10)); newdb1=> CREATE TABLE newdb1=> insert into newtb2 values ('shanglei','nanjing'); INSERT 0 1 newdb1=> select * from newtb2; name | city ------------+------------ shanglei | nanjing (1 row)
复制
2.5 查看表所在表空间
newdb1=> select * from pg_tables where tablename = 'newtb1'; schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_ddl_time ------------+-----------+------------+--------------+------------+----------+-------------+--------------+-------------------------------+------------------------------ - public | newtb1 | user1 | ds_location1 | f | f | f | user1 | 2022-12-01 14:45:33.951091+08 | 2022-12-01 14:45:33.951091+08 (1 row) newdb1=> select * from pg_tables where tablename = 'newtb2'; schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_ddl_time ------------+-----------+------------+------------+------------+----------+-------------+--------------+-------------------------------+------------------------------- public | newtb2 | user1 | | f | f | f | user1 | 2022-12-01 14:46:11.565852+08 | 2022-12-01 14:46:11.565852+08 (1 row)
复制
从以上执行结果可以看到当建表时指定非默认数据库表空间时,从pg_tables里会查看到该表所对应的表空间。
当表创建在默认表空间时,通过pg_tables查询未显示到默认表空间。
2.6 查看表空间对象
-- 查看默认表空间上的对象 newdb1=> select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner newdb1-> from pg_class a newdb1-> where a.relkind in ('r', 'i') newdb1-> and reltablespace='0' newdb1-> order by a.relpages desc; relname | relkind | relpages | pg_size_pretty | reltablespace | relowner ------------------------------------------------+---------+----------+----------------+---------------+---------- pg_attribute | r | 184 | 1472 kB | 0 | 10 pg_proc | r | 140 | 1120 kB | 0 | 10 pg_depend | r | 59 | 472 kB | 0 | 10 pg_class | r | 52 | 416 kB | 0 | 10 pg_attribute_relid_attnam_index | i | 44 | 352 kB | 0 | 10 pg_proc_proname_all_args_nsp_index | i | 41 | 328 kB | 0 | 10 pg_proc_proname_args_nsp_new_index | i | 39 | 312 kB | 0 | 10 pg_proc_proname_args_nsp_index | i | 39 | 312 kB | 0 | 10 pg_rewrite | r | 37 | 296 kB | 0 | 10 pg_depend_depender_index | i | 34 | 272 kB | 0 | 10 pg_depend_reference_index | i | 34 | 272 kB | 0 | 10 pg_description | r | 31 | 248 kB | 0 | 10 pg_attribute_relid_attnum_index | i | 30 | 240 kB | 0 | 10 pg_type | r | 20 | 160 kB | 0 | 10 pg_statistic | r | 19 | 152 kB | 0 | 10 pg_operator | r | 15 | 120 kB | 0 | 10 pg_class_relname_nsp_index | i | 14 | 112 kB | 0 | 10 pg_proc_oid_index | i | 13 | 104 kB | 0 | 10 pg_amop | r | 9 | 72 kB | 0 | 10 --More-- pg_description_o_c_o_index | i | 16 | 128 kB | 0 | 10 pg_class_tblspc_relfilenode_index | i | 10 | 80 kB | 0 | 10 pg_class_oid_index | i | 7 | 56 kB | 0 | 10 sql_features | r | 7 | 56 kB | 0 | 10 pg_type_typname_nsp_index | i | 7 | 56 kB | 0 | 10 pg_index | r | 7 | 56 kB | 0 | 10 pg_amop_fam_strat_index | i | 6 | 48 kB | 0 | 10 pg_operator_oprname_l_r_n_index | i | 6 | 48 kB | 0 | 10 pg_amop_opr_fam_index | i | 6 | 48 kB | 0 | 10 pg_amop_oid_index | i | 5 | 40 kB | 0 | 10 pg_operator_oid_index | i | 5 | 40 kB | 0 | 10 pg_type_oid_index | i | 5 | 40 kB | 0 | 10 pg_opclass_am_name_nsp_index | i | 4 | 32 kB | 0 | 10 pg_rewrite_rel_rulename_index | i | 4 | 32 kB | 0 | 10 pg_amproc_fam_proc_index | i | 4 | 32 kB | 0 | 10 pg_amproc | r | 4 | 32 kB | 0 | 10 pg_opclass | r | 4 | 32 kB | 0 | 10 pg_statistic_relid_kind_att_inh_index | i | 4 | 32 kB | 0 | 10 pg_ts_config_map_index | i | 4 | 32 kB | 0 | 10 pg_amproc_oid_index | i | 4 | 32 kB | 0 | 10 pg_toast_2618_index | i | 4 | 32 kB | 0 | 10 pg_conversion | r | 3 | 24 kB | 0 | 10 pg_cast | r | 3 | 24 kB | 0 | 10 --More-- pg_cast_oid_index | i | 4 | 32 kB | 0 | 10 pg_cast_source_target_index | i | 4 | 32 kB | 0 | 10 pg_opfamily | r | 3 | 24 kB | 0 | 10 pg_conversion_default_index | i | 2 | 16 kB | 0 | 10 pg_conversion_name_nsp_index | i | 2 | 16 kB | 0 | 10 pg_conversion_oid_index | i | 2 | 16 kB | 0 | 10 pg_namespace_oid_index | i | 2 | 16 kB | 0 | 10 pg_namespace_nspname_index | i | 2 | 16 kB | 0 | 10 pg_toast_1255_index | i | 2 | 16 kB | 0 | 10 pg_ts_template_oid_index | i | 2 | 16 kB | 0 | 10 pg_ts_dict_dictname_index | i | 2 | 16 kB | 0 | 10 pg_extension_oid_index | i | 2 | 16 kB | 0 | 10 pg_collation_oid_index | i | 2 | 16 kB | 0 | 10 pg_ts_template_tmplname_index | i | 2 | 16 kB | 0 | 10 pg_foreign_server_name_index | i | 2 | 16 kB | 0 | 10 pg_foreign_server_oid_index | i | 2 | 16 kB | 0 | 10 pg_collation_name_enc_nsp_index | i | 2 | 16 kB | 0 | 10 pg_rewrite_oid_index | i | 2 | 16 kB | 0 | 10 streaming_gather_agg_index | i | 2 | 16 kB | 0 | 10 pg_ts_config_cfgname_index | i | 2 | 16 kB | 0 | 10 pg_range_rngtypid_index | i | 2 | 16 kB | 0 | 10 pg_ts_parser_oid_index | i | 2 | 16 kB | 0 | 10 pg_foreign_data_wrapper_oid_index | i | 2 | 16 kB | 0 | 10 pg_aggregate_fnoid_index | i | 2 | 16 kB | 0 | 10 --More-- pg_foreign_data_wrapper_name_index | i | 2 | 16 kB | 0 | 10 pg_aggregate | r | 2 | 16 kB | 0 | 10 pg_ts_parser_prsname_index | i | 2 | 16 kB | 0 | 10 pg_ts_config_oid_index | i | 2 | 16 kB | 0 | 10 pg_attrdef_adrelid_adnum_index | i | 2 | 16 kB | 0 | 10 pg_attrdef_oid_index | i | 2 | 16 kB | 0 | 10 pg_language_oid_index | i | 2 | 16 kB | 0 | 10 pg_ts_dict_oid_index | i | 2 | 16 kB | 0 | 10 pg_constraint_conname_nsp_index | i | 2 | 16 kB | 0 | 10 pg_constraint_conrelid_index | i | 2 | 16 kB | 0 | 10 pg_constraint_contypid_index | i | 2 | 16 kB | 0 | 10 pg_toast_2619_index | i | 2 | 16 kB | 0 | 10 pg_am_oid_index | i | 2 | 16 kB | 0 | 10 pg_language_name_index | i | 2 | 16 kB | 0 | 10 pg_index_indrelid_index | i | 2 | 16 kB | 0 | 10 pg_constraint_oid_index | i | 2 | 16 kB | 0 | 10 pg_ts_config_map | r | 2 | 16 kB | 0 | 10 pg_index_indexrelid_index | i | 2 | 16 kB | 0 | 10 pg_am_name_index | i | 2 | 16 kB | 0 | 10 pg_opclass_oid_index | i | 2 | 16 kB | 0 | 10 pg_opfamily_am_name_nsp_index | i | 2 | 16 kB | 0 | 10 pg_opfamily_oid_index | i | 2 | 16 kB | 0 | 10 gs_encrypted_proc_oid | i | 1 | 8192 bytes | 0 | 10 pg_extension_name_index | i | 2 | 16 kB | 0 | 10 pg_toast_12165_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12172_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12178_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12465_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12479_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12489_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12541_index | i | 1 | 8192 bytes | 0 | 10 statement_history_time_idx | i | 1 | 8192 bytes | 0 | 10 pg_toast_12512_index | i | 1 | 8192 bytes | 0 | 10 gs_errors_id_idx | i | 1 | 8192 bytes | 0 | 10 pg_toast_12554_index | i | 1 | 8192 bytes | 0 | 10 gs_errors_idx | i | 1 | 8192 bytes | 0 | 10 pg_toast_12547_index | i | 1 | 8192 bytes | 0 | 10 gs_source_id_idx | i | 1 | 8192 bytes | 0 | 10 gs_source_idx | i | 1 | 8192 bytes | 0 | 10 gs_client_global_keys_args_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_3220_index | i | 1 | 8192 bytes | 0 | 10 pg_statistic_ext_relid_kind_inh_key_index | i | 1 | 8192 bytes | 0 | 10 pg_user_mapping_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_largeobject_loid_pn_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_7815_index | i | 1 | 8192 bytes | 0 | 10 pg_user_mapping_user_server_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_12526_index | i | 1 | 8192 bytes | 0 | 10 gs_package_name_index | i | 1 | 8192 bytes | 0 | 10 gs_package_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_9016_index | i | 1 | 8192 bytes | 0 | 10 pg_partition_reloid_index | i | 1 | 8192 bytes | 0 | 10 pg_partition_parentoid_index | i | 1 | 8192 bytes | 0 | 10 pg_partition_indextblid_index | i | 1 | 8192 bytes | 0 | 10 pg_partition_partoid_index | i | 1 | 8192 bytes | 0 | 10 pg_partition_indextblid_parentoid_reloid_index | i | 1 | 8192 bytes | 0 | 10 pg_attrdef | r | 1 | 8192 bytes | 0 | 10 pg_toast_2604_index | i | 1 | 8192 bytes | 0 | 10 pg_constraint | r | 1 | 8192 bytes | 0 | 10 pg_toast_2606_index | i | 1 | 8192 bytes | 0 | 10 pg_inherits_parent_index | i | 1 | 8192 bytes | 0 | 10 pg_am | r | 1 | 8192 bytes | 0 | 10 pg_language | r | 1 | 8192 bytes | 0 | 10 pg_inherits_relid_seqno_index | i | 1 | 8192 bytes | 0 | 10 pg_largeobject_metadata_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_2620_index | i | 1 | 8192 bytes | 0 | 10 pg_trigger_tgconstraint_index | i | 1 | 8192 bytes | 0 | 10 pg_trigger_tgrelid_tgname_index | i | 1 | 8192 bytes | 0 | 10 pg_trigger_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_2609_index | i | 1 | 8192 bytes | 0 | 10 pg_enum_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_namespace | r | 1 | 8192 bytes | 0 | 10 streaming_cont_query_schema_change_index | i | 1 | 8192 bytes | 0 | 10 pg_enum_typid_label_index | i | 1 | 8192 bytes | 0 | 10 pg_enum_typid_sortorder_index | i | 1 | 8192 bytes | 0 | 10 streaming_reaper_status_id_index | i | 1 | 8192 bytes | 0 | 10 streaming_reaper_status_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_matview_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_matviewdep_oid_index | i | 1 | 8192 bytes | 0 | 10 pgxc_slice_relid_index | i | 1 | 8192 bytes | 0 | 10 gs_model_name_index | i | 1 | 8192 bytes | 0 | 10 gs_opt_model_name_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_3991_index | i | 1 | 8192 bytes | 0 | 10 gs_model_oid_index | i | 1 | 8192 bytes | 0 | 10 pgxc_slice_order_index | i | 1 | 8192 bytes | 0 | 10 gs_recyclebin_id_index | i | 1 | 8192 bytes | 0 | 10 gs_recyclebin_baseid_index | i | 1 | 8192 bytes | 0 | 10 gs_recyclebin_name_index | i | 1 | 8192 bytes | 0 | 10 gs_recyclebin_dbid_spcid_rcycsn_index | i | 1 | 8192 bytes | 0 | 10 gs_recyclebin_dbid_nsp_oriname_index | i | 1 | 8192 bytes | 0 | 10 gs_recyclebin_dbid_relid_index | i | 1 | 8192 bytes | 0 | 10 gs_txn_snapshot_time_csn_index | i | 1 | 8192 bytes | 0 | 10 gs_txn_snapshot_csn_xmin_index | i | 1 | 8192 bytes | 0 | 10 gs_txn_snapshot_xmin_index | i | 1 | 8192 bytes | 0 | 10 gs_job_argument_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_job_argument_name_index | i | 1 | 8192 bytes | 0 | 10 gs_job_argument_position_index | i | 1 | 8192 bytes | 0 | 10 gs_job_attribute_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_job_attribute_name_index | i | 1 | 8192 bytes | 0 | 10 gs_uid_relid_index | i | 1 | 8192 bytes | 0 | 10 gs_db_privilege_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_db_privilege_roleid_index | i | 1 | 8192 bytes | 0 | 10 pg_publication_pubname_index | i | 1 | 8192 bytes | 0 | 10 pg_publication_rel_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_publication_rel_map_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_name_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_access_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_db_privilege_roleid_privilege_type_index | i | 1 | 8192 bytes | 0 | 10 pg_publication_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_access_row_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_filters_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_filters_row_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_privileges_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_auditing_policy_privileges_row_index | i | 1 | 8192 bytes | 0 | 10 gs_policy_label_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_policy_label_name_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_name_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_actions_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_actions_row_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_actions_policy_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_filters_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_masking_policy_filters_row_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_13703_index | i | 1 | 8192 bytes | 0 | 10 sql_implementation_info | r | 1 | 8192 bytes | 0 | 10 pg_toast_13708_index | i | 1 | 8192 bytes | 0 | 10 sql_languages | r | 1 | 8192 bytes | 0 | 10 pg_toast_13713_index | i | 1 | 8192 bytes | 0 | 10 sql_packages | r | 1 | 8192 bytes | 0 | 10 pg_toast_13718_index | i | 1 | 8192 bytes | 0 | 10 sql_parts | r | 1 | 8192 bytes | 0 | 10 pg_toast_13723_index | i | 1 | 8192 bytes | 0 | 10 sql_sizing | r | 1 | 8192 bytes | 0 | 10 pg_toast_13930_index | i | 1 | 8192 bytes | 0 | 10 snapshot_pkey | i | 1 | 8192 bytes | 0 | 10 pg_toast_13728_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_13733_index | i | 1 | 8192 bytes | 0 | 10 snapshot_id_key | i | 1 | 8192 bytes | 0 | 10 pg_ts_config | r | 1 | 8192 bytes | 0 | 10 --More-- pg_ts_template | r | 1 | 8192 bytes | 0 | 10 pg_extension | r | 1 | 8192 bytes | 0 | 10 pg_ts_dict | r | 1 | 8192 bytes | 0 | 10 pg_ts_parser | r | 1 | 8192 bytes | 0 | 10 pg_foreign_data_wrapper | r | 1 | 8192 bytes | 0 | 10 pg_foreign_server | r | 1 | 8192 bytes | 0 | 10 pg_toast_9001_index | i | 1 | 8192 bytes | 0 | 10 pg_foreign_table_relid_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_3254_index | i | 1 | 8192 bytes | 0 | 10 pg_rlspolicy_oid_index | i | 1 | 8192 bytes | 0 | 10 pgxc_class_pcrelid_index | i | 1 | 8192 bytes | 0 | 10 pg_rlspolicy_polrelid_polname_index | i | 1 | 8192 bytes | 0 | 10 pg_default_acl_role_nsp_obj_index | i | 1 | 8192 bytes | 0 | 10 pg_default_acl_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_collation | r | 1 | 8192 bytes | 0 | 10 pg_toast_3596_index | i | 1 | 8192 bytes | 0 | 10 pg_seclabel_object_index | i | 1 | 8192 bytes | 0 | 10 pg_range | r | 1 | 8192 bytes | 0 | 10 gs_column_keys_name_index | i | 1 | 8192 bytes | 0 | 10 gs_encrypted_columns_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_encrypted_columns_rel_id_column_name_index | i | 1 | 8192 bytes | 0 | 10 gs_column_keys_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_column_keys_distributed_id_index | i | 1 | 8192 bytes | 0 | 10 gs_column_keys_args_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_client_global_keys_oid_index | i | 1 | 8192 bytes | 0 | 10 gs_client_global_keys_name_index | i | 1 | 8192 bytes | 0 | 10 gs_encrypted_proc_func_id_index | i | 1 | 8192 bytes | 0 | 10 gs_asp_sampletime_index | i | 1 | 8192 bytes | 0 | 10 pg_object_index | i | 1 | 16 kB | 0 | 10 pg_synonym_name_nsp_index | i | 1 | 8192 bytes | 0 | 10 pg_directory_name_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_9027_index | i | 1 | 8192 bytes | 0 | 10 pg_hashbucket_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_synonym_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_directory_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_hashbucket_bid_index | i | 1 | 8192 bytes | 0 | 10 streaming_stream_oid_index | i | 1 | 8192 bytes | 0 | 10 pg_toast_5818_index | i | 1 | 8192 bytes | 0 | 10 gs_global_chain_relid_index | i | 1 | 8192 bytes | 0 | 10 streaming_stream_relid_index | i | 1 | 8192 bytes | 0 | 10 streaming_cont_query_relid_index | i | 1 | 8192 bytes | 0 | 10 streaming_cont_query_defrelid_index | i | 1 | 8192 bytes | 0 | 10 streaming_cont_query_id_index | i | 1 | 8192 bytes | 0 | 10 streaming_cont_query_oid_index | i | 1 | 8192 bytes | 0 | 10 streaming_cont_query_matrelid_index | i | 1 | 8192 bytes | 0 | 10 streaming_cont_query_lookupidxid_index | i | 1 | 8192 bytes | 0 | 10 pg_enum | r | 0 | 0 bytes | 0 | 10 pgxc_slice | r | 0 | 0 bytes | 0 | 10 pg_trigger | r | 0 | 0 bytes | 0 | 10 gs_masking_policy_filters | r | 0 | 0 bytes | 0 | 10 pg_largeobject_metadata | r | 0 | 0 bytes | 0 | 10 pg_inherits | r | 0 | 0 bytes | 0 | 10 pg_partition | r | 0 | 0 bytes | 0 | 10 plan_table_data | r | 0 | 0 bytes | 0 | 10 gs_package | r | 0 | 0 bytes | 0 | 10 pg_directory | r | 0 | 0 bytes | 0 | 10 pg_largeobject | r | 0 | 0 bytes | 0 | 10 gs_errors | r | 0 | 0 bytes | 0 | 10 gs_auditing_policy | r | 0 | 0 bytes | 0 | 10 statement_history | r | 0 | 0 bytes | 0 | 10 gs_source | r | 0 | 0 bytes | 0 | 10 gs_opt_model | r | 0 | 0 bytes | 0 | 10 gs_wlm_ec_operator_info | r | 0 | 0 bytes | 0 | 10 gs_wlm_plan_encoding_table | r | 0 | 0 bytes | 0 | 10 pg_obsscaninfo | r | 0 | 0 bytes | 0 | 10 pg_hashbucket | r | 0 | 0 bytes | 0 | 10 gs_wlm_plan_operator_info | r | 0 | 0 bytes | 0 | 10 gs_wlm_operator_info | r | 0 | 0 bytes | 0 | 10 gs_job_attribute | r | 0 | 0 bytes | 0 | 10 pg_user_mapping | r | 0 | 0 bytes | 0 | 10 gs_wlm_user_resource_history | r | 0 | 0 bytes | 0 | 10 pgxc_class | r | 0 | 0 bytes | 0 | 10 gs_model_warehouse | r | 0 | 0 bytes | 0 | 10 gs_masking_policy_actions | r | 0 | 0 bytes | 0 | 10 pg_foreign_table | r | 0 | 0 bytes | 0 | 10 streaming_stream | r | 0 | 0 bytes | 0 | 10 gs_global_chain | r | 0 | 0 bytes | 0 | 10 pg_rlspolicy | r | 0 | 0 bytes | 0 | 10 gs_policy_label | r | 0 | 0 bytes | 0 | 10 gs_uid | r | 0 | 0 bytes | 0 | 10 gs_auditing_policy_access | r | 0 | 0 bytes | 0 | 10 pg_seclabel | r | 0 | 0 bytes | 0 | 10 streaming_cont_query | r | 0 | 0 bytes | 0 | 10 gs_db_privilege | r | 0 | 0 bytes | 0 | 10 pg_default_acl | r | 0 | 0 bytes | 0 | 10 gs_recyclebin | r | 0 | 0 bytes | 0 | 10 snapshot | r | 0 | 0 bytes | 0 | 10 gs_wlm_session_query_info_all | r | 0 | 0 bytes | 0 | 10 gs_wlm_instance_history | r | 0 | 0 bytes | 0 | 10 sql_sizing_profiles | r | 0 | 0 bytes | 0 | 10 pg_statistic_ext | r | 0 | 0 bytes | 0 | 10 gs_encrypted_columns | r | 0 | 0 bytes | 0 | 10 gs_auditing_policy_filters | r | 0 | 0 bytes | 0 | 10 pg_publication | r | 0 | 0 bytes | 0 | 10 gs_column_keys | r | 0 | 0 bytes | 0 | 10 gs_txn_snapshot | r | 0 | 0 bytes | 0 | 10 gs_masking_policy | r | 0 | 0 bytes | 0 | 10 streaming_reaper_status | r | 0 | 0 bytes | 0 | 10 gs_column_keys_args | r | 0 | 0 bytes | 0 | 10 newtb2 | r | 0 | 8192 bytes | 0 | 16392 gs_client_global_keys | r | 0 | 0 bytes | 0 | 10 pg_publication_rel | r | 0 | 0 bytes | 0 | 10 gs_asp | r | 0 | 0 bytes | 0 | 10 gs_matview_dependency | r | 0 | 0 bytes | 0 | 10 gs_matview | r | 0 | 0 bytes | 0 | 10 gs_encrypted_proc | r | 0 | 0 bytes | 0 | 10 gs_client_global_keys_args | r | 0 | 0 bytes | 0 | 10 gs_job_argument | r | 0 | 0 bytes | 0 | 10 pg_object | r | 0 | 8192 bytes | 0 | 10 pg_synonym | r | 0 | 0 bytes | 0 | 10 (316 rows) gs_auditing_policy_privileges | r | 0 | 0 bytes | 0 | 10
复制
通过查询pg_class可以看到表newtb2并未显示对应的默认表空间名称。
-- 查询数据库非默认表空间上的对象 newdb1=> select relname, relkind, relpages,pg_size_pretty(pg_relation_size(a.oid)),reltablespace,relowner newdb1-> from pg_class a, pg_tablespace tb newdb1-> where a.relkind in ('r', 'i') newdb1-> and a.reltablespace=tb.oid newdb1-> and tb.spcname='ds_location1' newdb1-> order by a.relpages desc; relname | relkind | relpages | pg_size_pretty | reltablespace | relowner ---------+---------+----------+----------------+---------------+---------- newtb1 | r | 0 | 8192 bytes | 16390 | 16392 (1 row)
复制
三、学习心得
对于学习过Oracle数据库的同学来说,学习openGauss数据库时,在表空间这块可能会感觉有些疑惑,特别是在表空间这块,和Oracle数据库还是有些区别的,所以还是需要通过理论并结合实际来进行学习。
最后修改时间:2022-12-01 15:16:13
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论

2年前

评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
555次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
308次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
201次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
172次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
162次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
151次阅读
2025-04-30 16:39:58
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
96次阅读
2025-04-18 10:49:53
Postgresql数据库单个Page最多存储多少行数据
maozicb
93次阅读
2025-04-23 16:02:19
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
66次阅读
2025-04-17 10:41:47
RISC-V 首迎 openGauss 7.0.0-RC1 全量版适配!数据库核心功能完整落地开源架构
openGauss
49次阅读
2025-04-16 10:33:59
TA的专栏
热门文章
Elasticsearch运维篇_ES启动失败常见问题及解决办法整理
2023-05-09 14782浏览
Centos 7 静默安装Oracle 11.2.0.4 单机版安装指南
2023-05-24 7715浏览
达梦数据库初始化数据库需特别注意的几个参数
2022-11-08 6997浏览
记一次Oracle数据库SQL执行超时产生ORA-609报错导致进程被abort问题分析及处理
2022-11-29 5581浏览
ORA-1652: unable to extend temp segment by 128 in tablespace导致流复制中断影响数据同步问题分析
2022-11-22 5475浏览
最新文章
企业版 YashanDB 23.2.4 分布式集群 数据库一主二备集群安装部署指南
2024-12-23 422浏览
企业版 YashanDB 23.2.4 YAC 单库多实例架构多活共享集群安装部署指南
2024-12-23 278浏览
打工人的心声:眼花缭乱的世界,疲惫的心和不安的未来
2024-12-05 207浏览
[【ClickHouse 运维系列】ClickHouse 集群从 22.5.1.2079 滚动升级到 24.8.6.70 流程步骤
2024-12-02 302浏览
金仓数据库 KingbaseES V9 详解:目录结构与配置文件 (上)
2024-11-27 307浏览
目录