SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
ActiveRecordの
  PostgreSQLアダプタ
 周辺について調べてみた

(株)サイクル・オブ・フィフス
      石田朗雄
はじめに
ActiveRecordのPostgreSQLアダプタについて調べてみて、
はまったところや気になったとこをまとめました。
でもメインはその下のレイヤの話です。
普段Rubyを使っているわけではないので、僕の話にRubyに対
する愛が足りないように聞こえたらごめんなさい。
構成
                    ActiveRecord::Base

                AR::ConnectionAdapter::Base

 AR::CA::PostgreSQLAdapter           AR::CA::他のRDBMS向け

ruby-postgres
                 postgres-pr
                 (pure ruby)
   libpq(C言語)




04:54:22 PM           Ruby-Sapporo 2007-11-17            3
postgres-prとの比較
    ruby-postgres-0.7.1.2006.04.06-mswin32
    postgres-pr-0.4.0
    postgres-prは、postgres.soがあればそっちを呼ぶので、両
    方入っている環境では工夫が必要
  ruby-postgres
  irb(main):002:0> require quot;postgresquot;
  => true

  postgres-pr
  irb(main):003:0> require quot;postgres-pr/postgres-compatquot;
  => true




04:54:22 PM                 Ruby-Sapporo 2007-11-17        4
postgres-prとの比較
  > PGconn.instance_methods(false).sort
  => [quot;async_execquot;, quot;async_queryquot;, quot;client_encodingquot;, quot;closequot;, quot;dbquot;,
  quot;endcopyquot;, quot;errorquot;, quot;execquot;, quot;finishquot;, quot;get_notifyquot;, quot;getlinequot;, quot;hostquot;,
  quot;insert_tablequot;, quot;lo_createquot;, quot;lo_exportquot;, quot;lo_importquot;, quot;lo_openquot;,
  quot;lo_unlinkquot;, quot;locreatequot;, quot;loexportquot;, quot;loimportquot;, quot;loopenquot;, quot;lounlinkquot;,
  quot;on_noticequot;, quot;optionsquot;, quot;portquot;, quot;protocol_versionquot;, quot;putlinequot;, quot;queryquot;,
  quot;resetquot;, quot;select_onequot;, quot;select_valuequot;, quot;select_valuesquot;, quot;server_versionquot;,
  quot;set_client_encodingquot;, quot;statusquot;, quot;tracequot;, quot;transaction_statusquot;, quot;ttyquot;,
  quot;untracequot;, quot;userquot;]


  > PGconn.instance_methods(false).sort
  => [quot;closequot;, quot;dbquot;, quot;execquot;, quot;hostquot;, quot;queryquot;, quot;userquot;]




04:54:22 PM                 Ruby-Sapporo 2007-11-17                           5
接続
  irb(main):013:0> c=PGconn.new(nil, 9999, nil, nil, 'ishida', 'ishida',
  nil)
  PGError: could not connect to server: Connection refused
  (0x0000274D/10061)
          Is the server running on host quot;???quot; and accepting
          TCP/IP connections on port 9999?

              from (irb):13:in `initialize'      postgres-prではhostがnilだと
              from (irb):13:in `new'             portが無視される
              from (irb):13

  irb(main):004:0> c=PGconn.new(nil, 9999, nil, nil, 'ishida', 'ishida',
  nil)
  => #<PGconn:0x2dc3d98 @db=quot;ishidaquot;, @host=nil,
  @conn=#<PostgresPR::Connection:0x2dc3d70
  @params={quot;integer_datetimesquot;=>quot;offquot;, quot;TimeZonequot;=>quot;JST-9quot;,
  quot;server_encodingquot;=>quot;EUC_JPquot;, quot;standard_conforming_stringsquot;=>quot;offquot;,
  quot;DateStylequot;=>quot;ISO, MDYquot;, quot;client_encodingquot;=>quot;EUC_JPquot;,
  quot;session_authorizationquot;=>quot;ishidaquot;, quot;server_versionquot;=>quot;8.1.3quot;,
  quot;is_superuserquot;=>quot;offquot;}, @conn=#<TCPSocket:0x2dc3bf4>>, @user=quot;ishidaquot;>
