首页 > 其他分享 >MogDB/openGauss学习笔记-获取对象DDL

MogDB/openGauss学习笔记-获取对象DDL

时间:2024-03-30 11:44:06浏览次数:16  
标签:SET get text normal MogDB catalog pg DDL openGauss

MogDB/openGauss 学习笔记-获取对象 DDL
本文出处:https://www.modb.pro/db/399230

内置函数
omm2=# \df *def List of functions Schema | Name | Result data type | Argument data types | Type | fencedmode | propackage | prokind ------------+----------------------+------------------+----------------------------------------------------------+--------+------------+------------+--------- pg_catalog | pg_get_constraintdef | text | oid | normal | f | f | f pg_catalog | pg_get_constraintdef | text | oid, boolean | normal | f | f | f pg_catalog | pg_get_functiondef | record | funcid oid, OUT headerlines integer, OUT definition text | normal | f | f | f pg_catalog | pg_get_indexdef | text | oid | normal | f | f | f pg_catalog | pg_get_indexdef | text | oid, boolean | normal | f | f | f pg_catalog | pg_get_indexdef | text | oid, integer, boolean | normal | f | f | f pg_catalog | pg_get_ruledef | text | oid | normal | f | f | f pg_catalog | pg_get_ruledef | text | oid, boolean | normal | f | f | f pg_catalog | pg_get_tabledef | text | regclass | normal | f | f | f pg_catalog | pg_get_triggerdef | text | oid | normal | f | f | f pg_catalog | pg_get_triggerdef | text | oid, boolean | normal | f | f | f pg_catalog | pg_get_viewdef | text | oid | normal | f | f | f pg_catalog | pg_get_viewdef | text | oid, boolean | normal | f | f | f pg_catalog | pg_get_viewdef | text | oid, integer | normal | f | f | f pg_catalog | pg_get_viewdef | text | text | normal | f | f | f pg_catalog | pg_get_viewdef | text | text, boolean | normal | f | f | f (16 rows)
示例
获取表的 DDL
omm2=# select pg_get_tabledef('t');
pg_get_tabledef

SET search_path = public; +
CREATE TABLE t ( +
id numeric, +
c character varying(100) +
) +
WITH (orientation=row, fillfactor=50, compression=no);
(1 row)

omm2=# \x
Expanded display is on.
omm2=# select pg_get_tabledef('t');
-[ RECORD 1 ]---+-------------------------------------------------------
pg_get_tabledef | SET search_path = public;
| CREATE TABLE t (
| id numeric,
| c character varying(100)
| )
| WITH (orientation=row, fillfactor=50, compression=no);
获取索引 DDL
omm2=# select pg_get_indexdef('idx_t_id'::regclass);
pg_get_indexdef

CREATE INDEX idx_t_id ON t USING btree (id) TABLESPACE pg_default
(1 row)

还可以直接查询视图
omm2=# \x
Expanded display is on.
omm2=# select * from pg_indexes where indexname='idx_t_id';
-[ RECORD 1 ]-----------------------------------------------------------------
schemaname | public
tablename | t
indexname | idx_t_id
tablespace |
indexdef | CREATE INDEX idx_t_id ON t USING btree (id) TABLESPACE pg_default
通过 gs_dump 生成 ddl
这样还可以生成表及表上的索引定义等 $ gs_dump -t t –section pre-data omm2

$ gs_dump -t t --section pre-data omm2

SET statement_timeout = 0;
SET xmloption = content;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: t; Type: TABLE; Schema: public; Owner: omm2; Tablespace:

CREATE TABLE t (
id numeric,
c character varying(100)
)
WITH (orientation=row, fillfactor=50, compression=no);

ALTER TABLE public.t OWNER TO omm2;
$ gs_dump -t t –section post-data omm2

$ gs_dump -t t --section post-data omm2

SET statement_timeout = 0;
SET xmloption = content;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public;

SET default_tablespace = '';

--
-- Name: idx_t_id; Type: INDEX; Schema: public; Owner: omm2; Tablespace:

CREATE INDEX idx_t_id ON t USING btree (id) TABLESPACE pg_default;

