Cloud Nine

Avatar

About IT things and others.

PostgreSQL 8.1.3→PostgreSQL 9.1.2に変更したらJoinでトラブった件
3月 23, 2012 0

先月、とあるシステムをPostgreSQL 8.1.3→PostgreSQL 9.1.2にアップグレードしたら、既存システムが動かなくなった。
よく調べてみるとSQLのJoin部分のKeyの型がcharacterだと接続エラーになっていました。

解決方法

で、単純に下記のSQLで型を変更しようと思ったのですが、場所によっては下記のSQLでは型変更ができないところがありました。

ALTER TABLE toiawase ALTER COLUMN kokyaku_id TYPE integer USING kokyaku_id::integer;

解決方法(IndexやViewがある場合)

また調べてみると変更しようとしたKeyがIndexやViewの中でも使用されていることが判明
なので、変更対象のKeyが使用されているIndexやViewをいったん削除して、上記SQLを再度実行して、その後に、削除したIndexやViewを復元させて、
事無きを得ました。ちゃんちゃん

#Indexの削除
DROP INDEX name toiawase_Index;

#型の変更
ALTER TABLE toiawase ALTER COLUMN kokyaku_id TYPE integer USING kokyaku_id::integer;

#Indexの作成
CREATE INDEX toiawase_Index ON toiawase USING btree (kokyaku_id);

PostgresSQL9.1.2の設定 in CentOS5.7
2月 21, 2012 0

基本設定部分

$ vi /var/lib/pgsql/9.1/data/postgresql.conf
#listen_addresses = 'localhost'
↓
listen_addresses = '*'
#port = 5432
↓
port = 5432

ログの名前
log_filename = 'postgresql-%Y-%m-%d_%H%M.log'
ログのローテーション
log_rotation_age = 1d
ログのサイズ
log_rotation_size = 2MB
同名のファイルが存在する時は上書きする。ローテーション用。
log_truncate_on_rotation = on
ログのレベル
log_min_error_statement = error

ログの細かい内容はこちらを参照してください。
http://lets.postgresql.jp/documents/technical/log_setting

セキュリティ設定部分

$ vi /var/lib/pgsql/9.1/data/pg_hba.conf
ローカル接続の許可
local    all             all                      peer
外部からの接続の設定
host    all             all             123.123.123.123/32(接続元のIP)            password

CentOS5.7にPostgresSQL9.1.2をyumでインストール
2月 13, 2012 0

Postgresのサイトからrpmを取得
http://yum.postgresql.org/reporpms/

インストール

$ wget http://yum.postgresql.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm
$ rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
$ vi /etc/yum.repos.d/CentOS-Base.repo
[base]の中に下記のコメントを追加
exclude=postgresql*
[update]の中に下記のコメントを追加
exclude=postgresql*
$ yum -y install postgresql-server
Installed:
  postgresql91-server.i386 0:9.1.2-1PGDG.rhel5
Dependency Installed:
  postgresql91.i386 0:9.1.2-1PGDG.rhel5                    postgresql91-libs.i386 0:9.1.2-1PGDG.rhel5

初期設定

$ chkconfig postgresql-9.1 on
DBの初期化
$ service postgresql-9.1 initdb
データベースを初期化中: mkdir: ディレクトリ `/var/lib/pgsql/9.1/data/pg_log' を作成できません: ファイルが存在します
$ rm -rf /var/lib/pgsql/9.1/data/pg_log/
$ service postgresql-9.1 initdb
データベースを初期化中:                                    [  OK  ]
$ service postgresql-9.1.2 start
postgresql-9.1 サービスを開始中:                           [  OK  ]
$ su - postgres
$ psql -V
psql (PostgreSQL) 9.1.2

設定関連

基本関係
$ vi /var/lib/pgsql/9.1/data/postgresql.conf
セキュリティ関係
$ vi /var/lib/pgsql/9.1/data/pg_hba.conf

What logs does your Postgres dump?
4月 1, 2009 0

What logs does your Postgres dump?
I set these setting on postgresql.conf

#The default is NOTICE.
log_min_error_statement = WARNING
#I set ten seconds.
log_min_duration_statement = 10000

log_min_error_statement

Controls whether or not the SQL statement that causes an error condition will be recorded in the server log.

log_min_duration_statement

Causes the duration of each completed statement to be logged if the statement ran for at least the specified number of milliseconds.

How to make testing environment about Postgres.
3月 31, 2009 0

I often use postgres server,so sometimes I have to make testing environment for postgres in my windows pc.
So I want to write how to make testing environment about Postgres for my memo.

postgres

First Step

Please login postgres server, and then you have to change user what this user is postgres user.
And I use pg_dump.

# pg_dump -f filename.sql.gz -Z 1 -c database-name

-f to write file about output.
-Z。。Number this is level of compression.
-c it is cleaning for schema.

Second Step

You get dump file from server.And then you decompress file.

Third Step

You install postgres in your windows PC. Please check Postgres sites.

Fourth Step

Please copy dump file to there.

\Program Files\PostgresSQL\8.3\bin\

And please open command prompt and write this command.

cd \Program Files\PostgresSQL\8.3\bin\
psql dbname < dumpfile

That's all!!!

And if you see these message.Please make user on for postgres.
psql: FATAL: role "・譯シ・カフセ" does not exist、ネクタ、??ソ、饅r

Or

please change user what this user is postgres user.

psql -u

初心者用pg_dumpの方法
4月 30, 2008 0

pg_dumpは

pg_dump database_name > database_name.sql

を実行すればできると、あるが実際はいろいろと気をつけないことが、たくさんあるのでそのメモ

その一、ユーザの準備
postgresでDBを作成しているなら、postgresユーザがいります。

useradd -d /home/postgres/ postgres

このときに、ホームディレクトリーも作っておきます。

その二、ファイルの準備
先ほど上のつくったホームディレクトリーの中にdatabase_name.sqlのファイルを作っておきます。

touch database_name.sql

その三、bushが引けてない場合があるのでlocateでpg_dumpを調べてひいいておきましょう。

その四、いざ実行

[postgres@www postgres]$ pg_dump database_name.sql > database_name.sql

Real Time Analytics