Upgrade to Pro — share decks privately, control downloads, hide ads and more …

extensionとschema

Avatar for Yasuo Honda Yasuo Honda
February 01, 2025

 extensionとschema

Avatar for Yasuo Honda

Yasuo Honda

February 01, 2025
Tweet

More Decks by Yasuo Honda

Other Decks in Technology

Transcript

  1. • Yasuo Honda @yahonda ◦ Rails committer ◦ 第50回 PostgreSQLアンカンファレンス

    以来5回目の参加です ▪ PostgreSQL 15とRailsと - Speaker Deck ▪ 遅延可能な一意性制約 - Speaker Deck ▪ pg_stat_statementsで inの数が違うSQLをまとめて ほしい - Speaker Deck ▪ NOT VALIDな検査制約 / check constraint that is not valid - Speaker Deck 自己紹介
  2. • NOT VALIDな検査制約 / check constraint that is not valid

    - Speaker Deck • Rails ◦ https://github.com/rails/rails/pull/54286 • PostgreSQL ◦ https://www.postgresql.org/message-id/202501141746.ztgt jtjcehr3%40alvherre.pgsql 第50回からのアップデート
  3. • Ruby on Railsのmigrationでextensionを作成、削除するDSL ◦ enable_extension(“schema_name.extension_name”) ▪ Rails 7.1 https://github.com/rails/rails/pull/46894

    以降で dot notationな引数に取れるようになった ◦ disable_extension(“schema_name.extension_name”) ▪ extensionが削除されていなかった 背景
  4. • enable_extension(“myschema.hstore”) ◦ test=# CREATE EXTENSION IF NOT EXISTS "hstore"

    SCHEMA myschema; ◦ 成功する • disable_extension(“myschema.hstore”) ◦ test=# DROP EXTENSION IF EXISTS "myschema.hstore"; ◦ NOTICE: extension "myschema.hstore" does not exist, skipping ◦ エラーになっていた: 発行されていた SQL
  5. • dot notationが利用できない ◦ test=# CREATE EXTENSION IF NOT EXISTS

    "myschema.hstore"; ◦ ERROR: extension "myschema.hstore" is not available ◦ DETAIL: Could not open extension control file "/usr/share/postgresql/16/extension/myschema.hstore.co ntrol": No such file or directory. ◦ HINT: The extension must first be installed on the system where PostgreSQL is running. 他のオブジェクトとの違い : create時
  6. • そのデータベース内に作成されていたら複数作成できない ◦ スキーマ名に関わらず ◦ test=# CREATE EXTENSION IF NOT

    EXISTS "hstore"; ◦ CREATE EXTENSION ◦ test=# CREATE EXTENSION IF NOT EXISTS "hstore" SCHEMA myschema; ◦ NOTICE: extension "hstore" already exists, skipping ◦ CREATE EXTENSION 他のオブジェクトとの違い : create時
  7. • SCHEMA句も利用できない ◦ test=# DROP EXTENSION IF EXISTS "hstore" SCHEMA

    myschema; ◦ ERROR: syntax error at or near "SCHEMA" • dot notationも利用できない ◦ test=# DROP EXTENSION IF EXISTS "myschema.hstore"; ◦ NOTICE: extension "myschema.hstore" does not exist, skipping 他のオブジェクトとの違い : drop時
  8. • https://www.postgresql.org/docs/current/sql-createextension .html • > The name of the schema

    in which to install the extension's objects, given that the extension allows its contents to be relocated. • https://www.postgresql.jp/document/16/html/sql-createexten sion.html • > 拡張の内容を再配置させることができる場合に、拡張のオブジェクトを インストールするスキーマの名前です。 Documentation (下線部は発表者による )
  9. • https://www.postgresql.org/docs/current/catalog-pg-extensio n.html ◦ Note that unlike most catalogs with

    a “namespace” column, extnamespace is not meant to imply that the extension belongs to that schema. Extension names are never schema-qualified. Rather, extnamespace indicates the schema that contains most or all of the extension's objects. If extrelocatable is true, then this schema must in fact contain all schema-qualifiable objects belonging to the extension. Relocated / 再配置 (下線は発表者 )
  10. • create schema another_schema; • alter extension hstore set schema

    another_schema; • https://www.postgresql.org/docs/current/sql-alterextension.h tml Relocated / 再配置
  11. • PostgreSQL 9.1から導入 ◦ https://www.postgresql.org/docs/9.1/sql-createextension. html • 関連commit(s) ◦ https://github.com/postgres/postgres/commit/d9572c4e3

    b4 ◦ https://github.com/postgres/postgres/commit/1214749901f extensionが導入されたバージョン / commit