PG cannot execute UPDATE in a read-only transaction | How to add column if not exists on PostgreSQL


  PG cannot execute UPDATE in a read-only transaction出現這種情況時,說明SQL語句可能是運行在一個PG集群中的非master節點上。查看data/pg_hba.conf。

  SELECT pg_is_in_recovery();

   This cannot return true in a master server because the only time a master server can be in recovery。

  還有如下可能Normally the most plausible reasons for this kind of error are :

  • trying create statements on a read-only replica (the entire instance is read-only).

  • <username> has default_transaction_read_only set to ON

  • the database has default_transaction_read_only set to ON

  alter database exercises set default_transaction_read_only = off;

      https://stackoverflow.com/questions/31186414/error-cannot-execute-create-table-in-a-read-only-transaction

 

  How to add column if not exists on PostgreSQL

  With Postgres 9.6 this can be done using the option if not exists

  ALTER TABLE table_name ADD COLUMN IF NOT EXISTS column_name INTEGER;

  https://stackoverflow.com/questions/12597465/how-to-add-column-if-not-exists-on-postgresql

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM