工作中用pg,有些语法和其他的并不一样,记录下。
- 查看数据库中各个表(索引)大小
select
(n.nspname::text),
c.relname::text as relation,
pg_size_pretty(pg_total_relation_size(c.oid::regclass)) as total_table_size,
pg_size_pretty(pg_indexes_size(c.oid::regclass)) as total_index_size
from
pg_class c
left join pg_tablespace t on c.reltablespace = t.oid
left join pg_namespace n on n.oid = c.relnamespace
where (n.nspname <> all (array['pg_catalog'::name, 'information_schema'::name, 'pg_toast'::name]))
and c.relkind = 'r'::"char"
order by
(pg_total_relation_size(c.oid::regclass))
desc;
- 查看各个数据库的大小
select pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size from pg_database;
- 查看表的各个字段
select * from information_schema.columns where table_schema='test_schema' and table_name='test_table';
- 关联更新
update
tmp.order_table
set
create_time = tmp.test_order.create_time
from
tmp.test_order
where
tmp.test_order.id = tmp.order_table.id;
- 去掉字段的非空限制
alter table test.table_name alter column column_1 drop not null;