iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >数据库postgres index vaccum学习
  • 386
分享到

数据库postgres index vaccum学习

2024-04-02 19:04:59 386人浏览 八月长安
摘要

VoicePortal=# create table testindex (no serial primary key, value integer);NOTICE: CREATE TABLE will

VoicePortal=# create table testindex (no serial primary key, value integer);
NOTICE: CREATE TABLE will create implicit sequence "testindex_no_seq" for serial column "testindex.no"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "testindex_pkey" for table "testindex"

VoicePortal=# insert into testindex(value)
VoicePortal-# select trunc(random() *10) from generate_series(1,1000); random()会产生一个0.**的数字,10就是十以内的数字
INSERT 0 1000 产生一千个10以内的随机数,并且把他们作为value值插入到testindex里面去
VoicePortal=# select * from testindex limit 10;
no | value
----+-------
1 | 0
2 | 8
3 | 3
4 | 2
5 | 8
6 | 9
7 | 6
8 | 5
9 | 9
10 | 9
(10 rows)

这样testindex的表建好了,用它来做测试

VoicePortal=# \d testindex
Table "public.testindex"
Column | Type | Modifiers
--------+---------+--------------------------------------------------------
no | integer | not null default nextval('testindex_no_seq'::reGClass)
value | integer |
Indexes:
"testindex_pkey" PRIMARY KEY, btree (no) 自动建立索引
流出一个table的详细信息。

VoicePortal=# \di+ testindex_pkey 查表的索引大小
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+----------------+-------+----------+-----------+-------+-------------
public | testindex_pkey | index | postgres | testindex | 40 kB |
(1 row)

VoicePortal=# \dt+ testindex 查表大小
List of relations
Schema | Name | Type | Owner | Size | Description
--------+-----------+-------+----------+-------+-------------
public | testindex | table | postgres | 64 kB |
(1 row)

现在testindex里面有1000条数据,我再往里面加1000条。

VoicePortal=# insert into testindex VALUES ('1001',8);
INSERT 0 1
VoicePortal=# select count(*) from testindex;
count

1001
(1 row)
VoicePortal=# insert into testindex(value)
select trunc(random() *10) from generate_series(1002,1100);
INSERT 0 99

VoicePortal=# insert into testindex(value)
VoicePortal-# select trunc(random()*10)from generate_series(1101,2000);
INSERT 0 900

VoicePortal=# \di+ testindex_pkey;
List of relations
-[ RECORD 1 ]---------------
Schema | public
Name | testindex_pkey
Type | index
Owner | postgres
Table | testindex
Size | 64 kB
Description |

VoicePortal=# \dt+ testindex;
List of relations
-[ RECORD 1 ]----------
Schema | public
Name | testindex
Type | table
Owner | postgres
Size | 96 kB
Description |

再删除一些数据

VoicePortal=# delete FROM testindex where value <8;
DELETE 605

VoicePortal=# select * from pg_stat_user_tables where relname='testindex';
-[ RECORD 1 ]-----+------------------------------
relid | 1445721
schemaname | public
relname | testindex
seq_scan | 8
seq_tup_read | 5831
idx_scan | 1
idx_tup_fetch | 1001
n_tup_ins | 2001
n_tup_upd | 0
n_tup_del | 1597
n_tup_hot_upd | 0
n_live_tup | 403
n_dead_tup | 605
last_vacuum |
last_autovacuum | 2016-12-08 18:09:00.7149-07
last_analyze | 2016-12-08 18:03:16.074174-07
last_autoanalyze | 2016-12-08 18:09:00.715874-07
vacuum_count | 0
autovacuum_count | 1
analyze_count | 2
autoanalyze_count | 3

这些数据会暂时放在dead里面等待autovaccum

