• Home
  • 悦读
    • WYN photo

      WYN

      ridikuius

    • Learn More
    • Email
    • Github
  • 技术小札
    • 所有文章
    • 所有标签
  • 阅心笔记

数据库系统配置函数

20 Jul 2016

Reading time ~3 minutes

PostgreSQL

系统信息函数

Session级信息函数

函数名 返回值类型 描述
current_catalog name 当前数据库名称
current_database() name 当前数据库名称
current_query() text 当前执行的查询文本,提交的客户(可能包含不止一个声明)
current_schema() name 当前schema名称
current_schemas(boolean) name[] 名字在搜索路径的schema,可选地包括隐式schema
current_user name 当前执行上下文的用户名
user name 当前执行上下文的用户名
inet_client_addr() inet 远程连接的地址
inet_client_port() int 远程连接的端口
inet_server_addr() inet 本地连接的地址
inet_server_port() int 本地连接的端口
pg_backend_pid() int 当前会话的服务器进程ID
pg_conf_load_time() timestamp with time zone 配置加载时间
pg_is_other_temp_schema(oid) boolean 当前schema是否是另一个会话的临时schema
pg_listening_channels() setof text 会话正在监听的channel名称
pg_my_temp_schema() oid OID的会话的临时schema,0或者none
pg_postmaster_start_time() timestamp with time zone 服务启动时间
pg_trigger_depth() int 目前PostgreSQL的嵌套级触发器(0或者没有,直接或间接地从内部触发器)
session_user name session的用户名称
version() text PostgreSQL的版本信息

访问权限查询函数

函数名 返回值类型 描述
has_any_column_privilege(user, table, privilege) boolean 指定用户是否有操作指定表的每一列的指定权限
has_any_column_privilege(table, privilege) boolean 当前用户是否有操作指定表的每一列的指定权限
has_column_privilege(user, table, column, privilege) boolean 指定用户是否有操作指定表的指定列的指定权限
has_column_privilege(table, column, privilege) boolean 当前用户是否有操作指定表的指定列的指定权限
has_database_privilege(user, database, privilege) boolean 指定用户是否有操作指定数据库的指定权限
has_database_privilege(database, privilege) boolean 当前用户是否有操作指定数据库的指定权限
has_foreign_data_wrapper_privilege(user, fdw, privilege) boolean 指定用户是否有操作foreign-data wrapper的指定权限
has_foreign_data_wrapper_privilege(fdw, privilege) boolean 当前用户是否有操作foreign-data wrapper的指定权限
has_function_privilege(user, function, privilege) boolean 指定用户是否有操作指定函数的指定权限
has_function_privilege(function, privilege) boolean 当前用户是否有操作指定函数的指定权限
has_language_privilege(user, language, privilege) boolean 指定用户是否有操作指定语言的指定权限
has_language_privilege(language, privilege) boolean 当前用户是否有操作指定语言的指定权限
has_schema_privilege(user, schema, privilege) boolean 指定用户是否有操作指定schema的指定权限
has_schema_privilege(schema, privilege) boolean 当前用户是否有操作指定schema的指定权限
has_sequence_privilege(user, sequence, privilege) boolean 指定用户是否有操作指定sequence的指定权限
has_sequence_privilege(sequence, privilege) boolean 当前用户是否有操作指定sequence的指定权限
has_server_privilege(user, server, privilege) boolean 指定用户是否有操作指定外接服务器的指定权限
has_server_privilege(server, privilege) boolean 当前用户是否有操作指定外接服务器的指定权限
has_table_privilege(user, table, privilege) boolean 指定用户是否有操作指定表的指定权限
has_table_privilege(table, privilege) boolean 当前用户是否有操作指定表的指定权限
has_tablespace_privilege(user, tablespace, privilege) boolean 指定用户是否有操作指定表空间的指定权限
has_tablespace_privilege(tablespace, privilege) boolean 当前用户是否有操作指定表空间的指定权限
pg_has_role(user, role, privilege) boolean 指定用户是否有操作指定角色的指定权限
pg_has_role(role, privilege) boolean 当前用户是否有操作指定角色的指定权限
row_security_active(table) boolean 当前用户对指定表是否有行级安全活动

模式能见度查询函数

