aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #19090 from ↵Matthew Draper2017-12-011-0/+17
|\ | | | | | | | | gregnavis/support-postgresql-operator-classes-in-indexes Add support for PostgreSQL operator classes to add_index
| * Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | Add support for specifying non-default operator classes in PostgreSQL indexes. An example CREATE INDEX query that becomes possible is: CREATE INDEX users_name ON users USING gist (name gist_trgm_ops); Previously it was possible to specify the `gist` index but not the custom operator class. The `add_index` call for the above query is: add_index :users, :name, using: :gist, opclasses: {name: :gist_trgm_ops}
* | Add :nodoc: to `StatementPool` which is internal used [ci skip]Ryuta Kamizono2017-11-301-2/+1
|/ | | | | | In #30510, `StatementPool` in `AbstractMysqlAdapter` was hidden in the doc. But that class is also had in sqlite3 and postgresql adapters and the base class is :nodoc: class.
* Add new error class `QueryCanceled` which will be raised when canceling ↵Ryuta Kamizono2017-11-271-1/+1
| | | | | | | | | | | | | | | statement due to user request (#31235) This changes `StatementTimeout` to `QueryCanceled` for PostgreSQL. In MySQL, errno 1317 (`ER_QUERY_INTERRUPTED`) is only used when the query is manually cancelled. But in PostgreSQL, `QUERY_CANCELED` error code (57014) which is used `StatementTimeout` is also used when the both case. And, we can not tell which reason happened. So I decided to introduce new error class `QueryCanceled` closer to the error code name.
* Rename `TransactionTimeout` to more descriptive `LockWaitTimeout` (#31223)Ryuta Kamizono2017-11-271-1/+1
| | | | | | Since #31129, new error class `StatementTimeout` has been added. `TransactionTimeout` is caused by the timeout shorter than `StatementTimeout`, but its name is too generic. I think that it should be a name that understands the difference with `StatementTimeout`.
* Improve AR connection fork safetyMatthew Draper2017-11-181-0/+5
| | | | | | Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
* Add new error class `StatementTimeout` which will be raised when statement ↵Ryuta Kamizono2017-11-131-0/+3
| | | | | | | | | | | | timeout exceeded (#31129) We are sometimes using The MAX_EXECUTION_TIME hint for MySQL depending on the situation. It will prevent catastrophic performance down by wrong performing queries. The new error class `StatementTimeout` will make to be easier to handle that case. https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
* Raise `TransactionTimeout` when lock wait timeout exceeded for PG adapterRyuta Kamizono2017-11-111-0/+3
| | | | Follow up of #30360.
* `supports_extensions?` return always true since PostgreSQL 9.1Yasuo Honda2017-10-241-9/+3
| | | | | | | | since the minimum version of PostgreSQL currently Rails supports is 9.1, there is no need to handle if `supports_extensions?` Refer https://www.postgresql.org/docs/9.1/static/sql-createextension.html "CREATE EXTENSION"
* [Active Record] require => require_relativeAkira Matsuda2017-10-211-14/+14
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Fix longer sequence name detection for serial columns (#28339)Ryuta Kamizono2017-10-151-2/+3
| | | | | | | | We already found the longer sequence name, but we could not consider whether it was the sequence name created by serial type due to missed a max identifier length limitation. I've addressed the sequence name consideration to respect the max identifier length. Fixes #28332.
* Prefer official name PostgreSQL over PostgresRyuta Kamizono2017-10-041-2/+2
|
* Refactor `SchemaDumper` to make it possible to adapter specific customizationRyuta Kamizono2017-08-221-1/+0
| | | | | | | Currently `SchemaDumper` is only customizable for column options. But 3rd party connection adapters (oracle-enhanced etc) need to customizable for table or index dumping also. To make it possible, I introduced adapter specific `SchemaDumper` classes for that.
* Update links to use https instead of http [ci skip]Yoshiyuki Hirano2017-08-221-1/+1
|
* Prevent extra `SET time zone` in `configure_connection` (#28413)Ryuta Kamizono2017-08-211-6/+8
| | | | | | | | `SET time zone 'value'` is an alias for `SET timezone TO 'value'`. https://www.postgresql.org/docs/current/static/sql-set.html So if `variables["timezone"]` is specified, it is enough to `SET timezone` once.
* Place `update_table_definition` consistently in `SchemaStatements`Ryuta Kamizono2017-08-211-4/+0
|
* Register integer types limit correctly for postgresql adapter (#26386)Ryuta Kamizono2017-08-201-15/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | currently integer types extracts the `limit` from `sql_type`. But the lookup key of type map is the `oid` in postgresql adapter. So in most case `sql_type` is passed to `extract_limit` as `""` and `limit` is extracted as `nil`. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L445 In mysql2 adapter, `limit` is registered correctly without extracting from `sql_type`. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L678-L682 Postgresql adapter should also be registered correctly. ``` ruby conn = ActiveRecord::Base.connection conn.select_all("SELECT 1::smallint, 2::integer, 3::bigint").column_types.map do |name, type| [name, type.limit] end ``` Before: ``` ruby # => [["int2", nil], ["int4", nil], ["int8", nil]] ``` After: ``` ruby # => [["int2", 2], ["int4", 4], ["int8", 8]] ```
* Change http postgresql.org links to https [ci skip]yuuji.yaginuma2017-07-301-4/+4
| | | | | It seems that it accepts only HTTPS connections. Ref: https://github.com/postgres/postgres/commit/7f77cbd996855a06fb742ea11adbe55c42b48fe2
* Merge pull request #29869 from kamipo/make_type_map_to_privateRafael França2017-07-211-6/+6
|\ | | | | Make `type_map` to private because it is only used in the connection adapter
| * Make `type_map` to private because it is only used in the connection adapterRyuta Kamizono2017-07-201-6/+6
| | | | | | | | | | | | | | `type_map` is an internal API and it is only used in the connection adapter. And also, some type map initializer methods requires passed `type_map`, but those instances already has `type_map` in itself. So we don't need explicit passing `type_map` to the initializers.
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|/
* Catch postgres connection errors when trying to dealloc the statement poolChris Williams2017-07-131-0/+1
| | | | | | connection_active? will sometimes return true when the connection is actually dead/disconnected (see #3392 for a discussion of why this is). When this happens, a query is run on the dead connection which causes various postgres connection errors to be raised. This fix catches any such errors and ignores them. Closes #29760
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-021-7/+6
|\
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| | |
| * | Don't cache queries for schema statementsRyuta Kamizono2017-06-301-7/+6
| |/ | | | | | | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* / [Active Record] require => require_relativeAkira Matsuda2017-07-011-14/+14
|/
* Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-291-5/+0
| | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-301-2/+1
|
* Deprecate `supports_statement_cache?`Ryuta Kamizono2017-05-011-6/+0
| | | | | | | | | | | | | | `supports_statement_cache?` was introduced in 3.1.0.beta1 (104d0b2) for bind parameter substitution, but it is no longer used in 3.1.0.rc1 (73ff679). Originally it should respect `prepared_statements` rather than `supports_statement_cache?` (fd39847). One more thing, named `supports_statement_cache?` is pretty misreading. We have `StatementCache` and `StatementPool`. However, `supports_statement_cache?` doesn't mean `StatementCache`, but `StatementPool` unlike its name. https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/statement_cache.rb https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/statement_pool.rb
* Merge pull request #28883 from yahonda/fix28797Rafael França2017-04-261-1/+1
|\ | | | | PostgreSQL 10 does not convert `CURRENT_DATE` into `('now'::text)::date`
| * PostgreSQL 10 allows `CURRENT_DATE` and `CURRENT_TIMESTAMP` as default functionsYasuo Honda2017-04-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | Address #28797 In the previous versions of PostgreSQL, `CURRENT_DATE` converted to `('now'::text)::date` and `CURRENT_TIMESTAMP` converted to `now()`. Refer these discussions and commit at PostgreSQL : https://www.postgresql.org/message-id/flat/5878.1463098164%40sss.pgh.pa.us#5878.1463098164@sss.pgh.pa.us https://github.com/postgres/postgres/commit/0bb51aa96783e8a6c473c2b5e3725e23e95db834
* | Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-261-6/+0
|/ | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* Add comprehensive locking around DB transactionsMatthew Draper2017-04-111-12/+20
| | | | | | | | | | | | | | | | | | Transactional-fixture using tests with racing threads and inter-thread synchronisation inside transaction blocks will now deadlock... but without this, they would just crash. In 5.0, the threads didn't share a connection at all, so it would've worked... but with the main thread inside the fixture transaction, they wouldn't've been able to see each other. So: as far as I can tell, the set of operations this "breaks" never had a compelling use case. Meanwhile, it provides an increased level of coherency to the operational feel of transactional fixtures. If this does cause anyone problems, they're probably best off disabling transactional fixtures on the affected tests, and managing transactions themselves.
* Merge pull request #28052 from kamipo/make_internal_methods_to_privateRafael França2017-03-281-15/+2
|\ | | | | Make internal methods to private
| * Make internal methods to privateRyuta Kamizono2017-03-271-15/+2
| |
* | Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-261-0/+6
|/ | | | | | | | | | | | | | | privileges (take 2) Re-create https://github.com/rails/rails/pull/21233 eeac6151a5 was reverted (127509c071b4) because it breaks tests. ---------------- ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* Move comment to inside the method [ci skip]Fumiaki MATSUSHIMA2017-03-231-1/+1
| | | | | | Because this comment is not document for `supports_ranges?` ref: https://github.com/rails/rails/pull/27636#discussion_r107560081
* [PostgreSQL]: Replace deprecated PG constants.Lars Kanis2017-03-221-9/+9
| | | | | The old top level classes PGconn, PGresult and PGError were deprecated since pg-0.13.0: https://github.com/ged/ruby-pg/blob/master/History.rdoc#v0130-2012-02-09-michael-granger-gedfaeriemudorg
* Revert "Merge pull request #28369 from ↵Matthew Draper2017-03-141-2/+2
| | | | | | | | | mylake/reduce-postgresql-adapter-memory-bloat" This reverts commit 192db64452d148c7b51713979459e38407380dc6, reversing changes made to 9893955363cf6358556ed3b36f4538d5b54e9d17. We can't sacrifice correctness for performance.
* Merge pull request #28369 from mylake/reduce-postgresql-adapter-memory-bloatRafael França2017-03-131-2/+2
|\ | | | | 500x memory reduction of 10k schemas for postgresql adapter
| * Use “distinct” to filter redundant types from pg_typeto reduce memory ↵mylake2017-03-101-2/+2
| | | | | | | | bloat especially in multi-schema structure database
* | Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-1/+1
|\ \ | |/ |/| Extract `data_source_sql` to refactor data source statements
| * Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-1/+1
| |
* | Use `max_identifier_length` for `index_name_length` in PostgreSQL adapterRyuta Kamizono2017-02-271-2/+3
| | | | | | | | | | Actually `index_name_length` depend on `max_identifier_length`, not always 63.
* | Deprecate `supports_migrations?` on connection adaptersRyuta Kamizono2017-02-271-5/+0
| | | | | | | | | | | | | | `supports_migrations?` was added at 4160b518 to determine if schema statements (`create_table`, `drop_table`, etc) are implemented in the adapter. But all tested databases has been supported migrations since a4fc93c3 at least.
* | Push `valid_type?` up to abstract adapterRyuta Kamizono2017-02-261-4/+0
| | | | | | | | | | | | | | `valid_type?` should return true if a type exists in `native_database_types` at least. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L136
* | Ensure test threads share a DB connectioneileencodes2017-02-201-14/+20
|/ | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* Add `default_index_type?` to the generic schema dumper doesn't have the ↵Ryuta Kamizono2017-02-141-0/+4
| | | | knowledge about an index type