Skip to content

Instantly share code, notes, and snippets.

View ycku's full-sized avatar
😈
Be evil

Yung-Chung Ku ycku

😈
Be evil
View GitHub Profile
@ycku
ycku / DeleteVMrecord.sql
Last active April 8, 2020 02:52
[VMware Horizon] Desktop Composer Fault: Virtual Machine with Input Specification already exists
DECLARE @vmname VARCHAR(20)
set @vmname='VMXX-001'
delete FROM [vdi7s_composer].[dbo].[SVI_VM_NAME] where NAME=@vmname
delete FROM [vdi7s_composer].[dbo].[SVI_COMPUTER_NAME] where NAME=@vmname
delete FROM [vdi7s_composer].[dbo].[SVI_TASK_STATE] where SIM_CLONE_ID=(select id FROM [vdi7s_composer].[dbo].[SVI_SIM_CLONE] where VM_NAME=@vmname)
delete
FROM [vdi7s_composer].[dbo].[SVI_SC_PDISK_INFO] where PARENT_ID=(select id FROM [vdi7s_composer].[dbo].[SVI_SIM_CLONE] where VM_NAME=@vmname)
delete
FROM [vdi7s_composer].[dbo].[SVI_SC_BASE_DISK_KEYS] where PARENT_ID=(select id FROM [vdi7s_composer].[dbo].[SVI_SIM_CLONE] where VM_NAME=@vmname)
delete
@ycku
ycku / db-over-size.md
Last active May 23, 2020 15:14
你的資料庫有87%機率超過用量
Date Scale Size (MB)
2020/01/01 0 7.77
2020/02/01 10 157.00
2020/03/01 50 756.00
2020/04/01 100 1503.00
2020/04/02 100 1507.00
2020/04/03 100 1510.00
2020/04/04 100 1515.00
@ycku
ycku / view_to_pgbouncer.sql
Last active August 7, 2020 08:35
Create view to get information of pgbouncer if you need to process the pools
-- password is saved in ~/.pgpass
-- Connect to your pgbouncer and then get "SHOW CLIENTS"
-- SELECT * FROM pgbouncer.connect;
-- SELECT * FROM pgbouncer.clients;
CREATE EXTENSION IF NOT EXISTS dblink;
CREATE SCHEMA IF NOT EXISTS pgbouncer;
DROP VIEW pgbouncer.connect;
CREATE VIEW pgbouncer.connect AS SELECT dblink_connect('pgbouncer','host=localhost port=5432 user=pgbouncer dbname=pgbouncer');
@ycku
ycku / fix-permissions.ps1
Created August 24, 2020 09:48
Change/Fix the permissions after creating user's directory
$target_dir = "d:\temp"
# WHERE for safe test
# Process the whole directories by removing WHERE clause
$target_list = Get-ChildItem $target_dir | WHERE { $_.name -eq "00123456" }
foreach ($userdir in $target_list) {
$userdir.Fullname
$ACL = Get-ACL $userdir.Fullname
# Disable inheritance
$ACL.SetAccessRuleProtection($True, $False)
@ycku
ycku / Plan-Before-Tuning.md
Last active October 8, 2020 15:21
Query Plan 案例入門
                                                                     QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop Left Join  (cost=107446.22..266934.22 rows=1 width=60) (actual time=561.213..14329.521 rows=15 loops=1)
   ->  Nested Loop Left Join  (cost=107445.79..139804.60 rows=1 width=24) (actual time=558.920..7446.517 rows=15 loops=1)
         ->  Index Scan using dtapb001_pk on dtapb001 a  (cost=0.56..19.74 rows=1 width=18) (actual time=0.209..1.322 rows=15 loops=1)
               Index Cond: ((emp_id = 'JXXXXXXXXX'::bpchar) AND (vrfy_wkym <= '202009'::numeric) AND (vrfy_wkym >= '201908'::numeric))
               Filter: (substr((emp_org_id)::text, 2, 1) = '3'::text)
               Rows Removed by Filter: 30
         ->  Bitmap Heap Scan on pg060 s  (cost=107445.23..139784.85 rows=1 width=24) (actual time=496.333..496.333 rows=0 loops=15)
@ycku
ycku / Plan-After-Tuning.md
Created October 8, 2020 15:18
Query Plan 案例入門
                                                                 QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------
 Nested Loop Left Join  (cost=1.43..6360.93 rows=1 width=60) (actual time=19.573..273.880 rows=15 loops=1)
   ->  Nested Loop Left Join  (cost=0.99..2521.89 rows=1 width=24) (actual time=9.920..134.981 rows=15 loops=1)
         ->  Index Scan using dtapb001_pk on dtapb001 a  (cost=0.56..19.74 rows=1 width=18) (actual time=0.025..0.135 rows=15 loops=1)
               Index Cond: ((emp_id = 'JXXXXXXXXX'::bpchar) AND (vrfy_wkym <= '202009'::numeric) AND (vrfy_wkym >= '201908'::numeric))
               Filter: (substr((emp_org_id)::text, 2, 1) = '3'::text)
               Rows Removed by Filter: 30
         ->  Index Scan using pg060_idx2 on pg060 s  (cost=0.43..2502.14 rows=1 width=24) (actual time=8.987..8.987 rows=0 loops=15)
@ycku
ycku / README.md
Last active October 16, 2020 02:11
REINDEX order by indexsize

REINDEX 會影響線上作業, 在有限的作業時間內, 儘可能進行更多的 REINDEX

  • 在 DEADLINE 之前能做多少算多少, DEADLINE 之後就放棄
  • 此例以 INDEX SIZE 為最基本的排序, 大的先做
  • 後續可以再加上使用統計的條件, 更精確地 REINDEX 需要重建的索引
  • scripts.list 每行一個 shell 指令
  • maintenance.sh 可用於其他排程控制
  • SQL 語句條件記得要修改
$ psql --dbname=pgbench -t -f reindex_by_size_desc.sql &gt; scripts.list
@ycku
ycku / Disable-Secure-Boot.md
Created November 11, 2020 07:53
Disable Secure Boot in shim-signed
sudo mokutil --disable-validation
@ycku
ycku / wget-repository.md
Last active December 11, 2020 08:33
Quick notes of wget
  • 把指定來源的 repository 檔案都抓回來
wget -r -np --no-check-certificate http://fedora.cs.nctu.edu.tw/epel/8/Everything/x86_64/
@ycku
ycku / ssh.md
Last active December 11, 2020 08:56
Quick notes of ssh
  • 使用ssh跳版機(Bastion server)連線到 remote host
ssh -J bastion_user@bastion_host remote_user@remote_host
  • 使用ssh跳版機執行 scp
scp -oProxyJump=bastion_user@bastion_host remote_user@remote_host:/tmp/test.txt .