在 Postgres 8.4 上执行以下操作时:
select * from pg_stat_all_indexes where relname = 'table_name';
Run Code Online (Sandbox Code Playgroud)
它返回字段 idx_tup_read 和 idx_tup_fetch,有什么区别?
我正在阅读 postgresql 教程,我创建了我的数据库、2 个表、天气和城市,并添加了几行数据。例如,当我使用此 sql 语句查询我的数据库时:
SELECT city, temp_lo, temp_hi, prcp, date FROM weather;
Run Code Online (Sandbox Code Playgroud)
我应该得到这个:
city | temp_lo | temp_hi | prcp | date
--------------+---------+---------+------+------------
San Francisco | 46 | 50 | 0.25 | 1994-11-27
San Francisco | 43 | 57 | 0 | 1994-11-29
Hayward | 37 | 54 | | 1994-11-29
(3 rows)
Run Code Online (Sandbox Code Playgroud)
但我明白了:
San Francisco | 46 | 50 | 0.25 | 1994-11-27
San Francisco | 43 | 57 | 0 | 1994-11-29
Hayward | 37 …Run Code Online (Sandbox Code Playgroud) 有没有办法将 PostgreSQL 9.3 表空间从 物理移动/old/dir到/new/dir?我只想找到mv目录并告诉 PostgreSQL 表空间现在位于/new/dir. 看起来ALTER TABLESPACE只能让你重命名。
我想避免创建一个新的表空间并将数据库移动到它。我认为这将是一个需要大量时间和磁盘空间的缓慢复制过程。我也想避免符号链接/old/dir到/new/dir.
我希望标题是自我描述的。我希望能够以某种方式将任何 Postgres 元命令转换为其相应的/基础 SQL 查询,至少可以了解有关 Postgres 及其在表中存储元信息的方式的更多信息。
如果可能的话,有什么想法吗?
例如:
当连接到数据库的例子,
\dt并SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;返回相同的结果。
如果可能的话,我想找到一种SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;在输入\dt到函数/宏/任何东西时获取值的方法。
根据文档:
PL/Python 仅可用作“不受信任”的语言,这意味着它不提供任何方式来限制用户可以在其中执行的操作,因此被命名为 plpythonu。如果在 Python 中开发了安全执行机制,那么将来可能会出现可信变体 plpython。
为什么为 Python 开发安全执行机制却很难,而为其他语言(如 Perl)开发安全执行机制却没有?
在 Postgres 列上创建唯一约束是否不需要对其进行索引?
我希望自动需要一个索引来有效地维护约束。
有没有办法从表中删除任何列字段为空的行而无需明确指定哪一列为空?
我正在使用 postgreSQL。
这是我的关系模式:
Column | Type | Modifiers
--------------+---------+----------------------------------------------------------------------
id | integer | not null default nextval('aurostat.visitor_center_id_seq'::regclass)
date | date |
persons | integer |
two_wheelers | integer |
cars | integer |
vans | integer |
buses | integer |
autos | integer |
Run Code Online (Sandbox Code Playgroud)
谢谢
除了常规列之外,Postgres 表还有各种可用的系统列。其中之一,xmin,存储用于创建行的事务 ID。它的数据类型是xid,一个四字节整数,在某个点环绕(即不一定是唯一的)。该函数txid_current()反过来返回当前事务 ID,但作为bigint,因为它“使用“纪元”计数器进行了扩展,因此它不会在安装的生命周期内回绕”(引用手册)。
如果尚未发生交易回绕,则两个值似乎都匹配:
# CREATE TABLE test (label text);
CREATE TABLE
# INSERT INTO test VALUES ('test') RETURNING txid_current();
txid_current
--------------
674500
(1 row)
INSERT 0 1
# SELECT xmin FROM test;
xmin
--------
674500
(1 row)
Run Code Online (Sandbox Code Playgroud)
但我想知道:这两个值总是具有可比性吗?据我了解,txid_current()将在交易 ID 环绕(最多 2^32 个交易)后继续提供唯一值,xmin并将从零开始。这意味着两者都在那时开始返回不同的值?
如果这是真的,有没有办法来提取规则xid一的txid_current()结果,以便它匹配xmin的表(例如铸造项目txid_current(),以整数)?
编辑:更清楚地说明我关心事务 ID 环绕之后会发生什么,这很可能发生在 2^32 事务之前很久。感谢 Daniel Vérité 在评论中指出这一点。
以下对外部的查询在 320 万行上执行大约需要 5 秒:
SELECT x."IncidentTypeCode", COUNT(x."IncidentTypeCode")
FROM "IntterraNearRealTimeUnitReflexes300sForeign" x
WHERE x."IncidentDateTime" >= '05/01/2016'
GROUP BY x."IncidentTypeCode"
ORDER BY 1;
Run Code Online (Sandbox Code Playgroud)
当我在普通表上执行相同的查询时,它会在 0.6 秒内返回。执行计划完全不同:
SELECT x."IncidentTypeCode", COUNT(x."IncidentTypeCode")
FROM "IntterraNearRealTimeUnitReflexes300sForeign" x
WHERE x."IncidentDateTime" >= '05/01/2016'
GROUP BY x."IncidentTypeCode"
ORDER BY 1;
Run Code Online (Sandbox Code Playgroud)
Sort (cost=226861.20..226861.21 rows=4 width=4) (actual time=646.447..646.448 rows=7 loops=1)
Sort Key: "IncidentTypeCode"
Sort Method: quicksort Memory: 25kB
-> HashAggregate (cost=226861.12..226861.16 rows=4 width=4) (actual time=646.433..646.434 rows=7 loops=1)
Group Key: "IncidentTypeCode"
-> Bitmap Heap Scan on "IntterraNearRealTimeUnitReflexes300s" x (cost=10597.63..223318.41 rows=708542 width=4) …Run Code Online (Sandbox Code Playgroud) postgresql performance postgresql-fdw postgresql-9.5 query-performance
PgAdmin 4 1.0 刚刚发布,但在 Linux 的下载页面上只有一个指向 yum 安装程序的链接。
有人知道是否有计划创建 deb 安装程序吗?或者如果已经有一个?
postgresql ×10
debian ×1
index ×1
performance ×1
pgadmin ×1
plpython ×1
psql ×1
python ×1
security ×1
transaction ×1
ubuntu ×1