<分区>
我很惊讶这还没有发布。您知道 Postgres 中任何有趣的技巧吗?晦涩的配置选项和缩放/性能技巧特别受欢迎。
我相信我们可以击败相应 MySQL thread 上的 9 条评论:)
最佳答案
因为 postgres 比 MySQL 更理智,所以没有那么多“技巧”可以报告;-)
manual有一些不错的performance提示。
其他一些与性能相关的事情要记住:
这里有一些我发现有用的东西,它们本身与配置或性能无关。
查看当前发生的情况:
select * from pg_stat_activity;
搜索杂项函数:
select * from pg_proc WHERE proname ~* '^pg_.*'
查找数据库的大小:
select pg_database_size('postgres');
select pg_size_pretty(pg_database_size('postgres'));
查找所有数据库的大小:
select datname, pg_size_pretty(pg_database_size(datname)) as size
from pg_database;
查找表和索引的大小:
select pg_size_pretty(pg_relation_size('public.customer'));
或者,列出所有表和索引(可能更容易查看):
select schemaname, relname,
pg_size_pretty(pg_relation_size(schemaname || '.' || relname)) as size
from (select schemaname, relname, 'table' as type
from pg_stat_user_tables
union all
select schemaname, relname, 'index' as type
from pg_stat_user_indexes) x;
哦,你还可以嵌套事务,回滚部分事务++
test=# begin;
BEGIN
test=# select count(*) from customer where name='test';
count
-------
0
(1 row)
test=# insert into customer (name) values ('test');
INSERT 0 1
test=# savepoint foo;
SAVEPOINT
test=# update customer set name='john';
UPDATE 3
test=# rollback to savepoint foo;
ROLLBACK
test=# commit;
COMMIT
test=# select count(*) from customer where name='test';
count
-------
1
(1 row)
关于database - PostgreSQL 的隐藏特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/761327/