小编Iva*_*Paz的帖子

如何判断哪些索引没有被使用

PostgreSQL 9.3 Debian 7

我正在尝试优化的旧数据库中有很多巨大的索引。考虑丢弃所有无用的,但我怎么知道它们被使用的频率以及它们是否根本不使用。

是否有任何使用统计数据或一些技巧查询来做到这一点?

postgresql index index-statistics postgresql-9.3

7
推荐指数
2
解决办法
8448
查看次数

优化对两个大表的查询

我的系统中有一个非常重要的查询,由于表上的数据量很大,执行时间太长。我是一名初级 DBA,我需要为此进行最佳优化。每个表大约有 8000 万行。

表是:

tb_pd

   Column            |  Type   | Modifiers | Storage | Stats target | Description 
---------------------+---------+-----------+---------+--------------+-------------
 pd_id               | integer | not null  | plain   |              | 
 st_id               | integer |           | plain   |              | 
 status_id           | integer |           | plain   |              | 
 next_execution_date | bigint  |           | plain   |              | 
 priority            | integer |           | plain   |              | 
 is_active           | integer |           | plain   |              | 
Indexes:
    "pk_pd" PRIMARY KEY, btree (pd_id)
    "idx_pd_order" btree (priority, next_execution_date) …
Run Code Online (Sandbox Code Playgroud)

postgresql optimization index-tuning query-performance

4
推荐指数
1
解决办法
5466
查看次数

另一个模式中的序列权限

Postgres 9.3 Debian 7.0

我为特定用户创建了特定模式,并在此模式中为该用户创建了一个视图,因此这是他知道存在的唯一表。问题是这个用户需要使用这个表的主键的序列,但它说“错误:序列的权限被拒绝”

原始表及其序列属于模式 A。此用户的模式 B 具有此表 T 的可插入视图。我不能为该用户授予模式 A 的使用权,否则他将能够看到所有的名称和定义我的桌子。

问题是:有没有办法为这个序列创建某种视图,以便他可以调用 nextval() 和 currval()?目标是使该序列可用于该受限用户,而无需让他访问该序列实际所属的主模式。

schema postgresql permissions sequence postgresql-9.3

4
推荐指数
1
解决办法
9198
查看次数

为什么 postgres 使用与查询无关的奇数索引

(Debian 7, Postgres 9.3, 具有巨大缓存的专用机器)

我有一个名为 process_data (14gb) 的大表和另一个名为 process_location 的小查找表。我正在这两者之间进行查询,并且在解释查询中 Postgres 使用了一个与查询内容完全无关的奇数索引,如下所示:

询问:

select l.name,
       count(1) as quantity
from process_data pd
     join process_location l on pd.fk_location = l.id_process_location
where pd.active and pd.fk_status = 1
group by l.name
order by l.name
limit 1000
Run Code Online (Sandbox Code Playgroud)

解释查询给了我这个:

+----------------------------------------------------------------------------------------------------------------------------------------------+
|                                                                  QUERY PLAN                                                                  |
+----------------------------------------------------------------------------------------------------------------------------------------------+
| Limit  (cost=166513.62..166513.88 rows=107 width=33)                                                                                         |
|   ->  Sort  (cost=166513.62..166513.88 rows=107 width=33)                                                                                    |
|         Sort Key: s.name                                                                                                                     |
|         ->  HashAggregate  (cost=166508.94..166510.01 rows=107 width=33)                                                                     |
|               ->  Hash Join  (cost=4.84..165278.56 …
Run Code Online (Sandbox Code Playgroud)

postgresql index index-tuning postgresql-9.3

3
推荐指数
1
解决办法
206
查看次数