我的站点

一个系统软件工程师的随手涂鸦

Month: 二月 2016 (Page 2 of 3)

Oracle笔记(5)——连接数据库

Oracle的网络协议称之为Oracle NetSQL*NetNet8

连接数据库的两种方式:

(1)本地连接(Local

这种方式client和数据库位于同一台服务器上,数据通信不需要经过listener进程,而是通过Unix pipe方式进行通信。比如以SYS用户连接数据库:

sqlplus as / sysdba

或是利用ORACLE_SID环境变量指定本地数据库,然后使用用户名和密码进行连接:

sqlplus username/password

需要注意的是还有一个TWO_TASK环境变量指定远端数据库,而当这两个变量同时指定时,TWO_TASK优先级更高。

(2)远端连接(remote

这种方式client和数据库位于不同服务器上,连接时需要指定连接的数据库TNS名字:

sqlplus username/password@orcl

这种方式需要利用tnsnames.ora文件来解析数据库主机和端口,此外数据通信也要经过listener进程。

区分“本地连接”和“远端连接”的一个方法就是看连接数据库时是否指定数据库TNS名字:@tns_alia

(3)

Oracle client和数据库之间通信使用TNS(Transparent Network Substrate)协议,可以用wireshark解析:

Capture

 

参考资料:

research oracle tns protocol

Oracle Database Communication Protocol

Oracle 12c For Dummies ;

http://ora-exp.blogspot.com/2007/06/oraclesid-and-twotask-environment_21.html

Re: sqlplus connection from unix with and without the oracle sid

In Oracle, how do you change the ‘default’ database?

Should we consider “sqlplus” as an Oracle client?

SYSDBA password in Oracle DB

 

Oracle笔记(4)——tnsnames.ora文件

tnsnames.ora文件包含着Oracle数据库连接信息,是供client使用的(TNS代表Transport Network Substrate),位于$ORACLE_HOME/network/admin目录。举例如下:

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = npar1.xxxxxx.com)(PORT = 9005))
     (CONNECT_DATA =
      (SID = ORCL)
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCL)
    )
  )

client发起连接数据库请求:“"connect system/system@ORCL"”,就需要解析tnsnames.ora来获得Oracle数据库的地址和端口信息。在配置文件中,HOST指定数据库instance运行的主机,PORTlistener进程监听的端口。

参考资料:
LISTENER.ORA and TNSNAMES.ORA
Local Naming Parameters in the tnsnames.ora File

 

docker笔记(5)—— Volume

Docker image是一系列的read-only layer。当启动container以后,在read-only layer之上会增加一个read-write layer。当需要对文件进行修改时,就要把数据从read-only layer拷贝到read-write layer。因此,image的数据不会被破坏,container相当于操作的是image数据的副本。这种read-only layerread-write layer的结合称之为Union File System

因此,为使对数据的修改能够保存下来,docker引入了volume概念:volume即是位于主机文件系统上,而不是Union File System上的目录和文件。

(1)

$ docker run -it --name container-test -h CONTAINER -v /data debian /bin/bash
root@CONTAINER:/# ls /data
root@CONTAINER:/#   

container-test中的/data目录位于主机的位置:

$ docker inspect -f {{.Volumes}} container-test
map[/data:/var/lib/docker/vfs/dir/cde167197ccc3e138a14f1a4f7c0d65b32cecbada822b0db4cc92e79059437a9] 

(2)

$ docker run -v /home/adrian/data:/data debian ls /data

这种方式直接把主机上的目录映射到container中的一个目录。

参考资料:
Understanding Volumes in Docker

Oracle笔记(3)——Net Listener进程

Oracle Net Listener是一个独立的进程,负责处理client的请求,并把这些请求分发给相应的database instance。配置文件是listener.ora,位于$ORACLE_HOME/network/admin目录下。修改这个文件必须重启listener进程。

listener.ora如下所示:

# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/lis
tener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
 (SID_LIST =
  (SID_DESC =
   (GLOBAL_DBNAME = db01)
   (ORACLE_HOME = /u01/app/oracle/product/11.1.0/db_1)
   (SID_NAME = db01)
  )
  (SID_DESC =
   (GLOBAL_DBNAME = dev12c)
   (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
   (SID_NAME = dev12c)
  )
 )
LISTENER =
 (DESCRIPTION_LIST =
  (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = orasvr01)(PORT = 1521))
  )
  (DESCRIPTION =
   (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
  )
 )

SID_LIST_LISTENER部分指定listener进程需要处理的数据库连接;而LISTENER部分指定这些数据库所在的主机,以及listener进程需要监听的端口。

在数据库能够服务客户端请求之前,必须要启动listener进程。使用lsnrctl命令可以启动和停止listener进程:

$ lsnrctl start
$ lsnrctl stop

lsnrctl status命令可以用来检查listener的状态。

$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 16-FEB-2016 04:55:25

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=npar1.atc-hp.com)(PORT=9012)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                04-FEB-2016 01:01:06
Uptime                    12 days 3 hr. 54 min. 18 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File         /app/oracle/diag/tnslsnr/npar1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=npar1.atc-hp.com)(PORT=9012)))
Services Summary...
Service "ORCL2" has 1 instance(s).
  Instance "ORCL2", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

参考资料:
Configuring and Administering Oracle Net Listener
How to Configure the Database Listener with Listener.ora in Oracle 12c

 