04:54:22 PM                     Ruby-Sapporo 2007-11-17                    6
ParameterStatus
    PostgreSQLのコンフィグのうち、クライアントの動作に影響
    するものをサーバからクライアントに対して送る
    接続時、SETコマンドによる変更、コンフィグファイルのリ
    ロード等
        server_version
        client_encoding
        DateStyle
        等々
    バージョンが上がると増えることがあるの
    で、PGconn#getparamみたいのが欲しい



04:54:22 PM               Ruby-Sapporo 2007-11-17   7
postgres-prとの比較
  irb(main):004:0> c.client_encoding
  => quot;SQL_ASCIIquot;
  irb(main):005:0> c.exec(quot;set client_encoding to sjisquot;)
  => #<PGresult:0x2dc2358>
  irb(main):006:0> c.client_encoding
  => quot;SJISquot;

   irb(main):010:0>
   c.instance_variable_get(:@conn).instance_variable_get(:@params)
   [quot;client_encodingquot;]
   => quot;SQL_ASCIIquot;
   irb(main):011:0> c.exec(quot;set client_encoding to sjisquot;)
   => #<PGresult:0x2e98cb4 @result=[], @fields=[],
   @res=#<PostgresPR::Connection::Result:0x2e98c50 @cmd_tag=quot;SETquot;,
   @fields=[], @rows=[]>>
   irb(main):012:0>
   c.instance_variable_get(:@conn).instance_variable_get(:@params)
   [quot;client_encodingquot;]
   => quot;SQL_ASCIIquot;                                     postgres-prは
                                                      ParameterStatusの変更を
04:54:22 PM                  Ruby-Sapporo 2007-11-17  拾っていない             8
コイツ、、、動くぞ、、、
  PGconn.translate_results = false if PGconn.respond_to? :translate_results=
  ....
  if @connection.respond_to?(:status)
  ...
  # TODO: postgres-pr doesn't have PGconn#reset.
  if @connection.respond_to?(:reset)

  但し、allow_concurrencyだけは使ってはいけない
     def query(sql, name = nil) #:nodoc:
       log(sql, name) do
         if @async
           @connection.async_query(sql)
         else
           @connection.query(sql)
         end
       end




