自己安装的openGauss环境
启动openGauss
gs_ctl -D /gauss/data/db1/ start
登录openGauss
gsql -d postgres -p 26000 -r
1.创建表products, 分别为表创建一个unique索引1,指定b-tree索引2和表达式索引3
create schema hc;
create table hc.products
(product_id INTEGER,
product_name Char(30),
category Char(20)
);
create unique index products_idx1 on hc.products(product_id);
create index products_idx2 on hc.products USING btree(product_id);
create index products_idx3 on hc.products (SUBSTR(product_name,1 ,4));

2.设置索引1不可用,修改索引2的表空间,重命名索引3
ALTER INDEX hc.products_idx1 UNUSABLE;
CREATE TABLESPACE tspc1 RELATIVE LOCATION ‘tablespace/tablespace_1’;
alter index hc.products_idx2 set tablespace tspc1;
alter index hc.products_idx3 rename to products_idx300;

3.重建索引2和products的所有索引
reindex index hc.products_idx2;
reindex table hc.products;

4.使用\d+和系统视图pg_indexes查看索引信息
\d+ hc.products
select * from pg_indexes where tablename = ‘products’;

5.删除索引、表和表空间
drop index hc.products_idx1;
drop index hc.products_idx2;
drop index hc.products_idx300;
drop table hc.products;
drop schema hc;
drop tablespace tspc1;