标签:SET,get,text,normal,MogDB,catalog,pg,DDL,openGauss
From: https://www.cnblogs.com/helloopenGauss/p/18105282

相关文章

  • openGauss 数据库认证机制
    数据库认证机制可获得性本特性自openGauss1.1.0版本开始引入。特性简介提供基于客户端/服务端(C/S)模式的客户端连接认证机制。客户价值加密认证过程中采用单向Hash不可逆加密算法PBKDF2,有效防止彩虹攻击。特性描述openGauss采用基本的客户端连接认证机制,客户端发起连接请......
  • openGauss 数据库指标采集-预测与异常监控
    数据库指标采集、预测与异常监控可获得性本特性自openGauss1.1.0版本开始引入。特性简介本特性是openGauss集成的、可以用于数据库指标采集、预测以及异常监控与诊断的AI工具,是DBMind套间中的一个组件。当前通过兼容Prometheus平台来采集数据库系统的指标,提供Prometheusexpo......
  • openGauss 事件触发器
    事件触发器可获得性本特性自openGauss5.0.0版本开始引入。特性简介支持事件触发器,允许捕获DDL操作并做相应处理。客户价值典型使用场景是:通过事件触发器捕获DDL操作和目标对象,来实现数据同步。特性描述事件触发器支持捕获当前数据库下的ddl操作以及ddl操作的目标对象(事件......
  • openGauss 数据加密存储
    数据加密存储可获得性本特性自openGauss1.1.0版本开始引入。特性简介提供对导入数据的加密存储。客户价值为客户提供加密导入接口,对客户认为是敏感信息的数据进行加密后存储在表内。特性描述openGauss提供加密函数gs_encrypt_aes128()、gs_encrypt()和解密函数gs_decrypt......
  • openGauss 全文索引
    全文索引可获得性本特性自openGauss1.1.0版本开始引入。特性简介openGauss中提供的全文索引功能可以对文档进行预处理,并且可以使后续的搜索更快速。客户价值openGauss全文索引功能提供了查询可读性文档的能力,并且通过查询相关度将结果进行排序。特性描述构建全文索引的......
  • openGauss 使用kubernetes部署分布式数据库
    使用kubernetes部署分布式数据库可获得性本特性自openGauss2.1.0版本开始引入。特性简介一键式部署分布式数据库。客户价值快速完成分布式数据库搭建,验证和使用分布式能力。特性描述通过patroni实现计划内switchover和故障场景自动failover,通过haproxy实现openGauss主备......
  • openGauss 全量迁移gs_mysync
    全量迁移gs_mysync可获得性本特性自openGauss5.0.0版本开始引入。特性简介gs_mysync工具是一个基于Python语言的MySQL到openGauss的复制工具。该工具提供了初始全量数据及对象(视图、触发器、函数、存储过程)的复制能力,可实现数据及对象从MySQL迁移至openGauss。对于数据的全量......
  • openGauss 全密态数据库等值查询
    全密态数据库等值查询可获得性本特性自openGauss1.1.0版本开始引入。特性简介密态数据库意在解决数据全生命周期的隐私保护问题,使得系统无论在何种业务场景和环境下,数据在传输、运算以及存储的各个环节始终都处于密文状态。当数据拥有者在客户端完成数据加密并发送给服务端后......
  • openGauss 全局临时表
    全局临时表可获得性本特性自openGauss1.1.0版本开始引入。特性简介临时表顾名思义是不保证持久化的表,其生命周期一般跟session或者事务绑定,可以方便用于表达处理过程中的一些临时数据存放,加速查询。客户价值提升临时表的表达能力和易用性。特性描述全局临时表的元数据对......
  • openGauss 企业级增强特性
    企业级增强特性数据分区数据分区是数据库产品普遍具备的功能。在openGauss中,数据分区是对数据按照用户指定的策略对数据做的水平分表,将表按照指定范围划分为多个数据互不重叠的部分(Partition)。openGauss支持:范围分区(RangePartitioning)功能,即根据表的一列或者多列,将要插入表......