VoicePortal=# select * from pg_stat_user_tables where relname='testindex';
-[ RECORD 1 ]-----+------------------------------
relid | 1445721
schemaname | public
relname | testindex
seq_scan | 8
seq_tup_read | 5831
idx_scan | 1
idx_tup_fetch | 1001
n_tup_ins | 2001
n_tup_upd | 0
n_tup_del | 1597
n_tup_hot_upd | 0
n_live_tup | 403
n_dead_tup | 0
last_vacuum |
last_autovacuum | 2016-12-08 18:11:00.715995-07
last_analyze | 2016-12-08 18:03:16.074174-07
last_autoanalyze | 2016-12-08 18:11:00.716891-07
vacuum_count | 0
autovacuum_count | 2
analyze_count | 2
autoanalyze_count | 4
之后清空dead。
VoicePortal=# \di+ testindex_pkey;
List of relations
-[ RECORD 1 ]---------------
Schema | public
Name | testindex_pkey
Type | index
Owner | postgres
Table | testindex
Size | 64 kB
Description |

VoicePortal=# \dt+ testindex;
List of relations
-[ RECORD 1 ]----------
Schema | public
Name | testindex
Type | table
Owner | postgres
Size | 104 kB
Description |

也就是说只要最后一个数据存在,vacuum是无法真正释放空间的

VoicePortal=# vacuum FULL testindex;
VACUUM
VoicePortal=# \di+ testindex_pkey;
List of relations
-[ RECORD 1 ]---------------
Schema | public
Name | testindex_pkey
Type | index
Owner | postgres
Table | testindex
Size | 32 kB
Description |

VoicePortal=# \dt+ testindex;
List of relations
-[ RECORD 1 ]----------
Schema | public
Name | testindex
Type | table
Owner | postgres
Size | 16 kB
Description |

FULL vacuum可以做到,他会改变原来的排序,重新排列。
数据库postgres index vaccum学习

您可能感兴趣的文档:

--结束END--

本文标题: 数据库postgres index vaccum学习