04:54:22 PM                 Ruby-Sapporo 2007-11-17                            9
PGconn#async_exec
  pgconn_async_exec():postgres.c

       if (!PQsendQuery(conn, RSTRING(str)->ptr)) {
           rb_raise(rb_ePGError, PQerrorMessage(conn));
       }

       cs = PQsocket(conn);                  PQsendQueryで非同期にクエリ
       for(;;) {                             送信した後、結果が返ってくるの
           FD_ZERO(&rset);                   を待っている?
           FD_SET(cs, &rset);
           ret = rb_thread_select(cs + 1, &rset, NULL, NULL, NULL);




04:54:22 PM                  Ruby-Sapporo 2007-11-17                  10
まとめ?
    ruby-postgresとpostgres-prは結構違うけ
    ど、ActiveRecordが違いを吸収している
    今回挙げたものの他にもpostgres-prは、引数のoptionsを無
    視してたり環境変数も無視してたり、ParameterStatusを無
    視するケースがあったり、、、
    素のpostgres-prを使うには覚悟が必要




04:54:22 PM       Ruby-Sapporo 2007-11-17   11
C:rubylibrubygems1.8gemspostgres-pr-0.4.0lib>grep -r TODO *
 postgres-pr/connection.rb:         # TODO
 postgres-pr/connection.rb:         # TODO: use transaction status
 postgres-pr/connection.rb:         # TODO
 postgres-pr/connection.rb:         # TODO
 postgres-pr/message.rb:# TODO
 postgres-pr/message.rb:# TODO
 postgres-pr/message.rb:         # TODO: zero means unspecified. map to nil?
 postgres-pr/message.rb:# TODO: duplicate message-type, split into
 client/servermessages
 postgres-pr/postgres-compat.rb:     # TODO: correct?
 postgres-pr/postgres-compat.rb: # TODO: status, getlength, cmdstatus
 postgres-pr/postgres-compat.rb:     # TODO: correct?
 postgres-pr/postgres-compat.rb:     # TODO: correct?
 postgres-pr/typeconv/TC_conv.rb:     assert_equal [quot;quot;], decode_array(quot;{ }quot;) #
 TODO: Correct?




04:54:22 PM                  Ruby-Sapporo 2007-11-17                             12

Weitere ähnliche Inhalte

Was ist angesagt?

Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyPeter Keung
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeJames Turnbull
 
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack
 
Token Based Authentication Systems
Token Based Authentication SystemsToken Based Authentication Systems
Token Based Authentication SystemsHüseyin BABAL
 
Nginx常见应用技术指南(Nginx Tips)
Nginx常见应用技术指南(Nginx Tips)Nginx常见应用技术指南(Nginx Tips)
Nginx常见应用技术指南(Nginx Tips)dreamwing.org
 
5 issues
5 issues5 issues
5 issuesm0use
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbSmartTools
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)Geoffrey Anderson
 
OpenResty TCP 服务代理和动态路由
OpenResty TCP 服务代理和动态路由OpenResty TCP 服务代理和动态路由
OpenResty TCP 服务代理和动态路由Orangle Liu
 
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Ryosuke IWANAGA
 
PyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPerrin Harkins
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupBadoo Development
 
Ajax и будущее Java Script
Ajax и будущее Java ScriptAjax и будущее Java Script
Ajax и будущее Java ScriptConstantin Kichinsky
 
HTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionHTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionXavier Mertens
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL SchemaSean Chittenden
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeAndrea Cardinale
 
Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]Erhwen Kuo
 

Was ist angesagt? (20)

Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites fly
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
 
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injectionStHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
StHack 2013 - Florian "@agixid" Gaultier No SQL injection but NoSQL injection
 
Token Based Authentication Systems
Token Based Authentication SystemsToken Based Authentication Systems
Token Based Authentication Systems
 
Nginx常见应用技术指南(Nginx Tips)
Nginx常见应用技术指南(Nginx Tips)Nginx常见应用技术指南(Nginx Tips)
Nginx常见应用技术指南(Nginx Tips)
 
5 issues
5 issues5 issues
5 issues
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
Perl dancer
Perl dancerPerl dancer
Perl dancer
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
 
OpenResty TCP 服务代理和动态路由
OpenResty TCP 服务代理和动态路由OpenResty TCP 服务代理和动态路由
OpenResty TCP 服务代理和动态路由
 
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
 
PyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to ProfilingPyGotham 2014 Introduction to Profiling
PyGotham 2014 Introduction to Profiling
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
Ajax и будущее Java Script
Ajax и будущее Java ScriptAjax и будущее Java Script
Ajax и будущее Java Script
 
HTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionHTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC Edition
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL Schema
 
20070329 Phpconf2007 Training
20070329 Phpconf2007 Training20070329 Phpconf2007 Training
20070329 Phpconf2007 Training
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtime
 
Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]Spark手把手:[e2-spk-s02]
Spark手把手:[e2-spk-s02]
 

Andere mochten auch

Ruby Postgres 2009
Ruby Postgres 2009Ruby Postgres 2009
Ruby Postgres 2009Akio Ishida
 
Getting start with knockout.js
Getting start with knockout.jsGetting start with knockout.js
Getting start with knockout.jsAkio Ishida
 
