設定資料庫旗標

本頁面說明如何設定 Cloud SQL 的資料庫旗標,並列出可為執行個體設定的旗標。資料庫旗標可用於多項作業,包括調整 PostgreSQL 參數、調整選項,以及設定和調整執行個體。

在某些情況下,您可能需要設定另一個旗標,才能完整啟用要使用的功能。

設定、移除或修改資料庫執行個體的旗標時,資料庫可能會重新啟動。移除之前,系統都會保留執行個體的旗標值。如果執行個體是副本的來源,且執行個體重新啟動,副本也會重新啟動,以配合執行個體的目前設定。

設定資料庫旗標

以下各節將說明常見的旗標管理工作。

設定資料庫旗標

控制台

  1. 在 Google Cloud 控制台中,選取要設定資料庫旗標的 Cloud SQL 執行個體所在專案。
  2. 開啟執行個體並按一下 [編輯]。
  3. 前往「旗標」部分。
  4. 如要設定先前未在執行個體上設定的旗標,請按一下「Add item」(新增項目),從下拉式選單中選擇旗標,然後設定其值。
  5. 按一下 [儲存] 以儲存變更。
  6. 在「總覽」頁面的「標記」下方,確認您所做的變更。

gcloud

編輯執行個體:

gcloud sql instances patch INSTANCE_NAME --database-flags=FLAG1=VALUE1,FLAG2=VALUE2

這個指令會覆寫先前設定的所有資料庫旗標。如要保留這些旗標並新增旗標,請加入您要在執行個體上設定的所有旗標值;任何未明確加入的旗標都會設為預設值。如果旗標不接受值,請指定旗標名稱,後面加上等號 (「=」)。

舉例來說,如要設定 log_connections 和 log_min_error_statement 旗標,可以使用下列指令:

gcloud sql instances patch INSTANCE_NAME \
  --database-flags=log_connections=on,log_min_error_statement=error

Terraform

如要新增資料庫旗標,請使用 Terraform 資源。

resource "google_sql_database_instance" "instance" {
  name             = "postgres-instance"
  region           = "us-central1"
  database_version = "POSTGRES_14"
  settings {
    database_flags {
      name  = "log_connections"
      value = "on"
    }
    database_flags {
      name  = "log_min_error_statement"
      value = "error"
    }
    tier = "db-custom-2-7680"
  }
  # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
  # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
  deletion_protection = false
}

套用變更

如要在 Google Cloud 專案中套用 Terraform 設定,請完成下列各節的步驟。

準備 Cloud Shell

  1. 啟動 Cloud Shell。
  2. 設定要套用 Terraform 設定的預設 Google Cloud 專案。

    每個專案只需執行這個指令一次,而且可以在任何目錄中執行。

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    如果您在 Terraform 設定檔中設定明確的值,環境變數就會遭到覆寫。

準備目錄

每個 Terraform 設定檔都必須有自己的目錄 (也稱為根模組)。

  1. 在 Cloud Shell 中建立目錄,並在該目錄中建立新檔案。檔案名稱必須有 .tf 副檔名,例如 main.tf。在本教學課程中,這個檔案稱為 main.tf。
    mkdir DIRECTORY && cd DIRECTORY && touch main.tf
  2. 如果您正在進行教學課程,可以複製每個章節或步驟中的程式碼範例。

    將程式碼範例複製到新建立的 main.tf。

    您也可以從 GitHub 複製程式碼。如果 Terraform 程式碼片段是端對端解決方案的一部分,建議您採用這種做法。

  3. 請查看並修改範例參數,以便套用至您的環境。
  4. 儲存變更。
  5. 初始化 Terraform。每個目錄只需執行一次這項操作。
    terraform init

    如要使用最新版 Google 供應商,請視需要加入 -upgrade 選項:

    terraform init -upgrade

套用變更

  1. 查看設定,確認 Terraform 要建立或更新的資源符合預期:
    terraform plan

    視需要修正設定。

  2. 執行下列指令,並在提示中輸入 yes,套用 Terraform 設定:
    terraform apply

    等待 Terraform 顯示「Apply complete!」訊息。

  3. 開啟 Google Cloud 專案即可查看結果。在 Google Cloud 控制台的使用者介面中,前往資源頁面,確認 Terraform 已建立或更新資源。

刪除變更

如要刪除變更,請按照下列步驟操作:

  1. 如要停用防刪除功能,請在 Terraform 設定檔中將 deletion_protection 引數設為 false。
    deletion_protection =  "false"
  2. 執行下列指令,並在提示中輸入 yes,套用更新後的 Terraform 設定:
    terraform apply
  1. 執行下列指令,並在提示中輸入 yes,移除先前使用 Terraform 設定套用的資源:

    terraform destroy

REST v1

如要為現有資料庫設定旗標,請按照下列步驟操作:

使用任何要求資料之前,請先修改下列項目的值:

  • project-id:專案 ID
  • instance-id:執行個體 ID

HTTP 方法和網址:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

JSON 要求主體:

