Not Code

Setup Master Slave Replication on Postgresql

| Comments

1. 常用的命令

  • pg_ctl init -D DIR -o "--no-locale"

    初始化数据目录. -o表示要传递给initdb的参数. --no-locale将encoding设置为SQL_ASCII,Collation和Ctype设置为C,可以避免各种编码的问题.

  • pg_ctl start -D <DATA DIR> -l <LOG FILE>

    启动pg

  • pg_ctl stop -D <DATA DIR>

    停止pg

  • pg_dump <DBNAME> [-t <TBNAME>]...

    导出数据库/表

Refactor Database Design

| Comments

原来的设计

最近被临时调入一个项目,任务是重写后台计算程序, 所以要保持现有的接口和数据库设计。 原有的数据库被设计成每个task一张表,表名为<prefix>_<taskid>,简单说明一下:

  • prefix 用于区别报表类型,每个task有10多种报表类型
  • taskid 整数,用于标识task 每个task有一个开始日期和结束日期,在这个日期区间内,每天计算一次该task的报表。 每个table都有date列, 表明该行记录是哪一天的计算结果

Be Careful With Mapreduce While Writing Into Database

| Comments

A Strange Case

Recently we come across a problem when writing into database in mapreduce jobs. The job gets lots of failure attempt, though succeeds finally. We reviewed the source code of job, nothing seemed suspicious, there must be something wrong in our cluster.

So we reproduce the scenario.

Replica Strategy in Hdfs Is Not Good Enough

| Comments

Two methods of Replica

I’ve known two methods of replica in distributed storage system. One is like hadoop, which distributes the three replicas of a block on three different nodes. The other is like mongodb, which store data into shardings with three nodes in each sharding.These three nodes in the same sharding are identical.

Both of the two strategy has a “at most two dead node” tolerance,that meanings if one or two node in cluster crash,all the data is still available. But what happen to three nodes?

Mongodb Performance Tuning

| Comments

1.背景

mongodb的写性能很一般,即使采用bulk insert,也达不到我们的业务需求。 另外,mongodb有一个DB粒度的读写锁,因此采用并发写也无法提高写性能。因为读写锁的关系,在有写负载较高的情况下,读性能也被拉低了。

引自mongodb官网:

Beginning with version 2.2, MongoDB implements locks on a per-database basis for most read and write operations.

Modeline: Vim Configuration Per File

| Comments

简介

vim有一个叫做modeline的功能,它允许对单独的文件设置vim变量。当用vim打开文件时,这些变量便可生效。

当编辑python文件时,必须保证编辑环境的缩进和文件中原有的缩进一致。有多个开发人员协作时,缩进不一致的问题经常发生。 使用modeline可以解决这样的问题。

具体做法如下:

#!/usr/bin/env python2.7
# vim: ts=4 sw=4 et