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

Más contenido relacionado

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
 

Último

March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch TuesdayIvanti
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...DianaGray10
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2DianaGray10
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechProduct School
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4DianaGray10
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)IES VE
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNeo4j
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Libraryshyamraj55
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud DataEric D. Schabell
 

Último (20)

March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch Tuesday
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile Brochure
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)The Importance of Indoor Air Quality (English)
The Importance of Indoor Air Quality (English)
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4j
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Library
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data
 

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