Re: Stopping writes in master

From: Rui DeSousa <rui(dot)desousa(at)icloud(dot)com>
To: Debraj Manna <subharaj(dot)manna(at)gmail(dot)com>
Cc: Shreeyansh Dba <shreeyansh2014(at)gmail(dot)com>, Robert Zenz <robert(dot)zenz(at)sibvisions(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: Stopping writes in master
Date: 2018-06-14 15:20:44
Message-ID: 773C842E-0684-424D-B7A0-E24264A87495@icloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

I can think of two other ways but the latter is more a pause than read-only. Neither are ideal solutions but hacks that may work depending on your needs.

1. If you’re restarting the server; then just make it a replia of nobody.
Con:
1. Requires database restart which could take a while depending on database activity
2. Truly is read only… i.e. no temp tables, etc.

i.e. Create a recovery.conf and restart the server… the database is truly read only.

recovery.conf:

standby_mode = 'on'
primary_conninfo = ‘host=nowhere'

2. Without restarting server; enable synchronous replication to nowhere and reload config.
Cons:
1. More of a pause than read-only
2. Clients can still write changes but will hang on commit (causing applications to hang).
3. Ctrl-c on a hanged session will actually commit the record on the master (oops)

Pro or Con depending on your view:
1. When releasing the synchronous setup to nowhere; hung sessions will carry on with their commit.

postgres.conf:

synchronous_standby_names = ‘1 (nowhere)’

If you trust your clients; then setting the default transaction state and killing the sessions forcing a reconnect might be the best solution like has already been suggested; however, if you dealing with end users they can change their session transaction level back.

> On Jun 14, 2018, at 9:46 AM, Debraj Manna <subharaj(dot)manna(at)gmail(dot)com> wrote:
>
> Thanks Shreeyansh.
>
> Can this be handled from the server side may be setting some config parameters and then restarting the master so that existing connections gets dropped and the new ones not able to write?
>
> On Thu 14 Jun, 2018, 5:36 PM Shreeyansh Dba, <shreeyansh2014(at)gmail(dot)com <mailto:shreeyansh2014(at)gmail(dot)com>> wrote:
> Hi Debraj Manna,
>
> Yes,You can make the database read only as well just by setting the below parameter is equal to true at the session level.But you need reconnect your existing connections.
>
>
> ALTER DATABASE YOUR_DATABASE_NAME SET default_transaction_read_only = true;
>
> Hope this helps..
>
>
> <http://www.shreeyansh.com/>
>
> On Thu, Jun 14, 2018 at 4:53 PM, Debraj Manna <subharaj(dot)manna(at)gmail(dot)com <mailto:subharaj(dot)manna(at)gmail(dot)com>> wrote:
> Yes I want to switch the database to read-only mode. The existing connections should also be not able to write.
>
> On Thu 14 Jun, 2018, 4:37 PM Robert Zenz, <robert(dot)zenz(at)sibvisions(dot)com <mailto:robert(dot)zenz(at)sibvisions(dot)com>> wrote:
> Can existing connections be dropped or do they need to stay established? Also,
> are you trying to switch the database to a read-only mode for backup purposes or
> something different?
>
>
> On 14.06.2018 12:46, Debraj Manna wrote:
> > Hi
> >
> > In a 3 node cluster with 1 master and 2 slaves with postgres 10.4 is there
> > any configuration setting that will stop all writes to the master from the
> > client. But the clients can read data from master and other slaves ?
> >
> > Thanks,
> >
>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David Modica 2018-06-14 15:51:20 binary upgade errors
Previous Message Shreeyansh Dba 2018-06-14 14:59:04 Re: Stopping writes in master