2通りあるようです。 1 DBログイン後SQLファイルを実行 $ psql -U user_name -d db_name (-h ホスト名) にてDBにログイン $ postgres=> \i ../dump_in.sql 2 DBに一時的にログインしSQLファイルを実行 $ psql -f ../dump_in.sql -U user_name -d db_name (-h ホスト名) ちなみにどちらの方法でもDBのユーザに権限がない場合、 「許可がありません」の警告が出て実行できません。
こんにちわ。開発エンジニアのsugimotoです。 今回はPostgresqlのデッドロックについてちょっと書いてみます。 確認した環境はPostgresql9.1.4です。 ロックとかデッドロックについての説明は省きます。 デッドロックの調査 カタログテーブルのpg_locksを確認すると現在のロック状態がわかります。 pg_classと結合すればテーブル名もわかります。 各ロックの競合関係図はhttp://www.ecoop.net/memo/archives/2008-05-30-1.htmlがわかりやすくてお勧めです。 デッドロックの例 自分が経験したことのあるデッドロックの例を3つほどあげます。 例1.明示的なロックによるデッドロック 一番普通のパターンです。 本にはこれが載っていることが多いです。 自分もつい2年くらい前まではデッドロックはこのパターンしかないと思ってました。
PostgreSQLのディクショナリテーブルからコメントを取得する PostgreSQLからメタ情報を取得する方法は2つあります。 1. pg_catalogからデータを取得する 2. information_schemaからデータを取得する 圧倒的に簡単なのは、information_schemaの方です。と言うか、pg_catalogにあるテーブルの構造が難解すぎるのです。 私が、今回悩んでいた問題・・・。それは、テーブルやカラムのコメントを取得する方法が解らなかったことです。 information_schemaには残念ながら、コメント情報はありません。したがって、pg_catalogから情報を取得する他ないわけです。 ちなみに、pg_catalogの情報は、以下のサイトに転がっています。 http://www.postgresql.jp/document/current/html/
PostgreSQLにはランダムな数値を取り出すRANDOM関数があり、これを使うことにより、テーブルからランダムにデータを取り出すことができる。 RANDOM関数は以下のように0以上1未満の値をランダムで返す。 > SELECT RANDOM(); random ------------------- 0.322386509888985 (1 row) > SELECT RANDOM(); random ------------------- 0.677151894977853 (1 row) これを使ってランダムにデータを取り出す。 例えば、以下のデータがあるとする。 > SELECT * FROM book; id | title ----+---------------------- 1 | 赤ずきん 2 | ブレーメンの音楽隊 3 | 白雪姫 4 | シンデレラ 5 | ヘンゼル
ORDER BY句と聞くと、整然と並べられたデータを取得できるイメージばかりが先行してしまう。でも、「ソート」という考え方を応用すると、実はぐちゃぐちゃな順列で取得することも可能。 // postgresql の場合 SELECT * FROM table ORDER BY random(); // MySQL の場合 SELECT * FROM table ORDER BY rand() 乱数でソートできるというのが、イカス! でも、データをそんなブサイクに並べてどうするのか。たとえば、テーブルから任意のレコードを抽出したい場合に、この方法が使える。統計で無作為抽出するときなんかは、有用なんじゃないでしょうか。
たまに実行計画で見かけるBitmap Heap Scan や Bitmap Index Scan が気になり調べてみた。ここの解説がわかりやすい。 【PostgreSQLウォッチ】第17回 新しい実行プラン・タイプによるPostgreSQL 8.1の性能向上 Indexの種類としてビットマップインデックスというものがB-Treeインデックスに並ぶものとしてあるというわけではなく、実行時にビットマップを使うよということ。ビットマップヒープスキャンが行われそうなクエリを投げて実行される処理を確認する。 ドキュメントで触れているのはここかな。 11.5. 複数のインデックスの組み合わせ 他のRDBMSでインデックスマージと呼んでいるものと同じなのかもしれない。 クエリ(explain analyze verboseつき) aidにはインデックスが張られている。aidに対してはorで検索。bidに
トランザクション機能をサポートしているのは、PostgreSQLとMySQL+InnoDBエンジンであり、MySQL+MyISAMエンジンはトランザクション機能をサポートしていません。ここでのトランザクション機能とは、複数のテーブルやレコードに影響をおよぼす処理を1つの単位とみなし、この単位での処理結果を保証する機能を指します。 具体的には、BEGIN文にてトランザクションを開始していくつかの処理を行った後、処理を確定する場合はCOMMIT文、処理を取り消す場合はROLLBACK文を使用し、トランザクションを終了させるまでの処理です。 トランザクション分離レベルとは、複数のトランザクションが同時に実行された場合に、他のトランザクションからの影響がどのくらい分離するかのレベルを意味します。 ANSI/ISO SQL規格(SQL92)では4つの分離レベル(下記コラム参照)が定義されています。P
ここのところ、javaccとawsに魅了されている米林です。 よく使うDB(Oracle/MySQL/PostgreSQL/SQLServer)における設計時のサイズ見積もりで使うサイトの備忘録。 あとは、OracleからのPython情報。 Oracle Oracle 物理設計 http://www.oracle.com/technology/global/jp/columns/skillup/oracle9i/index.html 領域サイズ見積もり http://otn.oracle.co.jp/document/estimate/index.html OTNにログインする必要ありますがオンラインで見積もりが出来ます。 アカウント持っていない人は、この見積もりツールを使う目的でアカウントを作ってみてはいかがでしょうか。 OLTP系とDWH系においてブロックサイズを考慮し、DWH系はブ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く