Wednesday, December 16, 2015

auto clean up in-doubt distributed transaction

[How the problem comes]

Mirror database and DB link technology are used intensively in my environment.
Mirror database is created by using storage level technology daily at mid-night specific time.

In the source database, transactions may not be still running (yet commit yet), however the hard storage split has to happen, which also transparent to operator.

As such, although the mirror database is open to application team, but below error can be encountered when accessing the interested table.

ERROR at line 1:
ORA-01591: lock held by in-doubt distributed transaction



[Solution]

To solve the issue, we come out a script as shown below, to perform the clean up after database recovery. 




 cat check_dba_2pc_pending_trans.sql
--set echo on
set serveroutput on
set lines 150
col HOST format a20
col OS_USER format a20
col spoolname new_value spoolname
select '/oracle/node1/ops/logs/check_dba_2pc_pending_'||to_char(sysdate, 'yymmddhh24mmss')||(select '_'||instance_name from v$instance) spoolname from dual;
spool '&spoolname'
select LOCAL_TRAN_ID,STATE,FAIL_TIME,OS_USER,HOST,DB_USER,COMMIT#,ADVICE from dba_2pc_pending;
ALTER SYSTEM DISABLE DISTRIBUTED RECOVERY;
declare
   cursor_name     pls_integer default dbms_sql.open_cursor;
   ignore          pls_integer;
--   x  varchar2(22);

   procedure execute_immediate( p_sql in varchar2 )
   is
   BEGIN
      dbms_sql.parse(cursor_name, p_sql, dbms_sql.native);
      ignore := dbms_sql.execute(cursor_name);
      --dbms_sql.close_cursor(cursor_name);
   END;