函数名 返回值类型 描述
pg_collation_is_visible(collation_oid) boolean 在搜索路径指定排序是否是可见的
pg_conversion_is_visible(conversion_oid) boolean 在搜索路径指定转换是否是可见的
pg_function_is_visible(function_oid) boolean 在搜索路径指定函数是否是可见的
pg_opclass_is_visible(opclass_oid) boolean 在搜索路径指定操作类是否是可见的
pg_operator_is_visible(operator_oid) boolean 在搜索路径指定操作是否是可见的
pg_opfamily_is_visible(opclass_oid) boolean 在搜索路径指定操作族是否是可见的
pg_table_is_visible(table_oid) boolean 在搜索路径指定表是否是可见的(pg_table_is_visible can also be used with views, materialized views, indexes, sequences and foreign tables)
pg_ts_config_is_visible(config_oid) boolean 在搜索路径指定搜索配置文本是否是可见的
pg_ts_dict_is_visible(dict_oid) boolean 在搜索路径指定搜索字典文本是否是可见的
pg_ts_parser_is_visible(parser_oid) boolean 在搜索路径指定搜索解析器文本是否是可见的
pg_ts_template_is_visible(template_oid) boolean 在搜索路径指定搜索模板文本是否是可见的
pg_type_is_visible(type_oid) boolean 在搜索路径指定类型(或者域)是否是可见的

系统表信息函数

名字 返回类型 描述
format_type(type_oid,typemod) text 获取一个数据类型的SQL名称
pg_get_viewdef(view_oid) text 为视图获取CREATE VIEW命令
pg_get_viewdef(view_oid,pretty_bool) text 为视图获取CREATE VIEW命令
pg_get_ruledef(rule_oid) text 为规则获取CREATE RULE命令
pg_get_ruledef(rule_oid,pretty_bool) text 为规则获取CREATE RULE命令
pg_get_indexdef(index_oid) text 为索引获取CREATE INDEX命令
pg_get_indexdef(index_oid,column_no,pretty_bool) text 为索引获取CREATE INDEX命令, 如果column_no不为零,则是只获取一个索引字段的定义
pg_get_triggerdef(trigger_oid) text 为触发器获取CREATE [CONSTRAINT] TRIGGER
pg_get_constraintdef(constraint_oid) text 获取一个约束的定义
pg_get_constraintdef(constraint_oid,pretty_bool) text 获取一个约束的定义
pg_get_expr(expr_text,relation_oid) text 反编译一个表达式的内部形式,假设其中的任何Vars都引用第二个参数指出的关系
pg_get_expr(expr_text,relation_oid, pretty_bool) text 反编译一个表达式的内部形式,假设其中的任何Vars都引用第二个参数指出的关系
pg_get_userbyid(roleid) name 获取给出的ID的角色名(数据库的所有者)
pg_get_serial_sequence(table_name,column_name) text 获取一个serial或者bigserial字段使用的序列名字
pg_tablespace_databases(tablespace_oid) setof oid 获取在指定表空间(OID表示)中拥有对象的一套数据库的OID的集合

对象信息和地址函数

函数名 返回值类型 描述
pg_describe_object(catalog_id, object_id, object_sub_id) text 得到数据库对象的描述
pg_identify_object(catalog_id oid, object_id oid, object_sub_id integer) type text, schema text, name text, identity text 得到数据库对象的身份
pg_identify_object_as_address(catalog_id oid, object_id oid, object_sub_id integer) type text, name text[], args text[] 得到数据库对象地址的外部表示
pg_get_object_address(type text, name text[], args text[]) catalog_id oid, object_id oid, object_sub_id int32 从数据库的外部表示得到数据库地址

注释信息函数

函数名 返回值类型 描述
col_description(table_oid, column_number) text 得到数据表指定列的注释
obj_description(object_oid, catalog_name) text 得到数据库对象的注释
obj_description(object_oid) text 得到数据库对象的注释(已弃用)
shobj_description(object_oid, catalog_name) text 得到共享数据库对象的注释

事务ID和快照

函数名 返回值类型 描述
txid_current() bigint 得到当前的事务ID,如果当前事务没有分配一个新的
txid_current_snapshot() txid_snapshot 得到当前快照
txid_snapshot_xip(txid_snapshot) setof bigint 得到在快照中正在进行的事务ID
txid_snapshot_xmax(txid_snapshot) bigint 得到xmax快照
txid_snapshot_xmin(txid_snapshot) bigint 得到xmin快照
txid_visible_in_snapshot(bigint, txid_snapshot) boolean 事务ID在快照中是否可见(不使用子事务ID)

快照组件

组件名称 描述
xmin 最早的事务ID(txid)仍然是活跃的。所有更早事务要么是已提交和可见的,要么是回滚或已死亡。
xmax First as-yet-unassigned txid. All txids greater than or equal to this are not yet started as of the time of the snapshot, and thus invisible.
xip_list Active txids at the time of the snapshot. The list includes only those active txids between xmin and xmax; there might be active txids higher than xmax. A txid that is xmin <= txid < xmax and not in this list was already completed at the time of the snapshot, and thus either visible or dead according to its commit status. The list does not include txids of subtransactions.

提交事务信息

函数名 返回自类型 描述
pg_xact_commit_timestamp(xid) timestamp with time zone 获得提交事务的时间戳
pg_last_committed_xact() xid xid, timestamp timestamp with time zone 或得最新提交事务的事务ID和时间戳


数据库PostgreSQLMySQL Like Tweet +1