2008-01-26 21:46:58

PostgreSQLが起動しない

[ PostgreSQL ]

突然の電源断でPostgreSQL(CentOS4.4 x86_64)が起動しなくなった。

[root@server ~]# su - postgres
-bash-3.00$ postmaster
LOG:  database system was interrupted while in recovery at 2008-01-07 10:43:32 JST
HINT:  This probably means that some data is corrupted and you will have to use the last backup for recovery.
LOG:  checkpoint record is at 9C/40879F60
LOG:  redo record is at 9C/40879F60; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 794151748; next OID: 260490482
LOG:  database system was not properly shut down; automatic recovery in progress
LOG:  redo starts at 9C/40879FA8
PANIC:  could not access status of transaction 794151753
DETAIL:  could not read from file "/var/lib/pgsql/data/pg_clog/02F5" at offset 90112: Success
LOG:  startup process (PID 4893) was terminated by signal 6
LOG:  aborting startup due to startup process failure

/var/lib/pgsql/data/pg_clog/02F5 が壊れてるようだ。
http://ton.xii.jp/b/2006/09/06/145749-000263.html
を真似てみる。

[root@server ~]# cd /var/lib/pgsql/data/pg_clog/
[root@server pg_clog]# ls -alth | less
total 193M
drwx------  6 postgres postgres 4.0K Jan  7 11:09 ..
-rw-------  1 postgres postgres  72K Jan  4 09:36 02F5
drwx------  2 postgres postgres  20K Jan  4 09:11 .
-rw-------  1 postgres postgres 256K Jan  4 09:11 02F4
[root@server pg_clog]# rm -f 02F5
[root@server pg_clog]# dd if=/dev/zero bs=8k count=1 >>02F5
[root@server pg_clog]# chmod 600 02F5
[root@server pg_clog]# chown postgres.postgres 02F5
[root@server pg_clog]# ls -alth | less
total 193M
drwx------  6 postgres postgres 4.0K Jan  7 11:15 ..
drwx------  2 postgres postgres  20K Jan  7 11:13 .
-rw-------  1 postgres postgres 8.0K Jan  7 11:13 02F5
-rw-------  1 postgres postgres 256K Jan  4 09:11 02F4
[root@server pg_clog]# /etc/init.d/postgresql start
Starting postgresql service:                               [FAILED]

起動失敗。
サイズを変えて他と同じになるようにする。

[root@server pg_clog]# dd if=/dev/zero bs=256k count=1 >02F5
1+0 records in
1+0 records out
[root@server pg_clog]# ls -alth | less
total 193M
-rw-------  1 postgres postgres 256K Jan  7 11:20 02F5
drwx------  6 postgres postgres 4.0K Jan  7 11:17 ..
drwx------  2 postgres postgres  20K Jan  7 11:13 .
-rw-------  1 postgres postgres 256K Jan  4 09:11 02F4
[root@server pg_clog]# /etc/init.d/postgresql start
Starting postgresql service:                               [  OK  ]
[root@server pg_clog]# /etc/init.d/postgresql status
postmaster (pid 5458 5457 5455) is running...

なんとか動いた。
その後、すぐバックアップ。

2007-04-19 19:54:57

Postgresの正規表現

[ PostgreSQL ]

とっさの時にはSQL

普通の正規表現
SELECT count(*) FROM table WHERE column1 ~ '[あ-ん]';
否定
SELECT count(*) FROM table WHERE column1 !~ '[あ-ん]';

ANDの場合
SELECT count(*) FROM table WHERE column1 ~ '[あ-ん]' AND column2 ~ '[あ-ん]';