本文链接: https://www.lsjlt.com/news/40612.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • postgres篇---docker安装postgres,python连接postgres数据库
    postgres篇---docker安装postgres,python连接postgres数据库 一、docker安装postgres1.1 安装Docker:1.2 从Docker Hub获...
    99+
    2023-09-23
    docker 数据库 python
  • MySQL数据库学习
    目录 从管理员cmd页面打开数据库 创建一个用户 数据库的基本操作 数据完整性 完整性约束管理 表的基本操作 判断关键字 聚合函数 多表连接查询 嵌套查询 联合查询 事务 锁 索引 视图 存储过程 函数(与存储过程类似) 光标 触发器   ...
    99+
    2023-10-19
    数据库 mysql 学习 java
  • 数据库怎么学习
    学习数据库的方法学习Access数据库,了解数据库的基础概念。学习如何建数据库。学习sql语句的运用。做一些实例进行深度学习。学习SQLserver,掌握关系型数据库的基本操作。学习Oracle、DB2等大型数据库的知识。...
    99+
    2024-04-02
  • 如何学习数据库
    学习数据库的方法从Access数据库入手,了解数据库的基础概念。自己动手建库。学习sql语句的运用。做一些实例进行深度学习。接着学习SQLserver掌握关系型数据库的基本操作。学习大型数据库的知识。最后需要再掌握Oracle、DB2等大型...
    99+
    2024-04-02
  • docker怎么部署访问postgres数据库
    这篇文章主要讲解了“docker怎么部署访问postgres数据库”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“docker怎么部署访问postgres数据库”吧!部署与访问宿主机创建pos...
    99+
    2023-06-29
  • 图数据库Neo4j学习五渲染图数据库neo4jd3
    文章目录 1.现成的工具2.Neo4j JavaScript Driver3.neovis4.neo4jd34.1neo4jd3和neovis对比4.2获取neo4jd34.3neo4jd3的数据结构4.4Spring data n...
    99+
    2023-08-30
    数据库 neo4j 学习
  • Spring学习JdbcTemplate数据库事务参数
    目录Spring JdbcTemplate数据库事务参数一、propagation1. REQUIRED2. REQUIRES_NEW3. SUPPORTS4. NOT_SUPPOR...
    99+
    2024-04-02
  • postgres数据库中怎么实现数据转换
    postgres数据库中怎么实现数据转换,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。 实际上&...
    99+
    2024-04-02
  • python学习笔记(三)—数据库篇
    一、数据库编程 数据库编程是指在应用程序中使用数据库管理系统(DBMS)进行数据存储、检索和处理的过程。数据库提供了一种结构化的方式来组织和存储数据,使得数据的管理更加高效和可靠。 1.1 关系数据库...
    99+
    2023-09-18
    python 学习 笔记
  • 阿里云数据库学习心得
    阿里云数据库学习心得 阿里云数据库是阿里集团自研的分布式关系型数据库,它采用了多种技术,包括分布式计算、内存计算、GPU加速等,可以满足大规模数据的存储和处理需求。在学习阿里云数据库的过程中,我收获了很多宝贵的经验和知识,也发现了一些值得...
    99+
    2023-10-30
    阿里 学习心得 数据库
  • PHP学习——phpstudy数据库连接(数据库创建,操作)
    一、创建一个数据库:   打开mysql 软件管理=》 phpMyAdmin=》安装=》管理 输入用户名密码(如果没有修改密码,密码为root)  创建一个数据库:  二、连接数据库 1.创建一个连接:使用mysqli_connec...
    99+
    2023-10-27
    php 数据库 开发语言 vscode sql
  • Python连接Postgres/Mysql/Mongo数据库基本操作
    这篇文章主要介绍“Python连接Postgres/Mysql/Mongo数据库基本操作”,在日常操作中,相信很多人在Python连接Postgres/Mysql/Mongo数据库基本操作问题上存在疑惑,小编查阅了各式资料,整理出简单好用的...
    99+
    2023-06-20
  • 大数据入门级学习:SQL与NOSQL数据库
    这几年的大数据热潮带动了一激活了一大批hadoop学习爱好者。有自学hadoop的,有报名培训班学习的。所有接触过hadoop的人都知道,单独搭建hadoop里每个组建都需要运行环境、修改配置文件测试等过程...
    99+
    2024-04-02
  • mysql数据库字符集学习总结
    MYSQL数据库字符集包括字符集(CHARACTER)和校对规则(COLLATION)两个概念。MYSQL 支持的字符集和校对规则可以通过命令showcharacter set;查看。和字符集有关的变量my...
    99+
    2024-04-02
  • MySQL学习之数据库备份详解
    目录1.DB,DBMS,SQL2.数据库的特点3.SQL分类4.mysql两种启动关闭方式5.mysql的登录方式()6.SQL语言规范7.navicat常用快捷键8.数据库的备份和...
    99+
    2024-04-02
  • Python深度学习albumentations数据增强库
    数据增强的必要性 深度学习在最近十年得以风靡得益于计算机算力的提高以及数据资源获取的难度下降。一个好的深度模型往往需要大量具有label的数据,使得模型能够很好的学习这种数据的分布。...
    99+
    2024-04-02
  • spring学习JdbcTemplate数据库事务管理
    目录spring JdbcTemplate数据库事务管理一、spring 中的事务管理二、spring 事务管理 API三、使用事务管理1. 配置文件2. 类上添加事务注解sprin...
    99+
    2024-04-02
  • 重新学习MySQL数据库开篇:数据库的前世今生
    本文内容出自刘欣的“码农翻身”公众号,强烈推荐刘欣大大的文章。...
    99+
    2024-04-02
  • 关于MongoDB数据库学习路线指南
    学习路线 1、MongoDB数据库学习大纲 2、MongoDB数据格式 3、MongoDB数据库特点 4、MongoDB数据库应用场景 5、MongoDB数据库单节点部署 6、MongoDB数据库常用操作指令 ...
    99+
    2023-04-12
    MongoDB数据库 MongoDB学习路线
  • Spring操作JdbcTemplate数据库的方法学习
    目录Spring操作JdbcTemplate一、准备工作1. 引入依赖2. 配置文件中配置数据库连接池3. 配置 JdbcTemplate 对象4. dao 中注入 JdbcTemp...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作