centos


----------ps -ewf显示所有进程,ps -a|grep ss指的是显示ss关键字的所有进程。top是动态显示进程。

---------cat直接将文件内容显示在终端上。

---------查看linux系统版本信息cat /etc/*release。

---------从一台Linux机子拷贝recovery.conf.sample到192.168.59.128机子:scp recovery.conf.sample root@192.168.59.128:/home/pg93/test_rep

---------ll 列出文件权限d表示是文件夹r表示可读w表示可行x表示可执行。(ll -t。是按照时间降序)

---------netstat -anp|grep ss指的是显示包括ss关键字的所有服务端口。

----------文件重命名:mv aaa bbb。(mv就是这个意思)。

----------解压tar -jxvf aaa.tar

-----------查看文件abc.txt大小单位MB:du -sh /home/abc.txt

--------------快速搜索文本grep -r xxx /usr/local/yyy 。搜索目录yyy下的所有文件内容中含有关键字xxx的文件,并列出来。

-----------查找文件或者文件夹的名字中含有recovery.conf关键字的:find -name recovery.conf。

-----------查看软件是否被安装:rpm -qa|grep readl。查看含有关键字readl的包是否被安装。

-----------在网上搜索含有readl的包yum search readl

----------查看一个包的路径:which psql

-----------显示当前路径:pwd

-----------改变pg93用户的环境变量:cd /home/pg93  vi .bash_profile 修改即可,完了之后需要执行source /home/pg93/.bash_profile,例如:

export PGPORT=1921
export PGDATA=/pgdata/pg_root
export LANG=en_US.utf8
export PGHOME=/home/pg93/pgsql
export
LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGHOST=$PGDATA
alias rm='rm -i'
alias ll='ls -lh'
export PGDATABASE=digoal

-----------修改防火墙ipstables:vi /etc/sysconfig/iptables,允许或限制端口。




登陆postgresql数据库后如果想:

--------------查看数据库所有参数:show all;

--------------查看表/视图等的详细信息:\d+ pg_stat_activity。(查看pg_stat_activity视图的详细信息,包括SQL语句的组成)

--------------切换查看SQL输出内容的方式(水平/垂直):\x

--------------查看有哪些表空间:\db

--------------请求一个checkpoint点:checkpoint;(将脏数据flush一下文件)

---------------强行将一个xlog:select pg_switch_xlog();(归档日志切换到下一个日志可以)

--------------查看表空间大小: select pg_size_pretty(pg_tablespace_size('pg_default')); 。pg_default是表空间名

--------------查看所的状态:select relation::regclass,* from pg_locks;(relation::regclass为table/index...)

--------------查看索引:\di

---------------查看当期那数据库连接的pid:select pg_backend_pid();

---------------查看数据库有安装有哪些中间件。\dx

---------------查看数据库有关键字page的所有函数。\df *page*

---------------查看当前的事务ID(XID):select txid_current();

---------------查看role:\du

---------------查看relation的行锁:select * from pgrowlocks('a');(查看a表的行级锁,需要create extension pgrowlocks;)

---------------查看一个表的所有tuple(行)在PAGE(页)中的位置:select ctid, xmin, xmax, * from testtb;(可以使用create extension pageinspect;查看PAGE的内容http://blog.163.com/digoal@126/blog/static/16387704020114273265960/

ctid:内容是(哪一个PAGE,属于此PAGE下的第几个)
xmin:插入此tuple的XID(事务ID)
xmax:更新(UPDATE/DELETE)此tuple的XID(事务ID)
--------------两个普通会话间事务等待

事务1:update testtb set info='aaaa' where id=1;
事务2:update testtb set info='bbbb' where id=1;
此时事务2会等待被事务1的提交,然后事务2才会提交,然后覆盖事务1提交的容。
-------------两个会话间使用repeatable read

事务1:update testtb set info='aaaa' where id=1;
事务2:update testtb set info='bbbb' where id=1;
此时事务2会等待事务1提交,然后会报错 ERROR:  could not serialize access due to concurrent update
-------------两个会话间使用repeatable read,一个使用read committed

事务1:update testtb set info='aaaa' where id=1;(repeatable read)
事务2:update testtb set info='bbbb' where id=1; (read committed)
此时事务2会等待事务1提交,然后用事务2提交后结果覆盖事务1。
事务1:update testtb set info='bbbb' where id=1; (read committed)
事务2:update testtb set info='aaaa' where id=1;(repeatable read)
此时事务2会等待事务1提交,然后会报错 ERROR:  could not serialize access due to concurrent update
-------------两个会话间都使用read committed

事务1:update testtb set info='aaaa' where id=1;(read committed)
事务2:update testtb set info='bbbb' where id=1; (read committed)
此时事务2会等待事务1提交,然后用事务2提交后结果覆盖事务1。
-------------Serializable(串行隔离)

事务1:update testtb set info='777777777' where id=1;(Serializable)
事务2:update testtb set info='888888888' where id=2;(Serializable)
此时事务2会等待事务1提交,然后会报错ERROR:  could not serialize access due to read/write dependencies among transactions
虽然更新表testtb的是两个不同的tuple到那时也会报错的原因是还没有给表testtb建立索引。串行隔离会锁住与之相关SQL语句相关执行计划的内容。
参看:http://pan.baidu.com/disk/home#dir/path=%2F%E6%95%B0%E6%8D%AE%E5%BA%93%2Fpostgresql%2FPostgreSQL%209.3%20%E5%9F%B9%E8%AE%AD%E8%A7%86%E9%A2%91 下的PostgreSQL 9.3 培训 - D3.pdf,然后所有‘Serializable’即可。
-----------一般事务的互锁,SERIALIZABLE事务的互锁,repeatable read,read committed事务的互锁都是一样,如下:参考http://blog.163.com/digoal@126/blog/static/16387704020113811711716/

事务1:update a set id=id+2 where id=55;
事务2:update b set id=id+2 where id=55;
事务1:update b set id=id+2 where id=55;------此时会等待事务2结束
事务2:update a set id=id+2 where id=55;------此时会等待事务1结束
然后等待1毫秒(在postgresql.conf设置deadlock_timeout参数)后会报错 DETAIL:  Process 2847 waits for ShareLock on transaction 1897; blocked by process 2845.
Process 2845 waits for ShareLock on transaction 1899; blocked by process 2847.
HINT:  See server log for query details.








--------------在安装postgresql的时候需要依赖一个flex,readline-devl:yum -y install flex, yum -y install readline-devel, yum -y install zlib-devel

--------------在安装postgresql的时候可以使用gmake word,gmake install-world这样会将postgresql所有的contrib下的包编译并安装。

--------------postgresql各个中间件project下载http://git.postgresql.org/gitweb/

--------------pgfincore使用说明http://francs3.blog.163.com/blog/static/4057672720107541611270/  http://villemain.org/projects/pgfincore  http://blog.163.com/digoal@126/blog/static/1638770402011630102117658/  http://blog.csdn.net/wanghai__/article/details/6547786

--------------postgresql.conf配置文件参数说明:

tcp_keepalives_count==>tcp_keepcnt 关闭一个非活跃连接之前进行探测的最大次数,默认为 8 次(0表示系统默认值)
tcp_keepalives_idle==>tcp_keepidle 对一个连接进行有效性探测之前运行的最大非活跃时间间隔,默认值为 14400(即 2 个小时)(0表示系统默认值)
tcp_keepalives_interval==>tcp_keepintvl 两个探测的时间间隔,默认值为 150 即 75 秒(0表示系统默认值)
authentication_timeout==>客户端连接数据库时的认证时长
max_prepared_transactions==>一个数据库可以同时开启几个事务停留在磁盘上。(0表示数据库将关闭此特性)
work_mem==>排序操作内存大小(DISTINCT,ORDER BY,MERGE会用到排序)
temp_buffers==>每个数据库的私有内存,临时表使用。
maintenance_work_mem==>每个数据库的私有内存,VACUUM,CREATE INDEX,ALTER TABLE等操作所用内存
max_stack_depth==>一个连接数据库的进程锁使用的栈大小。
max_fsm_relations==>FSM跟踪的表和索引的个数的上限,每个表和索引在FSM中占7个字节的存储空间
max_fsm_pages==>FSM中跟踪的数据块的个数的上限(FSM指的是数据块剩余的可用空间存放到一个MAP中,可以内存碎片的VACUUM)
max_files_per_process==>每个数据库进程能够打开的文件的数目
vacuum_cost_delay==>VACUUM进程的睡眠时间
--------------postgres除了wal日志以为ia,如果还需要输出csv日志,则postgresql.conf的配置需要修改一下几个地方:

log_destination = 'csvlog'
logging_collector = on
log_directory = '/home/postgres/pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
----------------------初始化数据库initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W

----------------------启动数据库pg_ctl start -D $PGDATA

----------------------登陆数据库psql -h localhost -p 1999 -U  postgres postgres

----------------------停止数据库pg_ctl stop -m fast|

----------------------重启数据库pg_ctl restart





下载vmware,可以安装多种操作系统(linux,unix,window等)

vmware workstation10的许可证密钥

MA491-6NL5Q-AZAM0-ZH0N2-AAJ5A
5A6F6-88247-XZH59-HL0Q6-8CD2V
HF6QX-20187-2Z391-522NH-9AELT
5F29M-48312-8ZDF9-A8A5K-2AM0Z

下载centos系统地址:

http://isoredirect.centos.org/centos/6.5/isos/ (CentOS系统镜像有两个,安装系统只用到第一个镜像即CentOS-6.x-i386-bin-DVD1.iso(32位)或者CentOS-6.x-x86_64-bin-DVD1.iso(64位),第二个镜像是系统自带软件安装包)

BinDVD版——就是普通安装版,需安装到计算机硬盘才能用,bin一般都比较大,而且包含大量的常用软件,安装时无需再在线下载(大部分情况)。
LiveDVD版——就是一个光盘CentOS系统,可通过光盘启动电脑,启动出CentOS系统,也有图形界面,也有终端。也可以安装到计算机,但是有些内容可能还需要再次到网站下载(自动)。
LiveCD版——相比LiveDVD是个精简的光盘CentOS系统。体积更小,便于维护使用。

----------------外网访问VMware的linux虚拟机

http://blog.csdn.net/hpwzd/article/details/7363694

VMware虚拟机的端口映射

使用NAT上网的linux虚拟机是和主机共享一个ip的,此时外网访问这个ip是访问你的主机,而不是你的linux虚拟机!因此此时需要对VMware虚拟机做一个端口映射!

具体方法如下:

a、VMware下Edit->Virtual Network Editor->VMnet8->NAT Setting->Add开始设置端口映射。

b、Host port 为要映射到主机的主机端口

   Type     依情况而定

   Virtual machine IP Address 为linux虚拟机的IP地址(超级权限,ifconfig可查看)

   Virtual machine port       为要映射到主机的虚拟机端口

c、举例:将linux虚拟机的ssh端口22映射到主机的6000端口,外界访问时直接访问主机地址的6000端口即访问linux虚拟机的22端口。其他的依样画葫芦即可!

------------------postgresql备份(backup)

http://bbs.chinaunix.net/thread-1771360-1-1.html
http://blog.163.com/digoal@126/blog/static/16387704020110442050808/
master:ip:127.0.0.1,port:1921,数据目录:$PGDATA=/home/pg93/pg_root
slave:ip:127.0.0.1,port:1922,数据目录:/home/pg93/dx_bak
建立master:
    mkdir /home/pg93/pg_root
    chown -R pg93 /home/pg93/pg_root
    initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
设置(master):
    vi postgresql.conf
        max_wal_sender=10   #master端会开启sender的进程,slave端会开启recevi进程
        wal_level = hot_standby
        listen_address='*'
        port=1921
        archive_mode = on
        archive_command = 'cp %p /home/pg93/arch/%f'
        log_destination = 'csvlog'
        logging_collector = on
    vi pg_hba.conf
        host all all 0.0.0.0/0 trust
        host replication all 0.0.0.0/0 trust
    mkdir /home/pg93/arch
    chown -R pg93 /home/pg93/arch
启动(master):	
	pg_ctl start -D $PGDATA
操作(slave):
	mkdir /home/pg93/dx_bak
	chown -R pg93 /home/pg93/dx_bak
	cd /home/pg93/dx_bak
	pg_basebackup -F t -x -D ./ -h 127.0.0.1 -p 1921
	tar -xvf base.tar
    vi pg_hba.conf
        host all all 0.0.0.0/0 trust
    vi postgresql.conf
	listen_address='*' 
	port=1922 
    cp /opt/pgsql934/share/recovery.conf.sample recovery.conf  #拷贝postgresql的安装目录中的sample文件到dx_bak目录
    vi recovery.conf
	restore_command = 'cp /home/pg93/arch%f %p'  #拷贝归档日志
操作(master):
    psql -h 127.0.0.1 -p 1921  #建立一个表然后查看是否备份成功
        create table abc(a int, b int);
	insert into abc values(1,1);
	insert into abc values(2,2);
	checkpoint;
	select pg_switch_xlog();
    pg_ctl stop -D $PGDATA
操作(slave):
    chmod 0700 /home/pg93/dx_bak
    pg_ctl start -D /home/pg93/dx_bak
    psql -h 127.0.0.1 -p 1921
	select * from abc; #查看备份是否成功




------------------------下载securecrt7然后连接linux系统

window下cmd测试连接ssh/ssh2:ssh honglianglu@192.168.59.128。(其中192.168.59.128是vmware的虚拟机中一个ubuntu的ip)。

在使用securecrt登陆linux的时候会报password authentication failed. please verify that the username and password are correct错误。无需更改配置需要重新启动一下window主机即可。

对于ubuntu来说默认没有安装ssh,需要sudo apt-get install openssh-server安装一下。然后sudo /etc/init.d/ssh start(或者service ssh start)启动。查看启动是否成功ps -e |grep ssh。

背景颜色设置:Options->Global Options...->Terminal->Appearance->Advanced->Monochrome->Edit->然后参见下图:


中文乱码解决方案:Options->Session Options->Appearance->Font->新宋体 字符集:中文GB2312 ->Character encoding 为UTF-8。

复制黏贴快捷键的设置:Options->Global Options...->Terminal,然后选中Mouse那一栏中的Paste on right button,然后确定即可。在使用的时候使用鼠标在securecrt中鼠标左键选中一部分内容,然后点击鼠标右键,即可直接黏贴到secureCRT中。

-------------securecrt上传下载:
安装lrzsz:yum -y install lrzsz。rz:上传;sz:下载。
-----------home键和end键将光标移至行首/行尾:




posted @ 2014-03-20 16:26  bielidefeng  阅读(363)  评论(0编辑  收藏  举报