Common command records (linux, postgersql, nginx)

1. linux

Find files

# 简单参数(递归查询log文件)
find ./ -name '*.log'
# 复杂参数
find ./ -maxdepth 1 -type d|grep -v '.svn'|sort -V

Statistics of file sizes in folders

du -ah --max-depth=1

firewall

systemctll status firewalld.service
systemctll stop firewalld.service

clear cache

echo 3 > /proc/sys/vm/drop_caches

Remote login copy

# password为远程密码, sourceFilePath为源文件路径,targetIp为远程主机ip, targetPath为远程机器存放你文件位置
sshpass -p password scp -P 22 sourceFilePath root@targetIp:targetPath

2. Database

postgresql

Commonly used basic commands on the client

# 查看数据库
\l
# 查看表名
\d
# 帮助
\h
# 选择数据库
\c

# 重启
su - postgres
/opt/pgsql/bin/pg_ctl -w restart
/opt/pgsql/bin/pg_ctl reload

# dump为sql
pg_dump -U postgres -d hz_base -f dump.sql
# 创建
create database new_base
# 导入dump文件
psql -d new_base -U postgres -f dump.sql

system tables

  • All table data volume query (non-real-time)
# 查询所有t_开头的表的数据量
select relname tableName, reltuples tableSize from pg_class where relkind = 'r' and relname like 't_%';
  • table analysis

Perform table analysis first, and then query pg_class to get the latest table data volume\color{red}{Perform table analysis first, and then query pg\_class to get the latest table data volume}First perform table analysis ,Then query p g _ c l a ss to get the latest table data volume

# 单一表分析
analyse t_user;
# 分析所有表
analyse;
  • Query occupied connection
select * from pg_activity;
  • query blocking sql
-- 查询阻塞sql
select pid,pg_blocking_pids(pid) as blocked_by, query from pg_stat_activity where pg_blocking_pids(pid):: text != '{}';
  • Close the blocking connection (if a port is found in the query, the table name port is being closed)
select pg_terminate_backend(pg_catalog.pg_stat_activity.pid) from pg_stat_activity where pid<>pg_backend_pid() and datname = 'hz_base'; 
  • Query table without primary key
select * from pg_tables where schemaname = 'public' and hasindexes is false;

3. Nginx

# 启动
start nginx
# 退出
nginx -s stop
# 启动
nginx -s quit

Guess you like

Origin blog.csdn.net/pp_lan/article/details/131826934