begin
   for x in ( select local_tran_id,state from dba_2pc_pending ) loop
      dbms_output.put_line( 'Local Trans Id:  ' || x.local_tran_id );
      if x.state = 'committed' then
        dbms_transaction.purge_lost_db_entry(x.local_tran_id);
        commit;
      else
        execute_immediate( 'rollback force ''' || x.local_tran_id || '''' );
        commit;
        dbms_transaction.purge_lost_db_entry(x.local_tran_id);
        commit;
      end if;
   end loop;
   dbms_sql.close_cursor(cursor_name);
end;
/
ALTER SYSTEM ENABLE DISTRIBUTED RECOVERY;
select LOCAL_TRAN_ID,STATE,FAIL_TIME,OS_USER,HOST,DB_USER,COMMIT#,ADVICE from dba_2pc_pending;
spool off

Wednesday, December 02, 2015

Displaying Oracle 10046 Trace File in SQL developer


Good know that SQL Developer can display 10046 Trace file in nice view,  as an alternative to using the TKPROF program.
To open a .trc file in SQL Developer, click File/Open, and choose the desired trace file.

Once opened, we can examine the information in the Tree View,  Statistics View, and List View.

Below is my sample screenshots.

BTW, it seems List View requires large Graphic card memory.





Friday, November 27, 2015

Tips for TortoiseSVN

Many discussion on internet, think it is a SVN client. In fact, it is also a SVN server.

As I practice, I found SNV over WebDV has view only capability, even I tried websvn which can't help on check-in and check-out. I decided to use SVN protocol only, i.e. use TortoiseSVN serves as both server (deploy it on server) and client GUI (install it too in various PCs).

To clear authentication info, go to settings/saved data/clear authentication data, as shown below.



The key config files of SVN server are under the repository directory by default.e.g.

authorization file:  authz
password file: passwd
main config file:  svnserve.conf


First funny problem is when I enable the password file and hit authentication failed.

This is due to a space before the userid.   Remove it, do so for all other type of configuration just in case.

The 2nd Funny problem with authorization failed, whenever I enable authz-db in the server config file, I even can't read the repository , which was functioning.Finally I got the solution from someone else on the web.

I use the "/" for repository instead of particular repository name. e.g. change it from "/dbasvn" to "/" in authz-db file. e.g.

Changed it from 
[/dbasvn]
liqy = rw
* = r

TO

[/]
liqy = rw
* = r

Now , everything works perfectly.


Run svnserve as a Microsoft Windows service, so that we can use SVN protocol.  below is my sample command.

sc create svnserver binpath= "\"C:\Program Files\Subversion\bin\svnserve.exe\" --service -r D:\svnrepos" displayname= "Subversion" depend= Tcpip start= auto

Note if we want to delete a window service, can use "sc delete " , followed by reboot

Above is based TortoiseSVN v1.9.2 






Monday, November 23, 2015

SQL server 2000 profiler

One system is getting slower and slower, so I decided to use profiler for investigation.

Googled and read out the following useful articles:


http://serverfault.com/questions/162245/how-do-i-identify-slow-queries-in-sql-server
http://www.codeproject.com/Articles/21371/SQL-Server-Profiler-Step-by-Step

to minimize changes to production, I select using tracing file instead of a table.

confirmed with below two articles for finding out indexes columns.

https://bytes.com/topic/sql-server/answers/562317-how-do-i-find-indexes-columns-sql-server-2000-a

http://stackoverflow.com/questions/765867/list-of-all-index-index-columns-in-sql-server-db



Finally, I got a huge return -- the system has ZERO indexes created.

Play with MERGE partition command

The partition name and high value



The error message has self-explanation.

ALTER TABLE TEST_UNBILLED  
MERGE PARTITIONS P2014_02_01, P2014_02_07 INTO PARTITION P2014_02_07
UPDATE INDEXES;

Table altered.



ALTER TABLE TEST_UNBILLED  
MERGE PARTITIONS P2014_02_07, P2014_02_11 INTO PARTITION P2014
UPDATE INDEXES;

Table altered.



SYS> ALTER TABLE TEST_UNBILLED
  2  MERGE PARTITIONS P2014_02_14, P2014 INTO PARTITION P2014
  3  UPDATE INDEXES;
MERGE PARTITIONS P2014_02_14, P2014 INTO PARTITION P2014
                 *
ERROR at line 2:
ORA-14273: lower-bound partition must be specified first


Elapsed: 00:00:00.01


SYS> ALTER TABLE TEST_UNBILLED
  2  MERGE PARTITIONS P2014, P2014_02_14 INTO PARTITION P2014
  3  UPDATE INDEXES;
MERGE PARTITIONS P2014, P2014_02_14 INTO PARTITION P2014
                 *
ERROR at line 2:
ORA-14275: cannot reuse lower-bound partition as resulting partition


Elapsed: 00:00:00.01

Friday, November 20, 2015

when oracle listener listens on all netowrk interfaces?

Learned below from https://community.oracle.com/thread/2126662?start=0&tstart=0

When you use HOSTNAME in listener definition and the HOSTNAME matches the result of `hostname` command, the listener will listen on all interfaces.

If you use an IP in listener definition, the listener will listen on THAT interface only.


So here is my test  to confirm this is correct.


--the test server info


orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> hostname
orarac2poc
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> ping orarac2poc
PING orarac2poc (10.139.90.42) 56(84) bytes of data.
64 bytes from orarac2poc (10.139.90.42): icmp_seq=1 ttl=64 time=0.021 ms
64 bytes from orarac2poc (10.139.90.42): icmp_seq=2 ttl=64 time=0.027 ms

--- orarac2poc ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.021/0.024/0.027/0.003 ms



--ifconfig output


[root@orarac2poc ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:9C:3D:C2
          inet addr:10.139.90.42  Bcast:10.139.255.255  Mask:255.255.0.0
          inet6 addr: fe80::250:56ff:fe9c:3dc2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:29146147 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20491711 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:33283609829 (30.9 GiB)  TX bytes:2225739822 (2.0 GiB)

eth0:1    Link encap:Ethernet  HWaddr 00:50:56:9C:3D:C2
          inet addr:10.139.92.42  Bcast:10.139.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:2    Link encap:Ethernet  HWaddr 00:50:56:9C:3D:C2
          inet addr:10.139.90.43  Bcast:10.139.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1      Link encap:Ethernet  HWaddr 00:50:56:9C:3D:C1
          inet addr:10.139.91.42  Bcast:10.139.255.255  Mask:255.255.0.0
          inet6 addr: fe80::250:56ff:fe9c:3dc1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4225633 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3336 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:477256264 (455.1 MiB)  TX bytes:761551 (743.7 KiB)

eth2      Link encap:Ethernet  HWaddr 00:50:56:9C:1D:68
          inet addr:10.149.0.12  Bcast:10.149.255.255  Mask:255.255.0.0
          inet6 addr: fe80::250:56ff:fe9c:1d68/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:203522763 errors:0 dropped:0 overruns:0 frame:0
          TX packets:192410252 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:86546647557 (80.6 GiB)  TX bytes:143237765923 (133.4 GiB)

eth2:1    Link encap:Ethernet  HWaddr 00:50:56:9C:1D:68
          inet addr:169.254.231.131  Bcast:169.254.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:459889795 errors:0 dropped:0 overruns:0 frame:0
          TX packets:459889795 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:145470946165 (135.4 GiB)  TX bytes:145470946165 (135.4 GiB)


--use the IP of `hostname`


-- use physical IP

orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl start LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:34:41

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0.4/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=orarac2poc)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orarac2poc)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER1
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                20-NOV-2015 15:34:41
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=orarac2poc)(PORT=1522)))
Services Summary...
Service "DGS_DGMGRL.POC" has 1 instance(s).
  Instance "DGS", status UNKNOWN, has 1 handler(s) for this service...
Service "RCAT" has 1 instance(s).
  Instance "RCAT", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> netstat -an |grep 1522
tcp        0      0 :::1522                     :::*                        LISTEN
tcp        0      0 ::ffff:10.139.90.42:1522    ::ffff:10.139.90.42:48332   TIME_WAIT
udp        0      0 127.0.0.1:51522             0.0.0.0:*
udp        0      0 169.254.231.131:51522       0.0.0.0:*
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl stop LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:35:42

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orarac2poc)(PORT=1522)))
The command completed successfully



We can see the LISTENER1 listeners on all IPs'  1522 port.

-- now use other ip


--Use virtual IP

orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl start LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:36:39

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0.4/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.139.92.42)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.139.92.42)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER1
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                20-NOV-2015 15:36:39
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.139.92.42)(PORT=1522)))
Services Summary...
Service "DGS_DGMGRL.POC" has 1 instance(s).
  Instance "DGS", status UNKNOWN, has 1 handler(s) for this service...
Service "RCAT" has 1 instance(s).
  Instance "RCAT", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> netstat -an |grep 1522
tcp        0      0 10.139.92.42:1522           0.0.0.0:*                   LISTEN
tcp        0      0 10.139.92.42:31765          10.139.92.42:1522           TIME_WAIT
udp        0      0 127.0.0.1:51522             0.0.0.0:*
udp        0      0 169.254.231.131:51522       0.0.0.0:*
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/adm


orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl stop LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:37:44

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.139.92.42)(PORT=1522)))
The command completed successfully


We can see the LISTENER1 only listens the exact IP we specified. 



--more testing

orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl start LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:38:40

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0.4/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.139.91.42)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.139.91.42)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER1
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                20-NOV-2015 15:38:40
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.139.91.42)(PORT=1522)))
Services Summary...
Service "DGS_DGMGRL.POC" has 1 instance(s).
  Instance "DGS", status UNKNOWN, has 1 handler(s) for this service...
Service "RCAT" has 1 instance(s).
  Instance "RCAT", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> netstat -an |grep 1522
tcp        0      0 10.139.91.42:1522           0.0.0.0:*                   LISTEN
tcp        0      0 10.139.91.42:51369          10.139.91.42:1522           TIME_WAIT
udp        0      0 127.0.0.1:51522             0.0.0.0:*
udp        0      0 169.254.231.131:51522       0.0.0.0:*
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl stop LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:39:50

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.139.91.42)(PORT=1522)))
The command completed successfully
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> vi listener.ora
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl start LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 15:40:23

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0.4/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.149.0.12)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.149.0.12)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER1
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                20-NOV-2015 15:40:23
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/orarac2poc/listener1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.149.0.12)(PORT=1522)))
Services Summary...
Service "DGS_DGMGRL.POC" has 1 instance(s).
  Instance "DGS", status UNKNOWN, has 1 handler(s) for this service...
Service "RCAT" has 1 instance(s).
  Instance "RCAT", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> netstat -an |grep 1522
tcp        0      0 10.149.0.12:1522            0.0.0.0:*                   LISTEN
tcp        0      0 10.139.91.42:58897          10.139.91.42:1522           TIME_WAIT
tcp        0      0 10.149.0.12:36482           10.149.0.12:1522            TIME_WAIT
udp        0      0 127.0.0.1:51522             0.0.0.0:*
udp        0      0 169.254.231.131:51522       0.0.0.0:*
orarac2poc:ORCL2:/u01/app/oracle/product/11.2.0.4/network/admin> lsnrctl stop LISTENER1

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 20-NOV-2015 16:47:15

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.149.0.12)(PORT=1522)))
The command completed successfully




Conclusion:

The finding is correct. Thanks.



Monitor metadata for a interval partition with a rolling window

We may hit below error when dropping a partition using interval range.

SQL> alter table orders2 drop partition p_second;
alter table orders2 drop partition p_second
                                   *
ERROR at line 1:
ORA-14758: Last partition in the range section cannot be dropped


As mentioned in "How to Use Interval Partitioning with a Rolling Partition Window and Avoid ORA-14758 (Doc ID 1590833.1)",

When you create an interval partitioned table, you must create at least one partition and specify the interval. This specified partition is created as a range partition; all future partitions that are automatically created by the database are interval
partitions. A known limitation is that you cannot drop the last range partition of an interval partitioned table. That means you cannot drop the first (last) partition that you specified when you created the table.
1. Enhancement Bug 17571086 : ENH: ALLOW DROP OF OLDEST PARTITION IN ROLLING WINDOW WHEN INTERVAL PARTITIONED is implemented in 12.2 and resolves this issue. This is a 12.2 feature and cannot be backported to lower
RDBMS versions.
2. Until 12.2 is released and your database is upgraded to 12.2, here is the description of and workaround to the issue:




Below experiment list down metadata changing over the maintenance.

1.  create the test table

create table orders2
(
invoice_no number not null,
invoice_date date not null,
comments varchar2(100)
)
partition by range (invoice_date)
interval (numtoyminterval(1,'month'))
(partition p_first values less than (to_date('01-Jan-2012','DD-MON-YYYY')) ,
 partition p_second values less than (to_date('01-Feb-2012','DD-MON-YYYY')) );

2. insert two test rows BUT not to commit

 Insert into orders2 values (150,'03-JAN-2012','test');

-- this follows into partition p_second

 Insert into orders2 values (150,'03-Feb-2012','test');
-- this created a new parttion

3. query the partitions

SQL>   select partition_name, partition_position, high_value from dba_tab_partitions where table_name='ORDERS2' order by partition_position;

PARTITION_NAME                 PARTITION_POSITION
------------------------------ ------------------
HIGH_VALUE
--------------------------------------------------------------------------------
P_FIRST                                         1
TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA

P_SECOND                                        2
TO_DATE(' 2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA

SYS_P194                                        3
TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA



SYS_P194 is the last partition.


3. the current metadata
  CREATE TABLE "LIQY"."ORDERS2"
   ( "INVOICE_NO" NUMBER NOT NULL ENABLE,
"INVOICE_DATE" DATE NOT NULL ENABLE,
"COMMENTS" VARCHAR2(100 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"
  PARTITION BY RANGE ("INVOICE_DATE") INTERVAL (NUMTOYMINTERVAL(1,'MONTH')) 
 (PARTITION "P_FIRST"  VALUES LESS THAN (TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS NOLOGGING
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ,
 PARTITION "P_SECOND"  VALUES LESS THAN (TO_DATE(' 2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS NOLOGGING
  STORAGE(INITIAL 8388608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ) ;


However, in the metadata, the P_SECOND is still shown as last partition, while SYS_P194 not updated to the metadata.    P_SECOND is so called statically partition

4.   try to drop the STATICALLY last partition P_SECOND


alter table orders2 drop partition p_second;

SQL> alter table orders2 drop partition p_second;
alter table orders2 drop partition p_second
            *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired


--commit the INSERT session now and try again



SQL> alter table orders2 drop partition p_second;
alter table orders2 drop partition p_second
                                   *
ERROR at line 1:
ORA-14758: Last partition in the range section cannot be dropped


5. use the workaround for DB prior to 12.2

5.1   reset it to normal range partition table and drop the partition

SQL> alter table orders2 set interval ();

Table altered.

SQL>  alter table orders2 drop partition p_second;

Table altered.


5.2 monitor the metadata again. Notice the metadata gets updated.


 CREATE TABLE "LIQY"."ORDERS2"
   ( "INVOICE_NO" NUMBER NOT NULL ENABLE,
"INVOICE_DATE" DATE NOT NULL ENABLE,
"COMMENTS" VARCHAR2(100 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"
  PARTITION BY RANGE ("INVOICE_DATE") 
 (PARTITION "P_FIRST"  VALUES LESS THAN (TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS NOLOGGING
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ,
 PARTITION "SYS_P194"  VALUES LESS THAN (TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS NOLOGGING
  STORAGE(INITIAL 8388608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ) ;



SQL>   select partition_name, partition_position, high_value from dba_tab_partitions where table_name='ORDERS2' order by partition_position;

PARTITION_NAME                 PARTITION_POSITION
------------------------------ ------------------
HIGH_VALUE
--------------------------------------------------------------------------------
P_FIRST                                         1
TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA

SYS_P194                                        2
TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA



6.1 change the partition back to interval
SQL>  alter table orders2 set interval (numtoyminterval(1,'month'));

Table altered.


6.2 monitor the metadata again

 CREATE TABLE "LIQY"."ORDERS2"
   ( "INVOICE_NO" NUMBER NOT NULL ENABLE,
"INVOICE_DATE" DATE NOT NULL ENABLE,
"COMMENTS" VARCHAR2(100 BYTE)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"
  PARTITION BY RANGE ("INVOICE_DATE") INTERVAL (NUMTOYMINTERVAL(1,'MONTH')) 
 (PARTITION "P_FIRST"  VALUES LESS THAN (TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS NOLOGGING
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ,
 PARTITION "SYS_P194"  VALUES LESS THAN (TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS NOLOGGING
  STORAGE(INITIAL 8388608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ) ;




Monday, November 02, 2015

install oracle sample data

Famous scott/tiger is here.

ORCL2:/u01/app/oracle/product/11.2.0.4/rdbms/admin> ls utlsampl.sql
utlsampl.sql


SQL> conn scott/tiger
Connected.
SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE


Install the sample schema installer files.
demo schemas are under $ORACLE_HOME/demo/schema directory.


DG:/u01/app/oracle/product/11.2.0.4/demo/schema/order_entry> sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Oct 19 15:11:28 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SYS@DG> @oe_main

specify password for OE as parameter 1:
Enter value for 1: oe

specify default tablespeace for OE as parameter 2:
Enter value for 2: USERS

specify temporary tablespace for OE as parameter 3:
Enter value for 3: temp

specify password for HR as parameter 4:
Enter value for 4: hr

specify password for SYS as parameter 5:
Enter value for 5: ****

specify directory path for the data files as parameter 6:
Enter value for 6: /u01/app/oracle/product/11.2.0.4/demo/schema/order_entry

writeable directory path for the log files as parameter 7:
Enter value for 7: /u01/app/oracle/product/11.2.0.4/demo/schema/order_entry

specify version as parameter 8:
Enter value for 8: v3


User dropped.

old   1: CREATE USER oe IDENTIFIED BY &pass
new   1: CREATE USER oe IDENTIFIED BY oe

User created.

old   1: ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs
new   1: ALTER USER oe DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS

User altered.

old   1: ALTER USER oe TEMPORARY TABLESPACE &ttbs
new   1: ALTER USER oe TEMPORARY TABLESPACE temp

User altered.

Thursday, October 01, 2015

No timesten tab in sql developer ?




Following https://docs.oracle.com/cd/E55747_01/doc.41/e39882/connect.htm to config sql developer.
But no timesten tab found.



googled and realize needing to install timesclient first.

following https://docs.oracle.com/cd/E11882_01/timesten.112/e21632/install.htm#TTINS171

for timesten client installation


Program Folder: TimesTen 11.2.2 (32-bit)
Register TimesTen enviroment variables: Enabled
World-Writeable: Enabled
PL/SQL: Enabled
Java Version: JDK 6
Java Classpath: C:\TimesTen\tt1122_32\lib\ttjdbc6.jar

Destination Location: C:\TimesTen\tt1122_32\
Demo Data_Store Location: C:\Users\liqy\AppData\Roaming\TimesTen\DemoDataStore

Features Selected:
            TimesTen Data Manager
            TimesTen Documentation
            TimesTen Client
            TimesTen Quickstart


Finally , see the timesten tab in sql developer.




Next, I am a bit confused by the username and password needed. Here are information found from various source.

UID


Specify a user name that is defined on the TimesTen server. When caching data from an Oracle database, the UID must match the UID on the Oracle database that is being cached in TimesTen.

In the Username field, enter the TimesTen user. If you use the TimesTen database to cache data from an Oracle database, enter the TimesTen cache manager user name. If you use the TimesTen database to load data from an Oracle database, enter the TimesTen user name that has SELECT privileges on the Oracle database tables that you want to load.


PWD

In the Password field, enter the password for the TimesTen user.


Specify the password that corresponds with the specified UID. When caching data from an Oracle database, PWD specifies the TimesTen password. You can specify the Oracle PWD in the connection string, if necessary.






As shown above, I can connect to timesten use either cacheadm or hr to connect to database, subject to purpose/function interested.

PLS-00201: identifier 'SYS.TT_STATS' must be declared in timesten 11.2.2.8.0

When using sql developer to create snapshot for timesten, following the demo http://www.oracle.com/webfolder/technetwork/tutorials/demos/db/timesten/tt1122/SQLDev/ttstats_viewlet_swf.html

An error was encountered performing the requested operation:

TT8503: ORA-06550: line 1, column 28:
PLS-00201: identifier 'TT_STATS' must be declared

Vendor code 8503



orarac1poc:DG:/u01/app/timesten/TimesTen/tt1122/quickstart/sample_code/jdbc> ttisql -version
TimesTen Release 11.2.2.8.0

orarac1poc:DG:/u01/app/timesten/TimesTen/tt1122> ttisql

Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
Type ? or "help" for help, type "exit" to quit ttIsql.


Command> connect  "dsn=cachedb1_1122;uid=cacheadm;oraclepwd=xxxxxx";
Enter password for 'cacheadm':
Connection successful: DSN=cachedb1_1122;UID=cacheadm;DataStore=/u01/app/timesten/TimesTen/tt1122                        /info/DemoDataStore/cachedb1_1122;DatabaseCharacterSet=WE8MSWIN1252;ConnectionCharacterSet=US7ASC                        II;DRIVER=/u01/app/timesten/TimesTen/tt1122/lib/libtten.so;PermSize=40;TempSize=32;TypeMode=0;OracleNetServiceName=DG;
(Default setting AutoCommit=1)

-- Able to describe the procedure

Command> desc tt_stats;

Package SYS.TT_STATS:

  Procedure CAPTURE_SNAPSHOT:
    Arguments:
      CAPTURE_LEVEL                   IN     VARCHAR2 DEFAULTED
      DESCRIPTION                     IN     VARCHAR2 DEFAULTED

 ...



  Procedure SHOW_SNAPSHOTS:
    Arguments:
      RESULTSET                       OUT    PL/SQL TABLE SYS.TT_STATS.REPORT_TABLE
                                               VARCHAR2(32767)

Command> select * from dba_objects where object_name='TT_STATS';
< SYS, TT_STATS, , 316, , PACKAGE, 2015-09-21 15:08:22, 2015-09-21 15:08:22, 2015-09-21:15:08:22, VALID, N, N, N, 1, >
< SYS, TT_STATS, , 318, , PACKAGE BODY, 2015-09-21 15:08:22, 2015-09-21 15:08:22, 2015-09-21:15:08:22, VALID, N, N, N, 2, >
< PUBLIC, TT_STATS, , 317, , SYNONYM, 2015-09-21 15:08:22, 2015-09-21 15:08:22, 2015-09-21:15:08:22, VALID, N, N, N, 1, >
3 rows found.

Command> set serveroutput on;

Command> call sys.TT_STATS.SHOW_SNAPSHOTS;
 8503: ORA-06550: line 1, column 6:
PLS-00201: identifier 'SYS.TT_STATS' must be declared
 8503: ORA-06550: line 1, column 1:
PL/SQL: Statement ignored
The command failed.
Command> select * from dba_tab_privs where table_name='TT_STATS';
0 rows found.


The solution

Command> grant execute on tt_stats to cacheadm;

Command> select * from dba_tab_privs where table_name='TT_STATS';
< CACHEADM, SYS, TT_STATS, CACHEADM, EXECUTE, NO, NO >
1 row found.
Command> call sys.TT_STATS.SHOW_SNAPSHOTS;
ID     TimeStamp            Level     Description
-----  -------------------  --------  -----------
0 snapshots were found in current datastore
Command>

Verified in sql developer okay too.




Monday, September 28, 2015

running tiddlywiki on node.js in Ubuntu 14.04.3 LTS with existing tiddlers loaded

1. create a directory for tiddlywiki
mkdir tdwiki

2. Under this directory, initialize a notebook named "mywiki"

user:~/tdwiki$ tiddlywiki mywiki --init server
Copied edition 'server' to mywiki


After this command, we are supposed to a see sub-directory named "mywiki" created under the parent directory "tdwiki"

3. To load exting tiddlers in index_2015-9-23.html created by tiddlywiki desktop verion

3.1 --type the help on load command
user:~/tdwiki$ tiddlywiki --help load
Load tiddlers from 2.x.x TiddlyWiki files (.html), .tiddler, .tid, .json or other files


3.2 --actual loading

To load tiddlers from the exsiting html file.

tiddlywiki ./MyWiki --load my_encrypted_wiki.html


user:~/tdwiki$ tiddlywiki ./mywiki  --load index_2015-9-23.html
syncer-server: Dispatching 'save' task: $:/StoryList
FileSystem: Saved file /home/user/tdwiki/mywiki/tiddlers/$__StoryList.tid
syncer-server: Dispatching 'save' task: bf Operator
FileSystem: Saved file /home/user/tdwiki/mywiki/tiddlers/bf_Operator.tid
syncer-server: Dispatching 'save' task: BetaReleases
FileSystem: Saved file /home/user/tdwiki/mywiki/tiddlers/BetaReleases.tid
syncer-server: Dispatching 'save' task: before Operator (Examples)
FileSystem: Saved file /home/user/tdwiki/mywiki/tiddlers/before_Operator_(Examples).tid
syncer-server: Dispatching 'save' task: before Operator
FileSystem: Saved file /home/user/tdwiki/mywiki/tiddlers/before_Operator.tid
...



4. verify that many tiddlers are created under the "miwiki" subdirectory



5. finaly, start the tiddlywiki service for "mywiki" on port 8080 of server ip 192.168.0.96, with logon id & password

nohup /usr/local/bin/tiddlywiki /home/user/tdwiki/mywiki --server 8080 $:/core/save/all text/plain text/html user xxxxxxx 192.168.0.96  &



6. To permanent add it as sysv service in 14.04. I created the following  3 scripts for init.d service to start the service called "mywiki" automatically upon rebooting.

 /home/user/tdwiki/start_mywiki.sh
 /home/user/tdwiki/stop_mywiki.sh
 /etc/init.d/mywiki
 



user:~/tdwiki$ cat start_mywiki.sh
#!/bin/bash

nohup /usr/local/bin/tiddlywiki /home/user/tdwiki/mywiki --server 8080 $:/core/save/all text/plain text/html user xxxxxxx 192.168.0.96   &




user:~/tdwiki$ cat stop_mywiki.sh
#!/bin/bash

ps -fu user |grep mywiki |grep 8080 |awk '{ print $2 }' | xargs kill




#Note here the scipt name /etc/init.d/mywiki should not have the suffix ".sh"

user:~/tdwiki$ cat /etc/init.d/mywiki
#! /bin/sh
### BEGIN INIT INFO
# Provides: daoqidao wiki
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: for daoqidao tiddlywiki service
# Description: This file starts and stops tiddlywiki server
#
### END INIT INFO

case "$1" in
 start)
   su user -c /home/user/tdwiki/start_mywiki.sh
   ;;
 stop)
   su user -c /home/user/tdwiki/stop_mywiki.sh
   sleep 1
   ;;
 status)
   ps -fu user |grep mywiki |grep 8080
   ;;
 restart)
   su user -c /home/user/tdwiki/stop_mywiki.sh
   sleep 2
   su user -c /home/user/tdwiki/start_mywiki.sh
   ;;
 *)
   echo "Usage: mywiki {start|stop|restart}" >&2
   exit 3
   ;;
esac

7. If all goes well then register the script as an init script:

sudo update-rc.d mywiki defaults

8. Reboot the machine and make sure that Tomcat has started.

References:  https://mobiarch.wordpress.com/2014/05/16/creating-an-init-script-in-ubuntu-14-04/


9. I also created a such service in one Ubuntu 15.04, which uses systemd instead to manage the service. The script is different.


user:~/tdwiki/ubuntu15.04$ cat /etc/tiddlywiki.conf
WIKI=/home/user/tdwiki/mywiki
PORT=8080
OPTS="$:/core/save/all text/plain text/html"
USER=user
PWD=xxxxxxx
IP=192.168.0.96

user:~/tdwiki/ubuntu15.04$ cat tiddlywiki.service
[Unit]
Description=TiddlyWiki
After=syslog.target

[Service]
User=user
Group=user
SyslogIdentifier=tiddlywiki
Restart=always
setuid=1000
StandardOutput=syslog
EnvironmentFile=/etc/tiddlywiki.conf
ExecStart=/usr/local/bin/tiddlywiki $WIKI --server $PORT $OPTS $USER $PWD $IP

[Install]
WantedBy=multi-user.target


10. move the file tiddlywiki.service to /etc/systemd/system and ran sudo systemctl enable tiddlywiki.service to create link scripts.

11. Restart server for verification

Friday, September 25, 2015

running tiddlywiki on windows as a service

Referenced below two links: http://tiddlywiki.com/static/Installing%2520TiddlyWiki%2520on%2520Node.js.html
http://www.rubix.nl/blogs/running-tiddlywiki-service-linux-and-windows

But they are not detai enough for me, so list down my steps after spending half an hour on the setup.

1. download node.js from https://nodejs.org/dist/latest/ and installed it.

2. now I have npm.exe to install tiddlywiki.


C:\Users\liqy>npm install -g tiddlywiki
C:\Users\liqy\AppData\Roaming\npm\tiddlywiki -> C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki\tiddlywiki.js
tiddlywiki@5.1.9 C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki

Note that tiddlywiki.js is installed under AppData sub-directory by default.

C:\Users\liqy>

3. now initialize the notebook named "mywiki". The step should be followed, which same as on Linux platform.


Note that the directory for notebook "mywiki" should be empty.

C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki>node .\tiddlywiki.js "
D:\mydoc\pp\sync\mywiki" --init server
Error: Wiki folder is not empty

--this is due to I put a local copy of tiddlywik html file there.

--after remove it , and try again

C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki>node .\tiddlywiki.js "
D:\mydoc\pp\sync\mywiki" --init server
Copied edition 'server' to D:\mydoc\pp\sync\mywiki


3.2 If not, I hit below error when I try to start the service

C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki>node .\tiddlywiki.js "
D:\mydoc\pp\sync\mywiki" --server 88 --verbose --rendertiddler $:/core/save/all
mywiki.html text/plain
Warning: Wiki folder 'D:\mydoc\pp\sync\mywiki' does not exist or is missing a ti
ddlywiki.info file
Serving on 127.0.0.1:88
(press ctrl-C to exit)

$:/core/modules/commands/server.js:304
        if($tw.boot.wikiInfo.plugins.indexOf("tiddlywiki/tiddlyweb") === -1 || $
tw.boot.wikiInfo.plugins.indexOf("tiddlywiki/filesystem") === -1) {
                            ^
TypeError: Cannot read property 'plugins' of null
    at Command.execute ($:/core/modules/commands/server.js:304:22)
    at Commander.executeNextCommand ($:/core/modules/commander.js:82:14)
    at Commander.execute ($:/core/modules/commander.js:46:7)
    at Object.exports.startup ($:/core/modules/startup/commands.js:34:12)
    at $tw.boot.executeNextStartupTask (C:\Users\liqy\AppData\Roaming\npm\node_m
odules\tiddlywiki\boot\boot.js:1905:10)
    at $tw.boot.executeNextStartupTask (C:\Users\liqy\AppData\Roaming\npm\node_m
odules\tiddlywiki\boot\boot.js:1903:21)
    at $tw.boot.executeNextStartupTask (C:\Users\liqy\AppData\Roaming\npm\node_m
odules\tiddlywiki\boot\boot.js:1903:21)
    at $tw.boot.executeNextStartupTask (C:\Users\liqy\AppData\Roaming\npm\node_m
odules\tiddlywiki\boot\boot.js:1903:21)
    at $tw.boot.executeNextStartupTask (C:\Users\liqy\AppData\Roaming\npm\node_m
odules\tiddlywiki\boot\boot.js:1903:21)
    at $tw.boot.startup (C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywi
ki\boot\boot.js:1856:11)








4.  Try to start the service to see if any error, before adding as a service

The command
node .\tiddlywiki.js "D:\mydoc\pp\sync\mywiki" --server 88 --verbose --rendertiddler $:/core/save/all mywiki.html text/plain

This is to start the tiddly service listening on localhost port 88 , for notebook named "mywiki"

C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki>node .\tiddlywiki.js "
D:\mydoc\pp\sync\mywiki" --server 88 --verbose --rendertiddler $:/core/save/all
mywiki.html text/plain
Serving on 127.0.0.1:88
(press ctrl-C to exit)
Boot log:
  Startup task: load-modules
  Startup task: info after: load-modules before: startup
  Startup task: startup after: load-modules
  Startup task: story after: startup
  Startup task: commands platforms: node after: story
Executing command: rendertiddler $:/core/save/all mywiki.html text/plain
syncer-server: Dispatching 'save' task: $:/StoryList
FileSystem: Saved file D:\mydoc\pp\sync\mywiki\tiddlers\$__StoryList.tid
syncer-server: Dispatching 'save' task: $:/StoryList
FileSystem: Saved file D:\mydoc\pp\sync\mywiki\tiddlers\$__StoryList.tid


5. Confirmed no issue with method, pressed CTRL+C to stop it , and invoke the nssm installed to add service to the windows registry.

D:\tools\nssm\win32>nssm install tiddlywiki
Service "tiddlywiki" installed successfully!

The startup directory in my case is:

 C:\Users\liqy\AppData\Roaming\npm\node_modules\tiddlywiki

The arguments in my case is :

.\tiddlywiki.js "D:\mydoc\pp\sync\mywiki" --server 88 --verbose --rendertiddler $:/core/save/all mywiki.html text/plain

By the way, command to edit the tiddlywiki is
D:\tools\nssm\win32>nssm edit  tiddlywiki



6.Verify that "tiddlywiki" service is added in "control panel/services"



7. Finally I see it in my web browser with address "http://localhost:88"




8. If there is existing tiddlers in a single html file, I believe tiddlywiki upload command can help to migrate existing tiddlers.







Monday, September 21, 2015

Migrate Centos 5.11 in my dual boot system

2nd round to migrate this CentOS after I bought a 3TB HDD, on top of one 120GB SSD, one 1TB and one 2TB HDD.  Now I want to decommission the 1TB HDD to save energy.

First round the CentOS5 was migrated to the new HDD 3TB,but failed to boot even I re-generate its UUID. After one week's think and research, finally I found that my motherboard doesn't have UEFI support.  The error message is like below.



So the solution is to migrate it to the 2TB HDD.  The steps are simple.

1. create new partition for / and swap.
2. Use gparted to copy the partition from 1TB HDD to the 2TB HDD partition /dev/sdb2 as shown below.


Before the copy, I gave beautiful label to the partition /dev/sdb2 (CentOS5_Root) and /dev/dba5 (CentOS5_Swap). In fact, these two labels will create new problem for me.

3. regenerate UUID for /dev/sdb2

4. I use GURB2 of ubuntu 15.04 as boot loader installed in SSD, so after copy centos5 I don't need to take care of the grub on this disk /dev/sdb .  Was a doubt in my mind.  To recognize the centos5 in /dev/sdb2, just issue sudo update-grub2
in Ubuntu, after which I see the /dev/sdb2 entry in the boot menu.




However, because I changed the two partition's LABEL and I didn't remember Volume Group was created in CentOS, caused I hit subsequent errors and spent me another two hours in the midnight.


mount: could not find filesystem '/dev/root'

Notice here not able to find root location /dev/root. As original "LABEL=/" is updated to Ubuntu grub.cfg. This seems Ubuntu grub doesn't know the LABEL being created in gparted.


After I updated root to use "LABEL=/CentOS5_Root", the booting process moved one step further.



This time, I learned faster and revert the two partitions' LABEL to original value.  And finally it brings me the clean GUI.




References:

http://ubuntuforums.org/showthread.php?t=1786292
https://frankfzw.wordpress.com/2014/12/23/migrate-ubuntu-14-04-from-hdd-to-ssd/
http://frugaltech.happystoic.com/ssdlinux
https://help.ubuntu.com/community/UsingUUID
https://help.ubuntu.com/community/MovingLinuxPartition
https://www.centos.org/forums/viewtopic.php?t=11207
https://theguyonthe3rdfloor.wordpress.com/2013/02/28/how-to-install-grub-2/

BIOS ACHI screenshots

when the SATA contorl mode =IDE

2 HDD, 1 SSD and  1 DVD ROM



After change the mode to ACHI








Notice the sequence changed, luckily I have already convert my dual boot system not to use the standard partition name, instead , most of my mount points are using by-id.

Sunday, September 20, 2015

few issues with Centos 7.1 installation and BIOS upgrade

1. failed to boot from USB for installation.

followed dd command in https://wiki.centos.org/HowTos/InstallFromUSBkey to create a bootable thumdrive without error, but the USB thumdrive is not detected in the BIOS.  My motherboard is GA-P55A-UD3. So the easier way for me is to burn the ISO to a DVD disc.

[ Added Later on ] during BIOS upgrade from version F10 to F11 , I found out the USB thumdrive was not detected due to the extendible USB cable was plugged into USB3.0 port. When I changed to USB2.0 port, my thumdrive is back.

2. I have two hard disks : 2TB and 3TB. Attempted to install on the newly bought 3TB hard disk. Remembered hit kind of internal error.  So I decided to install it on the 2TB hard disk.

3. This time round, I choose the software set GNOME-Desktop instead of default minimal installation, which gave me no network, no GUI. That was troublesome.

4. When I install the centos 7.1, the SATA control mode is ACHI. I had Ubuntu 15.04 and CentOS5.11 installed in this computer.  The installation finally completed successfuly.  And luckily, it didn't touch the GURB2 bootloader of my existing Ubuntu's.



5. However when I boot centos7.1, it panic at "no floppy controller found" and failed to show the GUI. I had no floppy driver and it is shown None in BIOS.

 6. Luckily, when I change the SATA controller mode to IDE. The centos7.1 finally boots up. That's is the workaround for the time being.  Ubuntu 15.04 will be still the main workstation.

[ Added Later on ] After BIOS upgrade from version F10 to F11, this issue is gone too. Worth it the upgrade.  I can stay with ACHI finally.


By upgrading the BIOS, I also gained the stability of Memory, to let my 4x4GB pieces of memory to run at 1600Mhz, and overclocking the CPU from 2.8Ghz to higher frequency @ 3.2GHz.  In Ubuntu, tools like hddtemp, sensors, psensor can tell the temperature inside.
cat /proc/cpuinfo helps to tell CPU speed.

This is article introduce rufus and helped to create a bootable MS-DOS in USB drive. In fact, I don't need it. It only after BIOS upgrade, I found there is Q-flash can do the upgrade without needing to boot into any OS.


Wednesday, September 09, 2015

SSD trim


This article explains what is TRIM and how to handle in Windows platform.

Below two related to Ubutu, and I am happy to see there is already weekly job for trimming.


tail -n1 /etc/cron.weekly/fstrim 
/sbin/fstrim --all || true
 
http://askubuntu.com/questions/443761/how-is-trim-enabled

http://askubuntu.com/questions/18903/how-to-enable-trim

 
However, due to my SSD capacity is small (120GB) only, I decided to have a daily cron job instead
 as shown below..


/etc/cron.daily$ cat trimssd
#!/bin/sh
LOG=/var/log/trimssd.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG


hmc@hmc-P55A-UD3:/etc/cron.daily$ sudo chmod 755 trimssd
hmc@hmc-P55A-UD3:/etc/cron.daily$ sudo ./trimssd
hmc@hmc-P55A-UD3:/etc/cron.daily$ cat /var/log/trimssd.log
*** Wed, 09 Sep 2015 23:11:59 +0800 ***
/: 3.3 GiB (3499556864 bytes) trimmed

SMART data alert: Airflow Temperature and bad sectors

gnome-disks is cool to warn me that my external WD 1TB HDD has 60 degree hot inside it .



At beginning I can't believe until I touch the casing and detach it.

Attempted to open it by viewing a video from Youtube. From the video, it is so compact that nothing I can do event I think I can open it.


From below two links, it seems nothing I can do now, except have an eye on it to prevent data lost. Important data shall be migrated to my NAS.

http://askubuntu.com/questions/342976/how-to-reset-smart-results

http://superuser.com/questions/697384/why-is-the-temperature-so-low-and-airflow-temperature-so-high-on-my-hd


Just now, I re-plug to the USB, running for few minutes on 34'C



For another alert "19 bad sectors" in another disk, my plan is to migrate data out of/dev/sda10 and format it to try my luck, since fsck doesn't overcome it. Its temperature is also 8'C higher than its neighbour - a 2TB HDD, maybe it is getting old truly. 

More discussion about bad sectors.

http://ubuntuforums.org/showthread.php?t=2061312

http://www.howtogeek.com/howto/37659/the-beginners-guide-to-linux-disk-utilities/



migrate ubuntu 15.04 from HDD to SSD

Factors:
a.) 9 bad sectors reported by gnome-disks.
b.) Interested on new stuff - SSD
e.) Attractive price from Comex: Sandisk 120GB only S$72.

Did some research on the web.

A good article https://help.ubuntu.com/community/MovingLinuxPartition , but seems not update-to-date. Anyway it explains what is going on in details. I followed from step 1 to 4,  and part of step 5 & 6 . Since I have no confidence on editing grub.cfg and didn't see below (maybe few detail steps is not descripted clearly)


1) UBUNTU...
  • Finally, once rebooted successfully on new Ubuntu partition
As I found it still use my HDD for bootup.

Thus I abandom the "Refresh the GRUB 2 menu "


sudo update-grub


Instead , I followed below step to install grub mentioned in http://frugaltech.happystoic.com/ssdlinux and https://frankfzw.wordpress.com/2014/12/23/migrate-ubuntu-14-04-from-hdd-to-ssd/


$ sudo mount -o bind /dev   /mnt/ssd/dev
$ sudo mount -o bind /sys   /mnt/ssd/sys
$ sudo mount -t proc /proc  /mnt/ssd/proc
#$ sudo cp /proc/mounts /media/SSD/etc/mtab    --> I skip this command, as it doesn't seem to use UUID. 

$ sudo chroot /mnt/ssd
$ grub-install /dev/sdc
$ grub-install --recheck /dev/sdc       # only in case of errors in the step before
$ update-grub2

Reboot PC and Yes!18 seconds instead of previous 45 seconds.




Later on I study somemore on mtab and fstab.

Here is one short comparison : http://www.linuxquestions.org/questions/linux-newbie-8/difference-between-mtab-and-fstab-924190/

and more can be found http://ubuntuforums.org/showthread.php?t=1737715



For UUID to be used in fstab, in fact I prefer to use device ID & partition ID, as I have 2 HDDs (1TB Hitachi and 2TB Toshiba) and 1 SDD (120GB Sandisk).  Here is my fstab, easier for me to understand.

root@hmc-P55A-UD3:/etc# cat   fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#              
# / was on /dev/sda10 during installation
# /mnt/shared was on /dev/sda8 during installation
# /mnt/staging was on /dev/sda9 during installation
# /mnt/vm was on /dev/sda7 during installation
# swap was on /dev/sda5 during installation

/dev/disk/by-id/ata-Hitachi_HDT721010SLA360_STF610MR15HK9P-part7 /mnt/vm ext3 defaults 0 2
/dev/disk/by-id/ata-Hitachi_HDT721010SLA360_STF610MR15HK9P-part8 /mnt/shared ext3 defaults 0 2
/dev/disk/by-id/ata-Hitachi_HDT721010SLA360_STF610MR15HK9P-part9 /mnt/staging ext3 defaults 0 2
#/dev/disk/by-id/ata-Hitachi_HDT721010SLA360_STF610MR15HK9P-part10 / ext4 errors=remount-ro 0 1
/dev/disk/by-id/ata-SanDisk_SDSSDA120G_152480401043-part1 / ext4 noatime,nodiratime,errors=remount-ro 0 1
/dev/disk/by-id/ata-Hitachi_HDT721010SLA360_STF610MR15HK9P-part5 none swap sw 0 0
#/dev/disk/by-id/ata-Hitachi_HDT721010SLA360_STF610MR15HK9P-part2 none swap sw 0 0
/dev/disk/by-id/ata-TOSHIBA_DT01ACA200_43J1EREGS-part1 /mnt/localubt ext4 defaults 0 2
/dev/disk/by-id/ata-TOSHIBA_DT01ACA200_43J1EREGS-part2 /mnt/shared2 ext4 defaults 0 2
 


gnome-disks a handy tool to manipulative this.



I also referenced https://radu.cotescu.com/migrating-your-ubuntu-machine-to-a-ssd-drive/

Prepared a few rescue Swiss knives like boot-repair, gparted, unetbootin, clonezilla, Ubuntu live CD (same version as my HDD) in bootable thumdrives.

Tuesday, September 08, 2015

steps to upgrade mysql 5.5 to 5.6

A general method:
  • use mysqldump to create backups of your database (users, trable structure and table data) and of your config file (probably /etc/mysql/my.cnf)

    /mnt/ssdata/mysql5.5_bak# time mysqldump --lock-all-tables -u root -p --all-databases > mysql5.5_dump.sql
    Enter password:
    -- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.

    real    1m50.291s
    user    0m52.281s
    sys     0m5.228s


     try to export again

    root@YZ37:/mnt/ssdata/mysql5.5_bak# time mysqldump --events --ignore-table=mysql.events --lock-all-tables -u root -p --all-databases > mysql5.5_dump2.sql
    Enter password:

    real    1m45.663s
    user    1m4.349s
    sys     0m5.483s
  • Remove 5.5. After removing 5.5 check that the innodb transactions files are gone (ibdata1, ib_logfile0 and ib_logfile1). As 5.6 uses the better version of transactioning I assume you also would to use this...
  • Install 5.6

    sudo apt-get remove mysql-server
    sudo apt-get autoremove
    sudo apt-get install mysql-client-5.6 mysql-client-core-5.6
    sudo apt-get install mysql-server-5.6
    
  • Change the new config file and add in what you changed for 5.5 (mind though the link above and check if any of the changes have become invalid).
  • Upload your backup into 5.6 (users first). Mind that this can take a bit of time since it will recreate new transaction files.


    I choose importing user databases one by one, except below these three system databases.
 information_schema 
 mysql              
 performance_schema 
 

mysql  Ver 14.04.3 LTS Distrib 5.6.19, for debian-linux-gnu (x86_64) using  EditLine wrapper

References:

http://askubuntu.com/questions/614886/upgrading-mysql-5-5-to-mysql-5-6-on-ubuntu-14-04-lts

another good article is http://xmodulo.com/upgrade-mysql-server-debian-ubuntu.html

http://sharadchhetri.com/2014/05/07/install-mysql-server-5-6-ubuntu-14-04-lts-trusty-tahr/

After upgrade, we may see this warning message:

2015-09-07 18:36:32 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql start/running, process 17378
Processing triggers for ureadahead (0.100.0-16) ...


The solution is set to explicit_defaults_for_timestamp=true in my.cnf

Do check mysql manual to understand its behaviour change of explicit_defaults_for_timestamp .