PostgreSQLの範囲型と排他制約
PostgreSQLの範囲型と排他制約PostgreSQLの範囲型と排他制約
PostgreSQLの範囲型と排他制約Akio Ishida
 
Local php-100828 2
Local php-100828 2Local php-100828 2
Local php-100828 2Akio Ishida
 
PostgreSQLで学ぶBoyer-Moore-Horspoolアルゴリズム
PostgreSQLで学ぶBoyer-Moore-HorspoolアルゴリズムPostgreSQLで学ぶBoyer-Moore-Horspoolアルゴリズム
PostgreSQLで学ぶBoyer-Moore-HorspoolアルゴリズムAkio Ishida
 
XIDを周回させてみよう
XIDを周回させてみようXIDを周回させてみよう
XIDを周回させてみようAkio Ishida
 
使いこなそうGUC
使いこなそうGUC使いこなそうGUC
使いこなそうGUCAkio Ishida
 
Rubysapporo Stringsearch
Rubysapporo StringsearchRubysapporo Stringsearch
Rubysapporo StringsearchAkio Ishida
 
phpspecで学ぶLondon School TDD
phpspecで学ぶLondon School TDDphpspecで学ぶLondon School TDD
phpspecで学ぶLondon School TDDAkio Ishida
 
textsearch_jaで全文検索
textsearch_jaで全文検索textsearch_jaで全文検索
textsearch_jaで全文検索Akio Ishida
 
よりよいPHPUnitの実行方法を求めて
よりよいPHPUnitの実行方法を求めてよりよいPHPUnitの実行方法を求めて
よりよいPHPUnitの実行方法を求めてAkio Ishida
 
Prophecyを使ったユニットテスト
Prophecyを使ったユニットテスト Prophecyを使ったユニットテスト
Prophecyを使ったユニットテスト Akio Ishida
 

Andere mochten auch (13)

Ruby Postgres 2009
Ruby Postgres 2009Ruby Postgres 2009
Ruby Postgres 2009
 
Getting start with knockout.js
Getting start with knockout.jsGetting start with knockout.js
Getting start with knockout.js
 
PostgreSQLの範囲型と排他制約
PostgreSQLの範囲型と排他制約PostgreSQLの範囲型と排他制約
PostgreSQLの範囲型と排他制約
 
Local php-100828 2
Local php-100828 2Local php-100828 2
Local php-100828 2
 
PostgreSQLで学ぶBoyer-Moore-Horspoolアルゴリズム
PostgreSQLで学ぶBoyer-Moore-HorspoolアルゴリズムPostgreSQLで学ぶBoyer-Moore-Horspoolアルゴリズム
PostgreSQLで学ぶBoyer-Moore-Horspoolアルゴリズム
 
XIDを周回させてみよう
XIDを周回させてみようXIDを周回させてみよう
XIDを周回させてみよう
 
使いこなそうGUC
使いこなそうGUC使いこなそうGUC
使いこなそうGUC
 
Rubysapporo Stringsearch
Rubysapporo StringsearchRubysapporo Stringsearch
Rubysapporo Stringsearch
 
phpspecで学ぶLondon School TDD
phpspecで学ぶLondon School TDDphpspecで学ぶLondon School TDD
phpspecで学ぶLondon School TDD
 
textsearch_jaで全文検索
textsearch_jaで全文検索textsearch_jaで全文検索
textsearch_jaで全文検索
 
よりよいPHPUnitの実行方法を求めて
よりよいPHPUnitの実行方法を求めてよりよいPHPUnitの実行方法を求めて
よりよいPHPUnitの実行方法を求めて
 
Elsevier与Lib2
Elsevier与Lib2Elsevier与Lib2
Elsevier与Lib2
 
Prophecyを使ったユニットテスト
Prophecyを使ったユニットテスト Prophecyを使ったユニットテスト
Prophecyを使ったユニットテスト
 

Ähnlich wie Ruby Postgres

