postgresql系统函数

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

postgresql系统函数

Configuration Settings Functions

  • current_setting(setting_name) 查询当前设置
  • set_config(setting_name, new_value, is_local) 设置参数

Server Signaling Functions

  • pg_cancel_backend(pid int) 结束进程
  • pg_terminate_backend(pid int) 强制结束进程
  • pg_reload_conf() 重载配置,修改pg_config
  • pg_rotate_logfile() 切分当前日志文件

Backup Control Functions

  • pg_current_xlog_location() 获取当前事务日志写入位置
postgres=# select pg_current_xlog_location();
    pg_current_xlog_location
    ------------------------------------------------------
    138B/A280A860
    (1 row)
  • pg_current_xlog_insert_location() 获取当前事务日志插入位置
postgres=# select pg_current_xlog_location(),pg_current_xlog_insert_location();
  pg_current_xlog_location | pg_current_xlog_insert_location
  --------------------------+---------------------------------
  138D/45A84000            | 138D/45AF7300
 (1 row)
  • pg_xlogfile_name(location pg_lsn) 通过事务日志转换为文件名
postgres=# select pg_xlogfile_name('15D2/32414638');
  pg_xlogfile_name     
  --------------------------
  00000001000015D200000032
  (1 row)

可以在pg_xlog中找到相应的文件

-bash-4.2$ cd pg_xlog/
-bash-4.2$ ll 00000001000015D200000032
-rw-------. 1 postgres dba 16777216 Jan 24 18:09 00000001000015D200000032
  • pg_xlogfile_name_offset(location pg_lsn) 把事务日志的位置转换为文件名和文件内部十进制字节的偏移量
postgres=# select pg_xlogfile_name_offset('15D2/32414638');
      pg_xlogfile_name_offset       
------------------------------------
 (00000001000015D200000032,4277816)
(1 row)
  • pg_xlog_location_diff(location pg_lsn, location pg_lsn) 计算两个事务日志差值
postgres=# select pg_xlog_location_diff(pg_current_xlog_location(),pg_current_xlog_insert_location());
 pg_xlog_location_diff 
-----------------------
               -126472
(1 row)

postgres=#

关于两个参数的区别,贴上官方解释:

pg_current_xlog_location displays the current transaction log write location in the same format used by the above functions. Similarly, pg_current_xlog_insert_location displays the current transaction log insertion point. The insertion point is the "logical" end of the transaction log at any instant, while the write location is the end of what has actually been written out from the server's internal buffers. The write location is the end of what can be examined from outside the server, and is usually what you want if you are interested in archiving partially-complete transaction log files. The insertion point is made available primarily for server debugging purposes. These are both read-only operations and do not require superuser permissions.

大概意思是 pg_xlog_location_diff表示已经写入到wal文件中transaction log事物号。
pg_xlogfile_name_offset数据库实例最后的transaction log,可能还未写入到wal文件中。

  • pg_is_in_backup() 判断数据库是否正在备份
  • pg_backup_start_time() 返回数据库开始备份时间
  • pg_switch_xlog() 强制切换wal日志文件

Database Object Management Functions

  • pg_database_size(name)
  • pg_indexes_size(regclass)
  • pg_relation_size(relation regclass)
  • pg_size_pretty()
  • pg_table_size(regclass) 表大小,不包括索引
  • pg_tablespace_size(name)
  • pg_total_relation_size(regclass) pg_table_size + pg_indexes_size 表加索引的大小

Advisory Lock Functions

link

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
存储 SQL 安全
2 PostgreSQL 物理,逻辑,进程结构以及系统表系统函数|学习笔记
快速学习2 PostgreSQL 物理,逻辑,进程结构以及系统表系统函数
313 0
2 PostgreSQL 物理,逻辑,进程结构以及系统表系统函数|学习笔记
|
关系型数据库 数据库 对象存储
PostgreSQL系统函数:pg_relation_filepath
pg_relation_filepath:数据对象存储位置 Name Return Type Description pg_relation_filepath text file path name of specified relation 创建表空间 postgres=# .
3139 0
|
9月前
|
SQL Cloud Native 关系型数据库
ADBPG(AnalyticDB for PostgreSQL)是阿里云提供的一种云原生的大数据分析型数据库
ADBPG(AnalyticDB for PostgreSQL)是阿里云提供的一种云原生的大数据分析型数据库
742 1
|
9月前
|
数据可视化 关系型数据库 MySQL
将 PostgreSQL 迁移到 MySQL 数据库
将 PostgreSQL 迁移到 MySQL 数据库
1065 2
|
11月前
|
SQL 关系型数据库 Linux
【PostgreSQL】基于CentOS系统安装PostgreSQL数据库
【PostgreSQL】基于CentOS系统安装PostgreSQL数据库
545 0
|
8月前
|
SQL 存储 自然语言处理
玩转阿里云RDS PostgreSQL数据库通过pg_jieba插件进行分词
在当今社交媒体的时代,人们通过各种平台分享自己的生活、观点和情感。然而,对于平台管理员和品牌经营者来说,了解用户的情感和意见变得至关重要。为了帮助他们更好地了解用户的情感倾向,我们可以使用PostgreSQL中的pg_jieba插件对这些发帖进行分词和情感分析,来构建一个社交媒体情感分析系统,系统将根据用户的发帖内容,自动判断其情感倾向是积极、消极还是中性,并将结果存储在数据库中。
玩转阿里云RDS PostgreSQL数据库通过pg_jieba插件进行分词
|
8月前
|
关系型数据库 测试技术 分布式数据库
PolarDB | PostgreSQL 高并发队列处理业务的数据库性能优化实践
在电商业务中可能涉及这样的场景, 由于有上下游关系的存在, 1、用户下单后, 上下游厂商会在自己系统中生成一笔订单记录并反馈给对方, 2、在收到反馈订单后, 本地会先缓存反馈的订单记录队列, 3、然后后台再从缓存取出订单并进行处理. 如果是高并发的处理, 因为大家都按一个顺序获取, 容易产生热点, 可能遇到取出队列遇到锁冲突瓶颈、IO扫描浪费、CPU计算浪费的瓶颈. 以及在清除已处理订单后, 索引版本未及时清理导致的回表版本判断带来的IO浪费和CPU运算浪费瓶颈等. 本文将给出“队列处理业务的数据库性能优化”优化方法和demo演示. 性能提升10到20倍.
597 4
|
9月前
|
SQL 存储 人工智能
NineData已支持「最受欢迎数据库」PostgreSQL
NineData 也在近期支持了 PostgreSQL,用户可以在 NineData 平台上进行创建数据库/Schema、管理用户与角色、导出数据、执行 SQL 等操作。另外,NineData SQL 开发企业版,还可以统一管理企业内部 PostgreSQL 的访问、规范与流程、变更发布等。
311 0
NineData已支持「最受欢迎数据库」PostgreSQL
|
9月前
|
存储 Cloud Native 关系型数据库
云原生之使用docker部署Postgresql数据库
云原生之使用docker部署Postgresql数据库
323 0
云原生之使用docker部署Postgresql数据库