aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
* applies remaining conventions across the projectXavier Noria2016-08-061-13/+13
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-74/+74
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Leave internal pgsql name intact as const referenceDavid Heinemeier Hansson2016-08-041-2/+2
|
* The problem isn't the detection but the deadlock itselfDavid Heinemeier Hansson2016-08-041-3/+3
|
* Merge pull request #25107 from Erol/introduce-new-ar-transaction-error-classesRafael Mendonça França2016-08-031-1/+4
|\ | | | | | | | | | | Introduce new ActiveRecord transaction error classes Closes #26018
| * Introduce new ActiveRecord transaction error classesErol Fornoles2016-05-241-1/+4
| |
* | Extract `type_casted_binds` methodRyuta Kamizono2016-07-261-2/+2
| | | | | | | | | | Because `type_cast` against `binds` always requires `attr.value_for_database` and this pattern appears frequently.
* | Pass `type_casted_binds` to log subscriber for logging bind values properlyRyuta Kamizono2016-07-191-2/+2
|/ | | | Address to https://github.com/rails/rails/commit/5a302bf553af0e6fedfc63299fc5cd6e79599ef3#commitcomment-18288388.
* Add AR::TransactionSerializationError for transaction serialization failures ↵Erol Fornoles2016-05-211-0/+3
| | | | or deadlocks
* Treat blank comments as no comment for indexesRyuta Kamizono2016-04-291-4/+0
| | | | | | Follow up of 1683410. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-0/+4
| | | | | | | | | | | | | | | | Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes #19090. Fixes #21765. Fixes #21819. Fixes #24359. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Follow up of #23461Vipul A M2016-04-241-1/+1
| | | | | | | | - Rename max to statement_limit - Remove magic number 1000 from everywhere - Defined StatementPool::DEFAULT_STATEMENT_LIMIT and started using it everywhere Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Include the Savepoints module in all adapters.Vipul A M2016-04-241-1/+4
| | | | | Adapters override `#supports_savepoints?` to return `true` if they support transaction savepoints. Defaults to `false`.
* Move `require 'ipaddr'` in `postgresql/oid/cidr.rb`Ryuta Kamizono2016-04-241-2/+0
| | | | `IPAddr` is used in `OID::Cidr`.
* Define `arel_visitor` method on all adaptersRyuta Kamizono2016-04-201-0/+4
| | | | `Arel::Visitors::VISITORS` was removed at https://github.com/rails/arel/pull/412.
* Merge pull request #23515 from kamipo/extract_arel_visitorJeremy Daer2016-04-191-8/+0
|\ | | | | | | Extract `arel_visitor` and move up to the abstract adapter
| * Extract `arel_visitor` and move up to the abstract adapterRyuta Kamizono2016-04-041-8/+0
| |
* | Merge pull request #23522 from kamipo/add_value_too_long_exception_classJeremy Daer2016-04-181-0/+3
|\ \ | | | | | | | | | Add `ActiveRecord::ValueTooLong` exception class
| * | Add `ActiveRecord::ValueTooLong` exception classRyuta Kamizono2016-02-061-0/+3
| | |
* | | Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-2/+6
| | | | | | | | | | | | | | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* | | Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-4/+9
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
* | use same name to type objectyuuji.yaginuma2016-03-091-1/+1
| | | | | | | | Follow up to #24079
* | Merge pull request #22170 from ↵Matthew Draper2016-03-021-13/+29
|\ \ | |/ |/| | | | | samphilipd/sam/properly_deallocate_prepared_statements_outside_of_transaction Correctly deallocate prepared statements if we fail inside a transaction
| * Correctly deallocate prepared statements if we fail inside a transactionSam Davies2015-11-051-13/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #12330 Overview ======== Cached postgres prepared statements become invalidated if the schema changes in a way that it affects the returned result. Examples: - adding or removing a column then doing a 'SELECT *' - removing the foo column then doing a 'SELECT bar.foo' In normal operation this isn't a problem, we can rescue the error, deallocate the prepared statement and re-issue the command. However in PostgreSQL transactions, once any command fails, the transaction becomes 'poisoned' and any subsequent commands will raise InFailedSQLTransaction. This includes DEALLOCATE statements, so the default deallocation strategy instead of removing the cached prepared statement instead raises InFailedSQLTransaction. Why this is bad =============== 1. InFailedSQLTransaction is a fairly cryptic error and doesn't communicate any useful information about what has actually gone wrong. 2. In the naive implementation the prepared statement never gets deallocated - it stays alive for the length of the session taking up memory on the postgres server. 3. It is unsafe to retry the transaction because the bad prepared statement is still in the cache and we would see the exact same failure repeated. Solution ======== If we are outside a transaction we can continue to handle these failures gracefully in the usual way. Inside a transaction instead of issuing a DEALLOCATE command that will certainly fail, we now raise ActiveRecord::PreparedStatementCacheExpired. This can be handled further up the stack, notably inside TransactionManager#within_new_transaction. Here we can make sure to first rollback the transaction, then safely issue DEALLOCATE statements to invalidate the rest of the cached prepared statements. This also allows the user (or some gem) the opportunity to catch this error and voluntarily retry the transaction if a schema change causes the prepared statement cache to become invalidated. Because the outdated statement has been deallocated, we can expect the transaction to succeed on the second try.
* | Mention supported PG version in the error message.Prathamesh Sonpatki2016-02-031-1/+1
| |
* | The minimum supported version of PostgreSQL is now >= 9.1Remo Mueller2016-02-021-3/+2
| |
* | Extract `ExplainPrettyPrinter` to appropriate filesRyuta Kamizono2016-02-011-0/+1
| |
* | `OID::Money.precision` is unused since #15239Ryuta Kamizono2016-01-311-6/+0
| | | | | | | | | | | | | | | | p PostgreSQLAdapter::OID::Money.precision # => 19 p PostgreSQLAdapter::OID::Money.new.precision # => nil
* | Revert "Merge pull request #23346 from kamipo/refactor_oid_money_precision"Rafael Mendonça França2016-01-301-1/+7
| | | | | | | | | | | | | | This reverts commit ff835f90800a3e4122d64606cb328908c2e0e071, reversing changes made to c4d85dfbc71043e2a746acd310e32f4f04db801a. Reason: This broke the tests. We will add back after investigated.
* | Refactor `OID::Money.precision`Ryuta Kamizono2016-01-301-7/+1
| |
* | Merge pull request #20005 from kamipo/default_expression_supportRafael França2016-01-161-3/+8
|\ \ | | | | | | Add `:expression` option support on the schema default
| * | Fix extract default with CURRENT_DATERyuta Kamizono2016-01-131-3/+8
| | | | | | | | | | | | The default 'now'::date is CURRENT_DATE.
* | | `last_insert_id_value` and `last_insert_id` are unused anymoreRyuta Kamizono2016-01-151-9/+1
|/ / | | | | | | These methods are private and unused from anywhere.
* | Make `postgresql_version` publicDerek Prior2015-12-301-5/+5
| | | | | | | | | | | | | | | | | | | | | | This is useful to libraries that want to feature gate based on the version of PostgreSQL the user is connected to. For instance, I want to know if the user is connected to a version of Postgres that supports concurrent materialized view refreshes. I could add that as a method on the adapter as a PR, but rails has no need for this itself. Rails is already using the postgresql_version for its own feature gating and this makes that possible for other libraries.
* | Call the new point behavior `:point`, not `:rails_5_1_point`Sean Griffin2015-12-171-2/+1
| | | | | | | | | | Since the attributes API is new in Rails 5, we don't actually need to keep the behavior of `attribute :point`, as it's not a breaking change.
* | Refactor `AbstractAdapter#initialize`Ryuta Kamizono2015-11-301-2/+2
| | | | | | | | `pool` in args is unused anymore. And `config` is used in all adapters.
* | Merge pull request #22304 from ↵Yves Senn2015-11-241-6/+12
|\ \ | | | | | | | | | | | | kamipo/schema_dumping_support_for_postgresql_geometric_types Add schema dumping support for PostgreSQL geometric data types
| * | Add schema dumping support for PostgreSQL geometric data typesRyuta Kamizono2015-11-241-6/+12
| | |
* | | Merge pull request #22214 from ↵Rafael França2015-11-241-1/+1
|\ \ \ | |/ / |/| | | | | | | | kamipo/not_passing_native_database_types_to_table_definition Not passing `native_database_types` to `TableDefinition`
| * | Not passing `native_database_types` to `TableDefinition`Ryuta Kamizono2015-11-081-1/+1
| |/ | | | | | | | | | | The `native_database_types` only used in `TableDefinition` for look up the default `:limit` option. But this is duplicated process with `type_to_sql`. Passing `native_database_types` is not needed.
* | Rename 'key' to 'lock_id' or 'lock_name' for advisory lockingSam Davies2015-11-181-8/+8
| | | | | | | | | | | | | | | | | | - key was a poor choice of name. A key implies something that will unlock a lock. The concept is actually more like a 'lock identifier' - mysql documentation calls this a 'lock name' - postgres documentation calls it a 'lock_id' - Updated variable names to reflect the preferred terminology for the database in question
* | Remove not needed `NATIVE_DATABASE_TYPES` entriesRyuta Kamizono2015-11-161-2/+0
|/
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-4/+4
|
* Merge pull request #22122 from ↵Sean Griffin2015-10-301-0/+18
|\ | | | | | | | | samphilipd/sam/manual_locking_on_schema_migrations Make migrations concurrent safe (using advisory locks)
| * Use advisory locks to prevent concurrent migrationsSam Davies2015-10-301-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #22092 - Works on Postgres and MySQL - Uses advisory locks because of two important properties: 1. The can be obtained outside of the context of a transaction 2. They are automatically released when the session ends, so if a migration process crashed for whatever reason the lock is not left open perpetually - Adds get_advisory_lock and release_advisory_lock methods to database adapters - Attempting to run a migration while another one is in process will raise a ConcurrentMigrationError instead of attempting to run in parallel with undefined behavior. This could be rescued and the migration could exit cleanly instead. Perhaps as a configuration option? Technical Notes ============== The Migrator uses generate_migrator_advisory_lock_key to build the key for the lock. In order to be compatible across multiple adapters there are some constraints on this key. - Postgres limits us to 64 bit signed integers - MySQL advisory locks are server-wide so we have to scope to the database - To fulfil these requirements we use a Migrator salt (a randomly chosen signed integer with max length of 31 bits) that identifies the Rails migration process as the owner of the lock. We multiply this salt with a CRC32 unsigned integer hash of the database name to get a signed 64 bit integer that can also be converted to a string to act as a lock key in MySQL databases. - It is important for subsequent versions of the Migrator to use the same salt, otherwise different versions of the Migrator will not see each other's locks.
* | Merge pull request #19511 from larskanis/replace_const_conn_paramsSean Griffin2015-10-291-7/+2
|\ \ | | | | | | PostgreSQL, Replace static connection param list by libpq's dynamic list
| * | PostgreSQL, Replace static connection param list by the one built into libpq.Lars Kanis2015-03-251-7/+2
| | | | | | | | | | | | | | | | | | | | | This makes the connection adapter future-proof regarding to new parameters. To maintain backward compatibility, :requiressl is added by hand. It is deprecated by PostgreSQL since 2003, but still accepted by libpq.
* | | Don't disable errors when turning standard_conforming_strings onHarry Marr2015-10-291-7/+2
| | |
* | | Check standard_conforming_strings is not readonlyHarry Marr2015-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | In Postgres 8.1 the standard_conforming_strings setting was read-only, meaning you got an error if you tried to update it. By filtering on `context = 'user'` we only try to update the setting if it's user-writable[1]. [1]: http://www.postgresql.org/docs/9.4/static/view-pg-settings.html
* | | Avoid disabling postgres errorsHarry Marr2015-10-281-4/+5
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The standard_conforming_strings setting doesn't exist on all versions of Postgres, but if it does exist, Rails turns it on. Previously this was done by effectively disabling errors on the Postgres connection, issuing a SET to turn the setting on, then re-enabling errors on the connection. However, if you're running pgbouncer in transaction-pooling mode, you can't guarantee that successive calls to `#execute` will be sent to the same pgbouncer-postgres connection, so you can end up disabling errors on a different postgres connection, and never re-enabling them. Future queries on that connection that result in errors (e.g. violating unique constraints) will leave the connection in a bad state where successive queries will fail. This commit sets standard_conforming_strings by issuing an UPDATE to pg_settings, which will update the setting if it exists, and do nothing if it doesn't (rather than erroring out like SET would), which means we can remove the error-disabling code. It's also worth noting that Postgres has allowed standard_conforming_strings to be updated since 8.2 (which is the oldest version Rails supports), so technically we probably don't even need to be defensive here.