pg_dump -t [表名] -f [导出文件名.sql] [数据库]
只导出insert语句:pg_dump --table=[表名] --data-only --column-inserts [数据库] > [导出文件.sql]
psql -d [数据库] -f [导入文件名.sql]
select a.relpages, a.reltuples, a.relfilenode,a.reltype,b.typname from pg_class a, pg_type b where a.relname like ‘[数据表]’ and a.reltype=b.oid;
–查看数据库表的磁盘文件路径
select pg_relation_filepath(‘t_company_risk’);
select pg_size_pretty(pg_database_size(‘[数据库]’));
select pg_size_pretty(pg_table_size(‘t_company_risk’));
select pg_size_pretty(pg_relation_size(‘t_company_risk_pkey’));
select * from pg_indexes where tablename=‘t_company_risk’; – 查看表的索引
select indexrelname, pg_size_pretty(pg_relation_size(indexrelid)) from pg_stat_user_indexes where schemaname=‘public’ order by pg_relation_size(relid) desc;
select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname=‘public’ order by pg_relation_size(relid) desc;
vacuum full t_company_risk; – 回收指定表
select setval(‘t_report_component_id_seq’,(select max(id) from t_report_component));
CREATE INDEX ix_t_company_risk_company_id on t_company_risk(company_id);
CREATE UNIQUE INDEX t_company_risk_pkey ON t_company_risk USING btree (insert_key);–主键索引
1)修改配置文件postgres.conf
vim /data10/pgdata/postgresql.conf
2)加载配置
select pg_reload_conf();
确定是否修改
3)查看log
tail -f /data10/pgdata/pg_log/ postgresql-*.log
select * from pg_stat_activity;
select pid,application_name,client_addr,query_start,waiting,state,query from pg_stat_activity;
select count(1) from pg_stat_activity;
show max_connections;
su - postgres
#导出数据库
pg_dump [数据库名]> [导出文件名.sql]
#创建数据库
psql
create database [新数据库名];
#导入数据库
\q
psql -d [新数据库名] -f [导出文件名.sql];
1)vacuum full会lock table ,vacuum不会。
2)vacuum只是将deadtuple的行的空间转换为能够使用的状态,额外空间一般不会返回给os(除非文件末尾有大量的连续空闲空间)。vacuum full会将这些空间碎片后面的数据上移,将数据写入一个新的磁盘文件中。
su - postgres
pg_dump --table=t_cascade_lower_info --data-only --column-inserts situation > t_cascade_lower_info20200818.sql
SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS current_statement_in_blocking_process
FROM pg_catalog.pg_locks blocked_locks
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks blocking_locks
ON blocking_locks.locktype = blocked_locks.locktype
AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple
AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid
AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid
AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid
AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid
AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid
AND blocking_locks.pid != blocked_locks.pid
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
WHERE NOT blocked_locks.granted;