Oracle笔记(2)——Oracle相关的环境变量

安装和使用Oracle时相关的环境变量:

(1)ORACLE_BASE
安装Oracle时的根目录,默认值为/u01/app/oracle

(2)ORACLE_HOME
安装特定版本Oracle时的目录,例如$ORACLE_BASE/product/11.2.0/dbhome_1

(3)ORACLE_SID
标明数据库的System Identifier(SID)SID用来代表某个数据库实例(instance),用来同其它instance相区分。

参考资料:
Administering Oracle Database
http://www.orafaq.com/wiki/ORACLE_SID
Oracle Database – Environment Variables / Registry Values

 

Sysdig笔记(3)——chisel

Sysdig中的chisel是用Lua语言编写的脚本,用来分析和处理sysdig产生的eventSysidg会在下列目录中查找chisel., ./chisels, ~/chisels和/usr/share/sysdig/chisels

列出sysdig所有的chisel

# sysdig -cl

Category: Application
---------------------
httplog         HTTP requests log
httptop         Top HTTP requests
memcachelog     memcached requests log

Category: CPU Usage
-------------------
spectrogram     Visualize OS latency in real time.
......

如果想查看关于某个chisel的详细信息,可以使用-i选项:

# sysdig -itopfiles_bytes

Category: I/O
-------------
topfiles_bytes  Top files by R+W bytes

Shows the top files in terms of disk usage. This chisel is compatable with cont
ainers using the sysdig -pc or -pcontainer argument, otherwise no container inf
ormation will be shown.
Args:
(None)

执行chisel使用-c选项:

# sysdig -c topfiles_bytes
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
144B                /dev/ptmx
Bytes               Filename
--------------------------------------------------------------------------------
165B                /dev/ptmx

也可以为chisel指定参数:

# sysdig -c topfiles_bytes "not fd.name contains /dev"
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
Bytes               Filename
--------------------------------------------------------------------------------
7.47KB              /proc/cpuinfo
1024B               /proc/meminfo

参考资料:

Sysdig Quick Reference Guide

Chisels User Guide

Haskell笔记 (18)—— Polymorphic function和oveloaded function

A function is called polymorphic (“of many forms”) if its type contains one or more type variables. E.g.: length :: [a] -> Int

A polymorphic function is called overloaded if its type contains one or more class constraints. E.g.: (+) :: Num a => a -> a -> a.

 

Haskell笔记 (17)—— Value和type

Because Haskell is a purely functional language, all computations are done via the evaluation of expressions (syntactic terms) to yield values (abstract entities that we regard as answers). Every value has an associated type. (Intuitively, we can think of types as sets of values.) Examples of expressions include atomic values such as the integer 5, the character ‘a’, and the function \x -> x+1, as well as structured values such as the list [1,2,3] and the pair (‘b’,4).

Just as expressions denote values, type expressions are syntactic terms that denote type values (or just types). Examples of type expressions include the atomic types Integer (infinite-precision integers), Char (characters), Integer->Integer (functions mapping Integer to Integer), as well as the structured types [Integer] (homogeneous lists of integers) and (Char,Integer) (character, integer pairs).

All Haskell values are “first-class”—they may be passed as arguments to functions, returned as results, placed in data structures, etc. Haskell types, on the other hand, are not first-class. Types in a sense describe values, and the association of a value with its type is called a typing. Using the examples of values and types above, we write typings as follows:

                      5  :: Integer
                     'a' :: Char
                     inc :: Integer -> Integer
                 [1,2,3] :: [Integer]
                 ('b',4) :: (Char,Integer)

The “::” can be read “has type.”

Haskell是一门纯函数式编程语言,所有的计算都是通过对表达式的求值完成的。每个值(value)都有一个相关的类型(type),也可以把类型看做是值的集合。在Haskell中,所有的值都是first-class,而类型却不是。类型和值的集合称之为typing

5  :: Integer

 

Haskell笔记 (16)—— Currying

Currying定义如下:

Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.

Haskell中所有函数都可以认为是curried,即函数只包含一个参数。在Haskell类型表示中,->是右相关的,因此f :: a -> b -> c实际上也是f :: a -> ( b -> c ),所以f x y(f x) y

参考资料:
Currying

 

如何理解“load average”?

*nix系统中,执行topuptime命令可以显示当前系统的load average(分别是过去1515分钟的load平均值):

# uptime
 14:43:37 up 22 days,  1:47,  5 users,  load average: 0.00, 0.01, 0.05

load指的是正在使用和等待使用CPUprocess的数量和。因此,在单核系统上,load average这个值低于1.00表示系统还很空闲,1.00表示系统已经达到100%利用率了,高于1.00就需要引起注意了。

此外,100%利用率和系统处理器数目有关,单核系统的值是1.00,双核系统值就是2.00了,以此类推。因此在多处理器系统上,有可能load average的值很高,可是系统CPU实际上还很空闲。

P.S.:得到CPU数目的方法:

# grep 'model name' /proc/cpuinfo | wc -l
8

参考资料:
WHAT ABOUT MULTI-PROCESSORS? MY LOAD SAYS 3.00, BUT THINGS ARE RUNNING FINE!

What’s the difference between load average and CPU load?

Examining Load Average

load average video

 

Page 2 of 3

Powered by WordPress & Theme by Anders Norén