dump partial data from postgresql table
For example I need to dump 1000 records from table my_table:
1 | COPY(SELECT * FROM my_table 1000) to '/path/to/my_table.sql' |
For details about COPY command, check PostgreSQL Document.
For example I need to dump 1000 records from table my_table:
1 | COPY(SELECT * FROM my_table 1000) to '/path/to/my_table.sql' |
For details about COPY command, check PostgreSQL Document.
To use xapian in virtualenv, you could manually compile and install into your virtualenv environment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | export VENV=$VIRTUAL_ENV mkdir $VENV/packages && cd $VENV/packages wget http://oligarchy.co.uk/xapian/1.2.8/xapian-core-1.2.8.tar.gz wget http://oligarchy.co.uk/xapian/1.2.8/xapian-bindings-1.2.8.tar.gz tar xzvf xapian-core-1.2.8.tar.gz tar xzvf xapian-bindings-1.2.8.tar.gz cd $VENV/packages/xapian-core-1.2.8 ./configure --prefix=$VENV && make && make install export LD_LIBRARY_PATH=$VENV/lib cd $VENV/packages/xapian-bindings-1.2.8 ./configure --prefix=$VENV --with-python && make && make install |
This tip was found from here, I have successfully installed xapian 1.2.8 under my fedora 16 system.
I got following message when doing a yum check-update:
rpmfusion-free-updates | 3.3 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Sat Jan 28 18:19:20 2012
Downloaded: Mon Jan 9 17:44:21 2012
rpmfusion-nonfree-updates | 3.3 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Sat Jan 28 18:26:14 2012
Downloaded: Tue Jan 10 19:44:54 2012
After google found solution from this post:
1 | yum clean all && yum check-update
|
First thing bothered me is that when using postgresql and psycopg2.4.4, run test will get following errors:
psycopg2.ProgrammingError: autocommit cannot be used inside a transaction
This turns out is a incompatible problem with django and newer version of psycopg2, this bug has been fixed(see here), but won't be backported to django 1.3.1, as the comments said, should stick with psycopg2.4.1:
1 | pip install psycopg2==2.4.1 |
Another problem I encountered hen using fixtures in tests, and I have defined post_save signals in model, sometime you'll get IntegrityError, since when loading data from fixtures, post_save signals will be triggered, the solution is simple, as the django dev docs mentioned, post_save signals now contains two useful arguments: created and raw, these two arguments are boolean type, if created is true means a new record was created, if raw is true means the model is saved exactly as presented(i.e. when loading a fixture), so the signal handler function should check first if the created is true and raw is false, then excute your logic:
1 2 3 4 | @receiver(post_save, sender=YourModel) def your_hander(sender, *args, **kwargs): if (kwargs.get('created', True) and not kwargs.get('raw', False)): your logic here... |
在VMware vSphere上安装linux虚拟机,在配置内核的时候出了差错,导致重启之后出现kernel panic,无法正常启动,想使用光盘引导但是启动速度太快了,总是来不及进BIOS,后来发现其实在虚拟机配置文件中有选项可以强制在启动的时候进入BIOS设置画面,不多说了,直接上图:

rinetd是一个简单易用的TCP端口转发工具,比如多台机器通过一台proxy server共享一个公网IP,如果想从外网ssh登录其中一台机器,可以在proxy server上安装rinetd,配置文件/etc/rinetd.conf,结构很简单,例如:
1 | 123.456.78.9 20007 192.168.0.3 22 |
这样只要ssh 12.456.78.9 -p 200007,就可以登录内网ip为192.168.9.3了。
gentoo系统默认安装的rinetd的init脚本没有reload项,如果需要修改配置文件,需要重启rinetd服务,如果有人在连线,一重启就得重新连线,不太方便,可以在/etc/init.d/rinetd中添加reload命令,如下:
1 2 3 4 5 | reload() { ebegin "Reloading rinetd" start-stop-daemon --signal HUP --pidfile /var/run/rinetd.pid eend $? } |
After set up a new gentoo server by using mkstage4.sh, I got following error when try to add cronjob by a normal user:
#!bash cannot chdir(/var/spool/cron), bailing out. /var/spool/cron: Permission denied
The simple solution is to run following command by root:
1 | # chmod o+rx /var/spool/cron
|
最近更新之后发现emerge的时候不再输出详细信息了,而是现实编译时的load average,gentoo论坛正在投票讨论这一改变,个人感觉这个变化还是挺大的,以前更新系统之后,如果有需要手工执行的操作,会直接显示提示,现在需要自己去log里面查看,如果没有在/etc/make.conf中指定PORT_LOGDIR变量的话,连log都没有得查,为了避免给系统造成不必要的麻烦,建议在/etc/make.conf中加入下面一行:
1 | PORT_LOGDIR='/var/log/portage/elog' |
如果想回复之前的输出详细信息,可以在/etc/make.conf中指定:
1 | EMERGE_DEFAULT_OPTS="--quiet-build=n" |
查看当天是星期几:
1 2 3 4 5 6 | $ date +%A Thursday $ date +%a Thu $ date +%w 4 |
查看某天是星期几:
1 2 3 4 5 6 | $ date +%A -d 20111106 Sunday $ date +%a -d 20111106 Sun $ date +%w -d 20111106 0 # 周日为0,周一为1... |
转换时间和unix time:
1 2 3 4 5 6 | $ date +%s #当前时间的unix time 1320290314 $ date +%s -d '20111106 12:00:00' 1320552000 $ date -d '@1320552000' Sun Nov 6 12:00:00 CST 2011 |
查看其他时区的时间
1 2 3 4 | $ TZ='Asia/Tokyo' date Thu Nov 3 12:26:23 JST 2011 $ TZ='Asia/Tokyo' date -d 'TZ="Asia/Shanghai" 20111106 12:30:00' Sun Nov 6 13:30:00 JST 2011 |