tags: PostgreSQL

change_table with Bulk Option Combines Multiple alter-table Statements

Today I learned that when doing database-migration on Rails, change_table :#{table_name}, bulk: true let us combine multiple alter-table statements and it could reduce the cost of the whole alteration. That is, instead of executing multiple alter-table separately, def change add_column :users, :first_name, :string, null: false add_column :users, :last_name, :string, null: false end we can run a single alter-table statement by change_table like as follows. def change change_table :users, bulk: true do |t| t.column :first_name, :string, null: false t.column :last_name, :string, null: false end end However, why should we do that? What are the differences between them?

Read more →

How to Fix PostgreSQL Error: canceling statement due to conflict with recovery

Today I learned how to fix a PostgreSQL error like this: ERROR: canceling statement due to conflict with recovery DETAIL: User query might have needed to see row versions that must be removed. It’s about database replication. I have been getting that on read-only database which uses PostgreSQL Hot Standby. This error didn’t happen always but happened occasionally. I fixed that by setting both max_standby_archive_delay and max_standby_streaming_delay to a longer time (300s) on the standby servers. The reason that this error occurs is query conflicts. This kind of error is not inevitable because of the nature of database replication, and in some cases, queries running on standby servers have to be canceled. Then the error shows up.

Read more →

Gentaro "hibariya" Terada

Otakanomori, Nagareyama, Chiba, Japan
Email me

Likes Ruby, Internet, and Programming.