How To Create Custom DSLs By PHP
How To Create Custom DSLs By PHPHow To Create Custom DSLs By PHP
How To Create Custom DSLs By PHPAtsuhiro Kubo
 
JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009gyuque
 
Shibuya.abc - Gnashで遊ぼう
Shibuya.abc - Gnashで遊ぼうShibuya.abc - Gnashで遊ぼう
Shibuya.abc - Gnashで遊ぼうgyuque
 
ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理Shinya Miyazaki
 
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編mochiko AsTech
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909Yusuke Wada
 
20090323 Phpstudy
20090323 Phpstudy20090323 Phpstudy
20090323 PhpstudyYusuke Ando
 
20080424 Cdb2008 Postgresql News Bartunov
20080424 Cdb2008 Postgresql News Bartunov20080424 Cdb2008 Postgresql News Bartunov
20080424 Cdb2008 Postgresql News BartunovNikolay Samokhvalov
 
企业级搜索引擎Solr交流
企业级搜索引擎Solr交流企业级搜索引擎Solr交流
企业级搜索引擎Solr交流chuan liang
 
とちぎRuby会議01(原)
とちぎRuby会議01(原)とちぎRuby会議01(原)
とちぎRuby会議01(原)Shin-ichiro HARA
 
Ruby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese VersionRuby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese VersionLibin Pan
 
4200 Kte7.0 Training V1.0
4200 Kte7.0 Training V1.04200 Kte7.0 Training V1.0
4200 Kte7.0 Training V1.0wayneliao
 
樽家昌也 (日本Rubyの会)
樽家昌也 (日本Rubyの会) 樽家昌也 (日本Rubyの会)
樽家昌也 (日本Rubyの会) toRuby
 
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTracterada
 
P2P Bug Tracking with SD
P2P Bug Tracking with SDP2P Bug Tracking with SD
P2P Bug Tracking with SDJesse Vincent
 
オブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 Rubyオブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 RubyKitajiro Kitayama
 

Ähnlich wie Ruby Postgres (20)

How To Create Custom DSLs By PHP
How To Create Custom DSLs By PHPHow To Create Custom DSLs By PHP
How To Create Custom DSLs By PHP
 
Grails紹介
Grails紹介Grails紹介
Grails紹介
 
JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009JSplash - Adobe MAX 2009
JSplash - Adobe MAX 2009
 
Revisited
RevisitedRevisited
Revisited
 
What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
Shibuya.abc - Gnashで遊ぼう
Shibuya.abc - Gnashで遊ぼうShibuya.abc - Gnashで遊ぼう
Shibuya.abc - Gnashで遊ぼう
 
ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理
 
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
 
20090323 Phpstudy
20090323 Phpstudy20090323 Phpstudy
20090323 Phpstudy
 
20080424 Cdb2008 Postgresql News Bartunov
20080424 Cdb2008 Postgresql News Bartunov20080424 Cdb2008 Postgresql News Bartunov
20080424 Cdb2008 Postgresql News Bartunov
 
object-shapes
object-shapesobject-shapes
object-shapes
 
企业级搜索引擎Solr交流
企业级搜索引擎Solr交流企业级搜索引擎Solr交流
企业级搜索引擎Solr交流
 
とちぎRuby会議01(原)
とちぎRuby会議01(原)とちぎRuby会議01(原)
とちぎRuby会議01(原)
 
Ruby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese VersionRuby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese Version
 
4200 Kte7.0 Training V1.0
4200 Kte7.0 Training V1.04200 Kte7.0 Training V1.0
4200 Kte7.0 Training V1.0
 
樽家昌也 (日本Rubyの会)
樽家昌也 (日本Rubyの会) 樽家昌也 (日本Rubyの会)
樽家昌也 (日本Rubyの会)
 
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac
 
P2P Bug Tracking with SD
P2P Bug Tracking with SDP2P Bug Tracking with SD
P2P Bug Tracking with SD
 
オブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 Rubyオブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 Ruby
 

