Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb
分类: Mysql/postgreSQL
2017-10-31 18:16:17
[postgres@test ~]$ /usr/local/pg10/bin/psql psql (10.0) Type "help" for help. postgres=# CREATE ROLE replication WITH REPLICATION PASSWORD '6220104' LOGIN; //复制账号 postgres=# CREATE ROLE tank SUPERUSER LOGIN PASSWORD '6220104'; //超级管理员
[postgres@test pgdata]$ grep -Ev "^$|^[#;]" postgresql.conf # (change requires restart) # (change requires restart) # (change requires restart) # (change requires restart) listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) max_connections = 100 # (change requires restart) # (change requires restart) # (change requires restart) # (change requires restart) # (change requires restart) # 0 selects the system default # 0 selects the system default # 0 selects the system default shared_buffers =2048MB # min 128kB # (change requires restart) # (change requires restart) # (change requires restart) work_mem = 128MB # min 64kB maintenance_work_mem = 256MB # min 1MB dynamic_shared_memory_type = posix # the default is the first option # supported by the operating system: # posix # sysv # windows # mmap # use none to disable dynamic shared memory # (change requires restart) # in kB, or -1 for no limit # (change requires restart) # can be used in parallel queries # (change requires restart) wal_level = replica # minimal, replica, or logical # (change requires restart) # (turning this off can cause # unrecoverable data corruption) synchronous_commit = on # synchronization level; # off, local, remote_write, remote_apply, or on # supported by the operating system: # open_datasync # fdatasync (default on Linux) # fsync # fsync_writethrough # open_sync # (change requires restart) # (change requires restart) max_wal_size = 16GB min_wal_size = 8GB # (change requires restart) # placeholders: %p = path of file to archive # %f = file name only # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' # number of seconds; 0 disables max_wal_senders = 10 # max number of walsender processes # (change requires restart) wal_sender_timeout = 10s # in milliseconds; 0 disables # (change requires restart) # (change requires restart) synchronous_standby_names = '*' # standby servers that provide sync rep # method to choose sync standbys, number of sync standbys, # and comma-separated list of application_name # from standby(s); '*' = all hot_standby = on # "off" disallows queries during recovery # (change requires restart) # when reading WAL from archive; # -1 allows indefinite delay # when reading streaming WAL; # -1 allows indefinite delay # 0 disables # query conflicts # communication from master # in milliseconds; 0 disables # retrieve WAL after a failed attempt # (change requires restart) effective_cache_size = 4GB # JOIN clauses log_timezone = 'PRC' timezone = 'PRC' # abbreviations. Currently, there are # Default # Australia (historical usage) # India # You can create your own file in # share/timezonesets/. # encoding lc_messages = 'C' # locale for system error message # strings 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' # (change requires restart) # (change requires restart) # (max_pred_locks_per_transaction # / -max_pred_locks_per_relation) - 1 # directory 'conf.d' [postgres@test pgdata]$
[postgres@test pgdata]$ grep -Ev "^$|^[#;]" pg_hba.conf local all all trust host all all 127.0.0.1/32 trust host all all 14.23.51.58/32 md5 host all all ::1/128 trust local replication all trust host replication all 14.23.51.58/32 md5 host replication all ::1/128 trust [postgres@test pgdata]$
# /etc/init.d/pg10 restart
[postgres@node02 ~]$ /usr/local/pg10/bin/pg_basebackup -D data -h 139.159.247.78 -U replication -X stream //注意其它表空间位置是否存在
# cp /usr/local/pg10/share/postgresql/recovery.conf.sample recovery.conf [postgres@node02 backup]$ vi recovery.conf #--------------------------------------------------------------------------- # STANDBY SERVER PARAMETERS #--------------------------------------------------------------------------- # # standby_mode # # When standby_mode is enabled, the PostgreSQL server will work as a # standby. It will continuously wait for the additional XLOG records, using # restore_command and/or primary_conninfo. # standby_mode = on # # primary_conninfo # # If set, the PostgreSQL server will try to connect to the primary using this # connection string and receive XLOG records continuously. # primary_conninfo = 'host=139.159.247.78 port=5432 user=replication password=6220104 application_name=ghan' # e.g. 'host=localhost po rt=5432'
//如果设置application_name=* 将同步所有主节点数据库
[postgres@node02 backup]$ /usr/local/pg10/bin/pg_ctl -D data start -l kkk.log
[postgres@test ~]$ /usr/local/pg10/bin/psql psql (10.0) Type "help" for help. postgres=# \x Expanded display is on. postgres=# SELECT * FROM pg_stat_replication; -[ RECORD 1 ]----+------------------------------ pid | 18242 usesysid | 16575 usename | replication application_name | ghan client_addr | 14.23.51.58 client_hostname | client_port | 52308 backend_start | 2017-10-31 17:41:04.982858+08 backend_xmin | state | streaming sent_lsn | B/31C17120 write_lsn | B/31C17120 flush_lsn | B/31C17120 replay_lsn | B/31C17120 write_lag | flush_lag | replay_lag | sync_priority | 1 sync_state | sync postgres=#
ghan=# insert into t2_test values(generate_series(1,70)); ^CCancel request sent WARNING: canceling wait for synchronous replication due to user request DETAIL: The transaction has already committed locally, but might not have been replicated to the standby. INSERT 0 70 ghan=# ^C ghan=#
# vi postgresql.conf synchronous_commit = off # synchronization level;
# /etc/init.d/pg10 restart
ghan2017-11-01 20:42:38
dreamakerjerry:您好,前辈,默默关注您有段时间了,非常喜欢您注重质量的文章风格。因为之前看您写过pgxl的文章,刚好今天遇到个问题没解决,所以冒昧请教:今天运行“create extension postgres_fdw”时报了版本不支持fdw错误,那么如何实现跨库关联查询呢?谢谢。
可以使用 dblink
回复 | 举报dreamakerjerry2017-10-31 22:53:35
您好,前辈,默默关注您有段时间了,非常喜欢您注重质量的文章风格。因为之前看您写过pgxl的文章,刚好今天遇到个问题没解决,所以冒昧请教:今天运行“create extension postgres_fdw”时报了版本不支持fdw错误,那么如何实现跨库关联查询呢?谢谢。