工作笔记知识点总结

📅 发布时间:2026/7/11 17:14:34 👁️ 浏览次数:
工作笔记知识点总结
1 MYSQL查看执行计划纤细1 explain format=tree或者explain analyze 看SQL真实执行计划。子查询推入。2 PG数据库确定主备角色的5种办法方式一:操作系统上查看WAL发送进程或WAL接收进程流复制主库上有WAL发送进程,流复制备库上有WAL接收进程主库[postgres@postgres pg11]$ ps -ef | grep "wal" | grep -v "grep"postgres 6199 6195 0 10:55 ? 00:00:01 postgres: walwriter postgres 25659 6195 0 19:03 ? 00:00:00 postgres: walsender replica 192.168.40.131(40508) streaming 0/5000360[postgres@postgres pg11]$备库[postgres@postgreshot ~]$ ps -ef | grep "wal" | grep -v "grep"postgres 4518 4511 0 10:19 ? 00:00:00 postgres: wal writer process postgres 93162 93157 0 19:03 ? 00:00:17 postgres: walreceiver streaming 0/5000360[postgres@postgreshot ~]$方式二:数据库上查看WAL发送进程或WAL接收进程数据库层面查看WAL发送进程和WAL接收进程,例如在主库上查询pg_stat_replication视图,如果返回记录说明是主库,备库上查询此视图无记录,如下所示:postgres=# SELECT pid,usename,application_name,client_addr,state,sync_state FROM pg_stat_replication ; pid | usename | application_name | client_addr | state | sync_state-------+---------+------------------+----------------+-----------+------------25659 | replica | pg1 | 192.168.40.131 | streaming | sync(1 row)同样,在备库上查看pg_stat_wal_receiver视图,如果返回记录说明是备库,流复制主库上