replicator/lib/ruby/pg-wal-plugin.rb
def plugin_flush
    # Make sure we are a master.
    if ! is_master()
      raise UserError, "You can only flush from a master"
    end
    
    # Switch logs on master.
    # Ensure tungsten database is created.
    create_tungsten_db(true)
    # Create table might fail, if it already exists, eg. after a failed flush
    # from the previous time.
    exec_cmd2("psql -p#{@config.getProperty("postgresql.port")} -t -c \"CREATE TABLE force_log_switch (i int)\" #{@tungsten_db};", true)
    # Drop table should always succeed, unless we failed to create table in the
    # previous step, which would indicate a problem.
    exec_cmd2("psql -p#{@config.getProperty("postgresql.port")} -t -c \"DROP TABLE force_log_switch\" #{@tungsten_db};", false)
    switch_sql = "SELECT pg_switch_xlog()"
    log switch_sql
    pg_switch_xlog = psql_atom_query(switch_sql)
    log "Logs flushed at: #{pg_switch_xlog}"
    
    # Bide a few seconds; PG will flush the log if there are committed
    # data.  This will get us the most recently sent data. 
    sleep(10)
    
    # See if we have a file to which we can write.
    if @out_params_file
      out = File.new(@out_params_file, "w")
    else
      out = STDOUT
    end
    
    # Write the last archived file.
    if is_streaming_replication
      out.puts("appliedLastSeqno=" + pg_switch_xlog)
    else
      out.puts("appliedLastSeqno=" + read_status_file(@wal_archived))
    end
    
    # Close file only if we are using output params.
    if @out_params_file
      out.close
    end
  end
# Flushes master events into replication stream. 
Flushes master events into replication stream.
Flushes master events into replication stream .
def plugin_flush
    if ! is_master()
      raise UserError, "You can only flush from a master"
    end
    create_tungsten_db(true)
    exec_cmd2("psql -p#{@config.getProperty("postgresql.port")} -t -c \"CREATE TABLE force_log_switch (i int)\" #{@tungsten_db};", true)
    exec_cmd2("psql -p#{@config.getProperty("postgresql.port")} -t -c \"DROP TABLE force_log_switch\" #{@tungsten_db};", false)
    switch_sql = "SELECT pg_switch_xlog()"
    log switch_sql
    pg_switch_xlog = psql_atom_query(switch_sql)
    log "Logs flushed at: #{pg_switch_xlog}"
    sleep(10)
    if @out_params_file
      out = File.new(@out_params_file, "w")
    else
      out = STDOUT
    end
    if is_streaming_replication
      out.puts("appliedLastSeqno=" + pg_switch_xlog)
    else
      out.puts("appliedLastSeqno=" + read_status_file(@wal_archived))
    end
    if @out_params_file
      out.close
    end
  end
def plugin_flush if ! is_master ( ) raise UserError , "You can only flush from a master" end create_tungsten_db ( true ) exec_cmd2 ( "psql -p#{@config.getProperty("postgresql.port")} -t -c \"CREATE TABLE force_log_switch (i int)\" #{@tungsten_db};" , true ) exec_cmd2 ( "psql -p#{@config.getProperty("postgresql.port")} -t -c \"DROP TABLE force_log_switch\" #{@tungsten_db};" , false ) switch_sql = "SELECT pg_switch_xlog()" log switch_sql pg_switch_xlog = psql_atom_query ( switch_sql ) log "Logs flushed at: #{pg_switch_xlog}" sleep ( 10 ) if @out_params_file out = File . new ( @out_params_file , "w" ) else out = STDOUT end if is_streaming_replication out . puts ( "appliedLastSeqno=" + pg_switch_xlog ) else out . puts ( "appliedLastSeqno=" + read_status_file ( @wal_archived ) ) end if @out_params_file out . close end end
Flushes master events into replication stream.
Flushes master events into replication stream .
# Make sure we are a master. # Switch logs on master. # Ensure tungsten database is created. # Create table might fail, if it already exists, eg. after a failed flush # from the previous time. # Drop table should always succeed, unless we failed to create table in the # previous step, which would indicate a problem. # Bide a few seconds; PG will flush the log if there are committed # data.  This will get us the most recently sent data.  # See if we have a file to which we can write. # Write the last archived file. # Close file only if we are using output params.