colorful

zc qq:1337220912

 

u盘centos64位

http://wenku.baidu.com/view/e63438745acfa1c7aa00cc83.html

posted @ 2013-07-15 07:14 多彩人生 阅读(232) | 评论 (0)编辑 收藏

Postgresql 学习

要看
http://www.cnblogs.com/stephen-liu74/archive/2012/05/30/2306493.html

http://www.cnblogs.com/ringofthec/archive/2010/11/14/hehe.html

http://jingyan.baidu.com/article/6766299717faec54d41b8477.html

http://www.cnblogs.com/hyddd/archive/2010/04/08/1706863.html  // vim学习

posted @ 2013-07-14 16:49 多彩人生 阅读(218) | 评论 (0)编辑 收藏

Postgresql跨数据库查询

postgres 跨数据库查询

dblink 的安装
   linux
      #cd postgres源码安装目录/contrib/dblink
      # make
      # make install
      注意: 如果你在安装了postgres后执行了 make clean, make distclean, 那你可能需要重新 ./configure make make install 一下
   windows
      windows 默认是安装的

dblink模块加载
   PostgreSQL 有很多外部模块可以加载,例如 dblink, pg_buffercache 等,在 9.1 版本
   以前,只要对应的 postgresql-contrib 已经安装,只需要将对应的 sql 文件导入到目标库
   即可,例如,要在 数据库 skytf 里安装 dblink 模块,只需要执行以下操作就行;

   cd $PGHOME/share/contrib
   psql -d skytf -U postgresql -f dblink.sql
   导入成功之后,那么 dblink 模块即加载成功。
   
   注意!!
   在 9.1 版本以后,模块加载环节 PostgreSQL 提供命令 "CREATE EXTENSION" 来替代以上操作。  
   通过执行 CREATE EXTENSION dblink来加载 dblink

dblink 使用:
   关于dblink, dblink_connect, dblink_disconnect 请参考手册
   http://www.postgresql.org/docs/9.1/static/dblink.html
   例1
   select dblink_connect('连接名','host=192.168.1.27  port=1921 dbname=testdb user=test_user password=test_user' );
   host, port, user等 可以跟据情况省略掉

   例2
   select * from tb1 inner join dblink('dbname=db2', 'select id from tb2 where id=\'20120623\'') as acc(id int) on tb1.id = acc.id order by tb1.id;

参考网站:
http://blog.sina.com.cn/s/blog_538d55be01010clc.html
http://francs3.blog.163.com/blog/static/4057672720108401139868/
http://www.postgresql.org/docs/9.1/static/dblink.html
http://zhenghaoju700.blog.163.com/blog/static/135859518201251382628663/

posted @ 2013-07-14 16:46 多彩人生 阅读(1303) | 评论 (0)编辑 收藏

open 与fopen

http://www.360doc.com/content/11/0901/14/2338020_144987612.shtml

posted @ 2013-07-13 22:48 多彩人生 阅读(191) | 评论 (0)编辑 收藏

Linux top 命令详解

http://blog.csdn.net/sunboy_2050/article/details/6129177

查看多核CPU命令

 mpstat -P ALL  和  sar -P ALL 

 

说明:sar -P ALL > aaa.txt   重定向输出内容到文件 aaa.txt

 

top命令经常用来监控linux的系统状况,比如cpu、内存的使用,程序员基本都知道这个命令,但比较奇怪的是能用好它的人却很少,例如top监控视图中内存数值的含义就有不少的曲解。

本文通过一个运行中的WEB服务器的top监控截图,讲述top视图中的各种数据的含义,还包括视图中各进程(任务)的字段的排序。

 

top进入视图

top视图 01

top视图 01

【top视图 01】是刚进入top的基本视图,我们来结合这个视图讲解各个数据的含义。

第一行:
10:01:23 — 当前系统时间
126 days, 14:29 — 系统已经运行了126天14小时29分钟(在这期间没有重启过)
2 users — 当前有2个用户登录系统
load average: 1.15, 1.42, 1.44 — load average后面的三个数分别是1分钟、5分钟、15分钟的负载情况。

