Use COPY TO trigger_file promote your hot-standby database

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
简介:
前提条件 : 
1. recovery.conf里面配置了 trigger_file, 并且这个文件所载目录可以被启动postgresql数据库的OS用户写入。
2. 有数据库超级用户权限。
3. 数据库是hot-standby模式的, 也就是recovery.conf.standby_mode = on, postgresql.conf.hot_standby = on . 

举例 : 
recovery.conf 配置了 :
trigger_file = '/pgdata/data01/promote.pg.5432'

连接到hot-standby超级用户,
psql -h 127.0.0.1 standby postgres
# COPY (SELECT now()) TO '/pgdata/data01/promote.pg.5432';
激活。

这种方法适用于远程执行, 因为COPY是服务端接口, 生成的文件也是写入到服务端的, 不会写到客户端.
例如
postgres@db6-> psql -h 172.16.3.150 -p 1921 -U postgres postgres
Password for user postgres: 
psql (9.1.2, server 9.4.1)
WARNING: psql version 9.1, server version 9.4.
         Some psql features might not work.
Type "help" for help.
以下COPY, 将文件写入数据库服务器的/home/postgres/abc, 而不是本地的/home/postgres/abc
postgres=# copy (select 1) to '/home/postgres/abc';
COPY 1
[postgres@db6 ~]$ ls -la /home/postgres/abc
ls: /home/postgres/abc: No such file or directory

pg_read_file也是服务端函数, 是查看服务端的$PGDATA/postgresql.conf
postgres=# select * from pg_read_file('postgresql.conf');
                                  pg_read_file                                   
---------------------------------------------------------------------------------
 listen_addresses = '0.0.0.0'            # what IP address(es) to listen on;    +
 port = 1921                             # (change requires restart)            +
 max_connections = 1000                  # (change requires restart)            +
 superuser_reserved_connections = 13     # (change requires restart)            +
 unix_socket_directories = '.'   # comma-separated list of directories          +
 shared_buffers = 4096MB                 # min 128kB                            +
 maintenance_work_mem = 64MB             # min 1MB                              +
 dynamic_shared_memory_type = posix      # the default is the first option      +
 synchronous_commit = off                # synchronization level;               +
 checkpoint_segments = 32                # in logfile segments, min 1, 16MB each+
 log_destination = 'csvlog'              # Valid values are combinations of     +
 logging_collector = on          # Enable capturing of stderr and csvlog        +
 log_truncate_on_rotation = on           # If on, an existing log file with the +
 log_min_duration_statement = 1s # -1 is disabled, 0 logs all statements        +
 log_checkpoints = on                                                           +
 log_connections = on                                                           +
 log_disconnections = on                                                        +
 log_error_verbosity = verbose           # terse, default, or verbose messages  +
 log_lock_waits = on                     # log lock waits >= deadlock_timeout   +
 log_timezone = 'PRC'                                                           +
 datestyle = 'iso, mdy'                                                         +
 timezone = 'PRC'                                                               +
 lc_messages = 'C'                       # locale for system error message      +
 lc_monetary = 'C'                       # locale for monetary formatting       +
 lc_numeric = 'C'                        # locale for number formatting         +
 lc_time = 'C'                           # locale for time formatting           +
 default_text_search_config = 'pg_catalog.english'                              +
 deadlock_timeout = 10ms                                                        +
 
(1 row)
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
SQL 关系型数据库 MySQL
Database Visualization using Metabase Part 2 - Use Metabase to Get Insights
In this tutorial, we will install Metabase on an Alibaba Cloud ECS Ubuntu 16.04 server to achieve data visualization.
2402 0
Database Visualization using Metabase Part 2 - Use Metabase to Get Insights
|
SQL Oracle 关系型数据库
FAQ: How to Use AWR reports to Diagnose Database Performance Issues [ID 1359094.1]
FAQ: How to Use AWR reports to Diagnose Database Performance Issues [ID 1359094.
1434 0
|
SQL Oracle 关系型数据库
WARNING: Too Many Parse Errors With error=911 When Running a JDBC Application Connected to an Oracle 19c database
WARNING: Too Many Parse Errors With error=911 When Running a JDBC Application Connected to an Oracle 19c database (
411 2
|
Oracle 关系型数据库
19c 开启Oracle Database Vault
19c 开启Oracle Database Vault
279 1
|
SQL Oracle 关系型数据库
Connect to Autonomous Database Using Oracle Database Tools
Connect to Autonomous Database Using Oracle Database Tools
139 1
|
人工智能 Oracle 关系型数据库
一篇文章弄懂Oracle和PostgreSQL的Database Link
一篇文章弄懂Oracle和PostgreSQL的Database Link
|
Oracle 关系型数据库 Linux
Requirements for Installing Oracle Database/Client 19c on OL8 or RHEL8 64-bit (x86-64) (Doc ID 2668780.1)
Requirements for Installing Oracle Database/Client 19c on OL8 or RHEL8 64-bit (x86-64) (Doc ID 2668780.1)
151 0

热门文章

最新文章