Thursday, December 13, 2007

Give a ticket number to your subversion commit message when you are using trac

If you give a number when you commit your changes to subversion

    svn commit -m "Fixed Ticket #456"

then Trac will connect the changeset to the Ticket, Wonderful feature, isn't it.

Friday, December 07, 2007

Migrate PostgreSQL 8.1 Data to PostgreSQL 8.2

Install PSQL 8.2

Felix:~ sunfmin$ sudo port install postgresql82

Dump all the PSQL 8.1 Databases to a file

Using The new installed PSQL 8.2 's pg_dumpall to dump all the PSQL 8.1 databases

Felix:~ sunfmin$ /opt/local/lib/postgresql82/bin/pg_dumpall > ~/pg81_all_dump

Initialize PSQL 8.2 Database instance

Felix:~/Developments sunfmin$ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
Password:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /opt/local/var/db/postgresql82/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 32MB/204800
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql82/defaultdb/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

    /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
or
    /opt/local/lib/postgresql82/bin/pg_ctl -D /opt/local/var/db/postgresql82/defaultdb -l logfile start

Start your database

Felix:~/Developments sunfmin$ sudo su postgres -c "/opt/local/lib/postgresql82/bin/pg_ctl -D /opt/local/var/db/postgresql82/defaultdb -l /opt/local/var/log/postgresql82/postgres.log start"
server starting

You may encounter some problem like this following

Felix:~/Developments sunfmin$ sudo su postgres /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
Password:
/opt/local/lib/postgresql82/bin/postgres: /opt/local/lib/postgresql82/bin/postgres: cannot execute binary file

Felix:~/Developments sunfmin$ sudo  /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.


Felix:~/Developments sunfmin$ psql
psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

Restore all the data

Felix:~ sunfmin$ /opt/local/lib/postgresql82/bin/psql -f pg81_all_dump template1 -U postgres
You are now connected to database "postgres".
SET
SET
SET
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE ROLE
ALTER ROLE
CREATE DATABASE

Failed system call was shmget

When I try to setup PostgreSQL 8.2 on Mac OS X 10.4 , I get the following error.

Felix:~ sunfmin$ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /opt/local/var/db/postgresql82/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 10
selecting default shared_buffers/max_fsm_pages ... 400kB/20000
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql82/defaultdb/base/1 ... FATAL:  could not create shared memory segment: Cannot allocate memory
DETAIL:  Failed system call was shmget(key=1, size=1646592, 03600).
HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 1646592 bytes), reduce PostgreSQL's shared_buffers parameter (currently 50) and/or its max_connections parameter (currently 10).
The PostgreSQL documentation contains more information about shared memory configuration.
child process exited with exit code 1
initdb: removing data directory "/opt/local/var/db/postgresql82/defaultdb"

Following http://brilliantcorners.org/node/tag/osx

I changed: /etc/rc

sysctl -w kern.sysv.shmmax=4194304 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=1024

to

sysctl -w kern.sysv.shmmax=167772160 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=65536

And Then the problem solved.

Felix:~/Developments sunfmin$ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
Password:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /opt/local/var/db/postgresql82/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 32MB/204800
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql82/defaultdb/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

    /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
or
    /opt/local/lib/postgresql82/bin/pg_ctl -D /opt/local/var/db/postgresql82/defaultdb -l logfile start

Monday, December 03, 2007

Update itself with single command

It is cool that like gem and MacPorts could update itself with just a single command.

sudo gem update --system
sudo port selfupdate

and also when you can not find software you want in port, don't forget to do a


sudo port -d sync

Saturday, December 01, 2007

Write your blog in Markdown with Emacs and post it directly to Google Blogger

For those who using Emacs, Markdown and Blogger

You write your blog entry in Emacs and with Markdown format Then you issue a M-x blogger-post command in emacs, It convert the markdown to html and post it to your Blogger blog.

How to Install

The code

(require 'gblogger)

(defvar markdown-blogger-new-entry-template
  "<entry xmlns='http://www.w3.org/2005/Atom'>
  <generator url=\"%s\">%s</generator>
  <author> <name>%s </name> </author>
  <title mode=\"escaped\" type=\"text/html\">%s </title>
  <content type='xhtml'>
    <div xmlns=\"http://www.w3.org/1999/xhtml\">
%s
    </div>
  </content>
</entry>"
  "Template for new Blogger entries.")

(defun blogger-post()
  (interactive)

  (markdown)
  (set-buffer (get-buffer "*markdown-output*"))

  (setq post-url "http://www\.blogger\.com/feeds/7841127/posts/default")
  (setq markdown-buffer (current-buffer))
  (setq markdown-content (buffer-string))

  (setq title (read-string "Title: "))

  (setq buffer (get-buffer-create "*markdown-blogger-post*"))

  (declare (special gblogger-auth-handle markdown-blogger-new-entry-template
                    gblogger-generator-name ))

  (g-auth-ensure-token gblogger-auth-handle)




  (set-buffer buffer)
  (erase-buffer)
  (insert (format markdown-blogger-new-entry-template
                  gblogger-generator-name gblogger-generator-name
                  "Felix Sun" title markdown-content))
  (switch-to-buffer buffer)
  (g-app-mode)

  (setq g-app-this-url post-url
        g-app-auth-handle gblogger-auth-handle
        g-app-publish-action 'g-app-post-entry)


  (g-app-publish)
)

Posted from emacs

You can do that also

http://emacspeak.blogspot.com/2007/03/emacs-client-for-google-services.html