Re: Trouble setting up replication - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Trouble setting up replication
Date
Msg-id 55EB60B0.5060708@aklaver.com
Whole thread Raw
In response to Re: Trouble setting up replication  (Chuck Martin <clmartin@theombudsman.com>)
Responses Re: Trouble setting up replication
List pgsql-general
On 09/05/2015 02:27 PM, Chuck Martin wrote:
>> On Sep 5, 2015, at 4:29 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>>
>> On 09/05/2015 11:00 AM, Chuck Martin wrote:

>>>
>>> I had added to my pg_hba.conf
>>>
>>> host    replication     rep     64.207.10.121/32   cert
>>
>>  From the above the only user that can use replication connecting from 64.207.10.121/32 is rep. You did not specify
a-U in your connection above and ran the command as root so pg_basebackup used that as the user, which is the default
behavior:
>>
>> http://www.postgresql.org/docs/9.4/interactive/libpq-connect.html#LIBPQ-PARAMKEYWORDS
>> "
>> user
>>
>>     PostgreSQL user name to connect as. Defaults to be the same as the operating system name of the user running the
application.
>> "
>>
>> There is no pg_hba entry for database replication and user root so the connection was rejected. To repeat, get out
ofthe habit of running Postgres commands as root, it is not necessary. What matters is the Postgres user you are
connectingas. When using replication, which is what pg_basebackup is doing, you need to connect as a user with
sufficientprivileges: 
>>
>> http://www.postgresql.org/docs/9.4/interactive/app-pgbasebackup.html
>>
>> ".. The connection must be made with a superuser or a user having REPLICATION permissions (see Section 20.2), and
pg_hba.confmust explicitly permit the replication connection. .." 
>>
>> Whatever user you choose to do this with then needs to authorized in pg_hba.conf.
>
> This is very helpful. I understood that pb_basebackup was for creating a backup for replication purposes, but did not
understandthat PG needs the same permissions for it as for the replication itself. I ran it as user “postgres” and not
as“rep”. I think I understand my error, but will study the links you included to make sure. 

Well the postgres user is a superuser so it will have the permissions to
run pg_basebackup. The problem is that your pg_hba.conf did not
authorize the postgres user to connect to the replication 'database'
only the rep user. That mismatch is what needs to corrected, assuming
the rep user has replication permissions.

>
> Thanks for your help, Adrian. I think I’ll get this working now.
>
> Chuck
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Chuck Martin
Date:
Subject: Re: Trouble setting up replication
Next
From: Andres Freund
Date:
Subject: Re: in defensive of zone_reclaim_mode on linux