load average数据是每隔5秒钟检查一次活跃的进程数,然后按特定算法计算出的数值。如果这个数除以逻辑CPU的数量,结果高于5的时候就表明系统在超负荷运转了。

第二行:
Tasks — 任务(进程),系统现在共有183个进程,其中处于运行中的有1个,182个在休眠(sleep),stoped状态的有0个,zombie状态(僵尸)的有0个。

第三行:cpu状态
6.7% us — 用户空间占用CPU的百分比。
0.4% sy — 内核空间占用CPU的百分比。
0.0% ni — 改变过优先级的进程占用CPU的百分比
92.9% id — 空闲CPU百分比
0.0% wa — IO等待占用CPU的百分比
0.0% hi — 硬中断(Hardware IRQ)占用CPU的百分比
0.0% si — 软中断(Software Interrupts)占用CPU的百分比

在这里CPU的使用比率和windows概念不同,如果你不理解用户空间和内核空间,需要充充电了。

第四行:内存状态
8306544k total — 物理内存总量(8GB)
7775876k used — 使用中的内存总量(7.7GB)
530668k free — 空闲内存总量(530M)
79236k buffers — 缓存的内存量 (79M)

第五行:swap交换分区
2031608k total — 交换区总量(2GB)
2556k used — 使用的交换区总量(2.5M)
2029052k free — 空闲交换区总量(2GB)
4231276k cached — 缓冲的交换区总量(4GB)

这里要说明的是不能用windows的内存概念理解这些数据,如果按windows的方式此台服务器“危矣”:8G的内存总量只剩下530M的可用内存。Linux的内存管理有其特殊性,复杂点需要一本书来说明,这里只是简单说点和我们传统概念(windows)的不同。

第 四行中使用中的内存总量(used)指的是现在系统内核控制的内存数,空闲内存总量(free)是内核还未纳入其管控范围的数量。纳入内核管理的内存不见 得都在使用中,还包括过去使用过的现在可以被重复利用的内存,内核并不把这些可被重新使用的内存交还到free中去,因此在linux上free内存会越 来越少,但不用为此担心。

如果出于习惯去计算可用内存数,这里有个近似的计算公式:第四行的free + 第四行的buffers + 第五行的cached,按这个公式此台服务器的可用内存:530668+79236+4231276 = 4.7GB。

对于内存监控,在top里我们要时刻监控第五行swap交换分区的used,如果这个数值在不断的变化,说明内核在不断进行内存和swap的数据交换,这是真正的内存不够用了。

第六行是空行

第七行以下:各进程(任务)的状态监控
PID — 进程id
USER — 进程所有者
PR — 进程优先级
NI — nice值。负值表示高优先级,正值表示低优先级
VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR — 共享内存大小,单位kb
S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU — 上次更新到现在的CPU时间占用百分比
%MEM — 进程使用的物理内存百分比
TIME+ — 进程使用的CPU时间总计,单位1/100秒
COMMAND — 进程名称(命令名/命令行)

多U多核CPU监控

在top基本视图中,按键盘数字“1”,可监控每个逻辑CPU的状况:

top视图 02

top视图 02

观察上图,服务器有16个逻辑CPU,实际上是4个物理CPU。

进程字段排序

默 认进入top时,各进程是按照CPU的占用量来排序的,在【top视图 01】中进程ID为14210的java进程排在第一(cpu占用100%),进程ID为14183的java进程排在第二(cpu占用12%)。可通过 键盘指令来改变排序字段,比如想监控哪个进程占用MEM最多,我一般的使用方法如下:

1. 敲击键盘“b”(打开/关闭加亮效果),top的视图变化如下:

top视图 03

top视图 03

我们发现进程id为10704的“top”进程被加亮了,top进程就是视图第二行显示的唯一的运行态(runing)的那个进程,可以通过敲击“y”键关闭或打开运行态进程的加亮效果。

