-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
1435 lines (1313 loc) · 61 KB
/
atom.xml
File metadata and controls
1435 lines (1313 loc) · 61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://hkxtor.github.io</id>
<title>老黄的养生会所</title>
<updated>2021-02-07T03:31:49.566Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="https://hkxtor.github.io"/>
<link rel="self" href="https://hkxtor.github.io/atom.xml"/>
<subtitle>宁可孤独,也不违心。不入我心者,不屑以敷衍。</subtitle>
<logo>https://hkxtor.github.io/images/avatar.png</logo>
<icon>https://hkxtor.github.io/favicon.ico</icon>
<rights>All rights reserved 2021, 老黄的养生会所</rights>
<entry>
<title type="html"><![CDATA[19C pdb开启awr以获取数据文件等io信息]]></title>
<id>https://hkxtor.github.io/k8frSam77/</id>
<link href="https://hkxtor.github.io/k8frSam77/">
</link>
<updated>2021-02-07T03:30:17.000Z</updated>
<content type="html"><![CDATA[<h1 id="现象">现象</h1>
<pre><code class="language-sql">sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Jan 24 12:50:58 2021
Version 19.10.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 HKXTOR READ WRITE NO
4 SJZX READ WRITE NO
SQL> alter session set container=hkxtor
2 ;
Session altered.
SQL> show con_name
CON_NAME
------------------------------
HKXTOR
SQL> @?/rdbms/admin/awrrpt.sql
Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type:
old 1: select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual
new 1: select 'Type Specified: ',lower(nvl('','html')) report_type from dual
Type Specified: html
Specify the location of AWR Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AWR_ROOT - Use AWR data from root (default)
AWR_PDB - Use AWR data from PDB
Enter value for awr_location: AWR_PDB
Location of AWR Data Specified:
AWR_PDB
Current Instance
~~~~~~~~~~~~~~~~
DB Id DB Name Inst Num Instance Container Name
-------------- -------------- -------------- -------------- --------------
3516530670 CDB 1 cdb HKXTOR
Root DB Id Container DB Id AWR DB Id
--------------- --------------- ---------------
299079762 3516530670 3516530670
Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Using 3516530670 for database Id
Using 1 for instance number
declare
*
ERROR at line 1:
ORA-20200: Database/Instance 3516530670/1 does not exist in
AWR_PDB_DATABASE_INSTANCE
ORA-06512: at line 27
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.10.0.0.0
</code></pre>
<h1 id="mos">MOS:</h1>
<p>ORA-20200 Error When Generating AWR or ADDM Report as a PDB DBA User From a 12.2.0.1 and higher CDB Database (Doc ID 2267849.1)<br>
Bug 25941188 - ORA-20200 WHEN ADDM REPORT GENERATED FROM A PDB DATABASE USING AWR_PDB OPTION <==closed as duplicate to following internal bug that is still being worked on:<br>
Bug 27747951 : CDB_MA: ADDMRPT.SQL EXECUTION IN PDB LEVEL</p>
<h1 id="解决办法">解决办法:</h1>
<pre><code>ALTER SYSTEM SET awr_pdb_autoflush_enabled= TRUE SID='*' SCOPE=BOTH;
ALTER SYSTEM SET awr_snapshot_time_offset=1000000 SID='*' SCOPE=BOTH;
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[RushQL勒索病毒的处理]]></title>
<id>https://hkxtor.github.io/ihIcEuWzN/</id>
<link href="https://hkxtor.github.io/ihIcEuWzN/">
</link>
<updated>2020-08-20T09:01:14.000Z</updated>
<content type="html"><![CDATA[<h1 id="rushql病毒简介">RushQL病毒简介</h1>
<p>RushQL专门针对Oracle数据库设计、具备一定潜伏期和隐蔽性的勒索病毒,该病毒是由“SQL RUSH Team”组织发起,最早于2016年11月出现,其主要感染方式是将破解版或绿色版的PL/SQL中的login.sql和Afterconnect.sql脚本篡改,所以在使用前需检查这两个脚本,若其大小不为零,则很有可能已被篡改。运行被篡改后的脚本会在数据库中增加下列存储过程和触发器:</p>
<pre><code class="language-sql">存储过程:
DBMS_SUPPORT_INTERNAL
DBMS_STANDARD_FUN9
DBMS_SYSTEM_INTERNA
DBMS_CORE_INTERNAL
触发器:
DBMS_SUPPORT_INTERNAL
DBMS_SYSTEM_INTERNAL
DBMS_CORE_INTERNAL
</code></pre>
<h1 id="中毒表现">中毒表现</h1>
<p>RushQL病毒感染Oracle数据库后,先判断数据库的创建时长是否达到1200天,若不满足此条件,则会一直潜伏,满足条件后再爆发。爆发后,用户使用客户端连接数据库或者数据库Alert日志中出现ORA-20312/ORA-20313/ORA-20315等报错信息,描述数据库已被锁死,需要发送比特币到某个地址来解锁数据库。</p>
<pre><code class="language-sql">Errors in file /oracle/diag/rdbms/liantiaodb/liantiaodb/trace/liantiaodb_ora_5213.trc:
ORA-00604: 递归 SQL 级别 1 出现错误
ORA-20315: 你的数据库已被SQL RUSH Team锁死 发送5个比特币到这个地址 166xk1FXMB2g8JxBVF5T4Aw1Z5JaZ6vrSE (大小写一致) 之后把你的Oracle SID邮寄地址 sqlrush@mail.com 我们将让你知道如何解锁你的数据库 Hi buddy, your database was hacked by SQL RUSH Team, send 5 bitcoin to address 166xk1FXMB2g8JxBVF5T4Aw1Z5JaZ6vrSE (case sensitive), after that send your Oracle SID to mail address sqlrush@mail.com, we will let you know how to unlock your database.
ORA-06512: 在 "AIQRY.DBMS_CORE_INTERNAL ", line 25
ORA-06512: 在 line 2
</code></pre>
<h1 id="病毒检测">病毒检测</h1>
<p>已中毒的Oracle数据库中会多出上述存储过程和触发器,且该病毒的制作者非常狡猾的在上述存储过程和触发器的名字中加入了多个空格,导致其无法被查询到和被删除,因此,在进行查询和删除时要加入通配符:</p>
<pre><code class="language-sql">SELECT owner,created,object_name,object_type FROM dba_objects WHERE object_name LIKE '%DBMS_SUPPORT%';
SELECT owner,created,object_name,object_type FROM dba_objects WHERE object_name LIKE '%DBMS_SYSTEM_INTERNAL%';
SELECT owner,created,object_name,object_type FROM dba_objects WHERE object_name LIKE '%DBMS_CORE_INTERNAL%';
SELECT owner,created,object_name,object_type FROM dba_objects WHERE object_name LIKE '%DBMS_STANDARD_FUN9%';
</code></pre>
<p>未爆发的数据库中可以检测到上述存储过程和触发器,已爆发的数据库中除了能检测到上述存储过程和触发器,还会存在很多truncate jobs,产生非常多的日志,导致数据库空间被大量占用,最终将数据库目录被挤爆,数据库服务中断。</p>
<pre><code class="language-sql">SELECT COUNT(*) FROM dba_jobs WHERE schema_user='username' AND what LIKE '%truncate%';
username为上述查询结果中的owner
</code></pre>
<h1 id="病毒处理">病毒处理</h1>
<p>参考:https://blogs.oracle.com/cnsupport_news/%e5%af%b9%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e2%80%9c%e6%af%94%e7%89%b9%e5%b8%81%e6%94%bb%e5%87%bb%e2%80%9d%e5%8f%8a%e9%98%b2%e6%8a%a4<br>
删除上述存储过程和触发器:</p>
<pre><code class="language-sql">DROP PROCEDURE %DBMS_SUPPORT_INTERNAL%;
DROP PROCEDURE %DBMS_STANDARD_FUN9%;
DROP PROCEDURE %DBMS_SYSTEM_INTERNA%;
DROP PROCEDURE %DBMS_CORE_INTERNAL%;
DROP TRIGGER %DBMS_SUPPORT_INTERNAL%;
DROP TRIGGER %DBMS_SYSTEM_INTERNAL%;
DROP TRIGGER %DBMS_CORE_INTERNAL%;
</code></pre>
<p>删除异常的jobs:</p>
<pre><code class="language-sql">DELETE FROM dba_jobs WHERE schema_user='username' AND what LIKE '%truncate%';
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[clickhouse installation on centos 7.8]]></title>
<id>https://hkxtor.github.io/t-ZQVW9TS/</id>
<link href="https://hkxtor.github.io/t-ZQVW9TS/">
</link>
<updated>2020-06-02T07:54:32.000Z</updated>
<content type="html"><![CDATA[<h2 id="系统检查">系统检查</h2>
<pre><code># grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
SSE 4.2 supported
</code></pre>
<h2 id="rpm包安装">RPM包安装</h2>
<pre><code>建议对CentOS,RedHat和所有其他基于rpm的Linux发行版使用官方的预编译rpm软件包。
sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64
</code></pre>
<h2 id="启动">启动</h2>
<pre><code>systemctl daemon-reload
systemctl start clickhouse-server.service
# systemctl status clickhouse-server.service
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-06-02 15:45:22 CST; 8s ago
Main PID: 13949 (clickhouse-serv)
Tasks: 44
Memory: 163.9M
CGroup: /system.slice/clickhouse-server.service
└─13949 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
Jun 02 15:45:22 hqcentos clickhouse-server[13949]: Include not found: clickhouse_compression
Jun 02 15:45:22 hqcentos clickhouse-server[13949]: Logging trace to /var/log/clickhouse-server/clickhouse-server.log
Jun 02 15:45:22 hqcentos clickhouse-server[13949]: Logging errors to /var/log/clickhouse-server/clickhouse-server.err.log
Jun 02 15:45:28 hqcentos clickhouse-server[13949]: Processing configuration file '/etc/clickhouse-server/users.xml'.
Jun 02 15:45:28 hqcentos clickhouse-server[13949]: Include not found: networks
Jun 02 15:45:28 hqcentos clickhouse-server[13949]: Saved preprocessed configuration to '/var/lib/clickhouse//preprocessed_configs/users.xml'.
Jun 02 15:45:30 hqcentos clickhouse-server[13949]: Processing configuration file '/etc/clickhouse-server/config.xml'.
Jun 02 15:45:30 hqcentos clickhouse-server[13949]: Include not found: clickhouse_remote_servers
Jun 02 15:45:30 hqcentos clickhouse-server[13949]: Include not found: clickhouse_compression
Jun 02 15:45:30 hqcentos clickhouse-server[13949]: Saved preprocessed configuration to '/var/lib/clickhouse//preprocessed_configs/config.xml'.
</code></pre>
<h2 id="登录">登录</h2>
<pre><code># clickhouse-client
ClickHouse client version 20.4.4.18 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 20.4.4 revision 54434.
hqcentos :) select 1;
SELECT 1
┌─1─┐
│ 1 │
└───┘
1 rows in set. Elapsed: 0.002 sec.
hqcentos :)
</code></pre>
<p>简单的安装配置到此结束</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Oracle rman恢复遇到Error validating file dummy (36) in piece xxx: missing header]]></title>
<id>https://hkxtor.github.io/DAs8G2vZY/</id>
<link href="https://hkxtor.github.io/DAs8G2vZY/">
</link>
<updated>2020-05-14T03:22:56.000Z</updated>
<content type="html"><![CDATA[<h1 id="过程">过程</h1>
<p>用参数拉起实例后,还原控制文件,数据库拉起到mount状态,catalog start with xx注册备份文件。</p>
<h1 id="现象">现象</h1>
<p>执行catalog start with xx后,alert日志出现以下信息</p>
<pre><code>Thu May 14 11:18:24 2020
Setting recovery target incarnation to 2
Setting recovery target incarnation to 2
Error validating file dummy (14) in piece xxx: missing header
Expanded controlfile section 14 from 245 to 490 records
Requested to grow by 245 recards; added 3 blocks of records
</code></pre>
<p>执行还原脚本出现以下报错后退出</p>
<pre><code>ORA-01180: can not create datafile 1
ORA-01110: data file 1: '+DATA/xxxx/datafile/system01.dbf'
</code></pre>
<h1 id="解决过程">解决过程</h1>
<p>rman中查看incarnation</p>
<pre><code>RMAN> list incarnation;
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- ------ ------------------ ----------
1 1 ORCL 1446008355 PARENT 1 2014/12/26 14:31:00
2 2 ORCL 1446008355 CURRENT 17034938503292 2020/05/09 17:34:36
</code></pre>
<p>重置incarnation回1</p>
<pre><code>RMAN> reset database to incarnation 1;
database reset to incatnation 1
RMAN> list incarnation;
List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- ------ ------------------ ----------
1 1 ORCL 1446008355 CURRENT 1 2014/12/26 14:31:00
2 2 ORCL 1446008355 ORPHAN 17034938503292 2020/05/09 17:34:36
</code></pre>
<p>观察alert日志</p>
<pre><code>Thu May 14 11:21:28 2020
Setting recovery target incarnation to 1
</code></pre>
<p>在执行还原脚本,还原成功</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[mysql无损/半同步复制]]></title>
<id>https://hkxtor.github.io/BwozcZWlU/</id>
<link href="https://hkxtor.github.io/BwozcZWlU/">
</link>
<updated>2020-04-28T11:34:45.000Z</updated>
<content type="html"><![CDATA[<p>1.参数文件里加</p>
<pre><code>plugin_dir=/usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
</code></pre>
<p>2.主库准备步骤</p>
<pre><code>grant replication slave, replication client on *.* to rep@'192.168.56.%' identified by '123456';
flush privileges;
mysql> show master status;
+------------+----------+--------------+------------------+----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------+----------+--------------+------------------+----------------------------------------------+
| bin.000007 | 57566891 | | | 35d3ad22-8862-11ea-97a1-080027bb5279:1-43998 |
+------------+----------+--------------+------------------+----------------------------------------------+
</code></pre>
<p>3.备库准备步骤</p>
<pre><code>change master to master_host='192.168.56.101',master_user='rep',master_password='123456',master_log_file='bin.000007', master_log_pos=57566891,master_port = 3306;
</code></pre>
<p>4.测试</p>
<pre><code># 主库执行
mysql> show variables like '%rpl%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 5000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
| rpl_stop_slave_timeout | 31536000 |
+-------------------------------------------+------------+
9 rows in set (0.00 sec)
mysql> show global status like "%rpl%";
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 0 |
| Rpl_semi_sync_master_no_times | 1 |
| Rpl_semi_sync_master_no_tx | 2 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 0 |
| Rpl_semi_sync_master_tx_wait_time | 0 |
| Rpl_semi_sync_master_tx_waits | 0 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 0 |
| Rpl_semi_sync_slave_status | OFF |
+--------------------------------------------+-------+
15 rows in set (0.00 sec)
# 从库执行
mysql> show global variables like '%semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 5000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.00 sec)
mysql> stop slave io_thread;
Query OK, 0 rows affected (0.00 sec)
# 主库执行
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database test;
Query OK, 1 row affected (5.00 sec) ---(rpl_semi_sync_master_timeout设置的5秒超时)
mysql> show global status like "%rpl%";
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 0 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 0 |
| Rpl_semi_sync_master_no_times | 2 |
| Rpl_semi_sync_master_no_tx | 3 |
| Rpl_semi_sync_master_status | OFF |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 0 |
| Rpl_semi_sync_master_tx_wait_time | 0 |
| Rpl_semi_sync_master_tx_waits | 0 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 0 |
| Rpl_semi_sync_slave_status | OFF |
+--------------------------------------------+-------+
15 rows in set (0.00 sec)
# 从库执行
start slave io_thread;
# 主库执行
mysql> show global status like "%rpl%";
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 1 |
| Rpl_semi_sync_master_no_times | 2 |
| Rpl_semi_sync_master_no_tx | 3 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 0 |
| Rpl_semi_sync_master_tx_wait_time | 0 |
| Rpl_semi_sync_master_tx_waits | 0 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 0 |
| Rpl_semi_sync_slave_status | OFF |
+--------------------------------------------+-------+
15 rows in set (0.00 sec)
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[MySQL自带的性能压力测试工具mysqlslap]]></title>
<id>https://hkxtor.github.io/DQakzE_dy/</id>
<link href="https://hkxtor.github.io/DQakzE_dy/">
</link>
<updated>2020-04-28T10:30:07.000Z</updated>
<content type="html"><![CDATA[<pre><code>--only-print 只打印测试语句而不实际执行。
--detach=N 执行N条语句后断开重连。
# 单线程测试。测试做了什么。
mysqlslap -a -uroot -p123456
# 多线程测试。使用–concurrency来模拟并发连接。
mysqlslap -a -c 100 -uroot -p123456
# 迭代测试。用于需要多次执行测试得到平均值。
mysqlslap -a -i 10 -uroot -p123456
mysqlslap --auto-generate-sql-add-autoincrement -a -uroot -p123456
mysqlslap -a --auto-generate-sql-load-type=mixed -uroot -p123456
mysqlslap -a --auto-generate-sql-secondary-indexes=3 -uroot -p123456
mysqlslap -a --auto-generate-sql-write-number=1000 -uroot -p123456
mysqlslap --create-schema world -q "select count(*) from City" -uroot -p123456
mysqlslap -a -e innodb -uroot -p123456
mysqlslap -a --number-of-queries=10 -uroot -p123456
# 测试同时不同的存储引擎的性能进行对比:
mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-info -uroot -p123456
# 500和1000个并发分别得到一次测试结果(Benchmark),并发数越多,执行完所有查询的时间越长。为了准确起见,可以多测试几次:
mysqlslap -a --concurrency=500,1000 --auto-generate-sql-add-autoincrement --auto-generate-sql-secondary-indexes=10 --number-of-queries 2000 --iterations=5
Benchmark
Average number of seconds to run all queries: 1.551 seconds
Minimum number of seconds to run all queries: 1.441 seconds
Maximum number of seconds to run all queries: 1.716 seconds
Number of clients running queries: 500
Average number of queries per client: 4
Benchmark
Average number of seconds to run all queries: 1.734 seconds
Minimum number of seconds to run all queries: 1.589 seconds
Maximum number of seconds to run all queries: 1.911 seconds
Number of clients running queries: 1000
Average number of queries per client: 2
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Mysql 长事务处理]]></title>
<id>https://hkxtor.github.io/0k4Pjffz5/</id>
<link href="https://hkxtor.github.io/0k4Pjffz5/">
</link>
<updated>2019-06-26T09:01:03.000Z</updated>
<content type="html"><![CDATA[<h1 id="1-背景">1. 背景</h1>
<pre><code>1. 某个SQL执行特别慢,导致整个transaction一直处于running阶段
2. 某个Session的SQL已经执行完了,但是迟迟没有commit,一直处于sleep阶段
3. 某个Session处于lock wait阶段,迟迟没有结束
4. 以上,大部分原因都是大事务导致的,怎么处理呢
</code></pre>
<h1 id="2-大事务的特征">2. 大事务的特征</h1>
<pre><code>1. transaction开启到结束的时间非常长
2. 正在执行的事务
3. 未提交的事务
</code></pre>
<h2 id="21-监控那些正在执行的事务">2.1 监控那些正在执行的事务</h2>
<pre><code class="language-sql">select * from sys.processlist;
show processlist;
select * from information_schema.processlist;
select * from sys.session;
select * from information_schema.innodb_trx;
select * from performance_schema.events_statements_current;
</code></pre>
<h2 id="22-如何监控那些未提交的事务">2.2 如何监控那些未提交的事务</h2>
<pre><code class="language-sql">select * from information_schema.innodb_trx
如何两者结合
select trx_id,INNODB_TRX.trx_state,INNODB_TRX.trx_started,se.conn_id as processlist_id,trx_lock_memory_bytes,se.user,se.command,se.state,se.current_statement,se.last_statement from information_schema.INNODB_TRX,sys.session as se where trx_mysql_thread_id=conn_id;
+---------+-----------+---------------------+----------------+-----------------------+------+---------+----------+-------------------------------------+-------------------------------------+
| trx_id | trx_state | trx_started | processlist_id | trx_lock_memory_bytes | user | command | state | current_statement | last_statement |
+---------+-----------+---------------------+----------------+-----------------------+------+---------+----------+-------------------------------------+-------------------------------------+
| 1592104 | LOCK WAIT | 2019-06-26 11:51:17 | 3 | 1136 | NULL | Query | updating | update test_1 set id=4 where id = 1 | NULL |
| 1592100 | RUNNING | 2019-06-26 11:49:08 | 2 | 1136 | NULL | Sleep | NULL | NULL | update test_1 set id=3 where id = 1 |
+---------+-----------+---------------------+----------------+-----------------------+------+---------+----------+-------------------------------------+-------------------------------------+
</code></pre>
<h1 id="3-如何快速解决锁等待问题">3. 如何快速解决锁等待问题</h1>
<pre><code class="language-sql">mysql:sys> select * from sys.innodb_lock_waits\G
*************************** 1. row ***************************
wait_started: 2019-06-26 11:49:58
wait_age: 00:00:03
wait_age_secs: 3
locked_table: `test`.`test_1`
locked_index: GEN_CLUST_INDEX
locked_type: RECORD
waiting_trx_id: 1592102
waiting_trx_started: 2019-06-26 11:49:58
waiting_trx_age: 00:00:03
waiting_trx_rows_locked: 2
waiting_trx_rows_modified: 0
waiting_pid: 3
waiting_query: update test_1 set id=4 where id = 1
waiting_lock_id: 1592102:32:3:4
waiting_lock_mode: X
blocking_trx_id: 1592100
blocking_pid: 2
blocking_query: NULL
blocking_lock_id: 1592100:32:3:4
blocking_lock_mode: X
blocking_trx_started: 2019-06-26 11:49:08
blocking_trx_age: 00:00:53
blocking_trx_rows_locked: 1
blocking_trx_rows_modified: 1
sql_kill_blocking_query: KILL QUERY 2
sql_kill_blocking_connection: KILL 2
MySQL连kill SQL 语句都提供了
通过innodb_lock_waits你只能看到被lock的语句,但是看不到是哪个query语句拥有的锁,如果幸运的话,可以看到上述的案例中 current_statement,last_statement 得到答案。
即便没有找到那条query,也不妨碍你解决当前的问题哈
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[11.2单机数据库转换为RAC -- 使用rconfig]]></title>
<id>https://hkxtor.github.io/eP0H2Pm3z/</id>
<link href="https://hkxtor.github.io/eP0H2Pm3z/">
</link>
<updated>2018-11-06T03:04:51.000Z</updated>
<content type="html"><![CDATA[<h1 id="简介">简介</h1>
<p>rconfig的功能除了单机转换为RAC,还可以单机转换为Standalone,Standalone转换为RAC,RAC转换为Standalone等等。</p>
<h1 id="配置文件">配置文件</h1>
<pre><code class="language-xml"><?xml version="1.0" encoding="UTF-8"?>
<n:RConfig xmlns:n="http://www.oracle.com/rconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oracle.com/rconfig rconfig.xsd">
<n:ConvertToRAC>
<!-- Verify does a precheck to ensure all pre-requisites are met, before the conversion is attempted. Allowable values are: YES|NO|ONLY -->
<n:Convert verify="YES">
<!--Specify current OracleHome of non-rac database for SourceDBHome -->
<n:SourceDBHome>/u01/app/oracle/product/11.2.0/db_1</n:SourceDBHome>
<!--Specify OracleHome where the rac database should be configured. It can be same as SourceDBHome -->
<n:TargetDBHome>/u01/app/oracle/product/11.2.0/db_1</n:TargetDBHome>
<!--Specify SID of non-rac database and credential. User with sysdba role is required to perform conversion -->
<n:SourceDBInfo SID="test">
<n:Credentials>
<n:User>sys</n:User>
<n:Password>Oracle123</n:Password>
<n:Role>sysdba</n:Role>
</n:Credentials>
</n:SourceDBInfo>
<!--Specify the list of nodes that should have rac instances running for the Admin Managed Cluster Database. LocalNode should be the first node in this nodelist. -->
<n:NodeList>
<n:Node name="rac1"/>
<n:Node name="rac2"/>
</n:NodeList>
<!--Specify RacOneNode along with servicename to convert database to RACOne Node -->
<!--n:RacOneNode servicename="salestestservice"/-->
<!--Instance Prefix tag is optional starting with 11.2. If left empty, it is derived from db_unique_name.-->
<n:InstancePrefix>test</n:InstancePrefix>
<!-- Listener details are no longer needed starting 11.2. Database is registered with default listener and SCAN listener running from Oracle Grid Infrastructure home. -->
<!--Specify the type of storage to be used by rac database. Allowable values are CFS|ASM. The non-rac database should have same storage type. ASM credentials are no needed for conversion. -->
<n:SharedStorage type="ASM">
<!--Specify Database Area Location to be configured for rac database.If this field is left empty, current storage will be used for rac database. For CFS, this field will have directory path. -->
<n:TargetDatabaseArea>+DATADG1</n:TargetDatabaseArea> # 如果已经转成使用asm,则留空,否则会使用rman进行backup as copy database的操作,消耗更多空间
<!--Specify Fast Recovery Area to be configured for rac database. If this field is left empty, current recovery area of non-rac database will be configured for rac database. If current database is not using recovery Area, the resulting rac database will not have a recovery area. -->
<n:TargetFlashRecoveryArea>+DATADG1</n:TargetFlashRecoveryArea> # 如果已经转成使用asm,则留空,否则会使用rman进行backup as copy database的操作,消耗更多空间
</n:SharedStorage>
</n:Convert>
</n:ConvertToRAC>
</n:RConfig>
</code></pre>
<h1 id="用法">用法</h1>
<pre><code>rconfig test.xml
</code></pre>
<h1 id="对应日志">对应日志</h1>
<pre><code>$ORACLE_BASE/cfgtoollogs/rconfig/
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[MySQL体系结构与管理]]></title>
<id>https://hkxtor.github.io/1VMe2UNvc/</id>
<link href="https://hkxtor.github.io/1VMe2UNvc/">
</link>
<updated>2018-04-27T10:24:03.000Z</updated>
<content type="html"><![CDATA[<h1 id="1体系结构">1.体系结构</h1>
<h2 id="11-cs模型">1.1 C/S模型</h2>
<pre><code>TCP/IP方式(远程、本地):
mysql -uroot -123456 -h 10.0.0.51 -P3306
Socket方式(仅本地):
mysql -uroot -123456 -S /tmp/mysql.sock
</code></pre>
<h2 id="12-实例">1.2 实例</h2>
<pre><code>实例=mysqld后台守护进程+Master Thread +干活的Thread+预分配的内存
</code></pre>
<h2 id="13-mysqld">1.3 mysqld</h2>
<h3 id="131-mysqld程序结构">1.3.1 mysqld程序结构</h3>
<figure data-type="image" tabindex="1"><img src="https://cdn.jsdelivr.net/gh/Hkxtor/picb/img/16956686-7824255ca53f23e5.png" alt="" loading="lazy"></figure>
<h4 id="1311-连接层">1.3.1.1 连接层</h4>
<pre><code>1.3.2.1 连接层
(1)提供连接协议:TCP/IP 、SOCKET
(2)提供验证:用户、密码,IP,SOCKET
(3)提供专用连接线程:接收用户SQL,返回结果
通过以下语句可以查看到连接线程基本情况
mysql> show processlist;
</code></pre>
<h4 id="1312-sql层">1.3.1.2 SQL层</h4>
<pre><code>(1)接收上层传送的SQL语句
(2)语法验证模块:验证语句语法,是否满足SQL_MODE
(3)语义检查:判断SQL语句的类型
DDL :数据定义语言
DCL :数据控制语言
DML :数据操作语言
DQL: 数据查询语言
(4)权限检查:用户对库表有没有权限
(5)解析器:对语句执行前,进行预处理,生成解析树(执行计划),说白了就是生成多种执行方案.
(6)优化器:根据解析器得出的多种执行计划,进行判断,选择最优的执行计划代价模型:资源(CPU IO MEM)的耗损评估性能好坏
(7)执行器:根据最优执行计划,执行SQL语句,产生执行结果执行结果:在磁盘的xxxx位置上
(8)提供查询缓存(默认是没开启的),会使用redis tair替代查询缓存功能
(9)提供日志记录(日志管理章节):binlog,默认是没开启的。
</code></pre>
<h4 id="1313-存储引擎层">1.3.1.3 存储引擎层</h4>
<pre><code>负责根据SQL层执行的结果,从磁盘上拿数据。
将16进制的磁盘数据,交由SQL结构化化成表,由连接层的专用线程返回给用户。
</code></pre>
<h2 id="14-逻辑结构">1.4 逻辑结构</h2>
<h3 id="141-库">1.4.1 库</h3>
<pre><code>每一个库都有库名、库属性组成,库属性包括字符集、校对规则等等。
</code></pre>
<h3 id="142-表二维表">1.4.2 表(二维表)</h3>
<pre><code>每一张表都有表名、属性、列(列名)、列属性(数据类型、约束等等)、数据行(record)、元数据组成。
</code></pre>
<h2 id="15-物理结构">1.5 物理结构</h2>
<h3 id="151-库的物理存储结构">1.5.1 库的物理存储结构</h3>
<pre><code>每一个库的物理存储结构都是由文件系统的目录来存储的,一个库就是一个目录。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
[root@mysql1 data]# ls -ltr
drwxr-x---. 2 mysql mysql 8192 Apr 27 16:36 performance_schema
drwxr-x---. 2 mysql mysql 4096 Apr 27 16:36 mysql
drwxr-x---. 2 mysql mysql 8192 Apr 27 16:36 sys
drwxr-x---. 2 mysql mysql 20 Apr 28 16:57 test
</code></pre>
<h3 id="152-表的物理存储结构">1.5.2 表的物理存储结构</h3>
<pre><code>MyISAM(一种引擎)的表:
-rw-r----- 1 mysql mysql 10816 Apr 18 11:37 user.frm
-rw-r----- 1 mysql mysql 396 Apr 18 12:20 user.MYD
-rw-r----- 1 mysql mysql 4096 Apr 18 14:48 user.MYI
InnoDB(默认的存储引擎)的表:
-rw-r----- 1 mysql mysql 8636 Apr 18 11:37 time_zone.frm
-rw-r----- 1 mysql mysql 98304 Apr 18 11:37 time_zone.ibd
time_zone.frm:存储列相关信息
time_zone.ibd:数据行+索引
</code></pre>
<h3 id="153-表的段-区-页">1.5.3 表的段、区、页</h3>
<pre><code>页:最小的存储单元,默认16k
区:64个连续的页,共1M
段:一个表就是一个段,包含一个或多个区
</code></pre>
<h1 id="2-基础管理">2. 基础管理</h1>
<h2 id="21-用户-权限管理">2.1 用户、权限管理</h2>
<h3 id="211-用户">2.1.1 用户</h3>
<p>作用:</p>
<pre><code>登录,管理数据库逻辑对象
</code></pre>
<p>定义:</p>
<pre><code>用户名@'白名单'
白名单支持的方式:
root@'%' 允许所有地址、域名
root@'192.0.0.%' 允许192.0.0.0/24
root@'192..0.0.200' 只允许这个用记在200地址的这台机器上登录
root@'localhost' 只能本地连接
root@'db01' 只能这个域名
root@'192.0.0.5%' 只能50-59ip的用户登录
root@'192.0.0.0/255.255.254.0' 只允许这个网段的子网掩码是254的用户登录
</code></pre>
<p>管理:</p>
<pre><code class="language-sql">增:
mysql> create user hkxtor@'10.0.0.%' identified by '123';
查:
mysql> desc mysql.user; ----> authentication_string
mysql> select user ,host ,authentication_string from mysql.user
改:
mysql> alter user hkxtor@'10.0.0.%' identified by '456';
删:
mysql> drop user hkxtor@'10.0.0.%';
</code></pre>
<h3 id="212-权限">2.1.2 权限</h3>
<p>权限介绍:</p>
<pre><code>相对于用户而言,用户所能访问只是权限的一部分功能,MySQL能精确针对用户修改用户对哪一个库或者哪一张表进行查询、修改、删除、创建权限,超级管理员还具备给别的用户进行用户授权的权限。
</code></pre>
<p>常用权限:</p>
<pre><code>ALL:
SELECT,INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE
ALL : 以上所有权限,一般是普通管理员拥有的
with grant option:超级管理员才具备的,给别的用户授权的功能
</code></pre>
<p>演示:</p>
<pre><code>create user hkxtor@'%' identified by '123'; 创建用户以及设置访问区域及密码
grant all on test.* to hkxtor@'%'; 赋予用户hkxtor所有区域进行访问库test的权限
show grants for hkxtor@'%'; 查看用户所被赋予的权限
mysql [(none)]>show grants for hkxtor@'%';
+--------------------------------------------------+
| Grants for hkxtor@% |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO 'hkxtor'@'%' |
| GRANT ALL PRIVILEGES ON `test`.* TO 'hkxtor'@'%' |
+--------------------------------------------------+
2 rows in set (0.01 sec)
revoke delete on test.* from 'hkxtor'@'%'; 删除用户的delete权限
</code></pre>
<p>管理员忘记密码:</p>
<pre><code>[root@mysql1 ~]# mysqld_safe --skip-grant-tables --skip-networking & 关闭用户密码的验证 关闭tcp/ip的远程连接
mysql> flush privileges;
mysql> alter user root@'localhost' identified by '123456';
[root@mysql1 ~]# pkill mysqld
</code></pre>
<h2 id="22-连接管理">2.2 连接管理</h2>
<h3 id="221-自带客户端">2.2.1 自带客户端</h3>
<pre><code>[root@mysql1 ~]# mysql -uroot -p -h localhost -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.29-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select @@socket;
+-----------------+
| @@socket |
+-----------------+
| /tmp/mysql.sock |
+-----------------+
1 row in set (0.00 sec)
mysql> ^DBye
[root@mysql1 ~]#
[root@mysql1 ~]# mysql -uroot -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.29-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
[root@mysql1 ~]# mysql -uroot -p -e "select user,host from mysql.user;"
Enter password:
+---------------+--------------+
| user | host |
+---------------+--------------+
| hkxtor | % |
| rep | 192.168.56.% |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+--------------+
[root@mysql1 ~]# mysql -uroot -p < all.sql #导入备份文件
Enter password:
</code></pre>
<h2 id="24-初始化配置">2.4 初始化配置</h2>
<h3 id="241-作用">2.4.1 作用</h3>
<pre><code>控制MySQL的启动,影响到客户端的连接,也就是直接在linux命令行操作的时候进行参数的添加
</code></pre>
<h3 id="242-初始化的方法">2.4.2 初始化的方法</h3>
<pre><code>预编译
**配置文件(所有启动方式)**
命令行参数 (仅限于 mysqld_safe mysqld)
</code></pre>
<h3 id="243-配置文件">2.4.3 配置文件</h3>
<p>默认路径:</p>
<pre><code>[root@db01 ~]# mysqld --help --verbose |grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
注:
默认情况下,MySQL启动时,会依次读取以上配置文件,如果有重复选项,会以最后一个文件设置的为准。
但是,如果启动时加入了--defaults-file=xxxx时,以上的所有文件都不会读取.
</code></pre>
<p>配置文件格式:</p>
<pre><code>[标签]
配置项=xxxx
标签类型:服务端、客户端
服务器端标签:
[mysqld]
[mysqld_safe]
[server]
客户端标签:
[mysql]
[mysqldump]
[client]
配置文件的示例展示:
[root@db01 ~]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
server_id=6
port=3306
log_error=/data/mysql/mysql.log
[mysql]
socket=/tmp/mysql.sock
prompt=Master [\\d]>
</code></pre>
<h2 id="25-多实例">2.5 多实例</h2>
<h3 id="251-准备数据目录">2.5.1 准备数据目录</h3>
<pre><code>mkdir -p /data/330{7,8,9}/data
</code></pre>
<h3 id="252-准备配置文件">2.5.2 准备配置文件</h3>
<pre><code>cat > /data/3307/my.cnf <<EOF
[mysqld]
basedir=/app/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
log_error=/data/3307/mysql.log
port=3307
server_id=7
log_bin=/data/3307/mysql-bin
EOF
cat > /data/3308/my.cnf <<EOF
[mysqld]
basedir=/app/mysql
datadir=/data/3308/data
socket=/data/3308/mysql.sock
log_error=/data/3308/mysql.log
port=3308
server_id=8
log_bin=/data/3308/mysql-bin
EOF
cat > /data/3309/my.cnf <<EOF
[mysqld]
basedir=/app/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
log_error=/data/3309/mysql.log
port=3309
server_id=9
log_bin=/data/3309/mysql-bin
EOF
</code></pre>
<h3 id="253-分别初始化">2.5.3 分别初始化</h3>
<pre><code>mv /etc/my.cnf /etc/my.cnf.bak
mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/app/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/app/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/app/mysql
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[12c可插拔数据库的几种克隆迁移方法]]></title>
<id>https://hkxtor.github.io/qulIB3Rk0/</id>
<link href="https://hkxtor.github.io/qulIB3Rk0/">
</link>
<updated>2017-11-30T03:03:34.000Z</updated>
<content type="html"><![CDATA[<h3 id="oacle-多租户环境包含一个容器数据库cdb和零个或多个可插拔数据库pdb这种让数据库系统扩展也变得非常的灵活oracle-12c提供了许多种关于多租户模式下数据库的克隆迁移方式以下对于几种克隆迁移的方式进行实验介绍">Oacle 多租户环境包含一个容器数据库(CDB)和零个或多个可插拔数据库(PDB),这种让数据库系统扩展也变得非常的灵活,oracle 12c提供了许多种关于多租户模式下数据库的克隆迁移方式,以下对于几种克隆迁移的方式进行实验介绍。</h3>
<h1 id="一通过现有pdb直接创建create-pluggable-databasefrom">一.通过现有PDB直接创建(CREATE PLUGGABLE DATABASE..FROM..)</h1>
<ol>
<li>
<p>从本地PDB创建</p>
<ol>
<li>
<p>克隆完整PDB</p>
<p>创建语句:</p>
<pre><code class="language-sql">CREATE PLUGGABLE DATABASE pdb3 FROM pdb2
PATH_PREFIX = ' /u01/app/oracle/oradata/ ' --- 指定pdb相关联的目录,可以不设置
FILE_NAME_CON VERT = (' /u01/app/oracle/oradata/orclcwd/pdb2/', '/u01/app/oracle/oradata/orclcwd/pdb3/' ) - - 数据文件存放路径,在ASM中可以指定DG
SERVICE_NAME_CONVERT = ('pdb2','pdb3') – 服务名转换
NOLOGGING;
CREATE PLUGGABLE DATABASE pdb3 FROM pdb2
PATH_PREFIX = '/u01/app/oracle/oradata/'
FILE_NAME_CONVERT = ('/u01/app/oracle/product/12.1.0/dbhome_1/dbs/u01/app/oracle/oradata/orclcwd/', '/u01/app/oracle/oradata/orclcwd/pdb3/')
SERVICE_NAME_CONVERT = ('pdb2','pdb3');
</code></pre>
<p>主要的选项说明:</p>
<p>PATH_PREFIX:将PDB的相对目录对象路径设置为特定目录。因此,需要设置PATH_PREFIX<br>
FILE_NAME_CONVERT:指定数据文件的转换路径<br>
Storage: 如果需要限制新建pdb的大小,可以使用storage=xxG 来限制。</p>
<p>创建的过程日志:</p>
<pre><code>CREATE PLUGGABLE DATABASE pdb3 FROM pdb2
PATH_PREFIX = '/u01/app/oracle/oradata/'
FILE_NAME_CONVERT = ('/u01/app/oracle/product/12.1.0/dbhome_1/dbs/u01/app/oracle/oradata/orclcwd/', '/u01/app/oracle/oradata/orclcwd/pdb3/')
SERVICE_NAME_CONVERT = ('pdb2','pdb3') <<<<<<<<<< 创建命令开始
Fri Aug 18 14:22:11 2017
Opatch XML is skipped for PDB PDB2 (conid=3) <<<<< 跳过PDB2(源)Opatch XML,看起来与版本检查有关
APEX_040200.WWV_FLOW_ADVISOR_CHECKS (CHECK_STATEMENT) - CLOB populated
Fri Aug 18 14:24:15 2017 <<<< 开始创建新的PDB3,但此时的状态先为UNUSABLE
****************************************************************
Pluggable Database PDB3 with pdb id - 4 is created as UNUSABLE.
If any errors are encountered before the pdb is marked as NEW,
then the pdb must be dropped
****************************************************************
Database Characterset for PDB3 is ZHS16GBK <<< 字符集检查
Fri Aug 18 14:24:26 2017 <<<<<<<< 删除换旧的数据文件并生成新的数据文件
Deleting old file#8 from file$
Deleting old file#9 from file$
Adding new file#11 to file$(old file#8)
Adding new file#12 to file$(old file#9)
Successfully created internal service pdb3 at open <<<<<< 创建服务成功
ALTER SYSTEM: Flushing buffer cache inst=0 container=4 local <<<<< 刷新新PDB的buffer
****************************************************************
Post plug operations are now complete. <<<<< 插入PDB操作
Pluggable database PDB3 with pdb id - 4 is now marked as NEW. <<<<PDB 状态定位NEW
****************************************************************
Completed: CREATE PLUGGABLE DATABASE pdb3 FROM pdb2 <<<< 完成
PATH_PREFIX = '/u01/app/oracle/oradata/'
FILE_NAME_CONVERT = ('/u01/app/oracle/product/12.1.0/dbhome_1/dbs/u01/app/oracle/oradata/orclcwd/', '/u01/app/oracle/oradata/orclcwd/pdb3/')
SERVICE_NAME_CONVERT = ('pdb2','pdb3')
</code></pre>
</li>
<li>
<p>仅克隆PDB元数据</p>
<p>有时并不需要克隆表里的数据,可使用NO DATA来克隆一个PDB,但仅仅克隆元数据。</p>
<p>以下示例:</p>
<ol>
<li>
<p>源PDB中表存在多行数据,这里特意选择了三种情况,看看是否NO DATA的机制如何:</p>
<ol>
<li>SYS 用户的表,表空间在SYSTEM</li>
<li>个人用户的表,表空间在SYSTEM</li>
<li>个人用户的表,表空间在普通表空间</li>
</ol>
</li>
<li>
<p>将源PDB打开到read only模式下:</p>
<pre><code>ALTER PLUGGABLE DATABASE pdb1 OPEN READ ONLY;
</code></pre>
</li>
<li>
<p>克隆PDB:</p>
<pre><code>CREATE PLUGGABLE DATABASE pdb4 FROM pdb3 NO DATA FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orclcwd/pdb3/', '/u01/app/oracle/oradata/orclcwd/pdb4/');