col*_*rco 4 postgresql psql postgresql-14
我需要编写一个 shell/bash 脚本来自动更改一些 PostgreSQL 配置。
这是我写的命令:
sudo -u postgres psql -U postgres -d postgres -c "
ALTER SYSTEM SET listen_addresses = '127.0.0.1';
ALTER SYSTEM SET max_connections = '200';
ALTER SYSTEM SET shared_buffers = '24GB';
ALTER SYSTEM SET work_mem = '128MB';
...
"
Run Code Online (Sandbox Code Playgroud)
但是我收到这个错误:
ERROR: ALTER SYSTEM cannot run inside a transaction block
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个错误?
使用几个-c
选项:
psql -c "ALTER SYSTEM SET param1 = 'val1'" \
-c "ALTER SYSTEM SET param2 = 'val2'" \
-c "SELECT pg_reload_conf()"
Run Code Online (Sandbox Code Playgroud)
需要最后的函数调用来激活更改。
归档时间: |
|
查看次数: |
1296 次 |
最近记录: |