2. 敲击键盘“x”(打开/关闭排序列的加亮效果),top的视图变化如下:

top视图 04

top视图 04

可以看到,top默认的排序列是“%CPU”。

3. 通过”shift + >”或”shift + <”可以向右或左改变排序列,下图是按一次”shift + >”的效果图:

top视图 05

top视图 05

视图现在已经按照%MEM来排序了。

改变进程显示字段

1. 敲击“f”键,top进入另一个视图,在这里可以编排基本视图中的显示字段:

top视图 06

top视图 06

这里列出了所有可在top基本视图中显示的进程字段,有”*”并且标注为大写字母的字段是可显示的,没有”*”并且是小写字母的字段是不显示的。如果要在基本视图中显示“CODE”和“DATA”两个字段,可以通过敲击“r”和“s”键:

top视图 07

top视图 07

2. “回车”返回基本视图,可以看到多了“CODE”和“DATA”两个字段:

top视图 08

top视图 08

top命令的补充

top 命令是Linux上进行系统监控的首选命令,但有时候却达不到我们的要求,比如当前这台服务器,top监控有很大的局限性。这台服务器运行着 websphere集群,有两个节点服务,就是【top视图 01】中的老大、老二两个java进程,top命令的监控最小单位是进程,所以看不到我关心的java线程数和客户连接数,而这两个指标是java的 web服务非常重要的指标,通常我用ps和netstate两个命令来补充top的不足。

监控java线程数:
ps -eLf | grep java | wc -l

监控网络客户连接数:
netstat -n | grep tcp | grep 侦听端口 | wc -l

上面两个命令,可改动grep的参数,来达到更细致的监控要求。

在 Linux系统“一切都是文件”的思想贯彻指导下,所有进程的运行状态都可以用文件来获取。系统根目录/proc中,每一个数字子目录的名字都是运行中的 进程的PID,进入任一个进程目录,可通过其中文件或目录来观察进程的各项运行指标,例如task目录就是用来描述进程中线程的,因此也可以通过下面的方 法获取某进程中运行中的线程数量(PID指的是进程ID):

ls /proc/PID/task | wc -l

在linux中还有一个命令pmap,来输出进程内存的状况,可以用来分析线程堆栈:

pmap PID

posted @ 2013-07-13 11:30 多彩人生 阅读(357) | 评论 (0)编辑 收藏

ERROR:invalid byte sequence for encoding"UTF8

http://blog.sina.com.cn/s/blog_680f6fa70100ldrg.html
     

原因是没有正确设置客户端字符集。

      默认情况下,PostgreSQL是不转换字符集的,如果你的数据库是UTF8的字符集,一般终端的中文字符集会设置为GBK,或en_US(查看终端的 字符集可以看LANG环境变量的设置),所以你输入的中文是GBK的编码,这个编码不经转换的存入数据库中,而数据库是UTF8的,PostgreSQL 一看没有这样的UTF8编码,所以当然报错了。
解决方法】:
方法一:设置postgresql的客户端编码为GBK,这时PostgreSQL就知道输入的内容是GBK编码的,这样PostgreSQL数据库会自动做字符集的转换,把其转换成UTF8编码。
方法二:直接设置终端的字符集编码为UTF8,让输入的编码直接为UTF8,而不是GBK。
 
具体演示】:
 设置postgresql的客户端编码:
设置psql客户端字符集为GBK,方法有两种,一种是在psql中输入“\encoding GBK” ,另一种是设置环境变量“export PGCLIENTENCODING=GBK”,演示如下:
#psql -d dsc
dsc=# insert into t values(1,'中国');
ERROR:  invalid byte sequence for encoding "UTF8": 0xd6d0
HINT:  This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
dsc=# show client_encoding;
 client_encoding
-----------------
 UTF8
(1 row)
dsc=# \encoding GBK 
dsc=# show client_encoding;
 client_encoding
