aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorJacob Evelyn <jevelyn@panoramaed.com>2018-10-15 15:00:07 -0400
committerJacob Evelyn <jevelyn@panoramaed.com>2018-11-13 09:37:20 -0500
commitbfc4d8be0a61b795ee122c5f426e0873938d0e41 (patch)
tree4c8c09a2c4a2a35b8681e89525909046d5a5071b /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parent82f2e9741fb075f209d6018de2777c0aab3a829c (diff)
downloadrails-bfc4d8be0a61b795ee122c5f426e0873938d0e41.tar.gz
rails-bfc4d8be0a61b795ee122c5f426e0873938d0e41.tar.bz2
rails-bfc4d8be0a61b795ee122c5f426e0873938d0e41.zip
Add support for UNLOGGED Postgresql tables
This commit adds support for the `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables` setting, which turns `CREATE TABLE` SQL statements into `CREATE UNLOGGED TABLE` statements. This can improve PostgreSQL performance but at the cost of data durability, and thus it is highly recommended that you *DO NOT* enable this in a production environment.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index a11a786ec7..f701292be3 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -85,6 +85,18 @@ module ActiveRecord
class PostgreSQLAdapter < AbstractAdapter
ADAPTER_NAME = "PostgreSQL"
+ ##
+ # :singleton-method:
+ # PostgreSQL allows the creation of "unlogged" tables, which do not record
+ # data in the PostgreSQL Write-Ahead Log. This can make the tables faster,
+ # bug significantly increases the risk of data loss if the database
+ # crashes. As a result, this should not be used in production
+ # environments. If you would like all created tables to be unlogged you
+ # can add the following line to your test.rb file:
+ #
+ # ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
+ class_attribute :create_unlogged_tables, default: false
+
NATIVE_DATABASE_TYPES = {
primary_key: "bigserial primary key",
string: { name: "character varying" },