Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop streaming replication

I want to make my PostgreSQL master / slave streaming replication setup into a single master slave setup without replication and without HA.

How is it possible to tell master that it no longer has slave and it should not replicate its data to the slave ?

Of course it should also not keep WALs to be sent to the slave as is done when the slave is temporarily down.

like image 432
user1409708 Avatar asked Jul 17 '16 12:07

user1409708


People also ask

How do I stop streaming replication?

from the master to the standby. So, that means that the only ways to stop streaming replication are to stop the slave server, to disable access to the master via the pg_hba. conf file (requiring the master configs be reloaded) or to set the trigger file on the slave to tell it to stop replicating the master.

What is streaming replication?

Streaming replication, a standard feature of PostgreSQL, allows the updated information on the primary server to be transferred to the standby server in real time, so that the databases of the primary server and standby server can be kept in sync.

What is Wal_level in Postgres?

wal_level determines how much information is written to the WAL. The default value is replica , which writes enough data to support WAL archiving and replication, including running read-only queries on a standby server.

What is Max_standby_streaming_delay?

max_standby_streaming_delay applies when WAL data is being received via streaming replication. If this value is specified without units, it is taken as milliseconds. The default is 30 seconds. A value of -1 allows the standby to wait forever for conflicting queries to complete.


2 Answers

Depending on the version of Postgres you're using, it's possible your replicatoin is done using "replication slots". If you don't have a client streaming from a replication slot anymore, you can drop the slot. Here are some useful queries:

Get disk usage per replication slot (for Postgres 9.6):

SELECT
    redo_location,
    slot_name,restart_lsn,
    round((redo_location-restart_lsn) / 1024 / 1024 / 1024, 2) AS GB_behind
FROM
    pg_control_checkpoint(),
    pg_replication_slots;

Get disk usage per replication slot (for Postgres 10+):

SELECT redo_lsn,
    slot_name,
    restart_lsn,
    round((redo_lsn-restart_lsn) / 1024 / 1024 / 1024, 2) AS GB_behind
FROM pg_control_checkpoint(),
    pg_replication_slots;

Drop replication slot:

select pg_drop_replication_slot('slot_name');

References:

  • https://severalnines.com/database-blog/using-postgresql-replication-slots :
like image 59
Aaron Avatar answered Nov 04 '22 01:11

Aaron


Here is what I did:

  • on both master / slave, edit pg_hba.conf, remove:

    host replication replicator x.x.x.x/32 md5

  • in master, reload config, via:

    select pg_reload_conf()

  • in slave's data dir, remove file: standby.signal
  • restart slave,

Then slave will keep the data, but don't replica from master any more, and slave is writable.

like image 39
user218867 Avatar answered Nov 03 '22 23:11

user218867