-----------------
 GBK
(1 row)
dsc=# insert into t values(1,'中国');
INSERT 0 1
dsc=# commit;
WARNING:  there is no transaction in progress
COMMIT
dsc=# select * from t;
 id | name
----+------
  1 | 中国
(1 row)

[postgres@dsc ~]$ export PGCLIENTENCODING=GBK
[postgres@dsc ~]$ psql
psql: FATAL:  conversion between GBK and LATIN1 is not supported
[postgres@dsc ~]$ psql -d dsc
psql (8.4.3)
Type "help" for help.
dsc=# select * from t;
 id | name
----+------
  1 | 中国
(1 row)
dsc=# insert into t values(2,'我的中国');
INSERT 0 1
dsc=# select * from t;                  
 id |   name  
----+----------
  1 | 中国
  2 | 我的中国
(2 rows)

posted @ 2013-07-12 14:00 多彩人生 阅读(606) | 评论 (0)编辑 收藏

安装postgresql 出现readline错误

http://blog.csdn.net/shutfuckingup/article/details/8532752

1 环境信息
OS: CentOS release 5.2(Final)
PG: postgresql-9.0.0]

2 根据提示,我测试了下 configre命令,果然报这个错
[root@HK81-107postgresql-9.0.0]# ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support...yes
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking if gcc supports -Wdeclaration-after-statement...yes
checking if gcc supports -Wendif-labels... yes
checking if gcc supports -fno-strict-aliasing... yes
checking if gcc supports -fwrapv... yes
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... yes
checking whether to build with Tcl... no
checking whether to build Perl modules... no
checking whether to build Python modules... no
checking whether to build with GSSAPI support... no
checking whether to build with Kerberos 5 support... no
checking whether to build with PAM support... no
checking whether to build with LDAP support... no
checking whether to build with Bonjour support... no
checking whether to build with OpenSSL support... no
checking for grep that handles long lines and -e.../bin/grep
checking for egrep... /bin/grep -E
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for ranlib... ranlib
checking for strip... strip
checking whether it is possible to strip libraries... yes
checking for ar... ar
checking for tar... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for bison... no
configure: WARNING:
*** Without Bison you will not be able to build PostgreSQL from CVSnor
*** change any of the parser definition files. You can obtain Bison from
*** a GNU mirror site.  (If you are using theofficial distribution of
*** PostgreSQL then you do not need to worry about this, becausethe Bison
*** output is pre-generated.)
checking for flex... no
configure: WARNING:
*** Without Flex you will not be able to build PostgreSQL from CVSnor
*** change any of the scanner definition files. You can obtain Flex from
*** a GNU mirror site.  (If you are using theofficial distribution of
*** PostgreSQL then you do not need to worry about this because theFlex
*** output is pre-generated.)
checking for perl... /usr/bin/perl
configure: using perl 5.8.8
checking for main in -lm... yes
checking for library containing setproctitle... no
checking for library containing dlopen... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... nonerequired
checking for library containing crypt... -lcrypt
checking for library containing fdatasync... nonerequired
checking for library containing gethostbyname_r... nonerequired
checking for library containing shmget... none required
checking for -lreadline... no
checking for -ledit... no
configure: error: readline library notfound
If you have readline already installed, see config.log for detailson the
failure.  It is possible the compiler isnt lookingin the proper directory.
Use --without-readline to disable readlinesupport.

    根据提示,应该是没有安装 readline包。

3 检查系统是否安装 readline 包
[root@HK81-107postgresql-9.0.0]# rpm -qa | grep readline
readline-5.1-3.el5

   说明系统已经安装了 readline包。

4 通过 yum 搜索相关的readline 包
[root@HK81-107postgresql-9.0.0]# yum search readline
lftp.i386 : A sophisticated file transfer program
lftp.i386 : A sophisticated file transfer program
php-readline.i386 : Standard PHP module provides readline librarysupport
lftp.i386 : A sophisticated file transfer program
readline.i386 : A library for editing typed commandlines.
compat-readline43.i386 : The readline 4.3 library for compatibilitywith older software.
readline-devel.i386 : Files needed to develop programs which usethe readline library.
readline.i386 : A library for editing typed command lines.

 根据提示,有一个包引起了我的注意 "readline-devel",猜想可能与这个包有关。
 
