2006.08.02

Category: PHP, PostgreSQL / Tags:

addslashes()ではなくpg_escape_string()を使おう

addslashesも、pg_escape_stringも文字列をエスケープさせる関数であるが、
postgreSQLに、データを流し込む(sqlを作成する)場合は、
addslashesでなく、pg_escape_stringを使うこと。
詳しいことは面倒なので
http://itpro.nikkeibp.co.jp/article/COLUMN/20060530/239359/?ST=lin-server&P=3
で確認してほしい。
要は、エスケープの方法が違うので、pg_escape_stringのほうが安全ということです。
ちなみに、postgreSQLをより安全に使うためには、
フロントエンドとバックエンドの文字コードは合わせておいたほうがいいみたいです。
つまりは、SJISは利用するなって事です。

2006.07.28

Category: PostgreSQL / Tags:

日本語、カナなどのソートがおかしい場合 – [locale]ロケールの確認

どのDBにでもいいので次のSQLで確認してみてください。

xxxx=# show lc_collate;
lc_collate
————
C
(1 row)

ここがCでない場合、文字コードによっては、ソートが上手くいかない場合があります。
ちなみに、ロケールは、initdbをする段階で決定してしまうので、DB自体を再構築しない限りは
変更する事ができません。

Freebsd ports で postgresql8.1.3 その2

初期チューニング編
ポストグレスの場合重要になる。
shared memory 共有メモリ
semaphore セマフォ
ファイルテーブル
について、チューニングです。参考はシーラカンス本
今回のマシンのメモリが512Mなので、
128MBを共有メモリとして割り当てる予定で。
-su-2.05b# ipcs -M
shminfo:
shmmax: 33554432 (max shared memory segment size)
shmmin: 1 (min shared memory segment size)
shmmni: 192 (max number of shared memory identifiers)
shmseg: 128 (max shared memory segments per process)
shmall: 8192 (max amount of shared memory in pages)
shmmax: 33554432 = 32MB
なので、
options “SHMMAX=(SMMAXPGS*PAGE_SIZE+1)”
options SHMMAXPGS = n
とするために
PAGE_SIZE は通常4096らしいので
SHMMAX を 128M(1024*1024*128=134217728)にするために
134217728 = n * 4096+1
をといて(1はとりあえず無視します。)
n = 32768
なので、 n = 32768
を設定します。
ユーザー数は、
確認(便宜上上から数値をつけてます。)
-su-2.05b# ipcs -S
seminfo:
1 semmap: 30 (# of entries in semaphore map)
2 semmni: 10 (# of semaphore identifiers)
3 semmns: 60 (# of semaphores in system)
4 semmnu: 30 (# of undo structures in system)
5 semmsl: 60 (max # of semaphores per id)
6 semopm: 100 (max # of operations per semop call)
7 semume: 10 (max # of undo entries per process)
8 semusz: 92 (size in bytes of undo structure)
9 semvmx: 32767 (semaphore maximum value)
10 semaem: 16384 (adjust on exit max value)
3の、セフォマの数(semmns)が、PostgreSQLのユーザー
semmni:
semmns: 60 (# of semaphores in system)

Freebsd ports で postgresql8.1.3 その1

http://d.hatena.ne.jp/kztmk/20051124
のサイトを参考に、比べながらやってみた。
セットアップしてもらったサーバーは /var 以下に容量がさかれている
ので、
# initdb data=/var/pgsql とする。
freebsd は、共有メモリをカーネルレベルから変更する必要が
あるので、シーラカンス本を参考に
http://d.hatena.ne.jp/kztmk/20051124
======================================================================
For procedural languages and postgresql functions, please note that
you might have to update them when updating the server.
If you have many tables and many clients running, consider raising
kern.maxfiles using sysctl(8), or reconfigure your kernel
appropriately.
You should vacuum and backup your database regularly. There is a
periodic script, ${LOCALBASE}/etc/periodic/daily/502.pgsql, that you
may find useful. Per default, it perfoms vacuum on all databases
nightly. See the script for instructions.
To allow many simultaneous connections to your PostgreSQL server, you
should raise the SystemV shared memory limits in your kernel. Here are
example values for allowing up to 180 clients (configurations in
postgresql.conf also needed, of course):
options SYSVSHM
options SYSVSEM
options SYSVMSG
options SHMMAXPGS=65536
options SEMMNI=40
options SEMMNS=240
options SEMUME=40
options SEMMNU=120
If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script /usr/local/share/postgresql/odbc.sql
to get the functions required for ODBC compliance.
======================================================================
To initialize the database, run
/usr/local/etc/rc.d/010.pgsql.sh initdb
You can then start PostgreSQL by running:
/usr/local/etc/rc.d/010.pgsql.sh start
For postmaster settings, see ~pgsql/data/postgresql.conf
NB. FreeBSD’s PostgreSQL port now by default logs to syslog
See ~pgsql/data/postgresql.conf for more info
======================================================================
To run PostgreSQL at startup, add
‘postgresql_enable=”YES”‘ to /etc/rc.conf
======================================================================
===> Registering installation for postgresql-server-8.1.3
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/bin/postgres
This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/010.pgsql.sh
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type ‘make deinstall’
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
http://www.postgresql.org/
とかいろいろ言われます。

2006.07.04

Category: PostgreSQL / Tags:

トランザクションログについてもろもろメモ書き

未完
PostgreSQLのトランザクションログ
pg_xlog というフォルダが、データベースディレクトリにありますが、
これは、トランザクション用のREDOログを記録するログファイル群です。

sqlの結果をダンプする方法

指定のquery のデータだだけをテキストとかに吐き出したいとき。
$ psql -c “query” db_name > dump.txt
とかしてあげれば、queryの結果がテキストとかに保存されます。
query を ダブルコーテーションとかで囲んであげることをわすれないで
ください。

2006.07.04

Category: MySql / Tags:

version – バージョンの確認方法

mysql のversion(バージョン)確認方法

version – バージョンの確認方法

data フォルダにある
PG_VERSION というファイルをみれば、
$cat PG_VERSION
下一桁まで(x.xまで)わかりますが、

  Newer Entries »