{
  "settings":
  {
    "databaseFlags":
    [
      {
        "name": "flag_name",
        "value": "flag_value"
      }
    ]
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

如果資料庫已設定旗標,請修改先前的指令,將這些旗標納入。PATCH 指令會以要求中指定的值覆寫現有的標記。

REST v1beta4

如要為現有資料庫設定旗標,請按照下列步驟操作:

使用任何要求資料之前,請先修改下列項目的值:

  • project-id:專案 ID
  • instance-id:執行個體 ID

HTTP 方法和網址:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

JSON 要求主體:

{
  "settings":
  {
    "databaseFlags":
    [
      {
        "name": "flag_name",
        "value": "flag_value"
      }
    ]
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

如果資料庫已設定旗標,請修改先前的指令,將這些旗標納入。PATCH 指令會以要求中指定的值覆寫現有的標記。

將所有旗標清除並還原為預設值

控制台

  1. 在Google Cloud 控制台中,選取要清除所有旗標的 Cloud SQL 執行個體所在專案。
  2. 開啟執行個體並按一下 [編輯]。
  3. 開啟「資料庫旗標」專區。
  4. 按一下畫面上所有顯示標記旁的 [X]。
  5. 按一下 [儲存] 以儲存變更。

gcloud

清除執行個體中所有標記並轉為預設值:

gcloud sql instances patch INSTANCE_NAME \
--clear-database-flags

系統會提示您將重新啟動執行個體。

REST v1

清除現有執行個體的所有標記:

使用任何要求資料之前,請先修改下列項目的值:

  • project-id:專案 ID
  • instance-id:執行個體 ID

HTTP 方法和網址:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

JSON 要求主體:

{
  "settings":
  {
    "databaseFlags": []
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

REST v1beta4

清除現有執行個體的所有標記:

使用任何要求資料之前,請先修改下列項目的值:

  • project-id:專案 ID
  • instance-id:執行個體 ID

HTTP 方法和網址:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

JSON 要求主體:

{
  "settings":
  {
    "databaseFlags": []
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

查看資料庫旗標的目前值

如要查看 PostgreSQL 設定的所有目前值,請使用 psql 用戶端登入執行個體,然後輸入下列陳述式:

 SELECT name, setting FROM pg_settings;

請注意,您只能變更支援的旗標值 (如下所示)。

判斷已為執行個體設定哪些資料庫旗標

如要查看 Cloud SQL 執行個體設定了哪些旗標,請按照下列步驟操作:

控制台

  1. 在 Google Cloud 控制台中,選取包含 Cloud SQL 執行個體的專案,查看已設定的資料庫旗標。
  2. 選取執行個體,開啟「Instance Overview」(執行個體總覽) 頁面。

    已設定的資料庫旗標會列在「Database flags」(資料庫旗標) 專區下方。

gcloud

取得執行個體狀態:

gcloud sql instances describe INSTANCE_NAME

在輸出內容中,資料庫旗標會列在 settings 下方,做為 databaseFlags 集合。如要進一步瞭解輸出內容中的旗標表示法,請參閱「執行個體資源表示法」。

REST v1

列出已針對執行個體設定的標記:

使用任何要求資料之前,請先修改下列項目的值:

  • project-id:專案 ID
  • instance-id:執行個體 ID

HTTP 方法和網址:

GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

在輸出內容中,尋找 databaseFlags 欄位。

REST v1beta4

列出已針對執行個體設定的標記:

使用任何要求資料之前,請先修改下列項目的值:

  • project-id:專案 ID
  • instance-id:執行個體 ID

HTTP 方法和網址:

GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

在輸出內容中,尋找 databaseFlags 欄位。

支援的標記

不支援下表未提及的旗標。

對於特定旗標,Cloud SQL 支援的值或範圍可能與對應的 PostgreSQL 參數或選項不同。

A | C | D | E | F | G | H | I | J | L | M | O | P | R | S | T | V | W

Cloud SQL 標記 類型
可接受的值和附註
是否需要重新啟動?
anon.algorithm String
預設值為 sha256。
否
anon.maskschema String
預設值為 mask。
否
anon.restrict_to_trusted_schemas boolean
on | off
預設為「關閉」。
否
anon.salt String
沒有預設值。
否
anon.sourceschema String
預設為公開。
否
auto_explain.log_analyze boolean
on | off
預設為「關閉」。
否
auto_explain.log_buffers boolean
on | off
預設為「關閉」。
否
auto_explain.log_min_duration Integer
-1 ... 2147483647
預設值為 -1。
否
auto_explain.log_format String
text|xml|json|yaml
預設值為 text。
否
auto_explain.log_level String
debug5|debug4|debug3|debug2|debug1|debug|
info|notice|warning|log
預設值為 log。
PostgreSQL 12 以上版本支援。
否
auto_explain.log_nested_statements boolean
on | off
預設為「關閉」。
否
auto_explain.log_settings boolean
on | off
預設值為 off。
支援 PostgreSQL 12 以上版本。
否
auto_explain.log_timing boolean
on | off
預設為「on」。
否
auto_explain.log_triggers boolean
on | off
預設為「關閉」。
否
auto_explain.log_wal boolean
on | off
預設值為 off。
PostgreSQL 13 以上版本支援。
否
auto_explain.log_verbose boolean
on | off
預設為「關閉」。
否
auto_explain.sample_rate Float
0 ... 1
預設值為 1。
否
autovacuum boolean
on | off
預設為「開啟」。
如要瞭解可能影響服務水準協議的使用資訊,請參閱「PostgreSQL 適用的 Cloud SQL 執行個體作業指南」。
否
autovacuum_analyze_scale_factor float
0 ... 100
預設值為 0.1。
否
autovacuum_analyze_threshold integer
0 ... 2147483647
預設值為 50。
否
autovacuum_freeze_max_age integer
100000 ... 2000000000
預設值為 200000000。
如要瞭解可能影響服務水準協議的使用資訊,請參閱「PostgreSQL 適用的 Cloud SQL 執行個體作業指南」。
是
autovacuum_max_workers integer
1 ... varies (see note)
預設值為 3。
是
autovacuum_multixact_freeze_max_age integer
10000 ... 2000000000
預設值為 400000000。
如要瞭解可能影響服務水準協議的使用資訊,請參閱「PostgreSQL 適用的 Cloud SQL 執行個體作業指南」。
是
autovacuum_naptime integer
1 ... 2147483 秒
預設值為 60 秒。
否
autovacuum_vacuum_cost_delay integer
0 ... 100 毫秒,或 -1 以使用 vacuum_cost_delay 值
PostgreSQL 9.6、10 和 11 的預設值為 2 毫秒。
否
autovacuum_vacuum_cost_limit integer
0... 10000,或 -1 (使用 vacuum_cost_limit 值)
預設值為 -1。
否
autovacuum_vacuum_insert_scale_factor float
0 ... 100
預設值為 0.2。
否
autovacuum_vacuum_insert_threshold integer
-1 ... 2147483647
預設值為 1000。
否
autovacuum_vacuum_max_threshold integer
-1 ... 2147483647
預設值為 100000000。
PostgreSQL 18 以上版本支援。
否
autovacuum_vacuum_scale_factor float
0 ... 100
預設值為 0.2。
否
autovacuum_vacuum_threshold integer
0 ... 2147483647
預設值為 50。
否
autovacuum_work_mem integer
0... 2147483647 KB,或 -1 以使用 maintenance_work_mem 值
預設值為 -1。
否
autovacuum_worker_slots integer
1 ... 262143
預設值為 16。
PostgreSQL 18 以上版本支援。
是
backend_flush_after integer
0 ... 256
單位為 8 KB。
預設值為 0。
否
bgwriter_delay integer
10 ... 10000 毫秒
預設值為 200。
否
bgwriter_flush_after integer
0 ... 256
單位為 8 KB。
預設值為 64。
否
bgwriter_lru_maxpages integer
0 ... 1073741823
預設值為 100。
否
bgwriter_lru_multiplier Float
0 ... 10
預設值為 2。
否
checkpoint_completion_target float
0.0 ... 1.0
預設值為 0.9。
否
checkpoint_flush_after integer
0 ... 256
單位為 8 KB。
預設值為 32。
否
checkpoint_timeout integer
30... 86,400 秒
預設值為 300 秒。
如要瞭解可能影響服務水準協議的使用資訊,請參閱「PostgreSQL 適用的 Cloud SQL 執行個體作業指南」。
否
checkpoint_warning integer
0 ... 2147483647s
預設值為 30 秒。
否
client_connection_check_interval integer
0 ... 2147483647
預設值為 0。
否
cloudsql.allow_passwordless_local_connections boolean
on | off
預設值為 off。
否
cloudsql.enable_anon boolean
on | off
預設值為 off。
否
cloudsql.enable_auto_explain boolean
on | off
預設值為 off。
是
cloudsql.enable_index_advisor boolean
on | off
預設值為 off。
是
cloudsql.enable_maintenance_mode boolean
on | off
預設值為 off。
是
cloudsql.enable_parameterized_secure_views boolean
on | off
預設值為 off。
是
cloudsql.enable_pgaudit boolean
on | off
預設為「off」。
是
cloudsql.enable_pg_bigm boolean
on | off
預設值:off
是
cloudsql.enable_pg_cron boolean
on | off
預設值為 off。
支援 PostgreSQL 10 以上版本。
是
cloudsql.enable_pg_hint_plan boolean
on | off
預設值為 off。
是
cloudsql.enable_pglogical boolean
on | off
預設值為 off。
是
cloudsql.enable_pg_squeeze boolean
on | off
預設值為 off。
是
cloudsql.enable_pg_textsearch boolean
on | off
預設值為 off。
是
cloudsql.enable_pg_wait_sampling boolean
on | off
是
cloudsql.enable_vector_assist boolean
on | off
預設值為 off。
是
cloudsql.iam_authentication boolean
on | off
預設值為 off。
否
cloudsql.logical_decoding boolean
on | off
預設值為 off。
是
cloudsql.max_failed_attempts_user integer
0 ... 10000
預設值為 10。
是
cloudsql.pgaudit_mask_literals boolean
on | off
預設值為 off。
否
cloudsql.pg_authid_select_role string
否
commit_delay integer
0 ... 100000
預設值為 0。
否
commit_siblings integer
0 ... 1000
預設值為 5。
否
constraint_exclusion enumeration
partition | on | off
預設值為 partition。
否
cpu_index_tuple_cost float
0.0 ... inf
預設值為 0.005。
否
cpu_operator_cost float
0.0 ... inf
預設值為 0.0025。
否
cpu_tuple_cost float
0.0 ... inf
預設值為 0.01。
否
cron.database_name String。
PostgreSQL 10 以上版本支援。
是
cron.log_statement boolean
on | off
預設為「on」。
PostgreSQL 10 以上版本支援。
是
cron.log_run boolean
on | off
預設為「開啟」。
PostgreSQL 10 以上版本支援。
是
cron.max_running_jobs Integer
0 ... varies
預設值為 5。
PostgreSQL 10 以上版本支援。
是
cron.log_min_messages String
debug5|debug4|debug3|debug2|debug1|debug|
info|notice|warning|error|log|fatal|panic
預設值為 warning。
PostgreSQL 10 以上版本支援。
否
cursor_tuple_fraction float
0.0 ... 1.0
預設值為 0.1。
否
deadlock_timeout integer
1 ... 2147483647 毫秒
預設值為 1000 毫秒。
否
default_statistics_target integer
1 ... 10000
預設值為 100。
否
default_tablespace string 否
default_toast_compression string
預設值為 pglz。
否
default_transaction_deferrable boolean
on | off
預設為「關閉」。
否
default_transaction_isolation enumeration
serializable | 'repeatable read' | 'read committed' | 'read uncommitted'
預設值為 'read committed'。
否
effective_cache_size integer
大小範圍為執行個體記憶體的 10% 至 70%。
單位為 8 KB。
預設值為 VM 記憶體的 40%。舉例來說,如果是 45 GB 的執行個體記憶體,預設值為 18537160 KB。
否
effective_io_concurrency integer
0 ... 1000
預設值為 1。
否
enable_async_append boolean
on | off
預設為「開啟」。
否
enable_bitmapscan boolean
on | off
預設為「開啟」。
否
enable_distinct_reordering boolean
on | off
預設為「開啟」。
PostgreSQL 18 以上版本支援。
否
enable_gathermerge boolean
on | off
預設為「開啟」。
否
enable_incremental_sort boolean
on | off
預設為「開啟」。
否
enable_memoize boolean
on | off
預設為「開啟」。
否
enable_parallel_append boolean
on | off
預設為「開啟」。
否
enable_parallel_hash boolean
on | off
預設為「開啟」。
否
enable_partition_pruning boolean
on | off
預設為「開啟」。
否
enable_partitionwise_aggregate boolean
on | off
預設為「關閉」。
否
enable_partitionwise_join boolean
on | off
預設為「關閉」。
否
enable_hashagg boolean
on | off
預設為「開啟」。
否
enable_hashjoin boolean
on | off
預設為「開啟」。
否
enable_indexonlyscan boolean
on | off
預設為「開啟」。
否
enable_indexscan boolean
on | off
預設為「開啟」。
否
enable_material boolean
on | off
預設為開啟
否
enable_mergejoin boolean
on | off
預設為「開啟」。
否
enable_nestloop boolean
on | off
預設為「開啟」。
否
enable_self_join_elimination boolean
on | off
預設為「開啟」。
PostgreSQL 18 以上版本支援。
否
enable_seqscan boolean
on | off
預設為「開啟」。
否
enable_sort boolean
on | off
預設為「開啟」。
否
enable_tidscan boolean
on | off
預設為「開啟」。
否
force_parallel_mode enumeration
off | on | regress
預設為關閉。
否
from_collapse_limit integer
1 ... 2147483647
預設值為 8。
否
geqo boolean
on | off
預設為「開啟」。
否
geqo_effort integer
1 ... 10
預設值為 5。
否
geqo_generations integer
0 ... 2147483647
預設值為 0。
否
geqo_pool_size integer
0 ... 2147483647
預設值為 0。
否
geqo_seed float
0.0 ... 1.0
預設值為 0。
否
geqo_selection_bias float
1.5 ... 2.0
預設值為 2。
否
geqo_threshold integer
2 ... 2147483647
預設值為 12。
否
gin_fuzzy_search_limit integer
0 ... 2147483647
預設值為 0。
否
gin_pending_list_limit integer
64 ... 2147483647KB
預設值為 4096 KB。
否
hash_mem_multiplier float
1 ... 1000
預設值為 2。
否
hot_standby_feedback boolean
on | off
預設為「關閉」。
否
huge_pages enumeration
try | off
預設值為 try。
是
idle_in_transaction_session_timeout integer
0 ... 2147483647 毫秒
預設值為 0。
否
io_max_concurrency integer
-1 ... 1024
預設值為 -1。
PostgreSQL 18 以上版本支援。
是
io_method string
sync、worker
預設值為 worker。
PostgreSQL 18 以上版本支援。
是
io_workers integer
-1 ... 32
預設值為 3。
PostgreSQL 18 以上版本支援。
否
ivfflat.probes integer
1 ... varies
預設值為 1。
PostgreSQL 11 以上版本支援。
否
join_collapse_limit integer
1 ... 2147483647
預設值為 8。
否
local_preload_libraries String
這個旗標可讓您指定一或多個共用程式庫,在資料庫連線開始時預先載入,並以逗號分隔清單。
否
lock_timeout integer
0 ... 2147483647 毫秒
預設值為 0。
否
log_autovacuum_min_duration integer
0... 2147483647 毫秒,或 -1 停用
預設值為 0。
否
log_checkpoints boolean
on | off
預設為「關閉」。
否
log_connections boolean
on | off
預設為「關閉」。
否
log_disconnections boolean
on | off
預設為「關閉」。
否
log_duration boolean
on | off
預設為「關閉」。
否
log_error_verbosity enumeration
terse | default | verbose
預設值為 default。
否
log_executor_stats boolean
on | off
預設為「關閉」。
否
log_hostname boolean
on | off
預設為「關閉」。
否
log_line_prefix String
在記錄檔每行開頭產生的 printf 樣式字串。
預設值為 %m [%p]: [%l-1] db=%d,user=%u,會記錄時間戳記、程序 ID、資料庫和使用者名稱。
否
log_lock_failures boolean
on | off
預設為關閉。
適用於 PostgreSQL 18 以上版本。
否
log_lock_waits boolean
on | off
預設為「關閉」。
否
log_min_duration_statement integer
-1 ... 2147483647 毫秒
預設值為 -1。
否
log_min_error_statement enumeration
debug5 | debug4 | debug3 | debug2 | debug1 | info | notice | warning | error | log | fatal | panic
預設值為 error。
否
log_min_messages enumeration
debug5 | debug4 | debug3 | debug2 | debug1 | info | notice | warning | error | log | fatal | panic
預設值為 warning。
否
log_parameter_max_length integer
-1 ... 1073741823
預設值為 -1。
PostgreSQL 13 以上版本支援。
否
log_parameter_max_length_on_error integer
-1 ... 1073741823
預設值為 0。
PostgreSQL 13 以上版本支援。
否
log_parser_stats boolean
on | off
預設為「關閉」。
否
log_planner_stats boolean
on | off
預設為「關閉」。
否
log_recovery_conflict_waits boolean
on | off
預設為「關閉」。
否
log_replication_commands boolean
on | off
預設為「關閉」。
否
log_statement enumeration
none | ddl | mod | all
設為 mod 即可記錄所有資料定義語言 (DDL) 陳述式,以及資料修改陳述式,例如 INSERT、UPDATE、DELETE、TRUNCATE
預設值為 none。
否
log_statement_stats boolean
on | off
無法與 log_parser_stats、log_planner_stats 或 log_executor_stats 一併啟用。
預設為關閉。
否
log_temp_files integer
0... 2147483647 KB,或輸入 -1 停用
預設值為 0。
否
log_timezone string
這個旗標可讓 PostgreSQL 適用的 Cloud SQL 使用者設定伺服器記錄中時間戳記使用的時區。

您必須依名稱指定時區。舉例來說,Europe/London 是倫敦的時區名稱。

您必須在主要執行個體和所有唯讀副本上手動更新這個旗標,才能解決這個問題。

時區名稱不區分大小寫。時區名稱不限大小寫。

我們支援 UTC+X 做為這個標記的有效格式,其中 X 為 +/-HH:MM。

是
logical_decoding_work_mem integer
64 ... 2147483647
預設值為 65536。
否
maintenance_io_concurrency integer
0 ... 1000
預設值為 10。
否
maintenance_work_mem integer
1024 ... 2147483647 KB
預設值為 64 MB。
否
max_active_replication_origins integer
0 ... 262143
預設值為 10。使用讀取集區時,必須設定這個旗標。
PostgreSQL 18 以上版本支援。
是
max_connections integer
14 ... varies (see note)
預設值取決於主要執行個體鏈中最大執行個體的記憶體容量 (這個執行個體;如果它是唯讀副本,則為其主要執行個體、其主要執行個體的主要執行個體等,一直到複製樹狀結構的根)。
最大執行個體的記憶體 (GB)預設值
極小 (~0.5)25
小 (~1.7)50
3.75 至 < 6100
6 到 < 7.5200
7.5 至 < 15400
15 至 < 30500
30 到 < 60600
60 到 < 120800
>=1201,000

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至副本,前提是副本的值低於主要執行個體的新值,或副本的值未從預設值變更。對主要執行個體進行這類變更會導致副本重新啟動。

是
max_locks_per_transaction integer
10 ... 2,147,483,647
預設值為 64。

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至副本,前提是副本的值低於主要執行個體的新值,或副本的值未從預設值變更。對主要執行個體進行這類變更會導致副本重新啟動。

是
max_logical_replication_workers integer
4 ... 8192
預設值為 4。
PostgreSQL 10 以上版本支援。
是
max_parallel_maintenance_workers integer
0 ... varies
預設值為 2。
PostgreSQL 11 以上版本支援。

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至值低於主要執行個體新值,或未從預設值變更的副本。

如果主要執行個體的值為 default,則無法變更副本的值。如要變更副本的值,請先將主要執行個體的值設為整數。

否
max_parallel_workers integer
0 ... varies
預設值為 8。
PostgreSQL 10 以上版本支援。

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至值低於主要執行個體新值,或未從預設值變更的副本。

如果主要執行個體的值為 default,則無法變更副本的值。如要變更副本的值,請先將主要執行個體的值設為整數。

否
max_parallel_workers_per_gather integer
0 ... varies
預設值為 2。

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至值低於主要執行個體新值,或未從預設值變更的副本。

如果主要執行個體的值為 default,則無法變更副本的值。如要變更副本的值,請先將主要執行個體的值設為整數。

否
max_pred_locks_per_page integer
0 ... 2147483647
預設值為 2。
PostgreSQL 10 以上版本支援。
否
max_pred_locks_per_relation integer
-2147483648 ... 2147483647
預設值為 -2。
PostgreSQL 10 以上版本支援。
否
max_pred_locks_per_transaction integer
64 ... 1048576
是
max_prepared_transactions integer
0 ... varies
記憶體大小 (MB)最大值
0 - 3,84030,000
3,840 - 7,68085,000
7,680 - 15,360200,000
15,360 以上版本262,000

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至副本,前提是副本的值低於主要執行個體的新值,或副本的值未從預設值變更。對主要執行個體進行這類變更會導致副本重新啟動。

是
max_replication_slots integer
10 ... varies
預設值為 10。
是
max_slot_wal_keep_size integer
102400 ... 10485760
單位為MB
否
max_stack_depth integer
100 ... 7680
單位為KB。
否
max_standby_archive_delay integer
0 ... 2147483647 毫秒,或 -1 永久等待
否
max_standby_streaming_delay integer
0 ... 2147483647 毫秒,或 -1 永久等待
否
max_sync_workers_per_subscription integer
2...64
不得大於 max_logical_replication_workers。
否
max_wal_senders integer
10 ... varies
預設值為 10。

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至副本,前提是副本的值低於主要執行個體的新值,或副本的值未從預設值變更。對主要執行個體進行這類變更會導致副本重新啟動。

是
max_wal_size integer
2 ... 2147483647

9.6 版的單位為 16 MB (WAL 檔案大小),PostgreSQL 10 以上版本則為 1 MB。

如果執行個體記憶體大於或等於 3.75 GB,預設值為 1504 MB。如果執行個體記憶體小於 3.75 GB,預設值為 1 GB。

如要瞭解可能影響服務水準協議的使用資訊,請參閱「PostgreSQL 適用的 Cloud SQL 執行個體操作指南」。
否
max_worker_processes integer
8 ... varies

備用資源中的值不能小於主要執行個體中的值。主要執行個體的變更會套用至副本,前提是副本的值低於主要執行個體的新值,或副本的值未從預設值變更。對主要執行個體進行這類變更會導致副本重新啟動。

是
min_parallel_index_scan_size integer
0 ... 715827882
單位為 8 KB
否
min_parallel_table_scan_size integer
0 ... 715827882
單位為 8 KB
否
min_parallel_relation_size integer
0 ... 715827882
單位為 8 KB
僅適用於 PostgreSQL 9.6。
否
min_wal_size integer
32 ... 2147483647

9.6 版的單位為 16 MB (WAL 檔案大小),PostgreSQL 10 以上版本則為 1 MB。

否
old_snapshot_threshold integer
0... 86400 分鐘,或 -1 停用
預設值為 -1。
是
parallel_setup_cost float
0.0 ... inf
預設值為 1000。
否
parallel_tuple_cost float
0.0 ... inf
預設值為 0.1。
否
password_encryption enumeration
md5 | scram-sha-256

預設值取決於 PostgreSQL 版本。PostgreSQL 10 至 13 版的預設值為 md5。如果是 PostgreSQL 14 以上版本,預設值為 scram-sha-256。

否
pg_bigm.enable_recheck boolean
on | off
否
pg_bigm.gin_key_limit integer
0 ... 2147483647
否
pg_bigm.similarity_limit float
0.0 ... 1.0
否
pg_hint_plan.enable_hint boolean
on | off
預設為「on」。
否
pg_hint_plan.debug_print String
off|on|detailed|verbose|0|1||2|3|no|yes|false|true
預設為「關閉」。
否
pg_hint_plan.parse_messages String
debug5|debug4|debug3|debug2|debug1|debug|
info|notice|warning|error|log
預設值為 info。
否
pg_hint_plan.message_level String
debug5|debug4|debug3|debug2|debug1|debug|
info|notice|warning|error|log
預設值為 log。
否
pg_hint_plan.enable_hint_table boolean
on | off
預設為「關閉」。
否
pglogical.batch_inserts boolean
on | off
預設值為 off。
是
pglogical.conflict_log_level String
預設為 LOG。
這個旗標接受的值與 log_min_messages 相同。
否
pglogical.conflict_resolution String
error|apply_remote|keep_local|last_update_wins|first_update_wins 預設值為 apply_remote。
否
pglogical.extra_connection_options String
接受 PostgreSQL 關鍵字/值連線字串。
預設值為空字串。
否
pglogical.synchronous_commit boolean
on | off
預設值為 on。
是
pglogical.use_spi boolean
on | off
預設值為 off。
是
pg_stat_statements.max integer
100 ... 2147483647
預設值為 5000。
是
pg_stat_statements.save boolean
on | off
預設為「開啟」。
否
pg_stat_statements.track enumeration
none | top | all
預設值為 top。
否
pg_stat_statements.track_planning boolean
on | off
預設為「關閉」。
適用於 PostgreSQL 13 以上版本。
否
pg_stat_statements.track_utility boolean
on | off
預設為「啟用」。
否
pg_textsearch.bulk_load_threshold integer
自動溢出前,每筆交易的字詞數量。設為 0 即可停用。
預設值為 100,000。
支援 PostgreSQL 17 以上版本。
否
pg_textsearch.compress_segments boolean
on | off
壓縮新區隔中的張貼區塊。
預設為「開啟」。
支援 PostgreSQL 17 以上版本。
否
pg_textsearch.default_limit integer
沒有 LIMIT 子句時,評分的文件數量上限。
預設值為 1,000。
支援 PostgreSQL 17 以上版本。
否
pg_textsearch.memtable_pages_threshold integer
自動溢出前要鏈結的頁面數量。如要停用,請設為 0。
預設值為 64。
支援 PostgreSQL 17 以上版本。
否
pg_textsearch.segments_per_level integer
每個層級在自動壓縮前可容納的區隔數量。
範圍為 0 至 64,預設值為 8。
支援 PostgreSQL 17 以上版本。
否
pgaudit.log enumeration
read | write | function | role | ddl | misc | misc_set | all|none

您可以使用以半形逗號分隔的清單提供多個類別,並在類別前面加上 - 符號來減去類別。預設值為 none。

否
pgaudit.log_catalog boolean
on | off
預設值為 on。
否
pgaudit.log_client boolean
on | off
預設值為 off。
否
pgaudit.log_level enumeration
debug5 | debug4 | debug3 | debug2 | debug1 | info | notice | warning | error | log
預設值為 log。此外,只有在 pgaudit.log_client 開啟時,系統才會啟用 pgaudit.log_level。
否
pgaudit.log_parameter boolean
on | off
預設值為 off。
否
pgaudit.log_relation boolean
on | off
預設值為 off。
否
pgaudit.log_statement_once boolean
on | off
預設值為 off。
否
pgaudit.role string
沒有預設值。
否
pgaudit.log_rows boolean
預設為關閉。
否
pgtt.enabled boolean
on | off
預設為「開啟」。
否
pg_wait_sampling.history_period integer
1 ... 2147483647
否
pg_wait_sampling.history_size integer
1 ... 2147483647
否
pg_wait_sampling.profile_period integer
1 ... 2147483647
否
pg_wait_sampling.profile_pid boolean
on | off
否
pg_wait_sampling.profile_queries boolean
on | off
否
random_page_cost float
0.0 ... inf
預設值為 4。
否
plan_cache_mode

String
auto|force_generic_plan|force_custom_plan
預設值為 auto。
否
rdkit.agent_FP_bit_ratio float
0 ... 3
否
rdkit.avalon_fp_size integer
64 ... 9192
否
rdkit.dice_threshold float
0 ... 1
否
rdkit.difference_FP_weight_agents integer
-10 ... 10
否
rdkit.difference_FP_weight_nonagents integer
1 ... 20
否
rdkit.do_chiral_sss boolean
on | off
否
rdkit.do_enhanced_stereo_sss boolean
on | off
否
rdkit.featmorgan_fp_size integer
64 ... 9192
否
rdkit.hashed_atompair_fp_size integer
64 ... 9192
否
rdkit.hashed_torsion_fp_size integer
64 ... 9192
否
rdkit.ignore_reaction_agents boolean
on | off
否
rdkit.init_reaction boolean
on | off
否
rdkit.layered_fp_size integer
64 ... 9192
否
rdkit.morgan_fp_size integer
64 ... 9192
否
rdkit.move_unmmapped_reactants_to_agents boolean
on | off
否
rdkit.rdkit_fp_size integer
64 ... 9192
否
rdkit.reaction_difference_fp_size integer
64 ... 9192
否
rdkit.reaction_difference_fp_type integer
1 ... 3
否
rdkit.reaction_sss_fp_size integer
64 ... 9192
否
rdkit.reaction_sss_fp_type integer
1 ... 5
否
rdkit.sss_fp_size integer
64 ... 4096
否
rdkit.tanimoto_threshold float
0 ... 1
否
rdkit.threshold_unmapped_reactant_atoms float
0 ... 1
否
recovery_prefetch string
on | off | try
預設值為 try。
PostgreSQL 15 以上版本支援。
否
replacement_sort_tuples integer
0 ... 2147483647
否
reserved_connections integer
0 ... 262143
支援 PostgreSQL 16 以上版本。
是
session_replication_role enumeration
origin | replica | local
只能在目前工作階段中設定
-
seq_page_cost float
0.0 ... inf
預設值為 1.0。
否
shared_buffers integer
大小範圍為執行個體記憶體的 10% 至 60%。
單位為 8 KB。
預設值為執行個體 VM 記憶體總量的三分之一 (以 MB 為單位)。舉例來說,如果執行個體記憶體為 45 GB,預設值為 15085 MB。
是
squeeze.max_xlock_time integer
1 ... 2147483647
否
squeeze.worker_autostart string
是
squeeze.worker_role string
是
ssl_max_protocol_version enumeration
Postgres 14:設定要使用的 SSL/TLS 通訊協定版本上限。有效值與 ssl_min_protocol_version 相同,但多了一個空字串,可指定任何通訊協定版本。
PostgreSQL 12 以上版本支援。
否
ssl_min_protocol_version enumeration
Postgres 14:設定要使用的最低 SSL/TLS 通訊協定版本。目前有效的值為:TLSv1、TLSv1.1、TLSv1.2、TLSv1.3。
預設為 TLSv1。
PostgreSQL 12 以上版本支援。
否
standard_conforming_strings boolean
on | off
預設為「開啟」。
否
synchronize_seqscans boolean
on | off
預設為「開啟」。
否
tcp_keepalives_count integer
0 ... 2147483647
預設值為 5。
否
tcp_keepalives_idle integer
0 ... 2147483647
預設值為 60。
否
tcp_keepalives_interval integer
0 ... 2147483647
預設值為 60。
否
temp_buffers integer
100 ... 1,073,741,823
單位為 8 KB
否
temp_file_limit integer
1048576 ... 2147483647 KB
預設值為初始磁碟大小的 10%。 舉例來說,如果是 100 GB 的磁碟,預設值為 10262623 KB。
否
TimeZone string
這個旗標可讓 PostgreSQL 適用的 Cloud SQL 使用者設定顯示及分析時間戳記的時區。

您必須依名稱指定時區。舉例來說,Europe/London 是倫敦的時區名稱。

您必須在主要執行個體和所有唯讀副本上手動更新這個旗標,才能解決這個問題。

時區名稱不區分大小寫。時區名稱不限大小寫。

我們支援 UTC+X 做為這個標記的有效格式,其中 X 為 +/-HH。

是
trace_notify boolean
on | off
預設為「關閉」。
否
trace_recovery_messages enumeration
debug5 | debug4 | debug3 | debug2 | debug1 | log | notice | warning | error
預設值為 log。
否
trace_sort boolean
on | off
預設為「關閉」。
否
track_activities boolean
on | off
預設為「開啟」。
否
track_activity_query_size integer
100 ... 102400
預設值為 1 KB。
是
track_commit_timestamp boolean
on | off
預設為「關閉」。
是
track_cost_delay_timing boolean
on | off
預設為關閉。
適用於 PostgreSQL 18 以上版本。
否
track_counts boolean
on | off
預設為「開啟」。
否
track_functions enumeration
none | pl | all
預設值為 none。
否
track_io_timing boolean
on | off
預設為「關閉」。
否
vacuum_cost_delay integer
0 ... 100 毫秒
預設值為 0。
否
vacuum_cost_limit integer
1 ... 10000
預設值為 200。
否
vacuum_cost_page_dirty integer
0 ... 10000
預設值為 20。
否
vacuum_cost_page_hit integer
0 ... 10000
預設值為 1。
否
vacuum_cost_page_miss integer
0 ... 10000
預設值為 10。
否
vacuum_failsafe_age integer
0 ... 2100000000
預設值為 1600000000。
否
vacuum_freeze_min_age integer
0 ... 1000000000
預設值為 50000000。
否
vacuum_freeze_table_age integer
0 ... 2000000000
預設值為 150000000。
否
vacuum_max_eager_freeze_failure_rate float
0 ... 1
預設值為 0.03。
PostgreSQL 18 以上版本支援。
否
vacuum_multixact_failsafe_age integer
0 ... 2100000000
預設值為 1600000000。
否
vacuum_multixact_freeze_min_age integer
0 ... 1000000000
預設值為 5000000。
否
vacuum_multixact_freeze_table_age integer
0 ... 2000000000
預設值為 150000000。
否
vacuum_truncate boolean
on | off
預設為「開啟」。
PostgreSQL 18 以上版本支援。
否
wal_buffers integer
大小範圍為執行個體記憶體的 -1% 至 5%。
單位為 8 KB。
預設值為 16 MB。
是
wal_compression enumeration
off | on | pglz | lz4 | zstd
Cloud SQL Enterprise 版執行個體,以及 vCPU 數量不超過 32 個的 Cloud SQL Enterprise Plus 版執行個體,預設為「關閉」。如果 Cloud SQL Enterprise Plus 版本執行個體採用 PostgreSQL 14 以上版本,且 vCPU 數量超過 32 個,則預設為「啟用」。
否
wal_decode_buffer_size integer
65536 ... 1073741823
單位為B。
PostgreSQL 15 以上版本支援。
是
wal_receiver_timeout integer
0 ... 2147483647
預設值為 60 秒。

這個旗標會影響 WAL 傳送者和接收者。 如果設定不當,這項旗標會影響邏輯和實體複製。這個旗標也會影響複製效能和延遲時間。 如果值為零,則會停用逾時機制。單位為毫秒。

否
wal_sender_timeout integer
0 ... 2147483647
預設值為 60 秒。

這個旗標會影響 WAL 傳送者和接收者。 如果未正確設定,這個旗標會影響邏輯和實體複製。這個旗標也會影響複製效能和延遲時間。如果值為零,則會停用逾時機制。 單位為毫秒。

否
wal_writer_delay integer
1 ... 10000
預設值為 200。
否
wal_writer_flush_after integer
0 ... 2147483647
預設值為 128。
否
work_mem integer
64 ... 2147483647 KB
預設值為 4 MB。
否

特殊標記

bgwriter

PostgreSQL 有背景寫入器 (bgwriter) 旗標。這個旗標會發出寫入新或修改過的共用緩衝區。這些共用緩衝區稱為「髒緩衝區」。當乾淨的共用緩衝區數量不足時,背景寫入器會將髒緩衝區寫入檔案系統,並標示為乾淨。

與 bgwriter 旗標相關聯的兩個旗標是 bgwriter_delay 和 bgwriter_lru_maxpages。bgwriter_delay 指定背景寫入器在活動回合之間的延遲時間 (以毫秒為單位),bgwriter_lru_maxpages 則指定背景寫入器會寫入多少緩衝區。

bgwriter 旗標的預設值為 200 ms。不過,如果您選取大於 500 GB 的固態硬碟 (SSD),bgwriter_delay 旗標的值會設為 50,bgwriter_lru_maxpages 旗標的值則會設為 200。

如要進一步瞭解背景寫入器,請參閱 PostgreSQL 說明文件。

cloudsql_session_read_only

您可以使用 cloudsql_session_read_only 旗標建立唯讀工作階段。

這個旗標可設為 on、off 或 locked。預設值為 off。

session_replication_role

PostgreSQL 具有 session_replication_role 旗標,可用於邏輯複製,並可停用個別工作階段中的限制觸發條件。

有時,這個旗標也可用於某些維護作業,以規避限制 (最常見的是外鍵) 檢查。

任何已設定 REPLICATION 屬性的使用者,都可以在工作階段中設定這個標記。如果為執行個體設定 cloudsql.enable_pglogical 或 cloudsql.logical_decoding 旗標,cloudsqlsuperuser 就能為任何使用者設定 REPLICATION 屬性。

無法為整個執行個體設定這個旗標。

疑難排解

問題 疑難排解
您設定的工作階段時區會在登出時失效。

連線至資料庫,並將資料庫時區設為所需時區 (依使用者或資料庫設定)。

在 PostgreSQL 適用的 Cloud SQL 中,您可以指定下列項目。 工作階段關閉後,這些設定仍會保留,模擬 .conf 設定:

ALTER DATABASE dbname SET TIMEZONE TO 'timezone';
ALTER USER username SET TIMEZONE TO 'timezone';

這些設定只會套用至資料庫的新連線。如要查看時區變更,請中斷與執行個體的連線,然後重新連線。

後續步驟