5 安装 readline-devel 包
[root@HK81-107postgresql-9.0.0]# yum -y install -y readline-devel
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package readline-devel.i386 0:5.1-3.el5 set tobe updated
--> Processing Dependency: libtermcap-devel forpackage: readline-devel
--> Running transaction check
---> Package libtermcap-devel.i386 0:2.0.8-46.1 setto be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                Arch      Version         Repository       Size 
=============================================================================
Installing:
 readline-devel         i386      5.1-3.el5       base             146 k
Installing for dependencies:
 libtermcap-devel       i386      2.0.8-46.1      base              56 k

Transaction Summary
=============================================================================
Install     2Package(s)         
Update      0Package(s)         
Remove      0Package(s)        

Total download size: 201 k
Downloading Packages:
(1/2): libtermcap-devel-2 100%|=========================|  56kB   00:00     
(2/2): readline-devel-5.1 100% |=========================| 146kB   00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing:libtermcap-devel            ######################### [1/2] 
  Installing:readline-devel              ######################### [2/2]

Installed: readline-devel.i386 0:5.1-3.el5
Dependency Installed: libtermcap-devel.i386 0:2.0.8-46.1
Complete!

6 再次执行 configure 成功。

7 关于 readline 的解释,来自官网
--without-readline
Prevents use of the Readline library (and libedit as well). Thisoption disables command-line 
editing and  history in psql, so it is notrecommended.

   说明: 根据步骤2 执行 configure时报错提示,可以加上 "--without-readline" 从而避开这个ERROR,
但Postgresql官方不推荐这么做,所以还是安装吧。

posted @ 2013-07-11 20:58 多彩人生 阅读(3602) | 评论 (0)编辑 收藏

centos 6.2 apache安装

Apache2的是作为一个CentOS的软件包,因此我们可以直接用下面命令安装它:

    yum install httpd

  现在配置系统在引导时启动Apache

    chkconfig --levels 235 httpd on

  并启动Apache

    /etc/init.d/httpd start

  现在,您的浏览器到http://192.168.0.100,你应该看到Apache2的测试页:

  Apache的默认文档根目录是在CentOS上的/var/www/html 目录 ,配置文件是/etc/httpd/conf/httpd.conf。配置存储在的/etc/httpd/conf.d/目录。

posted @ 2013-07-11 19:03 多彩人生 阅读(252) | 评论 (0)编辑 收藏

linux查看目录大小


可以使用:
[tuest@demoserver ~]$ du --max-depth 1 /tmp  -h
4.0K    /tmp/.X11-unix
4.0K    /tmp/.ICE-unix
4.0K    /tmp/.font-unix
5.9M    /tmp


就可以看到目录下所有文件夹的内容大小

如果只想看一个目录的大小可以使用:
[tuest@demoserver ~]$ du /tmp -sh
5.9M    /tmp

posted @ 2013-07-11 18:48 多彩人生 阅读(276) | 评论 (0)编辑 收藏

Linux 中如何卸载已安装的软件.