Kürzlich hochgeladen

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Kürzlich hochgeladen (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Ruby Postgres

  • 1. ActiveRecordの PostgreSQLアダプタ 周辺について調べてみた (株)サイクル・オブ・フィフス 石田朗雄
  • 3. 構成 ActiveRecord::Base AR::ConnectionAdapter::Base AR::CA::PostgreSQLAdapter AR::CA::他のRDBMS向け ruby-postgres postgres-pr (pure ruby) libpq(C言語) 04:54:22 PM Ruby-Sapporo 2007-11-17 3
  • 4. postgres-prとの比較 ruby-postgres-0.7.1.2006.04.06-mswin32 postgres-pr-0.4.0 postgres-prは、postgres.soがあればそっちを呼ぶので、両 方入っている環境では工夫が必要 ruby-postgres irb(main):002:0> require quot;postgresquot; => true postgres-pr irb(main):003:0> require quot;postgres-pr/postgres-compatquot; => true 04:54:22 PM Ruby-Sapporo 2007-11-17 4
  • 5. postgres-prとの比較 > PGconn.instance_methods(false).sort => [quot;async_execquot;, quot;async_queryquot;, quot;client_encodingquot;, quot;closequot;, quot;dbquot;, quot;endcopyquot;, quot;errorquot;, quot;execquot;, quot;finishquot;, quot;get_notifyquot;, quot;getlinequot;, quot;hostquot;, quot;insert_tablequot;, quot;lo_createquot;, quot;lo_exportquot;, quot;lo_importquot;, quot;lo_openquot;, quot;lo_unlinkquot;, quot;locreatequot;, quot;loexportquot;, quot;loimportquot;, quot;loopenquot;, quot;lounlinkquot;, quot;on_noticequot;, quot;optionsquot;, quot;portquot;, quot;protocol_versionquot;, quot;putlinequot;, quot;queryquot;, quot;resetquot;, quot;select_onequot;, quot;select_valuequot;, quot;select_valuesquot;, quot;server_versionquot;, quot;set_client_encodingquot;, quot;statusquot;, quot;tracequot;, quot;transaction_statusquot;, quot;ttyquot;, quot;untracequot;, quot;userquot;] > PGconn.instance_methods(false).sort => [quot;closequot;, quot;dbquot;, quot;execquot;, quot;hostquot;, quot;queryquot;, quot;userquot;] 04:54:22 PM Ruby-Sapporo 2007-11-17 5
  • 6. 接続 irb(main):013:0> c=PGconn.new(nil, 9999, nil, nil, 'ishida', 'ishida', nil) PGError: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host quot;???quot; and accepting TCP/IP connections on port 9999? from (irb):13:in `initialize' postgres-prではhostがnilだと from (irb):13:in `new' portが無視される from (irb):13 irb(main):004:0> c=PGconn.new(nil, 9999, nil, nil, 'ishida', 'ishida', nil) => #<PGconn:0x2dc3d98 @db=quot;ishidaquot;, @host=nil, @conn=#<PostgresPR::Connection:0x2dc3d70 @params={quot;integer_datetimesquot;=>quot;offquot;, quot;TimeZonequot;=>quot;JST-9quot;, quot;server_encodingquot;=>quot;EUC_JPquot;, quot;standard_conforming_stringsquot;=>quot;offquot;, quot;DateStylequot;=>quot;ISO, MDYquot;, quot;client_encodingquot;=>quot;EUC_JPquot;, quot;session_authorizationquot;=>quot;ishidaquot;, quot;server_versionquot;=>quot;8.1.3quot;, quot;is_superuserquot;=>quot;offquot;}, @conn=#<TCPSocket:0x2dc3bf4>>, @user=quot;ishidaquot;> 04:54:22 PM Ruby-Sapporo 2007-11-17 6
  • 7. ParameterStatus PostgreSQLのコンフィグのうち、クライアントの動作に影響 するものをサーバからクライアントに対して送る 接続時、SETコマンドによる変更、コンフィグファイルのリ ロード等 server_version client_encoding DateStyle 等々 バージョンが上がると増えることがあるの で、PGconn#getparamみたいのが欲しい 04:54:22 PM Ruby-Sapporo 2007-11-17 7
  • 8. postgres-prとの比較 irb(main):004:0> c.client_encoding => quot;SQL_ASCIIquot; irb(main):005:0> c.exec(quot;set client_encoding to sjisquot;) => #<PGresult:0x2dc2358> irb(main):006:0> c.client_encoding => quot;SJISquot; irb(main):010:0> c.instance_variable_get(:@conn).instance_variable_get(:@params) [quot;client_encodingquot;] => quot;SQL_ASCIIquot; irb(main):011:0> c.exec(quot;set client_encoding to sjisquot;) => #<PGresult:0x2e98cb4 @result=[], @fields=[], @res=#<PostgresPR::Connection::Result:0x2e98c50 @cmd_tag=quot;SETquot;, @fields=[], @rows=[]>> irb(main):012:0> c.instance_variable_get(:@conn).instance_variable_get(:@params) [quot;client_encodingquot;] => quot;SQL_ASCIIquot; postgres-prは ParameterStatusの変更を 04:54:22 PM Ruby-Sapporo 2007-11-17 拾っていない 8
  • 9. コイツ、、、動くぞ、、、 PGconn.translate_results = false if PGconn.respond_to? :translate_results= .... if @connection.respond_to?(:status) ... # TODO: postgres-pr doesn't have PGconn#reset. if @connection.respond_to?(:reset) 但し、allow_concurrencyだけは使ってはいけない def query(sql, name = nil) #:nodoc: log(sql, name) do if @async @connection.async_query(sql) else @connection.query(sql) end end 04:54:22 PM Ruby-Sapporo 2007-11-17 9
  • 10. PGconn#async_exec pgconn_async_exec():postgres.c if (!PQsendQuery(conn, RSTRING(str)->ptr)) { rb_raise(rb_ePGError, PQerrorMessage(conn)); } cs = PQsocket(conn); PQsendQueryで非同期にクエリ for(;;) { 送信した後、結果が返ってくるの FD_ZERO(&rset); を待っている? FD_SET(cs, &rset); ret = rb_thread_select(cs + 1, &rset, NULL, NULL, NULL); 04:54:22 PM Ruby-Sapporo 2007-11-17 10
  • 11. まとめ? ruby-postgresとpostgres-prは結構違うけ ど、ActiveRecordが違いを吸収している 今回挙げたものの他にもpostgres-prは、引数のoptionsを無 視してたり環境変数も無視してたり、ParameterStatusを無 視するケースがあったり、、、 素のpostgres-prを使うには覚悟が必要 04:54:22 PM Ruby-Sapporo 2007-11-17 11
  • 12. C:rubylibrubygems1.8gemspostgres-pr-0.4.0lib>grep -r TODO * postgres-pr/connection.rb: # TODO postgres-pr/connection.rb: # TODO: use transaction status postgres-pr/connection.rb: # TODO postgres-pr/connection.rb: # TODO postgres-pr/message.rb:# TODO postgres-pr/message.rb:# TODO postgres-pr/message.rb: # TODO: zero means unspecified. map to nil? postgres-pr/message.rb:# TODO: duplicate message-type, split into client/servermessages postgres-pr/postgres-compat.rb: # TODO: correct? postgres-pr/postgres-compat.rb: # TODO: status, getlength, cmdstatus postgres-pr/postgres-compat.rb: # TODO: correct? postgres-pr/postgres-compat.rb: # TODO: correct? postgres-pr/typeconv/TC_conv.rb: assert_equal [quot;quot;], decode_array(quot;{ }quot;) # TODO: Correct? 04:54:22 PM Ruby-Sapporo 2007-11-17 12