0%

卸载formula的当前版本

1
$ brew remove postgresql

卸载formula全部版本

1
$ brew uninstall --force postgresql

卸载formula指定版本

1
2
$ brew switch postgresql 9.3.4
$ brew remove postgresql

卸载formula全部旧版本,如果不指定formula则清理所有formula的旧版本。

1
$ brew cleanup postgresql

===
[erq]

macbook air外接显示器时,如果要合盖不休眠,必须外接电源,合盖后使用外接键盘或鼠标唤醒电脑。如果是蓝牙键盘和鼠标,需要设置相应的蓝牙设备可以唤醒电脑。

cqlsh是cassandra用于执行cql命令的交互式终端程序,就如postgresql的psql,或者oracle的sql plus。
cqlsh是用python编写的,但当前版本5.0.1尚不支持python 3及以上版本,其代码中有如下行:

1
2
python -c 'import sys; sys.exit(not (0x020500b0 < sys.hexversion < 0x03000000))' 2>/dev/null \\
&& exec python "$0" "$@"

可见其只支持大于2.5小于3.0的python。

使用

1
$ brew install cassandra

安装cassandra后,已经自动安装好了cqlsh,直接执行cqlsh会有提示需要安装cassandra-driver

1
2
3
4
5
6
7
8
$cqlsh
Python Cassandra driver not installed, or not on PYTHONPATH.
You might try "pip install cassandra-driver".

Python: /usr/bin/python
Module load path: \['/usr/local/Cellar/cassandra/2.1.2/bin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages'\]

Error: No module named cassandra

然后安装cassandra-driver

1
$ pip install cassandra-driver

如果cqlsh仍然提示需要安装cassandra-driver,则是因为系统当前的pip是python3的

1
2
3
4
5
6
$ pip show canssandra-driver
---
Name: cassandra-driver
Version: 2.1.3
Location: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Requires: futures, six

那么需要安装pip for python 2.x

1
$ brew install python

然后为python 2.x 安装cassandra-driver

1
2
3
4
5
6
7
$ pip2 install cassandra-driver
$ pip2 show cassandra-driver
---
Name: cassandra-driver
Version: 2.1.3
Location: /usr/local/lib/python2.7/site-packages
Requires: futures, six

因为brew安装的python库路径在/usr/local/lib/python2.7/site-packages,所以还需要将其添加到python模块搜索路径,.bashrc中添加如下行:

1
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

然后再执行cqlsh应该就可以了

1
2
3
4
5
$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
\[cqlsh 5.0.1 Cassandra 2.1.2 CQL spec 3.2.0 Native protocol v3\]
Use HELP for help.
cqlsh>

===
[erq]

大约有这么几种方法:
1、
添加环境变量PYTHONPATH,python会添加此路径下的模块,在.bashrc文件中添加如下类似行:

1
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

2、
在site-packages路径下添加一个路径配置文件,文件的扩展名为.pth,内容为要添加的路径即可

3、
sys.path.append()函数添加搜索路径,参数值即为要添加的路径。

===
[erq]

nodetool查看本地集群状态时,N久以后出现无法连接、连接超时的错误提示:

1
2
$ nodetool status
nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection timed out'.

经排查为/etc/hosts文件配置错误所致,文件中实际的主机名(不是localhost)对应的ip地址解析行设置错误,这是由于主机ip地址更换后未及时更新hosts文件所致。更改为正确的ip地址类似如下:

1
192.168.1.104 yoga.localdomain yoga

然后重新启动cassandra服务

1
2
$ sudo /etc/init.d/cassandra restart
\[ ok \] Restarting cassandra (via systemctl): cassandra.service.

或者

1
$ sudo systemctl restart cassandra.service

然后再重新执行

1
2
3
4
5
6
7
$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 139.45 KB 256 100.0% 27e51705-c13d-4f4b-b4f8-de3759fcd895 rack1

如果cassandra尚未完全启动时就执行该命令,会有异常抛出,类似如下:

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
$ nodetool status
error: No nodes present in the cluster. Has this node finished starting up?
-- StackTrace --
java.lang.RuntimeException: No nodes present in the cluster. Has this node finished starting up?
at org.apache.cassandra.dht.Murmur3Partitioner.describeOwnership(Murmur3Partitioner.java:129)
at org.apache.cassandra.service.StorageService.effectiveOwnership(StorageService.java:3762)
at org.apache.cassandra.service.StorageService.effectiveOwnership(StorageService.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:112)
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:46)
at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:237)
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138)
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:252)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Mac OS X平台上/etc/hosts文件中根本就不设置主机名对应的IP地址解析,而出现的错误提示也略有不同:

1
nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Operation timed out'.

解决办法也是一样的,对于动态ip的客户端测试环境而言,直接将主机名对应的ip设置为127.0.0.1亦可:

1
127.0.0.1 mba

重新加载cassandra就可以了

1
2
$ launchctl unload /usr/local/opt/cassandra/homebrew.mxcl.cassandra.plist
$ launchctl load /usr/local/opt/cassandra/homebrew.mxcl.cassandra.plist

===
[erq]

cassandra 2.1.2的启动日志中出现如下字样:

1
WARN \[main\] 2013-11-24 10:54:30,423 CassandraDaemon.java (line 155) OpenJDK is not recommended. Please upgrade to the newest Oracle Java release

查看CassandraDaemon.java源代码,有如下行:

1
2
3
4
5
6
7
8
9
10
11
12
 String javaVmName = System.getProperty("java.vm.name");
logger.info("JVM vendor/version: {}/{}", javaVmName, javaVersion);
if (javaVmName.contains("OpenJDK"))
{
// There is essentially no QA done on OpenJDK builds, and
// clusters running OpenJDK have seen many heap and load issues.
logger.warn("OpenJDK is not recommended. Please upgrade to the newest Oracle Java release");
}
else if (!javaVmName.contains("HotSpot"))
{
logger.warn("Non-Oracle JVM detected. Some features, such as immediate unmap of compacted SSTables, may not work as intended");
}

OpenJDK没这么差吧!

===
[erq]

git blame 命令用于Show what revision and author last modified each line of a file
直接

1
$ git blame filename

或者用git log命令

1
$ git log -p filename

然后搜索一下吧

===
[erq]

dataguard环境下使用alter user sys identified by 语句修改主库的sys用户密码时,不会自动更新备库的密码文件。而Oracle Dataguard环境的日志传输安全机制依赖于密码文件,因为备库也需要做相应的修改才可以正常的进行日志恢复。而备库随时有可能成为主库,因此修改密码后应该将主库的密码文件同步到备库。

首先,停止备库

1
SQL> shutdown immediate

然后,将主库密码文件覆盖备库的密码文件
最后,启动备库,打开日志实时恢复

1
2
SQL> startup mount
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

===
[erq]