Linux 中如何卸载已安装的软件.
  Linux软件的安装和卸载一直是困扰许多新用户的难题。在 Windows中,我们可以使用软件自带的安装卸载程序或在控制面板中的“添加/删除程序”来实现。与其相类似,在Linux下有一个功能强大的软件安装 卸载工具,名为RPM。它可以用来建立、安装、查询、更新、卸载软件。该工具是在命令行下使用的。在Shell的提示符后输入rpm,就可获得该命令的帮 助信息。

  软件的安装

  Linux下软件的安装主要有两种不同的形式。第一种安装文件名为xxx.tar.gz;另一种安装文件名为xxx.i386.rpm。以第一种方式发行的软件多为以源码形式发送的;第二种方式则是直接以二进制形式发送的。

  对于第一种,安装方法如下:

  1 .首先,将安装文件拷贝至你的目录中。例如,如果你是以root身份登录上的,就将软件拷贝至/root中。

  #cp xxx.tar.gz /root

  2 .由于该文件是被压缩并打包的,应对其解压缩。命令为:

  #tar xvzf filename.tar.gz 如果是filename.tar.bz2格式的,应该是tar jxvf filename.tar.bz2来解压

  3. 执行该命令后,安装文件按路径,解压缩在当前目录下。用ls命令可以看到解压缩后的文件。通常在解压缩后产生的文件中,有“Install”的文件。该文件为纯文本文件,详细讲述了该软件包的安装方法。

  4.执行解压缩后产生的一个名为configure的可执行脚本程序。它是用于检查系统是否有编译时所需的库,以及库的版本是否满足编译的需要等安装所需要的系统信息。为随后的编译工作做准备。命令为: #./configure

  如果您想把软件安装到指定目录,应该用#./configure --prefix=/您自己指定的目录,比如我想把一个mlterm安装到/opt/mlterm目录中,应该如下输入

  #./configure --prefix=/opt/mlterm

  5.检查通过后,将生成用于编译的MakeFile文件。此时,可以开始进行编译了。编译的过程视软件的规模和计算机性能的不同,所耗费的时间也不同。命令为: #make。

  6.成功编译后,键入如下的命令开始安装:

  #make install

  7.安装完毕,应清除编译过程中产生的临时文件和配置过程中产生的文件。键入如下命令:

  #make clean

  #make distclean

  至此,软件的安装结束。

  对于第二种,其安装方法要简单得多。

  同第一种方式一样,将安装文件拷贝至你的目录中。然后使用rpm来安装该文件。命令如下:

  #rpm -i filename.i386.rpm

  rpm将自动将安装文件解包,并将软件安装到缺省的目录下。并将软件的安装信息注册到rpm的数据库中。参数i的作用是使rpm进入安装模式。

  软件的卸载

  1.软件的卸载主要是使用rpm来进行的。卸载软件首先要知道软件包在系统中注册的名称。键入命令:

  #rpm -q -a

  即可查询到当前系统中安装的所有的软件包。

  2. 确定了要卸载的软件的名称,就可以开始实际卸载该软件了。键入命令:

  #rpm -e [package name]

  即可卸载软件。参数e的作用是使rpm进入卸载模式。对名为[package name]的软件包进行卸载。由于系统中各个软件包之间相互有依赖关系。如果因存在依赖关系而不能卸载,rpm将给予提示并停止卸载。你可以使用如下的命令来忽略依赖关系,直接开始卸载:

  #rpm -e [package name] -nodeps

  忽略依赖关系的卸载可能会导致系统中其它的一些软件无法使用

  如果想知道rpm包安装到哪里了呢?

  应该用 #rpm -ql [package name]

  3.如何卸载用源码包安装的软件?

  最好是看README和INSTALL ;一般的情况下都有说,但大多软件没有提供源码包的卸载方法;我们可以找到软件的安装点删除。主要看你把它安装在哪了。

  比如:

  如果安装软件时,指定个目录。这个问题也不会难;

  比如用源码包安装gaim 的

  #./configure --prefix=/opt/gaim

  #make

  #make install

  如果安装mlterm

  #./configure --prefix=/opt/mlterm

  #make

  #make install

  把源码包安装的软件,都指定安装在 /opt目录中,这样不就知道了;

  如果删除,就删除相应的软件目录;

  有些软件要在解压安装目录中执行 make uninstall ,这样就卸载掉了。

posted @ 2013-07-11 18:43 多彩人生 阅读(413) | 评论 (0)编辑 收藏

仅列出标题
共25页: First 4 5 6 7 8 9 10 11 12 Last 

导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