Skip to content

Instantly share code, notes, and snippets.

@greinacker
Last active September 11, 2023 01:10
Show Gist options
  • Save greinacker/4968619 to your computer and use it in GitHub Desktop.
Save greinacker/4968619 to your computer and use it in GitHub Desktop.

Revisions

  1. greinacker revised this gist Feb 16, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions status.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    sudo -u postgres psql -x -c "select * from pg_stat_replication;"
  2. greinacker revised this gist Feb 16, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion start_replication.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ sudo -u postgres pg_basebackup -h 1.2.3.4 -D /var/lib/postgresql/9.2/main -U rep
    echo Writing recovery.conf file
    sudo -u postgres bash -c "cat > /var/lib/postgresql/9.2/main/recovery.conf <<- _EOF1_
    standby_mode = 'on'
    primary_conninfo = 'host=1.2.3.4 port=5432 user=replicator password=password sslmode=require'
    primary_conninfo = 'host=1.2.3.4 port=5432 user=replicator password=thepassword sslmode=require'
    trigger_file = '/tmp/postgresql.trigger'
    _EOF1_
    "
    2 changes: 1 addition & 1 deletion user.sh
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    sudo -u postgres psql -c "CREATE USER replicator REPLICATION LOGIN ENCRYPTED PASSWORD 'password';"
    sudo -u postgres psql -c "CREATE USER replicator REPLICATION LOGIN ENCRYPTED PASSWORD 'thepassword';"
  3. greinacker revised this gist Feb 16, 2013. 2 changed files with 24 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions slave_postgresql.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    wal_level = hot_standby
    max_wal_senders = 3
    checkpoint_segments = 8
    wal_keep_segments = 8
    hot_standby = on
    19 changes: 19 additions & 0 deletions start_replication.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    echo Stopping PostgreSQL
    sudo service postgresql stop

    echo Cleaning up old cluster directory
    sudo -u postgres rm -rf /var/lib/postgresql/9.2/main

    echo Starting base backup as replicator
    sudo -u postgres pg_basebackup -h 1.2.3.4 -D /var/lib/postgresql/9.2/main -U replicator -v -P

    echo Writing recovery.conf file
    sudo -u postgres bash -c "cat > /var/lib/postgresql/9.2/main/recovery.conf <<- _EOF1_
    standby_mode = 'on'
    primary_conninfo = 'host=1.2.3.4 port=5432 user=replicator password=password sslmode=require'
    trigger_file = '/tmp/postgresql.trigger'
    _EOF1_
    "

    echo Startging PostgreSQL
    sudo service postgresql start
  4. greinacker revised this gist Feb 16, 2013. 2 changed files with 6 additions and 0 deletions.
    1 change: 1 addition & 0 deletions master_pg_hba.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    hostssl replication replicator 5.6.7.8 md5
    5 changes: 5 additions & 0 deletions master_postgresql.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    listen_address = # make sure we're listening as appropriate
    wal_level = hot_standby
    max_wal_senders = 3
    checkpoint_segments = 8
    wal_keep_segments = 8
  5. greinacker created this gist Feb 16, 2013.
    1 change: 1 addition & 0 deletions user.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    sudo -u postgres psql -c "CREATE USER replicator REPLICATION LOGIN ENCRYPTED PASSWORD 'password';"